internal static extern UInt32 HttpSetRequestQueueProperty( CriticalHandle Handle, HTTP_SERVER_PROPERTY Property, IntPtr pPropertyInformation, UInt32 PropertyInformationLength, UInt32 Reserved, IntPtr pReserved);
internal static void CloseInvalidOutCriticalHandle(CriticalHandle handle) { if (handle != null) { handle.SetHandleAsInvalid(); } }
internal static extern uint HttpSetRequestQueueProperty( CriticalHandle requestQueueHandle, // _In_ HANDLE Handle, HTTP_SERVER_PROPERTY serverProperty, // _In_ HTTP_SERVER_PROPERTY Property, ref uint pPropertyInfo, // _In_ PVOID pPropertyInformation, uint propertyInfoLength, // _In_ ULONG PropertyInformationLength, uint reserved, // _Reserved_ ULONG Reserved, IntPtr pReserved); // _Reserved_ PVOID pReserved
internal static extern uint HttpSetRequestQueueProperty( CriticalHandle requestQueueHandle, HTTP_SERVER_PROPERTY serverProperty, IntPtr pPropertyInfo, uint propertyInfoLength, uint reserved, IntPtr pReserved);
internal void CancelLastWrite(CriticalHandle requestQueueHandle) { if (m_ResponseStream != null) { m_ResponseStream.CancelLastWrite(requestQueueHandle); } }
internal void CancelLastWrite(CriticalHandle requestQueueHandle) { HttpResponseStreamAsyncResult asyncState = m_LastWrite; if (asyncState != null && !asyncState.IsCompleted) { UnsafeNclNativeMethods.CancelIoEx(requestQueueHandle, asyncState.m_pOverlapped); } }
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); }
/// <summary> /// Initializes the Request Queue Handler. Meant to be called once the servers <see cref="HttpListener"/> has been started. /// </summary> public void Initialize() { // 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); } }
/// <summary> /// Initializes a new instance of the <see cref="CriticalHandleAdapter"/> class. /// </summary> /// <param name="handle">Handle to be used by the adapter.</param> public CriticalHandleAdapter(CriticalHandle handle) : base(handle) { if (handle == null) { throw new ArgumentNullException(nameof(handle)); } _instance = handle; }
private bool IsSQLiteConnectionHandle(CriticalHandle handle) { if (handle is null) { return(false); } // if I can just get the type from somewhere and store it I can compare it here return(handle.GetType() == _sqliteConnectionHandleType);//typeof(SQLiteConnectionHandle); }
[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(); } }
// 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); } }
/// <summary> /// Initializes the Request Queue Handler. Meant to be called once the servers <see cref="HttpListener"/> has been started. /// </summary> public void Initialize() { // Get the request queue handle so we can register for disconnect var requestQueueHandleField = typeof(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); } }
internal static unsafe void SetRequestQueueLength(System.Net.HttpListener listener, long length) { Type listenerType = typeof(System.Net.HttpListener); PropertyInfo requestQueueHandleProperty = listenerType.GetProperty("RequestQueueHandle", BindingFlags.NonPublic | BindingFlags.Instance); if (requestQueueHandleProperty == null || requestQueueHandleProperty.PropertyType != typeof(CriticalHandle)) { // The property changed, no-op. return; } CriticalHandle requestQueueHandle = (CriticalHandle)requestQueueHandleProperty.GetValue(listener, null); uint result = HttpSetRequestQueueProperty(requestQueueHandle, HTTP_SERVER_PROPERTY.HttpServerQueueLengthProperty, new IntPtr((void *)&length), (uint)Marshal.SizeOf(length), 0, IntPtr.Zero); if (result != 0) { throw new Win32Exception((int)result); } }
internal DisconnectHandler(WebListener 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(WebListener).GetField("m_RequestQueueHandle", BindingFlags.Instance | BindingFlags.NonPublic); // Get the connection id field info from the request object _connectionIdField = typeof(Request).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 HttpReceiveRequestEntityBody2(CriticalHandle requestQueueHandle, ulong requestId, uint flags, void *pEntityBuffer, uint entityBufferLength, out uint bytesReturned, [In] SafeHandle pOverlapped);
internal static extern uint HttpReceiveHttpRequest(CriticalHandle requestQueueHandle, ulong requestId, uint flags, HTTP_REQUEST *pRequestBuffer, uint requestBufferLength, uint *pBytesReturned, NativeOverlapped *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 static extern uint HttpCancelHttpRequest(CriticalHandle requestQueueHandle, ulong requestId, IntPtr pOverlapped);
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);
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);
/// <summary> /// Converts <see cref="CriticalHandle"/> to <see cref="ICriticalHandle"/>. /// </summary> /// <param name="handle"><see cref="CriticalHandle"/> to convert.</param> /// <returns>Instance of <see cref="ICriticalHandle"/>.</returns> public static ICriticalHandle ToInterface(this CriticalHandle handle) { return((handle == null) ? null : new CriticalHandleAdapter(handle)); }
internal static void CancelRequest(CriticalHandle requestQueueHandle, ulong requestId) { uint statusCode = UnsafeNclNativeMethods.HttpApi.HttpCancelHttpRequest(requestQueueHandle, requestId, IntPtr.Zero); }
internal static extern unsafe uint HttpWaitForDisconnectEx(CriticalHandle requestQueueHandle, ulong connectionId, uint reserved, NativeOverlapped *pOverlapped);
internal static extern uint HttpReceiveClientCertificate(CriticalHandle requestQueueHandle, ulong connectionId, uint flags, byte *pSslClientCertInfo, uint sslClientCertInfoSize, uint *pBytesReceived, NativeOverlapped *pOverlapped);