//
// The overlapped function called (either by the thread pool or the socket)
// when IO completes. (only called on Win9x)
//
private void OverlappedCallback(object stateObject, bool Signaled)
{
#if DEBUG
// GlobalLog.SetThreadSource(ThreadKinds.Worker); Because of change 1077887, need logic to determine thread type here.
using (GlobalLog.SetThreadKind(ThreadKinds.System)) {
#endif
BaseOverlappedAsyncResult asyncResult = (BaseOverlappedAsyncResult)stateObject;
GlobalLog.Assert(!asyncResult.InternalPeekCompleted, "AcceptOverlappedAsyncResult#{0}::OverlappedCallback()|asyncResult.IsCompleted", ValidationHelper.HashString(asyncResult));
//
// the IO completed asynchronously, see if there was a failure the Internal
// field in the Overlapped structure will be non zero. to optimize the non
// error case, we look at it without calling WSAGetOverlappedResult().
//
uint errorCode = (uint)Marshal.ReadInt32(IntPtrHelper.Add(asyncResult.m_UnmanagedBlob.DangerousGetHandle(),
Win32.OverlappedInternalOffset));
uint numBytes = errorCode != 0 ? unchecked ((uint)-1) : (uint)Marshal.ReadInt32(IntPtrHelper.Add(asyncResult.m_UnmanagedBlob.DangerousGetHandle(),
Win32.OverlappedInternalHighOffset));
//
// this will release the unmanaged pin handles and unmanaged overlapped ptr
//
asyncResult.ErrorCode = (int)errorCode;
object returnObject = asyncResult.PostCompletion((int)numBytes);
asyncResult.ReleaseUnmanagedStructures();
asyncResult.InvokeCallback(returnObject);
#if DEBUG
}
#endif
}