System.Net.ListenerAsyncResult.QueueBeginGetContext C# (CSharp) Метод

QueueBeginGetContext() приватный Метод

private QueueBeginGetContext ( ) : uint
Результат uint
        internal uint QueueBeginGetContext()
        {
            uint statusCode = Interop.HttpApi.ERROR_SUCCESS;
            while (true)
            {
                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Calling Interop.HttpApi.HttpReceiveHttpRequest RequestId: {_requestContext.RequestBlob->RequestId}Buffer:0x {((IntPtr)_requestContext.RequestBlob).ToString("x")} Size: {_requestContext.Size}");
                uint bytesTransferred = 0;
                HttpListener listener = (HttpListener)AsyncObject;
                statusCode = Interop.HttpApi.HttpReceiveHttpRequest(
                    listener.RequestQueueHandle,
                    _requestContext.RequestBlob->RequestId,
                    (uint)Interop.HttpApi.HTTP_FLAGS.HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
                    _requestContext.RequestBlob,
                    _requestContext.Size,
                    &bytesTransferred,
                    _requestContext.NativeOverlapped);

                if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Call to Interop.HttpApi.HttpReceiveHttpRequest returned:" + statusCode);
                if (statusCode == Interop.HttpApi.ERROR_INVALID_PARAMETER && _requestContext.RequestBlob->RequestId != 0)
                {
                    // we might get this if somebody stole our RequestId,
                    // set RequestId to 0 and start all over again with the buffer we just allocated
                    _requestContext.RequestBlob->RequestId = 0;
                    continue;
                }
                else if (statusCode == Interop.HttpApi.ERROR_MORE_DATA)
                {
                    // the buffer was not big enough to fit the headers, we need
                    // to read the RequestId returned, allocate a new buffer of the required size
                    _requestContext.Reset(listener.RequestQueueBoundHandle, _requestContext.RequestBlob->RequestId, bytesTransferred);
                    continue;
                }
                else if (statusCode == Interop.HttpApi.ERROR_SUCCESS &&
                    HttpListener.SkipIOCPCallbackOnSuccess)
                {
                    // IO operation completed synchronously - callback won't be called to signal completion.
                    IOCompleted(this, statusCode, bytesTransferred);
                }
                break;
            }
            return statusCode;
        }

Usage Example

        private static unsafe void WaitCallback(uint errorCode, uint numBytes, NativeOverlapped *nativeOverlapped)
        {
            ListenerAsyncResult asyncResult = (ListenerAsyncResult)Overlapped.Unpack(nativeOverlapped).AsyncResult;
            object result = null;

            try
            {
                if ((errorCode != 0) && (errorCode != 0xea))
                {
                    asyncResult.ErrorCode = (int)errorCode;
                    result = new HttpListenerException((int)errorCode);
                }
                else
                {
                    HttpListener asyncObject = asyncResult.AsyncObject as HttpListener;
                    if (errorCode == 0)
                    {
                        bool stoleBlob = false;
                        try
                        {
                            result = asyncObject.HandleAuthentication(asyncResult.m_RequestContext, out stoleBlob);
                        }
                        finally
                        {
                            if (stoleBlob)
                            {
                                asyncResult.m_RequestContext = (result == null) ? new AsyncRequestContext(asyncResult) : null;
                            }
                            else
                            {
                                asyncResult.m_RequestContext.Reset(0L, 0);
                            }
                        }
                    }
                    else
                    {
                        asyncResult.m_RequestContext.Reset(asyncResult.m_RequestContext.RequestBlob.RequestId, numBytes);
                    }
                    if (result == null)
                    {
                        uint num = asyncResult.QueueBeginGetContext();
                        if ((num != 0) && (num != 0x3e5))
                        {
                            result = new HttpListenerException((int)num);
                        }
                    }
                    if (result == null)
                    {
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                if (NclUtilities.IsFatal(exception))
                {
                    throw;
                }
                result = exception;
            }
            asyncResult.InvokeCallback(result);
        }
All Usage Examples Of System.Net.ListenerAsyncResult::QueueBeginGetContext