use of zmq.io.IOThread in project jeromq by zeromq.
the class TcpListener method acceptEvent.
@Override
public void acceptEvent() {
SocketChannel channel;
try {
channel = accept();
// If connection was reset by the peer in the meantime, just ignore it.
if (channel == null) {
socket.eventAcceptFailed(endpoint, ZError.EADDRNOTAVAIL);
return;
}
TcpUtils.tuneTcpSocket(channel);
TcpUtils.tuneTcpKeepalives(channel, options.tcpKeepAlive, options.tcpKeepAliveCnt, options.tcpKeepAliveIdle, options.tcpKeepAliveIntvl);
} catch (IOException e) {
// If connection was reset by the peer in the meantime, just ignore it.
// TODO: Handle specific errors like ENFILE/EMFILE etc.
socket.eventAcceptFailed(endpoint, ZError.exccode(e));
return;
}
// remember our fd for ZMQ_SRCFD in messages
// socket.setFd(channel);
// Create the engine object for this connection.
StreamEngine engine = null;
try {
engine = new StreamEngine(channel, options, endpoint);
} catch (ZError.InstantiationException e) {
socket.eventAcceptFailed(endpoint, ZError.EINVAL);
return;
}
// Choose I/O thread to run connecter in. Given that we are already
// running in an I/O thread, there must be at least one available.
IOThread ioThread = chooseIoThread(options.affinity);
assert (ioThread != null);
// Create and launch a session object.
SessionBase session = Sockets.createSession(ioThread, false, socket, options, null);
assert (session != null);
session.incSeqnum();
launchChild(session);
sendAttach(session, engine, false);
socket.eventAccepted(endpoint, channel);
}
Aggregations