harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Lee <littlee1...@gmail.com>
Subject Problems about socket hang methods
Date Thu, 11 Jun 2009 05:28:16 GMT
Given the test case [1], on linux,  RI will throw a SocketException but
harmony is hanging forever. The problem is from such situation:
1. A fd is used by a slow api, such as read for example.
2. Another thread close the same fd.

Our api will hang forever, because we do not have any way to inform the slow
api that the fd is closed.
1. Do we have api to know this?
2. Is signal a way to solve this? If yes, more concern about this:
    i. Can we use all the real-time signals? For drlvm, I know it uses
SIGUSR2 for gc, any other signal it will use? For vme, no signal it uses, am
I right?
    ii. If we use signal, we need to know the exact process id which is
using the same fd, or we will miss-fire other process to close the read for
example.

Any other ideas about this?

[1]:
public class SocketHangTest {
    private Socket socket;
    private ServerSocket server;
    private SocketAddress localAddress;

    public SocketHangTest() {}

    public void hang() throws Exception{
        server = new ServerSocket(0);
        int port = server.getLocalPort();
        socket = new Socket();
        localAddress = new InetSocketAddress("127.0.0.1", port);

        new Thread() {
            public void run() {
                try {
                    Thread.sleep(1000*5);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    System.out.println("Connecting to local host .....");
                    socket.connect(localAddress, 5000);
                    System.out.println("Reading ....");
                    InputStream input = socket.getInputStream();
                    input.read();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }.start();

        server.accept();
        System.out.println("After accepting ...");
        Thread.sleep(1000);
        socket.close();
    }

    public static void main(String[] args) throws Exception{
        SocketHangTest test = new SocketHangTest();
        test.hang();
    }
}



-- 
Yours sincerely,
Charles Lee

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message