BeginXXX / Async IO

  • Thread starter Chad Z. Hower aka Kudzu
  • Start date
C

Chad Z. Hower aka Kudzu

The docs are not clear on a few points, particularly one. And considering
that the excerpted Async examples on MSDN have a bad link to the master, and
tha the one complete example appears to have a small bug that it wont compile
(Havent tried it, but syntax in one spot looks wrong and does not match
others, nor compile when that one item is duplicated) Im left to guess.

BeginRead/Write accepts a length of bytes to read/write. It makes a call back
at a later time when this is "complete". You can then use EndRead to
determine how many bytes were read. EndWrite does not return a value.

a) Can the call back ever be made in which the number of bytes is less than
requested in BeginRead - yet it not be an error. That is its just calling
back to you to say "I did this much" and you have to call BeginRead again.
Similar to how non blocking sockets work in Winsock. Or, is it that if
EndRead ever returns less bytes than requested in BeginRead, it should be
considered an error.

b) Same question - but EndWrite. But since EndWrite does not return a size,
it should thus be assumed that writes are ALWAYS completed successfully when
the call back is made, unless EndWrite raises an exception.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
C

Chris Taylor

Hi,

The async read callback can be called before the requested number of bytes
have been read, in this case it is up to you to restart a new async read.

As for the async write, the EndWrite will block untill the requested number
of bytes have been sent. So even if the callback got called prematurely
(Which I doubt would happen!), the EndWrite call would block. So if unless
there has been an error, the requested bytes have been written to the stream
once EndWrite returns.

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top