AsynchronousSocketChannel operation cancelling on b145
Gian Franco Zabarino
gfz87 at hotmail.com
Tue Jun 21 15:01:41 PDT 2011
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.
I've been looking around what the cancel(boolean) method does, and it seems to call a onCancel method on the AsynchronousChannel, which on both Windows and Unix implementations, cancels the operation for calling it again later, like I'm experimenting:
@Override
167 public void onCancel(PendingFuture<?,?> task) {
168 if (task.getContext() instanceof ConnectTask)
169 killConnect();
170 if (task.getContext() instanceof ReadTask)
171 killReading();
172 if (task.getContext() instanceof WriteTask)
173 killWriting();
174 }
Is there other way to accomplish what I'm trying to do? Greetings
Gian Franco Zabarino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20110621/d14e0688/attachment.html
More information about the nio-dev
mailing list