Update of /cvsroot/freenet/freenet/src/freenet/transport
In directory sc8-pr-cvs1:/tmp/cvs-serv11098/src/freenet/transport

Modified Files:
        AbstractSelectorLoop.java ReadSelectorLoop.java 
        ThrottledSelectorLoop.java 
Log Message:
6231:
Allow clients to unregister themselves from maintenance process() in RSL. This fixes 
some more FCP problems.
Prevent leak of TSL.dontReregister.
Bugfixes relating to SendData sending padding.
RSL.scheduleMaintenance takes a channel, not an NIOReader.
Cache Socket and SocketChannel on ConnectionHandler. Also changes the localport codes.
Logging


Index: AbstractSelectorLoop.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/AbstractSelectorLoop.java,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -w -r1.77 -r1.78
--- AbstractSelectorLoop.java   9 Oct 2003 15:49:22 -0000       1.77
+++ AbstractSelectorLoop.java   14 Oct 2003 19:41:38 -0000      1.78
@@ -691,7 +691,7 @@
                        }*/
        }
 
-       public void queueClose(Connection conn, SocketChannel sc) {
+       public final void queueClose(Connection conn, SocketChannel sc) {
                Socket s = null;
                try {
                        s = ((tcpConnection)conn).getSocket();
@@ -700,7 +700,7 @@
                        queueClose(new ClosePair(conn, null, sc));
        }
        
-       public void queueClose(Connection conn, NIOCallback cb, SocketChannel sc) {
+       public final void queueClose(Connection conn, NIOCallback cb, SocketChannel 
sc) {
                Socket s = null;
                try {
                        s = ((tcpConnection)conn).getSocket();
@@ -709,11 +709,11 @@
                        queueClose(new ClosePair(conn, cb, sc));
        }
        
-       public void queueClose(SocketChannel chan) {
+       public final void queueClose(SocketChannel chan) {
                queueClose(chan, null);
        }
        
-       public void queueClose(SocketChannel chan, NIOCallback nc) {
+       public final void queueClose(SocketChannel chan, NIOCallback nc) {
                if(chan == null) return;
                Socket sock = chan.socket();
                if(sock == null) return;
@@ -728,7 +728,7 @@
                queueClose(new ClosePair(c,nc,chan));
        }
        
-       public void queueClose(ChannelAttachmentPair pair) {
+       public final void queueClose(ChannelAttachmentPair pair) {
                NIOCallback cb = null;
                if(pair.attachment instanceof NIOCallback)
                        cb = (NIOCallback)(pair.attachment);

Index: ReadSelectorLoop.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/ReadSelectorLoop.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -w -r1.52 -r1.53
--- ReadSelectorLoop.java       26 Sep 2003 09:22:37 -0000      1.52
+++ ReadSelectorLoop.java       14 Oct 2003 19:41:38 -0000      1.53
@@ -105,13 +105,37 @@
                //make sure no message got stuck behind a trailing field
                
                while (maintenanceQueue.size() > 0) {
-                       NIOReader current;
-                       //process could take a while, so lock just this
+                       SocketChannel chan;
                        synchronized(maintenanceQueue) {
-                               current = (NIOReader)maintenanceQueue.removeFirst();
+                               chan = (SocketChannel)maintenanceQueue.removeFirst();
                        }
+                       SelectionKey k = chan.keyFor(sel);
+                       if(k == null) continue;
+                       NIOReader current = (NIOReader)(k.attachment());
+                       //process could take a while, so lock just this
                        try {
-                               current.process(null);
+                               int status = current.process(null);
+                               if(status == -1) {
+                                       if(logDebug)
+                                               Core.logger.log(this, "Closing 
connection "+chan+":"+
+                                                                               
current+" (process returned -1)", 
+                                                                               
Logger.DEBUG);
+                                       k.attach(null);
+                                       k.cancel();
+                                       current.unregistered();
+                                       queueClose((SocketChannel)chan,current);
+                               } else if (status == 0) {
+                                       if (logDebug) Core.logger.log(this, 
"Cancelling "+chan+
+                                                                                      
           ":"+current+"(returned 0)",
+                                                                                      
           Logger.DEBUG);
+                                       k.cancel();
+                                       synchronized(dontReregister) {
+                                               dontReregister.add(chan);
+                                       }
+                                       if (logDebug)Core.logger.log(this, "Cancelled 
"+chan+": "+
+                                                                                      
          k.isValid()+": "+k,
+                                                                                      
          Logger.DEBUG);
+                               }
                        } catch (OutOfMemoryError e) {
                                System.gc();
                                System.runFinalization();
@@ -129,12 +153,10 @@
                                                                t, Logger.ERROR);
                        }
                }
-               
                throttleBeforeSelect();
-               
        }
        
-       public final void scheduleMaintenance(NIOReader cb) {
+       public final void scheduleMaintenance(SocketChannel cb) {
                if(logDebug)
                        Core.logger.log(this, "Scheduling maintenance on "+cb, 
                                                        new Exception("debug"), 
Logger.DEBUG);
@@ -390,6 +412,9 @@
                                                                        nc, t, 
Logger.NORMAL);
                                        status = -1;
                                }
+                               if(logDebug)
+                                       Core.logger.log(this, ""+chan+":"+nc+" 
returned "+
+                                                                       status, 
Logger.DEBUG);
                                if(status == -1) {
                                        if(logDebug)
                                                Core.logger.log(this, "Closing 
connection "+chan+":"+nc+

Index: ThrottledSelectorLoop.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/ThrottledSelectorLoop.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -w -r1.24 -r1.25
--- ThrottledSelectorLoop.java  18 Sep 2003 17:48:13 -0000      1.24
+++ ThrottledSelectorLoop.java  14 Oct 2003 19:41:38 -0000      1.25
@@ -334,6 +334,13 @@
                super.register(ch, attachment);
        }
        
+       protected void queueClose(ClosePair chan) {
+               synchronized(dontReregister) {
+                       dontReregister.remove(chan.sc);
+               }
+               super.queueClose(chan);
+       }
+       
     /**
      * @return true if the pair should be registered NOW, false if later
      */

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to