This commit is contained in:
mkvore-commit
2009-04-04 10:28:31 +00:00
parent bc086a78eb
commit de6edc6a99
6 changed files with 55 additions and 47 deletions

View File

@ -23,6 +23,7 @@ class ConnectionHandler {
private Log _log;
private ConnectionManager _manager;
private LinkedBlockingQueue<Packet> _synQueue;
private Object _synSignal;
private boolean _active;
private int _acceptTimeout;
@ -81,7 +82,13 @@ class ConnectionHandler {
boolean success = _synQueue.offer(packet); // fail immediately if full
if (success) {
SimpleScheduler.getInstance().addEvent(new TimeoutSyn(packet), _acceptTimeout);
} else {
if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE))
synchronized (this._synSignal)
{
this._synSignal.notifyAll();
}
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Dropping new SYN request, as the queue is full");
if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE))
@ -89,8 +96,17 @@ class ConnectionHandler {
}
}
public boolean waitSyn( long ms ) throws InterruptedException {
throw new InterruptedException();
/**
* Wait until some SYN packet is available
* @param ms max amount of time to wait for a connection (if negative or null,
* wait indefinitely)
* @throws InterruptedException
*/
public void waitSyn( long ms ) throws InterruptedException {
synchronized (this._synSignal)
{
this._synSignal.wait(ms);
}
}
/**
@ -120,6 +136,9 @@ class ConnectionHandler {
return null;
}
if ( (timeoutMs > 0) && (expiration < _context.clock().now()) )
return null;
Packet syn = null;
while ( _active && syn == null) {
if (_log.shouldLog(Log.DEBUG))
@ -162,8 +181,6 @@ class ConnectionHandler {
}
}
// keep looping...
if ( (timeoutMs >= 0) && (expiration < _context.clock().now()) )
return null;
}
}

View File

@ -65,28 +65,20 @@ public class I2PServerSocketFull implements I2PServerSocket {
* @throws SocketTimeoutException if the timeout has been reached
*/
public I2PSocket accept(boolean blocking) throws I2PException, SocketTimeoutException {
long timeout = this.getSoTimeout();
public I2PSocket accept(long timeout) throws I2PException {
long reset_timeout = this.getSoTimeout();
try {
if (blocking)
{
this.setSoTimeout(-1);
} else {
this.setSoTimeout(0);
}
try {
return this.accept();
} catch (SocketTimeoutException e) {
if (blocking) throw e;
else return null ;
}
} finally {
this.setSoTimeout(timeout);
return this.accept();
} catch (SocketTimeoutException e) {
return null ;
} finally {
this.setSoTimeout(reset_timeout);
}
}
public boolean waitIncoming(long timeoutMs) throws InterruptedException {
return this._socketManager.getConnectionManager().getConnectionHandler().waitSyn(timeoutMs);
public void waitIncoming(long timeoutMs) throws InterruptedException {
this._socketManager.getConnectionManager().getConnectionHandler().waitSyn(timeoutMs);
}
}