Changeset f937809 for apps/ministreaming


Ignore:
Timestamp:
Aug 6, 2004 10:24:56 PM (17 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
be08e8f
Parents:
c0f32c9
git-author:
jrandom <jrandom> (08/06/04 22:24:56)
git-committer:
zzz <zzz@…> (08/06/04 22:24:56)
Message:

have a write() timeout after 60s instead of blocking forever by default (also used when injecting data into an input stream)

Location:
apps/ministreaming/java/src/net/i2p/client/streaming
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java

    rc0f32c9 rf937809  
    1010import net.i2p.client.I2PSessionException;
    1111import net.i2p.data.Destination;
     12import net.i2p.util.Clock;
    1213import net.i2p.util.I2PThread;
    1314import net.i2p.util.Log;
     
    415416            if (_log.shouldLog(Log.DEBUG))
    416417                _log.debug(getPrefix() + "Insert " + len + " bytes into queue: " + hashCode());
     418            Clock clock = I2PAppContext.getGlobalContext().clock();
     419            long endAfter = clock.now() + _options.getWriteTimeout();
    417420            synchronized (bc) {
    418421                if (_options.getMaxBufferSize() > 0) {
    419                     int waited = 0;
    420                     while (bc.getCurrentSize() + len > _options.getMaxBufferSize()) {
     422                    while (bc.getCurrentSize() > _options.getMaxBufferSize()) {
    421423                        if (_log.shouldLog(Log.DEBUG))
    422424                            _log.debug("Buffer size exceeded: pending " + bc.getCurrentSize() + " limit " + _options.getMaxBufferSize());
    423                         if ( (_options.getWriteTimeout() > 0) && (waited > _options.getWriteTimeout()) ) {
    424                             throw new InterruptedIOException("Waited " + waited + "ms to write " + len + " with a buffer at " + bc.getCurrentSize());
     425                        if (_options.getWriteTimeout() > 0) {
     426                            long timeLeft = endAfter - clock.now();
     427                            if (timeLeft <= 0) {
     428                                long waited = _options.getWriteTimeout() - timeLeft;
     429                                throw new InterruptedIOException("Waited too long (" + waited + "ms) to write "
     430                                                                 + len + " with a buffer at " + bc.getCurrentSize());
     431                            }
    425432                        }
    426433                        if (inStreamClosed)
    427434                            throw new IOException("Stream closed while writing");
     435                        if (_closedOn > 0)
     436                            throw new IOException("I2PSocket closed while writing");
    428437                        try {
    429438                            bc.wait(1000);
    430                             waited += 1000;
    431439                        } catch (InterruptedException ie) {}
    432440                    }
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java

    rc0f32c9 rf937809  
    1111    private int _maxBufferSize;
    1212
    13     public static final int DEFAULT_BUFFER_SIZE = 1024*128;
     13    public static final int DEFAULT_BUFFER_SIZE = 1024*64;
     14    public static final int DEFAULT_WRITE_TIMEOUT = 60*1000;
    1415   
    1516    public I2PSocketOptions() {
    1617        _connectTimeout = -1;
    1718        _readTimeout = -1;
    18         _writeTimeout = -1;
     19        _writeTimeout = DEFAULT_WRITE_TIMEOUT;
    1920        _maxBufferSize = DEFAULT_BUFFER_SIZE;
    2021    }
Note: See TracChangeset for help on using the changeset viewer.