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
Date Fri, 22 May 2009 07:26:48 GMT
Hi guys,
I have a small testcase as below:

InetSocketAddress isa = new
InetSocketAddress(InetAddress.getByName("xxx.xxx.xxx", xx);
SocketChannel sc = SocketChannel.open();
sc.socket().setSoTimeout(30000);
sc.configureBlocking(true);
sc.connect(isa);

System.out.println(sc.socket().isConnected());

sc.socket().shutdownOutput();
sc.socket().shutdownInput();
//sc.socket().shutdownInput();
//sc.socket().shutdownOutput();

sc.close();

Using hy5+drlvm, given some website with port 80, for example
"74.125.45.100" (this is what I got from pinging google.com), the testcase
will pass. But given some website with using Tomcat at backend, a exception
has raised:
java.net.SocketException: Socket is not connected
    at
org.apache.harmony.luni.platform.OSNetworkSystem.shutdownInput(OSNetworkSystem.java)
    at
org.apache.harmony.luni.net.PlainSocketImpl.shutdownInput(PlainSocketImpl.java:439)
    at java.net.Socket.shutdownInput(Socket.java:726)

I have dive into it and find this raised by the Linux system api shutdown.
shutdown(fd, SHUT_RD)  returns -1 and errno is 107 which indicates the
Socket is not connected. This exception is usually raised on the tomcat
backended website, but not always.
1. Is this the tomcat behavior? If the client shutdown(fd, SHUT_WR), which
makes socket half-duplexed, will the sever endpoint close the connection?
2. More interesting, if I exchange the position of shutdowninput with
shutdownoutput, that is shutdown(fd, SHUT_RD) first then shutdown(fd,
SHUT_WR), the test case will pass. Any idea about this?

I have spent some time fixing it, only to find some problems which can not
be solved with google:
3. Since I do not know why the connection is closed after shutdown(fd,
SHUT_WR), I am thingking about adding a condition checking whether the
socket is full-duplex or not maybe helpful. But how can I achieve this?
4. I am trying to enable the HYSOCKDEBUG by adding -DDEBUG flags when
compiling the src code. But no output is comming. Then I add the
fprintf(stderr, msg) just the place where HYSOCKDEBUG is. The message is
comming in the stderr. It seems that stdout(HYSOCKDEBUG is using printf) is
choked with some reason. Any idea about this?

Could anyone can help me with any of these questions? Thanks in advance :)

-- 
Yours sincerely,
Charles Lee

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