AsynchronousByteCharChannel and Timeouts
cowwoc at bbs.darktech.org
Mon Aug 3 10:23:47 PDT 2009
Alan Bateman wrote:
> 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
>> read against a serial port and then fire some method at a later time
>> it to return as much data has it managed to gather so far.
>> Looking at
>> 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)
>> 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?
Here is a simple counter-example that comes to mind:
write() to request a computation on the remote end
read() with a timeout waiting for the result
if a timeout occurs, write() telling the queue to abort the computation
In the above case you could disconnect on timeout, reconnect and request an
abort. Forcing a disconnect on a timeout is not the end of the world, but it
seems like an unnecessary limitation. Instead of invalidating the channel,
couldn't you have specified that in case of a timeout the API will return
the number of bytes that were written by the underlying implementation
(ideally zero) and leave it up to the user to decide if he wishes to
disconnect or do something else?
In parallel, I will ask on another mailing list whether they have real-life
use-cases of using a serial-port after a timeout.
View this message in context: http://n2.nabble.com/AsynchronousByteCharChannel-and-Timeouts-tp3363004p3379223.html
Sent from the nio-discuss mailing list archive at Nabble.com.
More information about the nio-discuss