Search in sources :

Example 1 with IZAddress

use of zmq.io.net.Address.IZAddress in project jeromq by zeromq.

the class SocketBase method termEndpoint.

public final boolean termEndpoint(String addr) {
    lock();
    try {
        // Check whether the library haven't been shut down yet.
        if (ctxTerminated) {
            errno.set(ZError.ETERM);
            return false;
        }
        // Check whether endpoint address passed to the function is valid.
        if (addr == null) {
            errno.set(ZError.EINVAL);
            return false;
        }
        // Process pending commands, if any, since there could be pending unprocessed processOwn()'s
        // (from launchChild() for example) we're asked to terminate now.
        boolean rc = processCommands(0, false, null);
        if (!rc) {
            return false;
        }
        SimpleURI uri = SimpleURI.create(addr);
        NetProtocol protocol = checkProtocol(uri.getProtocol());
        if (protocol == null) {
            return false;
        }
        // Disconnect an inproc socket
        if (protocol == NetProtocol.inproc) {
            if (unregisterEndpoint(addr, this)) {
                return true;
            }
            Collection<Pipe> olds = inprocs.remove(addr);
            if (olds == null || olds.isEmpty()) {
                errno.set(ZError.ENOENT);
                return false;
            } else {
                for (Pipe old : olds) {
                    old.sendDisconnectMsg();
                    old.terminate(true);
                }
            }
            return true;
        }
        String resolvedAddress = addr;
        // socket is connected or bound, try with both.
        if (protocol == NetProtocol.tcp) {
            boolean endpoint = endpoints.hasValues(resolvedAddress);
            if (!endpoint) {
                // TODO V4 resolve TCP address when unbinding
                IZAddress address = protocol.zresolve(uri.getAddress(), options.ipv6);
                resolvedAddress = address.address().toString();
                endpoint = endpoints.hasValues(resolvedAddress);
                if (!endpoint) {
                    // no luck, try with local resolution
                    InetSocketAddress socketAddress = address.resolve(uri.getAddress(), options.ipv6, true);
                    resolvedAddress = socketAddress.toString();
                }
            }
        }
        // Find the endpoints range (if any) corresponding to the addr_ string.
        Collection<EndpointPipe> eps = endpoints.remove(resolvedAddress);
        if (eps == null || eps.isEmpty()) {
            errno.set(ZError.ENOENT);
            return false;
        } else {
            // If we have an associated pipe, terminate it.
            for (EndpointPipe ep : eps) {
                if (ep.pipe != null) {
                    ep.pipe.terminate(false);
                }
                termChild(ep.endpoint);
            }
        }
        return true;
    } finally {
        unlock();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NetProtocol(zmq.io.net.NetProtocol) Pipe(zmq.pipe.Pipe) IZAddress(zmq.io.net.Address.IZAddress)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 IZAddress (zmq.io.net.Address.IZAddress)1 NetProtocol (zmq.io.net.NetProtocol)1 Pipe (zmq.pipe.Pipe)1