private static unsafe void IOCompleted(DisconnectAsyncResult asyncResult, uint errorCode, uint numBytes, NativeOverlapped* nativeOverlapped) { if (NetEventSource.IsEnabled) NetEventSource.Info(null, "_connectionId:" + asyncResult._connectionId); asyncResult._httpListener._requestQueueBoundHandle.FreeNativeOverlapped(nativeOverlapped); if (Interlocked.Exchange(ref asyncResult._ownershipState, 2) == 0) { asyncResult.HandleDisconnect(); } }
private void RegisterForDisconnectNotification(ulong connectionId, ref DisconnectAsyncResult disconnectResult) { Debug.Assert(disconnectResult == null); try { if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Calling Interop.HttpApi.HttpWaitForDisconnect"); DisconnectAsyncResult result = new DisconnectAsyncResult(this, connectionId); uint statusCode = Interop.HttpApi.HttpWaitForDisconnect( _requestQueueHandle, connectionId, result.NativeOverlapped); if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Call to Interop.HttpApi.HttpWaitForDisconnect returned:" + statusCode); if (statusCode == Interop.HttpApi.ERROR_SUCCESS || statusCode == Interop.HttpApi.ERROR_IO_PENDING) { // Need to make sure it's going to get returned before adding it to the hash. That way it'll be handled // correctly in HandleAuthentication's finally. disconnectResult = result; DisconnectResults[connectionId] = disconnectResult; } if (statusCode == Interop.HttpApi.ERROR_SUCCESS && HttpListener.SkipIOCPCallbackOnSuccess) { // IO operation completed synchronously - callback won't be called to signal completion. result.IOCompleted(statusCode, 0, result.NativeOverlapped); } } catch (Win32Exception exception) { uint statusCode = (uint)exception.NativeErrorCode; if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Call to Interop.HttpApi.HttpWaitForDisconnect threw, statusCode:" + statusCode); } }
private static unsafe void IOCompleted(DisconnectAsyncResult asyncResult, uint errorCode, uint numBytes, NativeOverlapped* nativeOverlapped) { GlobalLog.Print("DisconnectAsyncResult#" + ValidationHelper.HashString(asyncResult) + "::WaitCallback() m_ConnectionId:" + asyncResult.m_ConnectionId); Overlapped.Free(nativeOverlapped); if (Interlocked.Exchange(ref asyncResult.m_OwnershipState, 2) == 0) { asyncResult.HandleDisconnect(); } }
private unsafe void RegisterForDisconnectNotification(ulong connectionId, ref DisconnectAsyncResult disconnectResult) { try { DisconnectAsyncResult result = new DisconnectAsyncResult(this, connectionId); this.EnsureBoundHandle(); switch (UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnect(this.m_RequestQueueHandle, connectionId, result.NativeOverlapped)) { case 0: case 0x3e5: disconnectResult = result; this.DisconnectResults[connectionId] = disconnectResult; break; } } catch (Win32Exception exception) { int nativeErrorCode = exception.NativeErrorCode; } }
private void RegisterForDisconnectNotification(ulong connectionId, ref DisconnectAsyncResult disconnectResult) { GlobalLog.Assert(disconnectResult == null, "HttpListener#{0}::RegisterForDisconnectNotification()|Called with a disconnectResult.", ValidationHelper.HashString(this)); try { GlobalLog.Print("HttpListener#" + ValidationHelper.HashString(this) + "::RegisterForDisconnectNotification() calling UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnect"); DisconnectAsyncResult result = new DisconnectAsyncResult(this, connectionId); EnsureBoundHandle(); uint statusCode = UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnect( m_RequestQueueHandle, connectionId, result.NativeOverlapped); GlobalLog.Print("HttpListener#" + ValidationHelper.HashString(this) + "::RegisterForDisconnectNotification() call to UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnect returned:" + statusCode); if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS || statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_IO_PENDING) { // Need to make sure it's going to get returned before adding it to the hash. That way it'll be handled // correctly in HandleAuthentication's finally. disconnectResult = result; DisconnectResults[connectionId] = disconnectResult; } if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS && HttpListener.SkipIOCPCallbackOnSuccess) { // IO operation completed synchronously - callback won't be called to signal completion. result.IOCompleted(statusCode, 0, result.NativeOverlapped); } } catch (Win32Exception exception) { uint statusCode = (uint) exception.NativeErrorCode; GlobalLog.Print("HttpListener#" + ValidationHelper.HashString(this) + "::RegisterForDisconnectNotification() call to UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnect threw. statusCode:" + statusCode); } }