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

Modified Files:
        OpenConnectionManager.java 
Log Message:
My 'Lesser optimization' also added an accouting bug. Thanks to Dave Hooper for 
spotting it.

Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -w -r1.148 -r1.149
--- OpenConnectionManager.java  27 Oct 2003 12:07:18 -0000      1.148
+++ OpenConnectionManager.java  28 Oct 2003 13:34:32 -0000      1.149
@@ -806,33 +806,32 @@
 
     private final void incHardConnectionLimit(Address addr)
         throws ConnectFailedException {
-        int val = 0;
         logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
+               myInt count;
         if(logDEBUG)
             Core.logger.log(this, "Increasing blocked connection count for " + 
addr.toString(), Logger.DEBUG);
         synchronized(blockedConnections) {
             blockedConnectionCount++;
-                       myInt count = (myInt)blockedConnections.get(addr.toString());
-            if (count != null) {
-                if (count.intValue >= MAXBLOCKEDCONNECTIONS) {
-                    
-                    if(logDEBUG)
-                        Core.logger.log(OpenConnectionManager.this, " Too many 
blocked connection, aborting: " + addr.toString() + " " + val, Logger.ERROR);
-                    // This means the createConnection hashtable isn't working!
-            
-                    // So that the arithmetic works when
-                    // dec is called in finally block.
+                       count = (myInt)blockedConnections.get(addr.toString());
+            if (count == null){
+                               count = new myInt(1);
+                               blockedConnections.put(addr.toString(), count);
+            }else{
+                               //Inc even if we'll pass the limit (tested for below) 
so that the
+                               //arithmetic works when dec is called in finally block.
                                        count.intValue++;
-                    
+                if ((count.intValue-1) >= MAXBLOCKEDCONNECTIONS) { //compare to the 
non-inc:d value
+                                       // This means the createConnection hashtable 
isn't working!
+                    if(logDEBUG)
+                        Core.logger.log(OpenConnectionManager.this, "Too many blocked 
connection, aborting: " + addr.toString() + " " + count.intValue, Logger.ERROR);
                     // Terminal.
-                    throw new ConnectFailedException(addr, "Exceeded blocked 
connection limit: " + val + " for " + addr);
+                    throw new ConnectFailedException(addr, "Exceeded blocked 
connection limit: " + count.intValue + " for " + addr);
                 }
-            }
-            blockedConnections.put(addr.toString(), new myInt(0));
         
         }
+        }
         if (logDEBUG)
-            Core.logger.log(OpenConnectionManager.this, " blocked: " + 
addr.toString() + " " + (val), Logger.DEBUGGING);
+            Core.logger.log(OpenConnectionManager.this, "Blocked: " + addr.toString() 
+ " " + count.intValue, Logger.DEBUGGING);
         
     }
 

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

Reply via email to