Async socket IO

  • Thread starter Thread starter Alexander Muylaert
  • Start date Start date
A

Alexander Muylaert

Hi

I have a question about Sockets in C#.

Is it possible that the BeginReceive returns an AsyncResult where
CompletedSynchronously is set to true.
I would think it is, this is the way Overlapped IO worked in Win32.

Now, if this happens,
A. Is the Callback method executed?
B. Is this executed inside the caller thread or still on the
threadpool.
C. Is the callerthread blocked until this callback is executed?

kind regards

Alexander
 
And if I do need to check for this,

wich one is correct. Do I need to check the IsCompleted or
CompletedSynchronously member?

private void StartReceive(){
IAsyncResult Result;

do {

Result = Socket.BeginReceive(FReceiveBuffer, 0, 1024,
SocketFlags.None, new AsyncCallback(OnReceiveCallback), this);

} while (Result.CompletedSynchronously);

}

private void StartReceive(){
IAsyncResult Result;

do {

Result = Socket.BeginReceive(FReceiveBuffer, 0, 1024,
SocketFlags.None, new AsyncCallback(OnReceiveCallback), this);

} while (Result.IsCompleted);

}
 
Hi Alexander,
I have a question about Sockets in C#.

Is it possible that the BeginReceive returns an AsyncResult where
CompletedSynchronously is set to true.
I would think it is, this is the way Overlapped IO worked in Win32.

Now, if this happens,
A. Is the Callback method executed?

Yes, when you call EndReceive.
B. Is this executed inside the caller thread or still on the
threadpool.

On caller's thread.
C. Is the callerthread blocked until this callback is executed?

Yes. It blocks when you call EndReceive.

bye
Rob
 

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

Back
Top