Another NIO beginner's question
If I close a SocketChannel from some other thread than the selector thread, it causes several exceptions after next Selector::select() operation. Some selection keys gets invalidated, so readyOps() throws CancelledKeyException
and SocketChannel::read() throws AsynchronousCloseException
. I know why it happens, but I'm not sure what is the best way to handle it.
- should I simply catch and ignore these exceptions?
- should I try to avoid them by only closing a SocketChannel in selector thread?
- any other idea?