Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ListenerAsyncResult.cs
Go to the documentation of this file.
2
3namespace System.Net;
4
5internal sealed class ListenerAsyncResult : System.Net.LazyAsyncResult
6{
7 private unsafe static readonly IOCompletionCallback s_ioCallback = WaitCallback;
8
10
12
13 internal ListenerAsyncResult(HttpListenerSession session, object userState, AsyncCallback callback)
14 : base(session, userState, callback)
15 {
17 }
18
19 private unsafe static void IOCompleted(ListenerAsyncResult asyncResult, uint errorCode, uint numBytes)
20 {
21 object obj = null;
22 try
23 {
24 if (System.Net.NetEventSource.Log.IsEnabled())
25 {
26 System.Net.NetEventSource.Info(null, $"errorCode:[{errorCode}] numBytes:[{numBytes}]", "IOCompleted");
27 }
28 if (errorCode != 0 && errorCode != 234)
29 {
30 asyncResult.ErrorCode = (int)errorCode;
31 obj = new HttpListenerException((int)errorCode);
32 }
33 else
34 {
35 HttpListenerSession httpListenerSession = asyncResult.AsyncObject as HttpListenerSession;
36 if (errorCode == 0)
37 {
38 bool stoleBlob = false;
39 try
40 {
41 if (HttpListener.ValidateRequest(httpListenerSession, asyncResult._requestContext))
42 {
43 obj = httpListenerSession.Listener.HandleAuthentication(httpListenerSession, asyncResult._requestContext, out stoleBlob);
44 }
45 }
46 finally
47 {
48 if (stoleBlob)
49 {
50 asyncResult._requestContext = ((obj == null) ? new AsyncRequestContext(httpListenerSession.RequestQueueBoundHandle, asyncResult) : null);
51 }
52 else
53 {
54 asyncResult._requestContext.Reset(httpListenerSession.RequestQueueBoundHandle, 0uL, 0u);
55 }
56 }
57 }
58 else
59 {
60 asyncResult._requestContext.Reset(httpListenerSession.RequestQueueBoundHandle, asyncResult._requestContext.RequestBlob->RequestId, numBytes);
61 }
62 if (obj == null)
63 {
64 uint num = asyncResult.QueueBeginGetContext();
65 if (num != 0 && num != 997)
66 {
67 obj = new HttpListenerException((int)num);
68 }
69 }
70 if (obj == null)
71 {
72 return;
73 }
74 }
75 if (System.Net.NetEventSource.Log.IsEnabled())
76 {
77 System.Net.NetEventSource.Info(null, "Calling Complete()", "IOCompleted");
78 }
79 }
80 catch (Exception ex) when (!System.Net.ExceptionCheck.IsFatal(ex))
81 {
82 if (System.Net.NetEventSource.Log.IsEnabled())
83 {
84 System.Net.NetEventSource.Info(null, $"Caught exception: {ex}", "IOCompleted");
85 }
86 obj = ex;
87 }
88 asyncResult.InvokeCallback(obj);
89 }
90
91 private unsafe static void WaitCallback(uint errorCode, uint numBytes, NativeOverlapped* nativeOverlapped)
92 {
94 IOCompleted(asyncResult, errorCode, numBytes);
95 }
96
97 internal unsafe uint QueueBeginGetContext()
98 {
99 uint num = 0u;
100 while (true)
101 {
102 if (System.Net.NetEventSource.Log.IsEnabled())
103 {
104 System.Net.NetEventSource.Info(this, $"Calling Interop.HttpApi.HttpReceiveHttpRequest RequestId: {_requestContext.RequestBlob->RequestId} Buffer: 0x{(IntPtr)_requestContext.RequestBlob:x} Size: {_requestContext.Size}", "QueueBeginGetContext");
105 }
106 uint num2 = 0u;
107 HttpListenerSession httpListenerSession = (HttpListenerSession)base.AsyncObject;
108 num = global::Interop.HttpApi.HttpReceiveHttpRequest(httpListenerSession.RequestQueueHandle, _requestContext.RequestBlob->RequestId, 1u, _requestContext.RequestBlob, _requestContext.Size, &num2, _requestContext.NativeOverlapped);
109 if (System.Net.NetEventSource.Log.IsEnabled())
110 {
111 System.Net.NetEventSource.Info(this, "Call to Interop.HttpApi.HttpReceiveHttpRequest returned:" + num, "QueueBeginGetContext");
112 }
113 if (num == 87 && _requestContext.RequestBlob->RequestId != 0L)
114 {
115 _requestContext.RequestBlob->RequestId = 0uL;
116 continue;
117 }
118 switch (num)
119 {
120 case 234u:
121 _requestContext.Reset(httpListenerSession.RequestQueueBoundHandle, _requestContext.RequestBlob->RequestId, num2);
122 continue;
123 case 0u:
125 {
126 IOCompleted(this, num, num2);
127 }
128 break;
129 }
130 break;
131 }
132 return num;
133 }
134
135 protected override void Cleanup()
136 {
137 if (_requestContext != null)
138 {
141 }
142 base.Cleanup();
143 }
144}
unsafe NativeOverlapped * NativeOverlapped
unsafe void Reset(ThreadPoolBoundHandle boundHandle, ulong requestId, uint size)
static bool IsFatal(Exception exception)
ThreadPoolBoundHandle RequestQueueBoundHandle
static readonly bool SkipIOCPCallbackOnSuccess
unsafe HttpListenerContext HandleAuthentication(HttpListenerSession session, RequestContextBase memoryBlob, out bool stoleBlob)
static unsafe bool ValidateRequest(HttpListenerSession session, RequestContextBase requestMemory)
static IOCompletionCallback IOCallback
static unsafe void IOCompleted(ListenerAsyncResult asyncResult, uint errorCode, uint numBytes)
static unsafe void WaitCallback(uint errorCode, uint numBytes, NativeOverlapped *nativeOverlapped)
ListenerAsyncResult(HttpListenerSession session, object userState, AsyncCallback callback)
static unsafe readonly IOCompletionCallback s_ioCallback
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
unsafe global::Interop.HttpApi.HTTP_REQUEST * RequestBlob
static unsafe? object GetNativeOverlappedState(NativeOverlapped *overlapped)
unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)