I am implementing a protocol which transmits messages. The messages are
most naturally transferred using the a Stream so the protocol can
communicate over serial-ports, network links, ....
If the other party never answers I must timeout -- not block, and this
gives me a problem, since the Stream concept in .NET does not reflect
timeouts. If a timeout occurs I will still need to use the same Stream
for more messages, for example re-sends.
For implementing timeouts i have explored some solutions:
- Using async IO: this allows me to use WaitHandle.Wait One with a
timeout. But when A timeout occurs cancelling the pending async-io
operations (and the reulting synchronization ) is a problem.
- Using Socket.Select/Socket.Poll: Far from all Streams are based on
Socket, and I can't retrieve the Socket anyway since it's a protected
property in NetworkStream.
I've been googling a bit on stuff like .NET, C#, timeout, stream, read,
but it doesn't turn up much usefull info.
What could I do here? Basically i just wish to have an option to
wait-with-timeout ("select" or "poll" in unix/sockets terminology) for a
guarantee that Read will not block indefinatly if invoked.
--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-