Skip to main content

AsynchronousSocketChannel operation cancelling on b145

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
gfzabarino
Offline
Joined: 2011-06-21

I've been testing this on b145, and after I cancel a read request by cancelling the Future, I can no longer use the AsynchronousSocketChannel for reading. On NIO I always had the opportunity to remove the key from the Selector, and then to register the SocketChannel with another selector... Is there anyway to do this using NIO.2? Sometimes I need to read for detecting if a Socket was disconnected, and sometimes I need to read for user input. Both reads have different CompletionHandler classes, and different timeout parameters. Greetings

Gian Franco Zabarino

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alanb
Offline
Joined: 2005-08-08

Cancellation of I/O operations doesn't always make sense so you are best avoiding it. For your issue then I can only suggest using a CompletionHandler that dispatches to the appropriate handler based on the result.