Inheritance: IDisposable
 internal static void CloseInvalidOutCriticalHandle(CriticalHandle handle)
 {
     if (handle != null)
     {
         handle.SetHandleAsInvalid();
     }
 }
示例#2
0
 internal static extern uint HttpSetRequestQueueProperty(
     CriticalHandle requestQueueHandle,
     HTTP_SERVER_PROPERTY serverProperty,
     IntPtr pPropertyInfo,
     uint propertyInfoLength,
     uint reserved,
     IntPtr pReserved);
 internal static unsafe void CancelRequest(CriticalHandle requestQueueHandle, ulong requestId)
 {
     UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK http_data_chunk;
     http_data_chunk = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK {
         DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory,
         pBuffer = (byte*) &http_data_chunk
     };
     UnsafeNclNativeMethods.HttpApi.HttpSendResponseEntityBody(requestQueueHandle, requestId, 1, 1, &http_data_chunk, null, SafeLocalFree.Zero, 0, null, null);
 }
示例#4
0
        [SuppressMessage(FxCop.Category.Security, FxCop.Rule.TransparentMethodsMustNotReferenceCriticalCode)] // we got APTCA approval with no requirement to fix this transparency warning. plus, the callers of this method are not supported in partial trust.
        internal static void CloseInvalidOutCriticalHandle(CriticalHandle handle)
        {
            if (handle != null)
            {
#pragma warning disable 618
                Fx.Assert(handle.IsInvalid, "CloseInvalidOutCriticalHandle called with a valid handle!");
#pragma warning restore 618

                handle.SetHandleAsInvalid();
            }
        }
示例#5
0
 internal ConnectionEventArgs(SQLiteConnectionEventType eventType, StateChangeEventArgs eventArgs, IDbTransaction transaction, IDbCommand command, IDataReader dataReader, System.Runtime.InteropServices.CriticalHandle criticalHandle, string text, object data)
 {
     this.EventType      = eventType;
     this.EventArgs      = eventArgs;
     this.Transaction    = transaction;
     this.Command        = command;
     this.DataReader     = dataReader;
     this.CriticalHandle = criticalHandle;
     this.Text           = text;
     this.Data           = data;
 }
示例#6
0
        /// <summary>
        /// Starts the server connection.
        /// </summary>
        public void Start()
        {
            _listener.Start();

            // HACK: Get the request queue handle so we can register for disconnect
            var requestQueueHandleField = typeof(HttpListener).GetField("m_RequestQueueHandle", BindingFlags.Instance | BindingFlags.NonPublic);
            if (requestQueueHandleField != null)
            {
                _requestQueueHandle = (CriticalHandle)requestQueueHandleField.GetValue(_listener);
            }

            ReceiveLoop();
        }
        internal void Initialize()
        {
            // Get the request queue handle so we can register for disconnect
            FieldInfo requestQueueHandleField = typeof(Mono.Net.HttpListener).GetField("m_RequestQueueHandle", BindingFlags.Instance | BindingFlags.NonPublic);

            // Get the connection id field info from the request object
            _connectionIdField = typeof(HttpListenerRequest).GetField("m_ConnectionId", BindingFlags.Instance | BindingFlags.NonPublic);

            if (requestQueueHandleField != null)
            {
                _requestQueueHandle = (CriticalHandle)requestQueueHandleField.GetValue(_listener);
            }
        }
示例#8
0
        internal DisconnectHandler(System.Net.HttpListener listener, LoggerFunc logger)
        {
            _connectionCancellationTokens = new ConcurrentDictionary<ulong, ConnectionCancellation>();
            _listener = listener;
            _logger = logger;

            // Get the request queue handle so we can register for disconnect
            FieldInfo requestQueueHandleField = typeof(System.Net.HttpListener).GetField("m_RequestQueueHandle", BindingFlags.Instance | BindingFlags.NonPublic);

            // Get the connection id field info from the request object
            _connectionIdField = typeof(HttpListenerRequest).GetField("m_ConnectionId", BindingFlags.Instance | BindingFlags.NonPublic);

            if (requestQueueHandleField != null && requestQueueHandleField.FieldType == typeof(CriticalHandle))
            {
                _requestQueueHandle = (CriticalHandle)requestQueueHandleField.GetValue(_listener);
            }
            if (_connectionIdField == null || _requestQueueHandle == null)
            {
                LogHelper.LogInfo(_logger, "Unable to resolve handles. Disconnect notifications will be ignored.");
            }
        }
 internal static extern uint HttpRemoveUrl(CriticalHandle requestQueueHandle, string pFullyQualifiedUrl);
示例#10
0
 public static IntPtr GetCriticalHandle(CriticalHandle criticalHandle)
 {
     return(criticalHandle.GetHandleInternal());
 }
 internal static extern unsafe uint HttpAddUrl(CriticalHandle requestQueueHandle, string pFullyQualifiedUrl, void* pReserved);
示例#12
0
 internal static extern unsafe uint HttpWaitForDisconnect(CriticalHandle requestQueueHandle, ulong connectionId, NativeOverlapped* pOverlapped);
示例#13
0
 /// <summary>
 /// Used in Marshalling code
 /// Gets the handle of the CriticalHandle
 /// </summary>
 public static IntPtr GetHandle(CriticalHandle criticalHandle)
 {
     return(InteropExtensions.GetCriticalHandle(criticalHandle));
 }
 internal static extern uint HttpCancelHttpRequest(CriticalHandle requestQueueHandle, ulong requestId, IntPtr pOverlapped);
 internal static extern uint HttpSendHttpResponse(CriticalHandle requestQueueHandle, ulong requestId, uint flags, HTTP_RESPONSE* pHttpResponse, void* pCachePolicy, uint* pBytesSent, SafeLocalFree pRequestBuffer, uint requestBufferLength, NativeOverlapped* pOverlapped, void* pLogData);
 internal void CancelLastWrite(CriticalHandle requestQueueHandle)
 {
     HttpResponseStreamAsyncResult asyncState = m_LastWrite;
     if (asyncState != null && !asyncState.IsCompleted)
     {
         UnsafeNclNativeMethods.CancelIoEx(requestQueueHandle, asyncState.m_pOverlapped);
     }
 }
 private void CreateRequestQueueHandle()
 {
     uint num = 0;
     if (Version == UnsafeNclNativeMethods.HttpApi.HTTP_API_VERSION.Version20)
     {
         HttpRequestQueueV2Handle pReqQueueHandle = null;
         num = UnsafeNclNativeMethods.SafeNetHandles.HttpCreateRequestQueue(UnsafeNclNativeMethods.HttpApi.Version, null, null, 0, out pReqQueueHandle);
         if (num != 0)
         {
             throw new HttpListenerException((int) num);
         }
         this.m_RequestQueueHandle = pReqQueueHandle;
     }
     else
     {
         SafeCloseHandle handle2 = null;
         num = UnsafeNclNativeMethods.SafeNetHandles.HttpCreateHttpHandle(out handle2, 0);
         if (num != 0)
         {
             throw new HttpListenerException((int) num);
         }
         this.m_RequestQueueHandle = handle2;
     }
 }
        // The request is being aborted, but large writes may be in progress. Cancel them.
        internal void ForceCancelRequest(CriticalHandle requestQueueHandle, ulong requestId) {

            uint statusCode = UnsafeNclNativeMethods.HttpApi.HttpCancelHttpRequest(requestQueueHandle, requestId, 
                IntPtr.Zero);

            // Either the connection has already dropped, or the last write is in progress.
            // The requestId becomes invalid as soon as the last Content-Length write starts.
            // The only way to cancel now is with CancelIoEx.
            if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_CONNECTION_INVALID)
            {
                m_Response.CancelLastWrite(requestQueueHandle);
            }
        }
 internal static void CancelRequest(CriticalHandle requestQueueHandle, ulong requestId) {
     uint statusCode = UnsafeNclNativeMethods.HttpApi.HttpCancelHttpRequest(requestQueueHandle, requestId,
         IntPtr.Zero);
 }
示例#20
0
        private unsafe void CreateRequestQueueHandle() {
            uint statusCode = UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS;
            
            HttpRequestQueueV2Handle requestQueueHandle = null;
            statusCode =
                UnsafeNclNativeMethods.SafeNetHandles.HttpCreateRequestQueue(
                    UnsafeNclNativeMethods.HttpApi.Version, null, null, 0, out requestQueueHandle);

            if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) {
                throw new HttpListenerException((int)statusCode);
            }

            // Disabling callbacks when IO operation completes synchronously (returns ErrorCodes.ERROR_SUCCESS)
            if (SkipIOCPCallbackOnSuccess &&
                !UnsafeNclNativeMethods.SetFileCompletionNotificationModes(
                    requestQueueHandle,
                    UnsafeNclNativeMethods.FileCompletionNotificationModes.SkipCompletionPortOnSuccess |
                    UnsafeNclNativeMethods.FileCompletionNotificationModes.SkipSetEventOnHandle))
            {
                throw new HttpListenerException(Marshal.GetLastWin32Error());
            }

            m_RequestQueueHandle = requestQueueHandle;
        }
 internal static extern unsafe uint HttpReceiveClientCertificate(CriticalHandle requestQueueHandle, ulong connectionId, uint flags, HTTP_SSL_CLIENT_CERT_INFO* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
 internal static extern uint HttpReceiveClientCertificate(CriticalHandle requestQueueHandle, ulong connectionId, uint flags, byte* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
 internal static extern uint HttpReceiveHttpRequest(CriticalHandle requestQueueHandle, ulong requestId, uint flags, HTTP_REQUEST* pRequestBuffer, uint requestBufferLength, uint* pBytesReturned, NativeOverlapped* pOverlapped);
示例#24
0
 /// <summary>
 /// Used in Marshalling code
 /// Gets the handle of the CriticalHandle
 /// </summary>
 public static IntPtr GetHandle(CriticalHandle criticalHandle)
 {
     return(criticalHandle.handle);
 }
 internal static extern uint HttpSendResponseEntityBody(CriticalHandle requestQueueHandle, ulong requestId, uint flags, ushort entityChunkCount, HTTP_DATA_CHUNK* pEntityChunks, uint* pBytesSent, SafeLocalFree pRequestBuffer, uint requestBufferLength, NativeOverlapped* pOverlapped, void* pLogData);
示例#26
0
 /// <summary>
 /// Used in Marshalling code
 /// Sets the handle of the CriticalHandle
 /// </summary>
 public static void SetHandle(CriticalHandle criticalHandle, IntPtr handle)
 {
     criticalHandle.handle = handle;
 }
 internal static extern uint HttpSendResponseEntityBody2(CriticalHandle requestQueueHandle, ulong requestId, uint flags, ushort entityChunkCount, IntPtr pEntityChunks, out uint pBytesSent, SafeLocalFree pRequestBuffer, uint requestBufferLength, SafeHandle pOverlapped, IntPtr pLogData);
示例#28
0
 public static IntPtr GetCriticalHandle(CriticalHandle criticalHandle)
 {
     throw new NotSupportedException("GetCriticalHandle");
 }
示例#29
0
 /// <summary>
 /// Used in Marshalling code
 /// Sets the handle of the CriticalHandle
 /// </summary>
 public static void SetHandle(CriticalHandle criticalHandle, IntPtr handle)
 {
     InteropExtensions.SetCriticalHandle(criticalHandle, handle);
 }
 internal static unsafe extern uint CancelIoEx(CriticalHandle handle, NativeOverlapped* overlapped);
 internal void CancelLastWrite(CriticalHandle requestQueueHandle)
 {
     if (m_ResponseStream != null)
     {
         m_ResponseStream.CancelLastWrite(requestQueueHandle);
     }
 }
 internal static unsafe extern bool SetFileCompletionNotificationModes(CriticalHandle handle, FileCompletionNotificationModes modes);
示例#33
0
 public static void SetCriticalHandle(CriticalHandle criticalHandle, IntPtr handle)
 {
     throw new NotSupportedException("SetCriticalHandle");
 }
 internal static extern uint HttpReceiveRequestEntityBody2(CriticalHandle requestQueueHandle, ulong requestId, uint flags, void* pEntityBuffer, uint entityBufferLength, out uint bytesReturned, [In] SafeHandle pOverlapped);
示例#35
0
 public static void SetCriticalHandle(CriticalHandle criticalHandle, IntPtr handle)
 {
     criticalHandle.SetHandleInternal(handle);
 }
 internal static extern unsafe uint HttpReceiveRequestEntityBody(CriticalHandle requestQueueHandle, ulong requestId, uint flags, void* pEntityBuffer, uint entityBufferLength, uint* pBytesReturned, NativeOverlapped* pOverlapped);