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
 
Back
Top