Hi Michael,

Michael Koch wrote:

--- /var/tmp/PROJECTS/classpath//./java/net/ServerSocket.java   Fri Oct 17 19:05:29 
2003
+++ java/net/ServerSocket.java  Wed Oct 22 21:32:21 2003
@@ -339,7 +339,8 @@
   */
  public void close () throws IOException
  {
-    impl.close ();
+    if (impl != null)
+      impl.close ();

    if (getChannel() != null)
      getChannel().close ();


After thinking about this patch, its more and more bogus in my eyes as
impl never may be null. I provided a better fix to libgcj. When its
approved I will merge it into classpath too.

Not yet, but soon it will.


ServerSocket is still broken with respect to how it behaves when it's closed. When the socket is closed, access to methods like accept() should throw an IOException that it's closed. Currently, no such checks are done and you get weird exceptions.

bash-2.05a$ cat stest.java
import java.net.*;

public class stest {
        public static void main(String [] args) {

                try {
                        ServerSocket ss = new ServerSocket();
                        ss.close();
                        ss.accept();
                }
                catch (Exception e) {
                        e.printStackTrace();
                }
        }
}

bash-2.05a$ java stest
java.net.SocketException: Socket is closed
        at java.net.ServerSocket.accept(ServerSocket.java:415)
        at stest.main(stest.java:9)
bash-2.05a$ which java
/opt/misc/lib/java/jdk1.4.2//bin/java

vs.
bash-2.05a$ /tmp/topic/current-jit3/bin/kaffe stest
java.io.IOException: Bad file descriptor
   at gnu.java.net.PlainSocketImpl.socketAccept (PlainSocketImpl.java)
   at gnu.java.net.PlainSocketImpl.accept (PlainSocketImpl.java:51)
   at java.net.ServerSocket.implAccept (ServerSocket.java:332)
   at java.net.ServerSocket.accept (ServerSocket.java:307)
   at stest.main (stest.java:9)

I want to fix the server socket methods to behave properly after close. In order to do that, I want to set impl to null in close, and check for impl == null to determine if the socket has been closed already in all methods that should throw an IOException when the socket is closed.

But I first wanted to get the simple patches from Guilhem in before I start hacking on it myself. Seems to be hard enough ;)

cheers,
dalibor topic



_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to