Search in sources :

Example 1 with Listener

use of zmq.io.net.Listener in project jeromq by zeromq.

the class SocketBase method bind.

public final boolean bind(final String addr) {
    lock();
    try {
        if (ctxTerminated) {
            errno.set(ZError.ETERM);
            return false;
        }
        options.mechanism.check(options);
        // Process pending commands, if any.
        boolean brc = processCommands(0, false, null);
        if (!brc) {
            return false;
        }
        SimpleURI uri = SimpleURI.create(addr);
        String address = uri.getAddress();
        NetProtocol protocol = checkProtocol(uri.getProtocol());
        if (protocol == null) {
            return false;
        }
        switch(protocol) {
            case inproc:
                {
                    Ctx.Endpoint endpoint = new Ctx.Endpoint(this, options);
                    boolean rc = registerEndpoint(addr, endpoint);
                    if (rc) {
                        connectPending(addr, this);
                        // Save last endpoint URI
                        options.lastEndpoint = addr;
                    } else {
                        errno.set(ZError.EADDRINUSE);
                    }
                    return rc;
                }
            case pgm:
            // continue
            case epgm:
            // continue
            case norm:
                // connect for PGM, EPGM and NORM transports.
                return connect(addr);
            case tcp:
            // continue
            case ipc:
            // continue
            case tipc:
                {
                    // Remaining transports require to be run in an I/O thread, so at this
                    // point we'll choose one.
                    IOThread ioThread = chooseIoThread(options.affinity);
                    if (ioThread == null) {
                        errno.set(ZError.EMTHREAD);
                        return false;
                    }
                    Listener listener = protocol.getListener(ioThread, this, options);
                    boolean rc = listener.setAddress(address);
                    if (!rc) {
                        listener.destroy();
                        eventBindFailed(address, errno.get());
                        return false;
                    }
                    // Save last endpoint URI
                    options.lastEndpoint = listener.getAddress();
                    addEndpoint(options.lastEndpoint, listener, null);
                    return true;
                }
            default:
                throw new IllegalArgumentException(addr);
        }
    } finally {
        unlock();
    }
}
Also used : Listener(zmq.io.net.Listener) IOThread(zmq.io.IOThread) NetProtocol(zmq.io.net.NetProtocol)

Aggregations

IOThread (zmq.io.IOThread)1 Listener (zmq.io.net.Listener)1 NetProtocol (zmq.io.net.NetProtocol)1