Author: nextgens
Date: 2009-02-02 19:27:13 +0000 (Mon, 02 Feb 2009)
New Revision: 25473

Modified:
   trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
   trunk/freenet/src/freenet/io/NetworkInterface.java
   trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
Log:
Even better this way, thanks to toad

Modified: trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java     
2009-02-02 19:19:23 UTC (rev 25472)
+++ trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java     
2009-02-02 19:27:13 UTC (rev 25473)
@@ -637,16 +637,13 @@
                        synchronized(this) {
                                if(myThread == null) return;
                        }
-                       try {
-                               Socket conn = networkInterface.accept();
-                               if(Logger.shouldLog(Logger.MINOR, this))
-                                       Logger.minor(this, "Accepted 
connection");
-                               SocketHandler sh = new SocketHandler(conn);
-                               sh.start();
-                       } catch (SocketTimeoutException e) {
-                               // Go around again, this introduced to avoid 
blocking forever when told to quit
-                               /* FIXME: WTF? Why does 
networkInterface.accept() not support being interrupted ? */
-                       } 
+                       Socket conn = networkInterface.accept();
+            if(conn == null)
+                continue; // timeout
+            if(Logger.shouldLog(Logger.MINOR, this))
+                Logger.minor(this, "Accepted connection");
+            SocketHandler sh = new SocketHandler(conn);
+            sh.start();
                }
        }
        

Modified: trunk/freenet/src/freenet/io/NetworkInterface.java
===================================================================
--- trunk/freenet/src/freenet/io/NetworkInterface.java  2009-02-02 19:19:23 UTC 
(rev 25472)
+++ trunk/freenet/src/freenet/io/NetworkInterface.java  2009-02-02 19:27:13 UTC 
(rev 25473)
@@ -78,11 +78,6 @@
        
        private final Executor executor;
 
-    // @see
-    // 
http://blogs.sun.com/jrose/entry/longjumps_considered_inexpensive?resubmit=damnit
-    // We don't want it to be final because we would like to know which 
subsystem it belongs to
-    private final SocketTimeoutException socketException =  new 
SocketTimeoutException();
-
        public static NetworkInterface create(int port, String bindTo, String 
allowedHosts, Executor executor, boolean ignoreUnbindableIP6) throws 
IOException {
                NetworkInterface iface = new NetworkInterface(port, 
allowedHosts, executor);
                try {
@@ -200,22 +195,21 @@
         * {...@link SocketTimeoutException}. If no timeout has been set this 
method
         * will wait until a connection has been established.
         * 
-        * @return The socket that is connected to the client
-        * @throws SocketTimeoutException
-        *             if the timeout has expired waiting for a connection
+        * @return The socket that is connected to the client or null
+     * if the timeout has expired waiting for a connection
         */
-       public Socket accept() throws SocketTimeoutException {
+       public Socket accept() {
                synchronized (syncObject) {
                        while (acceptedSockets.size() == 0) {
                                if (acceptors.size() == 0) {
-                                       throw socketException;
+                                       return null;
                                }
                                try {
                                        syncObject.wait(timeout);
                                } catch (InterruptedException ie1) {
                                }
                                if ((timeout > 0) && (acceptedSockets.size() == 
0)) {
-                                       throw socketException;
+                                       return null;
                                }
                        }
                        return acceptedSockets.remove(0);

Modified: trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java   
2009-02-02 19:19:23 UTC (rev 25472)
+++ trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java   
2009-02-02 19:27:13 UTC (rev 25473)
@@ -276,8 +276,10 @@
                        // Maybe something has changed?
                                if(port != curPort) break;
                                if(!(this.bindTo.equals(tempBindTo))) break;
-                       try {
+                try {
                                Socket s = networkInterface.accept();
+                    if(s == null)
+                        continue; // timeout
                                InputStream in = s.getInputStream();
                                OutputStream out = s.getOutputStream();
                                
@@ -285,9 +287,6 @@
                                        new TextModeClientInterface(this, in, 
out);
                                
                                n.executor.execute(tmci, "Text mode client 
interface handler for "+s.getPort());
-                               
-                       } catch (SocketTimeoutException e) {
-                               // Ignore and try again
                        } catch (SocketException e){
                                Logger.error(this, "Socket error : "+e, e);
                        } catch (IOException e) {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to