traveh
traveh

Reputation: 2894

Further cleanup after closing a socket channel

Is there need to do further cleanup after closing a socket channel if the channel was used with a selector and the selector is still being used?

Upvotes: 0

Views: 129

Answers (1)

user207421
user207421

Reputation: 311052

No. Closing the channel cancels the selection key. It will be removed from the key set on the next select().

However, when the current select() returns, it is possible for a cancelled key to be in the selected-keys set, which you can detect via SelectionKey.isValid(), as seen in any decent NIO select loop example.

Upvotes: 2

Related Questions