public void bind(SocketAddress address, IoHandler handler,
            IoServiceConfig config) throws IOException {
        if (handler == null)
            throw new NullPointerException("handler");
        if (config == null) {
            config = getDefaultConfig();
        }

        if (address != null && !(address instanceof InetSocketAddress))
            throw new IllegalArgumentException("Unexpected address type: "
                    + address.getClass());

        RegistrationRequest request = new RegistrationRequest(address, handler,
                config);
        
        synchronized (lock) {
            startupWorker();
            registerQueue.add(request);
            selector.wakeup();
        }

        synchronized (request) {
            while (!request.done) {
                try {
                    request.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeIOException(e);
                }
            }
        }

        if (request.exception != null) {
            throw (IOException) new IOException("Failed to bind")
                    .initCause(request.exception);
        }
    }