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

Modified Files:
        ReadSelectorLoop.java 
Log Message:
6242:
Change needsConnection(true) algorithm: we need 2 conns not sending (but can be 
receiving), 1 conn not sending OR receiving.
FCP bugfixes (in NIO):
 Change RSL.scheduleMaintenance() to take SocketChannel, NIOReader.
 Use them when not registered.
Logging


Index: ReadSelectorLoop.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/ReadSelectorLoop.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -w -r1.53 -r1.54
--- ReadSelectorLoop.java       14 Oct 2003 19:41:38 -0000      1.53
+++ ReadSelectorLoop.java       14 Oct 2003 22:43:47 -0000      1.54
@@ -30,6 +30,15 @@
        
        private final LinkedList maintenanceQueue;
 
+       private class MaintenancePair {
+               NIOReader attachment;
+               SocketChannel chan;
+               MaintenancePair(NIOReader reader, SocketChannel sc) {
+                       this.attachment=reader;
+                       this.chan=sc;
+               }
+       }
+       
        //this needs to be taken from the settings.. wide guess is 2K
        //public static final int BUFFER_SIZE=2048;
        
@@ -104,31 +113,53 @@
                }
                //make sure no message got stuck behind a trailing field
                
+               if(logDebug)
+                       Core.logger.log(this, "beforeSelect(), mq.size="+
+                                                       maintenanceQueue.size(), 
Logger.DEBUG);
+               
                while (maintenanceQueue.size() > 0) {
-                       SocketChannel chan;
+                       MaintenancePair mp;
                        synchronized(maintenanceQueue) {
-                               chan = (SocketChannel)maintenanceQueue.removeFirst();
+                               mp = (MaintenancePair)maintenanceQueue.removeFirst();
                        }
+                       SocketChannel chan = mp.chan;
+                       NIOReader current = mp.attachment;
                        SelectionKey k = chan.keyFor(sel);
-                       if(k == null) continue;
-                       NIOReader current = (NIOReader)(k.attachment());
                        //process could take a while, so lock just this
                        try {
                                int status = current.process(null);
+                               if(logDebug)
+                                       Core.logger.log(this, "Running maintenance on 
"+chan+
+                                                                       ":"+current+", 
returned "+status,
+                                                                       Logger.DEBUG);
                                if(status == -1) {
                                        if(logDebug)
                                                Core.logger.log(this, "Closing 
connection "+chan+":"+
                                                                                
current+" (process returned -1)", 
                                                                                
Logger.DEBUG);
+                                       if(k != null) {
                                        k.attach(null);
                                        k.cancel();
                                        current.unregistered();
+                                       } else {
+                                               if(logDebug)
+                                                       Core.logger.log(this, 
"Maintenance process returned -1 but not registered on selector, queuing for 
unregistration", Logger.DEBUG);
+                                               unregisterWaiters.add(new 
ChannelAttachmentPair
+                                                                                      
   (chan, current));
+                                       }
                                        queueClose((SocketChannel)chan,current);
                                } else if (status == 0) {
                                        if (logDebug) Core.logger.log(this, 
"Cancelling "+chan+
                                                                                       
           ":"+current+"(returned 0)",
                                                                                       
           Logger.DEBUG);
+                                       if(k != null) {
                                        k.cancel();
+                                       } else {
+                                               if(logDebug)
+                                                       Core.logger.log(this, 
"Maintenance process returned 0 but not registered on selector, queuing for 
unregistration", Logger.DEBUG);
+                                               unregisterWaiters.add(new 
ChannelAttachmentPair
+                                                                                      
   (chan, current));
+                                       }
                                        synchronized(dontReregister) {
                                                dontReregister.add(chan);
                                        }
@@ -156,12 +187,13 @@
                throttleBeforeSelect();
        }
        
-       public final void scheduleMaintenance(SocketChannel cb) {
+       public final void scheduleMaintenance(SocketChannel cb,
+                                                                                 
NIOReader attachment) {
                if(logDebug)
                        Core.logger.log(this, "Scheduling maintenance on "+cb, 
                                                        new Exception("debug"), 
Logger.DEBUG);
                synchronized (maintenanceQueue) {
-                       maintenanceQueue.addLast(cb);
+                       maintenanceQueue.addLast(new MaintenancePair(attachment, cb));
                }
        }
        

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

Reply via email to