harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r419057 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
Date Tue, 04 Jul 2006 18:02:34 GMT
Author: gharley
Date: Tue Jul  4 11:02:33 2006
New Revision: 419057

URL: http://svn.apache.org/viewvc?rev=419057&view=rev
Log:
HARMONY 748 : [nio] java.nio.channels.ServerSocketChannel.accept() should throw IllegalBlockingModeException
if the channel is in non-blocking mode and there is no pending connections

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java?rev=419057&r1=419056&r2=419057&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java
Tue Jul  4 11:02:33 2006
@@ -19,10 +19,10 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketAddress;
-import java.net.SocketException;
 import java.net.SocketImpl;
 import java.net.SocketTimeoutException;
 import java.nio.channels.ClosedChannelException;
+import java.nio.channels.IllegalBlockingModeException;
 import java.nio.channels.NotYetBoundException;
 import java.nio.channels.SelectableChannel;
 import java.nio.channels.ServerSocketChannel;
@@ -33,7 +33,6 @@
 import org.apache.harmony.luni.net.SocketImplProvider;
 import org.apache.harmony.luni.platform.FileDescriptorHandler;
 import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.luni.util.Msg;
 
 /*
  * The default implementation class of java.nio.channels.ServerSocketChannel.
@@ -199,12 +198,12 @@
      */
     private class ServerSocketAdapter extends ServerSocket {
         /*
-         * Internal impl.
+         * The related ServerSocketChannel.
          */
         ServerSocketChannelImpl channelImpl;
 
         /*
-         * init the impl.
+         * The Constructor.
          */
         ServerSocketAdapter(SocketImpl impl,
                 ServerSocketChannelImpl aChannelImpl){
@@ -222,17 +221,28 @@
         }
 
         /*
-         * do the accept.
+         * @see java.net.ServerSocket#accept()
+         * 
+         * If the channel is in non-blocking mode and there is no connection
+         * ready to be accepted, invoking this method will causes an
+         * IllegalBlockingModeException.
          */
-        private Socket accept(Socket aSocket, SocketChannelImpl sockChannel)
-                throws IOException {
-            if (isClosed()) {
-                throw new SocketException(Msg.getString("K003d")); //$NON-NLS-1$
+        public Socket accept() throws IOException {
+            if (!isBound || !socket.isBound()) {
+                throw new IllegalBlockingModeException();
             }
-            if (!isBound()) {
-                throw new SocketException(Msg.getString("K031f")); //$NON-NLS-1$
+            SocketChannel sc = channelImpl.accept();
+            if(null == sc){
+                throw new IllegalBlockingModeException();
             }
+            return sc.socket();
+        }
 
+        /*
+         * do the accept.
+         */
+        private Socket accept(Socket aSocket, SocketChannelImpl sockChannel)
+                throws IOException {
             // a new socket is pass in so we do not need to "Socket aSocket =
             // new Socket();"
             boolean connectOK = false;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java?rev=419057&r1=419056&r2=419057&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
Tue Jul  4 11:02:33 2006
@@ -23,6 +23,7 @@
 import java.net.Socket;
 import java.nio.channels.AsynchronousCloseException;
 import java.nio.channels.ClosedChannelException;
+import java.nio.channels.IllegalBlockingModeException;
 import java.nio.channels.NotYetBoundException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.ServerSocketChannel;
@@ -437,6 +438,9 @@
         }
     }
     
+    /**
+     * @tests ServerSocketChannel#socket().getSoTimeout()
+     */
     public void test_accept_SOTIMEOUT() throws IOException {
         // regression test for Harmony-707        
         final int SO_TIMEOUT = 10;
@@ -454,6 +458,90 @@
             assertEquals(SO_TIMEOUT, soTimeout);
         } finally {
             sc.close();
+        }
+    }
+    
+    /**
+     * @tests ServerSocket#socket().accept()
+     */
+    public void test_socket_accept_Blocking_NotBound() throws IOException {
+        // regression test for Harmony-748       
+        ServerSocket gotSocket = serverChannel.socket();
+        serverChannel.configureBlocking(true);
+        try {
+            gotSocket.accept();
+            fail("Should throw an IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }        
+        serverChannel.close();
+        try {
+            gotSocket.accept();
+            fail("Should throw an IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }     
+    }
+
+    /**
+     * @tests ServerSocket#socket().accept()
+     */
+    public void test_socket_accept_Nonblocking_NotBound() throws IOException {
+        // regression test for Harmony-748       
+        ServerSocket gotSocket = serverChannel.socket();
+        serverChannel.configureBlocking(false);
+        try {
+            gotSocket.accept();
+            fail("Should throw an IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }        
+        serverChannel.close();
+        try {
+            gotSocket.accept();
+            fail("Should throw an IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }     
+    }
+    
+    /**
+     * @tests ServerSocket#socket().accept()
+     */
+    public void test_socket_accept_Nonblocking_Bound() throws IOException {
+        // regression test for Harmony-748
+        serverChannel.configureBlocking(false);
+        ServerSocket gotSocket = serverChannel.socket();
+        gotSocket.bind(localAddr1);         
+        try {
+            gotSocket.accept();
+            fail("Should throw an IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }
+        serverChannel.close();
+        try {
+            gotSocket.accept();
+            fail("Should throw a ClosedChannelException");
+        } catch (ClosedChannelException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests ServerSocket#socket().accept()
+     */
+    public void test_socket_accept_Blocking_Bound() throws IOException {
+        // regression test for Harmony-748
+        serverChannel.configureBlocking(true);
+        ServerSocket gotSocket = serverChannel.socket();
+        gotSocket.bind(localAddr1);         
+        serverChannel.close();
+        try {
+            gotSocket.accept();
+            fail("Should throw a ClosedChannelException");
+        } catch (ClosedChannelException e) {
+            // expected
         }
     }
 }



Mime
View raw message