AsynchronousByteCharChannel and Timeouts

Alan Bateman Alan.Bateman at Sun.COM
Sun Aug 2 13:07:48 PDT 2009


Gili wrote:
> :
> I wonder if this is a difference between socket communications and serial
> ports. As far as I know, there is no way for me to initiate a "wait forever"
> read against a serial port and then fire some method at a later time asking
> it to return as much data has it managed to gather so far.
>
> Looking at http://msdn.microsoft.com/en-us/library/aa363437%28VS.85%29.aspx
> and http://msdn.microsoft.com/en-us/library/aa363791%28VS.85%29.aspx it
> seems that if you cancel a read (the only way I know of interrupting it) the
> operation will return zero bytes. Am I missing something?
>   
Cancellation of I/O operations is an awkward topic and clearly not 
feasible on all operating systems and in all cases. The timeout support 
in AsynchronousSocketChannel does not require it. This approach might be 
worth exploring for your serial port channel but it really depends on it 
if makes sense to want to continue to use the channel after a timeout. 
In the case of AsynchronousSocketChannel, the timeout support is there 
to make it easy to deal with cases where the peer does not respond. The 
typical error handling includes close the channel. In the case of serial 
I/O, how would you expect the application to handle a timeout?

-Alan.



More information about the nio-discuss mailing list