use of org.webpieces.nio.api.jdk.JdkSocketChannel in project webpieces by deanhiller.
the class BasTCPServerChannel method accept.
/* (non-Javadoc)
* @see api.biz.xsoftware.nio.TCPServerChannel#accept()
*/
public boolean accept(int newSocketNum) throws IOException {
XFuture<Void> future;
try {
// special code...see information in close() method
if (isClosed())
return false;
JdkSocketChannel newChan = channel.accept();
if (newChan == null)
return false;
newChan.configureBlocking(false);
SocketAddress remoteAddress = newChan.getRemoteAddress();
String serverSocketId = id + "." + newSocketNum;
BasTCPChannel tcpChan = new BasTCPChannel(serverSocketId, newChan, remoteAddress, selMgr, router, pool, config);
if (log.isTraceEnabled())
log.trace(tcpChan + "Accepted new incoming connection");
XFuture<DataListener> connectFuture = connectionListener.connected(tcpChan, true);
future = connectFuture.thenCompose(l -> tcpChan.registerForReads(l)).thenApply(c -> null);
} catch (Throwable e) {
future = new XFuture<Void>();
future.completeExceptionally(e);
}
future.exceptionally(t -> {
log.error(this + "Failed to connect", t);
connectionListener.failed(this, t);
return null;
});
return true;
}
Aggregations