Should I cancel the key when SocketChannel#connect returns true?

41 views Asked by At

When SocketChannel#connect returns a true for a selector-registered SocketChannel, should I cancel the SelectionKey?

                final var client = SocketChannel.open();
                client.configureBlocking(false);
                final var key = client.register(selector, OP_CONNECT);

                if (client.connect(endpoint)) { // connected, immediately
                    key.cancel(); // Should I do this?
                    ...
                }

0

There are 0 answers