Update of /cvsroot/freenet/freenet/src/freenet/support/io
In directory sc8-pr-cvs1:/tmp/cvs-serv21267/src/freenet/support/io

Modified Files:
        NIOInputStream.java NIOOutputStream.java 
Log Message:
6170:
Fix synchronization on wrong object for runningConnections in LocalNIOInterface. Bug 
could conceivably have caused web interface to freeze.
Check if we need to reenable web interface if we runningConnections-- in 
ConnectionShell finalizer.
Logging.


Index: NIOInputStream.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/support/io/NIOInputStream.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- NIOInputStream.java 11 Jul 2003 21:37:30 -0000      1.18
+++ NIOInputStream.java 5 Sep 2003 02:00:46 -0000       1.19
@@ -101,6 +101,8 @@
        }
        
        public int process(ByteBuffer b) {
+               if(logDEBUG) Core.logger.log(this, "process("+b+") ("+this+")",
+                                                                        Logger.DEBUG);
                if(b == null) return 1;
                else 
                        synchronized(accumulator) {

Index: NIOOutputStream.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/support/io/NIOOutputStream.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- NIOOutputStream.java        6 Aug 2003 01:43:51 -0000       1.17
+++ NIOOutputStream.java        5 Sep 2003 02:00:46 -0000       1.18
@@ -58,161 +58,164 @@
                //WARNING:remove before release
                instances++;
                logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               if(logDEBUG)
+                       Core.logger.log(this, "Created "+this+" for "+conn+" on "+chan,
+                                                       Logger.DEBUG);
        }
-               
-               public void configWSL(WriteSelectorLoop wsl){
-                       this.wsl=wsl;
-               }
-               
-               public synchronized void write(byte[] b) throws IOException{
-                       if(b.length == 0) return;
-                       if (dead) {
-                               throw new SocketException("Connection already closed");
-                       }
-                       if(!wsl.send(b,chan,this,wsl.NEGOTIATION)) // trailers are 
CH.CHOS
-                               throw new SocketException("Couldn't send data: 
WSL.send returned false");
+       
+       public void configWSL(WriteSelectorLoop wsl){
+               this.wsl=wsl;
+       }
+       
+       public synchronized void write(byte[] b) throws IOException{
+               if(b.length == 0) return;
+               if (dead) {
+                       throw new SocketException("Connection already closed");
+               }
+               if(!wsl.send(b,chan,this,wsl.NEGOTIATION)) // trailers are CH.CHOS
+                       throw new SocketException("Couldn't send data: WSL.send 
returned false");
+               if(logDEBUG)
+                       Core.logger.log(this, "Sent write of "+b.length+
+                                                       " bytes, waiting: "+this, 
Logger.DEBUG);
+               try {
+                       long now = System.currentTimeMillis();
                        if(logDEBUG)
-                               Core.logger.log(this, "Sent write of "+b.length+
-                                                               " bytes, waiting: 
"+this, Logger.DEBUG);
-                       try {
-                               long now = System.currentTimeMillis();
-                               if(logDEBUG)
-                                       Core.logger.log(this, "Trying to write 
"+b.length+
-                                                                       " bytes at 
"+this, Logger.DEBUG);
-                               this.wait(5*60*1000);
-                               if (dead) {
-                                       if(logDEBUG)
-                                               Core.logger.log(this, "Stream "+this+
-                                                                               " 
closed while writing", Logger.DEBUG);
-                                       throw new SocketException("stream closed while 
writing");
-                               }
-                               if (System.currentTimeMillis() - now >= 5*60*1000) {
-                                       Core.logger.log(this,"NIOOS.write(byte[]) 
timed out. "+conn+" closing",Logger.ERROR);
-                                       close();
-                                       throw new SocketException("stream closed while 
writing");
-                               }
-                       } catch (InterruptedException e) {
+                               Core.logger.log(this, "Trying to write "+b.length+
+                                                               " bytes at "+this, 
Logger.DEBUG);
+                       this.wait(5*60*1000);
+                       if (dead) {
                                if(logDEBUG)
-                                       Core.logger.log(this, "Wait interrupted: 
"+this,
-                                                                       Logger.DEBUG);
+                                       Core.logger.log(this, "Stream "+this+
+                                                                       " closed while 
writing", Logger.DEBUG);
+                               throw new SocketException("stream closed while 
writing");
+                       }
+                       if (System.currentTimeMillis() - now >= 5*60*1000) {
+                               Core.logger.log(this,"NIOOS.write(byte[]) timed out. 
"+conn+" closing",Logger.ERROR);
+                               close();
+                               throw new SocketException("stream closed while 
writing");
                        }
-                       
+               } catch (InterruptedException e) {
                        if(logDEBUG)
-                               Core.logger.log(this, "CHOSsent now "+CHOSsent+", 
b.length="+
-                                                               b.length+" for "+this, 
Logger.DEBUG);
-                       if (CHOSsent < b.length) throw new SocketException("Could not 
send all data - send "+CHOSsent+" of "+b.length);
-                       currentJob=null;
-                       CHOSsent=0;
-                       
+                               Core.logger.log(this, "Wait interrupted: "+this,
+                                                               Logger.DEBUG);
                }
                
-               public synchronized void write(byte[] b, int off, int len) throws 
IOException{
-                       
-                       if (dead) throw new SocketException("Connection already 
closed");
-                       if(len == 0) return;
-                       if(logDEBUG)
-                               Core.logger.log(this, "Trying to write "+len+" bytes 
to "+chan+
-                                                               " ("+this+")", new 
Exception("debug"), 
-                                                               Logger.DEBUG);
-                       if(!wsl.send(b,off,len,chan,this,wsl.NEGOTIATION))
-                               throw new SocketException("Could not send data: 
WSL.send returned false");
-                       try {
-                               long now = System.currentTimeMillis();
-                               this.wait(5*60*1000);
-                               if (dead) {
-                                       Core.logger.log(this, "Socket "+this+
-                                                                       " closed while 
writing", Logger.MINOR);
-                                       throw new SocketException("stream closed while 
writing");
-                               }
-                               if (System.currentTimeMillis() - now >= 5*60*1000) {
-                                       
Core.logger.log(this,"NIOOS.write(byte[],int,int) timed out."+conn+" closing 
"+this,Logger.ERROR);
-                                       close();
-                                       throw new SocketException("stream closed while 
writing");
-                               }
-                       } catch (InterruptedException e) {}
-                       
-                       if (CHOSsent < len) {
-                               if (!dead)
-                               throw new SocketException("Could not send all data - 
send "+CHOSsent+" of "+b.length);
-                               else
-                               throw new SocketException("Could not send all data, 
stream DEAD "+CHOSsent+" of "+b.length);
+               if(logDEBUG)
+                       Core.logger.log(this, "CHOSsent now "+CHOSsent+", b.length="+
+                                                       b.length+" for "+this, 
Logger.DEBUG);
+               if (CHOSsent < b.length) throw new SocketException("Could not send all 
data - send "+CHOSsent+" of "+b.length);
+               currentJob=null;
+               CHOSsent=0;
+               
+       }
+       
+       public synchronized void write(byte[] b, int off, int len) throws IOException{
+               
+               if (dead) throw new SocketException("Connection already closed");
+               if(len == 0) return;
+               if(logDEBUG)
+                       Core.logger.log(this, "Trying to write "+len+" bytes to "+chan+
+                                                       " ("+this+")", new 
Exception("debug"), 
+                                                       Logger.DEBUG);
+               if(!wsl.send(b,off,len,chan,this,wsl.NEGOTIATION))
+                       throw new SocketException("Could not send data: WSL.send 
returned false");
+               try {
+                       long now = System.currentTimeMillis();
+                       this.wait(5*60*1000);
+                       if (dead) {
+                               Core.logger.log(this, "Socket "+this+
+                                                               " closed while 
writing", Logger.MINOR);
+                               throw new SocketException("stream closed while 
writing");
                        }
-                       currentJob=null;
-                       CHOSsent=0;
+                       if (System.currentTimeMillis() - now >= 5*60*1000) {
+                               Core.logger.log(this,"NIOOS.write(byte[],int,int) 
timed out."+conn+" closing "+this,Logger.ERROR);
+                               close();
+                               throw new SocketException("stream closed while 
writing");
+                       }
+               } catch (InterruptedException e) {}
                
-                       
+               if (CHOSsent < len) {
+                       if (!dead)
+                               throw new SocketException("Could not send all data - 
send "+CHOSsent+" of "+b.length);
+                       else
+                               throw new SocketException("Could not send all data, 
stream DEAD "+CHOSsent+" of "+b.length);
                }
+               currentJob=null;
+               CHOSsent=0;
                
-               public synchronized void write(int b) throws IOException{
-                       currentJob = new byte[1];
-                       currentJob[0]=(byte)b;
-                       write(currentJob);
-               }
                
-               /**
-                * this doesn't really flush.  it just throws if we didn't finish 
writing
-                */
-               public synchronized void flush() throws IOException{
-                       CHOSsent=0;
-                       this.notifyAll();
-                       if (dead) throw new SocketException("Already closed!");
-                       if (currentJob!=null) throw new SocketException("Still 
writing!");
-               }
+       }
+       
+       public synchronized void write(int b) throws IOException{
+               currentJob = new byte[1];
+               currentJob[0]=(byte)b;
+               write(currentJob);
+       }
+       
+       /**
+        * this doesn't really flush.  it just throws if we didn't finish writing
+        */
+       public synchronized void flush() throws IOException{
+               CHOSsent=0;
+               this.notifyAll();
+               if (dead) throw new SocketException("Already closed!");
+               if (currentJob!=null) throw new SocketException("Still writing!");
+       }
                
-               public void close() throws IOException{
-                       if(logDEBUG)
-                               Core.logger.log(this, "Closing "+this, Logger.DEBUG);
-                       //flush();
-                       //if(dead || (chan == null)) return;
-                       synchronized(this) {
-                               if(dead || (chan == null)) {
-                                       this.notifyAll();
-                                       return;
-                               }
-                               if(logDEBUG)
-                                       Core.logger.log(this, "Still closing "+this, 
Logger.DEBUG);
-                               dead=true;
+       public void close() throws IOException{
+               if(logDEBUG)
+                       Core.logger.log(this, "Closing "+this, Logger.DEBUG);
+               //flush();
+               //if(dead || (chan == null)) return;
+               synchronized(this) {
+                       if(dead || (chan == null)) {
                                this.notifyAll();
-                               if(conn.isClosed()) return; 
-                               // don't block if already closed or if called from 
tcpConn
-                               wsl.queueClose((SocketChannel)chan,this);
-                               //why the hell do we need to wait here?
-                               /*try{
-                                       if(logDEBUG)
-                                               Core.logger.log(this, "Waiting for 
close to finish on "+this,Logger.DEBUG);
-                                       this.wait(30000);
-                                       if(dead || chan == null) {
-                                               if(logDEBUG)
-                                                       Core.logger.log(this, "Close 
apparently finished on "+this, Logger.DEBUG);
-                                       } else {
-                                               if(logDEBUG)
-                                                       Core.logger.log(this, "Gave up 
on close after 10 "+
-                                                                                      
 "seconds for "+this, Logger.ERROR);
-                                       }
-                               } catch (InterruptedException e) {}     */
+                               return;
                        }
-               }
-               
-               public synchronized void closed() {
                        if(logDEBUG)
-                               Core.logger.log(this, "closed() on "+this+" 
("+conn+")",
-                                                               new 
Exception("debug"), Logger.DEBUG);
+                               Core.logger.log(this, "Still closing "+this, 
Logger.DEBUG);
                        dead=true;
-                       chan=null;
-                       conn=null;
                        this.notifyAll();
+                       if(conn.isClosed()) return; 
+                       // don't block if already closed or if called from tcpConn
+                       wsl.queueClose((SocketChannel)chan,this);
+                       //why the hell do we need to wait here?
+                       /*try{
+                         if(logDEBUG)
+                         Core.logger.log(this, "Waiting for close to finish on 
"+this,Logger.DEBUG);
+                         this.wait(30000);
+                         if(dead || chan == null) {
+                         if(logDEBUG)
+                         Core.logger.log(this, "Close apparently finished on "+this, 
Logger.DEBUG);
+                         } else {
+                         if(logDEBUG)
+                         Core.logger.log(this, "Gave up on close after 10 "+
+                         "seconds for "+this, Logger.ERROR);
+                         }
+                         } catch (InterruptedException e) {}   */
                }
+       }
+               
+       public synchronized void closed() {
+               if(logDEBUG)
+                       Core.logger.log(this, "closed() on "+this+" ("+conn+")",
+                                                       new Exception("debug"), 
Logger.DEBUG);
+               dead=true;
+               chan=null;
+               conn=null;
+               this.notifyAll();
+       }
            
-               public synchronized void jobDone(int size, boolean status) {
-                       CHOSsent=size;
-                       this.notifyAll();
-               }
+       public synchronized void jobDone(int size, boolean status) {
+               CHOSsent=size;
+               this.notifyAll();
+       }
        
        public void jobPartDone(int size) {};
        
-               //profiling
+       //profiling
        //WARNING:remove before release
        protected void finalize() {
                instances--;
        }
-    }
+}

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

Reply via email to