Search in sources :

Example 6 with IOThread

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);
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) StreamEngine(zmq.io.StreamEngine) ZError(zmq.ZError) IOThread(zmq.io.IOThread) IOException(java.io.IOException) SessionBase(zmq.io.SessionBase)

Aggregations

IOThread (zmq.io.IOThread)6 SessionBase (zmq.io.SessionBase)2 NetProtocol (zmq.io.net.NetProtocol)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Selector (java.nio.channels.Selector)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 ZError (zmq.ZError)1 StreamEngine (zmq.io.StreamEngine)1 Address (zmq.io.net.Address)1 IZAddress (zmq.io.net.Address.IZAddress)1 Listener (zmq.io.net.Listener)1 Pipe (zmq.pipe.Pipe)1