Changeset 6fe25cd


Ignore:
Timestamp:
Feb 22, 2018 4:59:14 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e71d1d38
Parents:
0196275
Message:

I2CP: Use setSoTimeout() when reading first byte
We originally looped because we used InternalSockets?,
but we don't anymore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/client/ClientListenerRunner.java

    r0196275 r6fe25cd  
    2424 * Listen for connections on the specified port, and toss them onto the client manager's
    2525 * set of connections once they are established.
     26 *
     27 * This is not used for internal (in-JVM) connections - see ClientManager and QueuedClientConnectionRunner.
     28 *
     29 * Note that this is extended by SSLClientListenerRunner for SSL,
     30 * and by DomainClientListenerRunner in Android for domain sockets.
    2631 *
    2732 * @author jrandom
     
    161166    /** give the i2cp client 5 seconds to show that they're really i2cp clients */
    162167    protected final static int CONNECT_TIMEOUT = 5*1000;
    163     private final static int LOOP_DELAY = 250;
    164168
    165169    /**
    166170     *  Verify the first byte.
    167      *  The InternalSocket doesn't support SoTimeout, so use available()
    168      *  instead to prevent hanging.
    169171     */
    170172    protected boolean validate(Socket socket) {
    171173        try {
    172174            InputStream is = socket.getInputStream();
    173             for (int i = 0; i < CONNECT_TIMEOUT / LOOP_DELAY; i++) {
    174                 if (is.available() > 0)
    175                     return is.read() == I2PClient.PROTOCOL_BYTE;
    176                 try { Thread.sleep(LOOP_DELAY); } catch (InterruptedException ie) {}
    177             }
     175            socket.setSoTimeout(CONNECT_TIMEOUT);
     176            boolean rv = is.read() == I2PClient.PROTOCOL_BYTE;
     177            socket.setSoTimeout(0);
     178            return rv;
    178179        } catch (IOException ioe) {}
    179180        if (_log.shouldLog(Log.WARN))
Note: See TracChangeset for help on using the changeset viewer.