diff --git a/src/Common/src/Interop/Windows/winhttp/Interop.SafeWinHttpHandle.cs b/src/Common/src/Interop/Windows/winhttp/Interop.SafeWinHttpHandle.cs index f04412fbc504..8342b8dd286d 100644 --- a/src/Common/src/Interop/Windows/winhttp/Interop.SafeWinHttpHandle.cs +++ b/src/Common/src/Interop/Windows/winhttp/Interop.SafeWinHttpHandle.cs @@ -12,9 +12,6 @@ internal partial class Interop { internal partial class WinHttp { - // Issue 2501: Fold SafeWinHttpHandleWithCallback and SafeWinHttpHandle into a single type. - // SafeWinHttpHandleWithCallback is incorrectly overriding the Dispose(bool disposing) method - // and will be fixed as part of merging the classes. internal class SafeWinHttpHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeWinHttpHandle _parentHandle = null; @@ -59,43 +56,5 @@ protected override bool ReleaseHandle() return Interop.WinHttp.WinHttpCloseHandle(handle); } } - - internal sealed class SafeWinHttpHandleWithCallback : SafeWinHttpHandle - { - // Add a reference to this object so that the AppDomain doesn't get unloaded before the last WinHttp callback. - public void AttachCallback() - { - bool ignore = false; - DangerousAddRef(ref ignore); - } - - public void DetachCallback() - { - DangerousRelease(); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - // We need to initiate the asynchronous process of closing the WinHttp handle: - // 1. Ensure that all other WinHttp function calls for this handle have returned. - // 2. Call WinHttpCloseHandle. - // 3. Wait for WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING in the callback. - // On this event, call DetachCallback. - // - // WinHttp guarantees that no other calls to the callback are made for this handle after - // WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING has been received. - // Holding the reference to the SafeHandle object ensures that the appdomain where the SafeHandle - // lives until it is guaranteed that no further callback calls are made from the native (WinHttp) side. - Interop.WinHttp.WinHttpCloseHandle(handle); - } - } - - protected override bool ReleaseHandle() - { - return base.ReleaseHandle(); - } - } } } diff --git a/src/Common/src/Interop/Windows/winhttp/Interop.winhttp.cs b/src/Common/src/Interop/Windows/winhttp/Interop.winhttp.cs index 4230bf7fd1a6..40c29fe741b8 100644 --- a/src/Common/src/Interop/Windows/winhttp/Interop.winhttp.cs +++ b/src/Common/src/Interop/Windows/winhttp/Interop.winhttp.cs @@ -29,14 +29,6 @@ public static extern SafeWinHttpHandle WinHttpConnect( ushort serverPort, uint reserved); - // NOTE: except for the return type, this refers to the same function as WinHttpConnect. - [DllImport(Interop.Libraries.WinHttp, EntryPoint = "WinHttpConnect", CharSet = CharSet.Unicode, SetLastError = true)] - public static extern SafeWinHttpHandleWithCallback WinHttpConnectWithCallback( - SafeWinHttpHandle sessionHandle, - string serverName, - ushort serverPort, - uint reserved); - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)] public static extern SafeWinHttpHandle WinHttpOpenRequest( SafeWinHttpHandle connectHandle, @@ -47,17 +39,6 @@ public static extern SafeWinHttpHandle WinHttpOpenRequest( string acceptTypes, uint flags); - // NOTE: except for the return type, this refers to the same function as WinHttpOpenRequest. - [DllImport(Interop.Libraries.WinHttp, EntryPoint = "WinHttpOpenRequest", CharSet = CharSet.Unicode, SetLastError = true)] - public static extern SafeWinHttpHandleWithCallback WinHttpOpenRequestWithCallback( - SafeWinHttpHandle connectHandle, - string verb, - string objectName, - string version, - string referrer, - string acceptTypes, - uint flags); - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool WinHttpAddRequestHeaders( @@ -256,61 +237,5 @@ public static extern IntPtr WinHttpSetStatusCallback( WINHTTP_STATUS_CALLBACK callback, uint notificationFlags, IntPtr reserved); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)] - public static extern SafeWinHttpHandleWithCallback WinHttpWebSocketCompleteUpgrade( - SafeWinHttpHandle requestHandle, - IntPtr context); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketSend( - SafeWinHttpHandle webSocketHandle, - WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType, - IntPtr buffer, - uint bufferLength); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketReceive( - SafeWinHttpHandle webSocketHandle, - IntPtr buffer, - uint bufferLength, - out uint bytesRead, - out WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketShutdown( - SafeWinHttpHandle webSocketHandle, - ushort status, - byte[] reason, - uint reasonLength); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketShutdown( - SafeWinHttpHandle webSocketHandle, - ushort status, - IntPtr reason, - uint reasonLength); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketClose( - SafeWinHttpHandle webSocketHandle, - ushort status, - byte[] reason, - uint reasonLength); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketClose( - SafeWinHttpHandle webSocketHandle, - ushort status, - IntPtr reason, - uint reasonLength); - - [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = false)] - public static extern uint WinHttpWebSocketQueryCloseStatus( - SafeWinHttpHandle webSocketHandle, - out ushort status, - byte[] reason, - uint reasonLength, - out uint reasonLengthConsumed); } }