Changeset 6630c29


Ignore:
Timestamp:
Sep 19, 2011 11:37:49 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e6d44a6
Parents:
f186076
Message:
  • Close output stream in StreamForwarder? to prevent lost data, existing bug but made worse by larger pipe
Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientRunner.java

    rf186076 r6630c29  
    2525 */
    2626public class I2PTunnelHTTPClientRunner extends I2PTunnelRunner {
    27     private Log _log;
    2827    public I2PTunnelHTTPClientRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData,
    2928                                     List<I2PSocket> sockList, Runnable onTimeout) {
    3029        super(s, i2ps, slock, initialI2PData, sockList, onTimeout);
    31         _log = I2PAppContext.getGlobalContext().logManager().getLog(I2PTunnelHTTPClientRunner.class);
    3230    }
    3331
     
    3836    }
    3937       
     38    /**
     39     *  Why is this overridden?
     40     *  Why flush in super but not here?
     41     *  Why do things in different order than in super?
     42     */
    4043    @Override
    41     protected void close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin, Socket s, I2PSocket i2ps, Thread t1, Thread t2) throws InterruptedException, IOException {
     44    protected void close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin,
     45                         Socket s, I2PSocket i2ps, Thread t1, Thread t2) throws InterruptedException, IOException {
    4246        try {
    4347            i2pin.close();
     48        } catch (IOException ioe) {
     49            // ignore
     50            if (_log.shouldLog(Log.DEBUG))
     51                _log.debug("Unable to close the i2p socket input stream: " + i2pin, ioe);
     52        }
     53        try {
    4454            i2pout.close();
    4555        } catch (IOException ioe) {
     
    5060        try {
    5161            in.close();
     62        } catch (IOException ioe) {
     63            // ignore
     64            if (_log.shouldLog(Log.DEBUG))
     65                _log.debug("Unable to close the browser input stream: " + in, ioe);
     66        }
     67        try {
    5268            out.close();
    5369        } catch (IOException ioe) {
     
    5672                _log.debug("Unable to close the browser output stream: " + out, ioe);
    5773        }
    58         i2ps.close();
    59         s.close();
     74        try {
     75            i2ps.close();
     76        } catch (IOException ioe) {
     77            // ignore
     78        }
     79        try {
     80            s.close();
     81        } catch (IOException ioe) {
     82            // ignore
     83        }
    6084        t1.join(30*1000);
    6185        t2.join(30*1000);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java

    rf186076 r6630c29  
    2222
    2323public class I2PTunnelRunner extends I2PAppThread implements I2PSocket.SocketErrorListener {
    24     private final Log _log;
     24    protected final Log _log;
    2525
    2626    private static volatile long __runnerId;
     
    9090        lastActivityOn = -1;
    9191        startedOn = Clock.getInstance().now();
    92         _log = I2PAppContext.getGlobalContext().logManager().getLog(I2PTunnelRunner.class);
     92        _log = I2PAppContext.getGlobalContext().logManager().getLog(getClass());
    9393        if (_log.shouldLog(Log.INFO))
    9494            _log.info("I2PTunnelRunner started");
     
    204204                    s.close();
    205205            } catch (IOException ex) {
    206                 if (_log.shouldLog(Log.ERROR))
    207                     _log.error("Could not close java socket", ex);
     206                if (_log.shouldLog(Log.WARN))
     207                    _log.warn("Could not close java socket", ex);
    208208            }
    209209            if (i2ps != null) {
     
    211211                    i2ps.close();
    212212                } catch (IOException ex) {
    213                     if (_log.shouldLog(Log.ERROR))
    214                         _log.error("Could not close I2PSocket", ex);
     213                    if (_log.shouldLog(Log.WARN))
     214                        _log.warn("Could not close I2PSocket", ex);
    215215                }
    216216                i2ps.setSocketErrorListener(null);
     
    219219    }
    220220   
    221     protected void close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin, Socket s, I2PSocket i2ps, Thread t1, Thread t2) throws InterruptedException, IOException {
     221    protected void close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin,
     222                         Socket s, I2PSocket i2ps, Thread t1, Thread t2) throws InterruptedException, IOException {
    222223        try {
    223224            out.flush();
     
    230231            // ignore
    231232        }
    232         in.close();
    233         i2pin.close();
     233        try {
     234            in.close();
     235        } catch (IOException ioe) {
     236            // ignore
     237        }
     238        try {
     239            i2pin.close();
     240        } catch (IOException ioe) {
     241            // ignore
     242        }
    234243        // ok, yeah, there's a race here in theory, if data comes in after flushing and before
    235244        // closing, but its better than before...
    236         s.close();
    237         i2ps.close();
     245        try {
     246            s.close();
     247        } catch (IOException ioe) {
     248            // ignore
     249        }
     250        try {
     251            i2ps.close();
     252        } catch (IOException ioe) {
     253            // ignore
     254        }
    238255        t1.join(30*1000);
    239256        t2.join(30*1000);
     
    350367                }
    351368                try {
    352                     out.flush();
     369                    // Thread must close() before exiting for a PipedOutputStream,
     370                    // or else input end gives up and we have data loss.
     371                    // http://techtavern.wordpress.com/2008/07/16/whats-this-ioexception-write-end-dead/
     372                    //out.flush();
     373                    out.close();
    353374                } catch (IOException ioe) {
    354375                    if (_log.shouldLog(Log.WARN))
Note: See TracChangeset for help on using the changeset viewer.