//
// This method is called after an asynchronous call is made for the user,
// it checks and acts accordingly if the IO:
// 1) completed synchronously.
// 2) was pended.
// 3) failed.
//
internal void CheckAsyncCallResult(int status)
{
Socket socket = (Socket)AsyncObject;
switch (status)
{
case SocketErrors.Success:
//
// the Async IO call completed synchronously:
//
break;
case SocketErrors.WSAEWOULDBLOCK:
//
// the Async IO call was pended:
// Queue our event to the thread pool.
//
GlobalLog.Assert(
socket.m_AsyncEvent != null,
"ConnectAsyncResult: m_AsyncConnectEvent == null", string.Empty);
ThreadPool.RegisterWaitForSingleObject(
socket.m_AsyncEvent,
m_ConnectCallback,
this,
-1,
true);
//
// we're done, return
//
return;
default:
//
// the Async IO call failed:
// set the Result to the Win32 error
//
ErrorCode = status;
break;
}
//
// cancel async event
//
socket.SetAsyncEventSelect(AsyncEventBits.FdNone);
//
// go back to blocking mode
//
socket.InternalSetBlocking(true);
if (status == SocketErrors.Success)
{
//
// synchronously complete the IO and call the user's callback.
//
InvokeCallback(true);
}
}