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);
}
}