mscorlib(4.0.0.0) API with additions
_IOCompletionCallback.cs
1 using System.Security;
2 
3 namespace System.Threading
4 {
5  internal class _IOCompletionCallback
6  {
7  [SecurityCritical]
8  private IOCompletionCallback _ioCompletionCallback;
9 
10  private ExecutionContext _executionContext;
11 
12  private uint _errorCode;
13 
14  private uint _numBytes;
15 
16  [SecurityCritical]
17  private unsafe NativeOverlapped* _pOVERLAP;
18 
19  internal static ContextCallback _ccb;
20 
21  [SecuritySafeCritical]
22  static _IOCompletionCallback()
23  {
24  _ccb = IOCompletionCallback_Context;
25  }
26 
27  [SecurityCritical]
28  internal unsafe _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark)
29  {
30  _ioCompletionCallback = ioCompletionCallback;
31  _executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
32  }
33 
34  [SecurityCritical]
35  internal unsafe static void IOCompletionCallback_Context(object state)
36  {
37  _IOCompletionCallback iOCompletionCallback = (_IOCompletionCallback)state;
38  iOCompletionCallback._ioCompletionCallback(iOCompletionCallback._errorCode, iOCompletionCallback._numBytes, iOCompletionCallback._pOVERLAP);
39  }
40 
41  [SecurityCritical]
42  internal unsafe static void PerformIOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped* pOVERLAP)
43  {
44  do
45  {
46  Overlapped overlapped = OverlappedData.GetOverlappedFromNative(pOVERLAP).m_overlapped;
47  _IOCompletionCallback iocbHelper = overlapped.iocbHelper;
48  if (iocbHelper == null || iocbHelper._executionContext == null || iocbHelper._executionContext.IsDefaultFTContext(ignoreSyncCtx: true))
49  {
50  IOCompletionCallback userCallback = overlapped.UserCallback;
51  userCallback(errorCode, numBytes, pOVERLAP);
52  }
53  else
54  {
55  iocbHelper._errorCode = errorCode;
56  iocbHelper._numBytes = numBytes;
57  iocbHelper._pOVERLAP = pOVERLAP;
58  using (ExecutionContext executionContext = iocbHelper._executionContext.CreateCopy())
59  {
60  ExecutionContext.Run(executionContext, _ccb, iocbHelper, preserveSyncCtx: true);
61  }
62  }
63  OverlappedData.CheckVMForIOPacket(out pOVERLAP, out errorCode, out numBytes);
64  }
65  while (pOVERLAP != null);
66  }
67  }
68 }
delegate void ContextCallback(object state)
Represents a method to be called within a new context.
Definition: __Canon.cs:3
Provides a managed representation of a Win32 OVERLAPPED structure, including methods to transfer info...
Definition: Overlapped.cs:8
unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)
Receives the error code, number of bytes, and overlapped value type when an I/O operation completes o...
Manages the execution context for the current thread. This class cannot be inherited.
static void Run(ExecutionContext executionContext, ContextCallback callback, object state)
Runs a method in a specified execution context on the current thread.
static ExecutionContext Capture()
Captures the execution context from the current thread.
Provides an explicit layout that is visible from unmanaged code and that will have the same layout as...