Use GeneratedDllImport in System.Net.HttpListener (#53904)
authorElinor Fung <elfung@microsoft.com>
Wed, 9 Jun 2021 00:56:14 +0000 (17:56 -0700)
committerGitHub <noreply@github.com>
Wed, 9 Jun 2021 00:56:14 +0000 (17:56 -0700)
src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.LoadLibraryEx_IntPtr.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketAbortHandle.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketCompleteAction.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketCreateClientHandle.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketCreateServerHandle.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketEndServerHandshake.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketGetAction.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketReceive.cs
src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketSend.cs

index e0982d9..3a00906 100644 (file)
@@ -455,54 +455,54 @@ internal static partial class Interop
         }
 
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern uint HttpInitialize(HTTPAPI_VERSION version, uint flags, IntPtr pReserved);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static partial uint HttpInitialize(HTTPAPI_VERSION version, uint flags, IntPtr pReserved);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern uint HttpSetUrlGroupProperty(ulong urlGroupId, HTTP_SERVER_PROPERTY serverProperty, IntPtr pPropertyInfo, uint propertyInfoLength);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static partial uint HttpSetUrlGroupProperty(ulong urlGroupId, HTTP_SERVER_PROPERTY serverProperty, IntPtr pPropertyInfo, uint propertyInfoLength);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpCreateServerSession(HTTPAPI_VERSION version, ulong* serverSessionId, uint reserved);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpCreateServerSession(HTTPAPI_VERSION version, ulong* serverSessionId, uint reserved);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpCreateUrlGroup(ulong serverSessionId, ulong* urlGroupId, uint reserved);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpCreateUrlGroup(ulong serverSessionId, ulong* urlGroupId, uint reserved);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern uint HttpCloseUrlGroup(ulong urlGroupId);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static partial uint HttpCloseUrlGroup(ulong urlGroupId);
 
-        [DllImport(Libraries.HttpApi, CharSet = CharSet.Unicode, SetLastError = true)]
-        internal static extern unsafe uint HttpCreateRequestQueue(HTTPAPI_VERSION version, string pName,
+        [GeneratedDllImport(Libraries.HttpApi, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial uint HttpCreateRequestQueue(HTTPAPI_VERSION version, string pName,
             Interop.Kernel32.SECURITY_ATTRIBUTES* pSecurityAttributes, uint flags, out HttpRequestQueueV2Handle pReqQueueHandle);
 
-        [DllImport(Libraries.HttpApi, CharSet = CharSet.Unicode, SetLastError = true)]
-        internal static extern uint HttpAddUrlToUrlGroup(ulong urlGroupId, string pFullyQualifiedUrl, ulong context, uint pReserved);
+        [GeneratedDllImport(Libraries.HttpApi, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static partial uint HttpAddUrlToUrlGroup(ulong urlGroupId, string pFullyQualifiedUrl, ulong context, uint pReserved);
 
-        [DllImport(Libraries.HttpApi, CharSet = CharSet.Unicode, SetLastError = true)]
-        internal static extern uint HttpRemoveUrlFromUrlGroup(ulong urlGroupId, string pFullyQualifiedUrl, uint flags);
+        [GeneratedDllImport(Libraries.HttpApi, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static partial uint HttpRemoveUrlFromUrlGroup(ulong urlGroupId, string pFullyQualifiedUrl, uint flags);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpReceiveHttpRequest(SafeHandle requestQueueHandle, ulong requestId, uint flags, HTTP_REQUEST* pRequestBuffer, uint requestBufferLength, uint* pBytesReturned, NativeOverlapped* pOverlapped);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpReceiveHttpRequest(SafeHandle requestQueueHandle, ulong requestId, uint flags, HTTP_REQUEST* pRequestBuffer, uint requestBufferLength, uint* pBytesReturned, NativeOverlapped* pOverlapped);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpSendHttpResponse(SafeHandle requestQueueHandle, ulong requestId, uint flags, HTTP_RESPONSE* pHttpResponse, void* pCachePolicy, uint* pBytesSent, SafeLocalAllocHandle pRequestBuffer, uint requestBufferLength, NativeOverlapped* pOverlapped, void* pLogData);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpSendHttpResponse(SafeHandle requestQueueHandle, ulong requestId, uint flags, HTTP_RESPONSE* pHttpResponse, void* pCachePolicy, uint* pBytesSent, SafeLocalAllocHandle pRequestBuffer, uint requestBufferLength, NativeOverlapped* pOverlapped, void* pLogData);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpWaitForDisconnect(SafeHandle requestQueueHandle, ulong connectionId, NativeOverlapped* pOverlapped);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpWaitForDisconnect(SafeHandle requestQueueHandle, ulong connectionId, NativeOverlapped* pOverlapped);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpReceiveRequestEntityBody(SafeHandle requestQueueHandle, ulong requestId, uint flags, void* pEntityBuffer, uint entityBufferLength, out uint bytesReturned, NativeOverlapped* pOverlapped);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpReceiveRequestEntityBody(SafeHandle requestQueueHandle, ulong requestId, uint flags, void* pEntityBuffer, uint entityBufferLength, out uint bytesReturned, NativeOverlapped* pOverlapped);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpSendResponseEntityBody(SafeHandle requestQueueHandle, ulong requestId, uint flags, ushort entityChunkCount, HTTP_DATA_CHUNK* pEntityChunks, uint* pBytesSent, SafeLocalAllocHandle pRequestBuffer, uint requestBufferLength, NativeOverlapped* pOverlapped, void* pLogData);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpSendResponseEntityBody(SafeHandle requestQueueHandle, ulong requestId, uint flags, ushort entityChunkCount, HTTP_DATA_CHUNK* pEntityChunks, uint* pBytesSent, SafeLocalAllocHandle pRequestBuffer, uint requestBufferLength, NativeOverlapped* pOverlapped, void* pLogData);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern uint HttpCloseRequestQueue(IntPtr pReqQueueHandle);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static partial uint HttpCloseRequestQueue(IntPtr pReqQueueHandle);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern uint HttpCancelHttpRequest(SafeHandle requestQueueHandle, ulong requestId, IntPtr pOverlapped);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static partial uint HttpCancelHttpRequest(SafeHandle requestQueueHandle, ulong requestId, IntPtr pOverlapped);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern uint HttpCloseServerSession(ulong serverSessionId);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static partial uint HttpCloseServerSession(ulong serverSessionId);
 
         internal sealed class SafeLocalFreeChannelBinding : ChannelBinding
         {
@@ -530,11 +530,11 @@ internal static partial class Interop
             }
         }
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpReceiveClientCertificate(SafeHandle requestQueueHandle, ulong connectionId, uint flags, HTTP_SSL_CLIENT_CERT_INFO* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpReceiveClientCertificate(SafeHandle requestQueueHandle, ulong connectionId, uint flags, HTTP_SSL_CLIENT_CERT_INFO* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
 
-        [DllImport(Libraries.HttpApi, SetLastError = true)]
-        internal static extern unsafe uint HttpReceiveClientCertificate(SafeHandle requestQueueHandle, ulong connectionId, uint flags, byte* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
+        [GeneratedDllImport(Libraries.HttpApi, SetLastError = true)]
+        internal static unsafe partial uint HttpReceiveClientCertificate(SafeHandle requestQueueHandle, ulong connectionId, uint flags, byte* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
 
         internal static readonly string?[] HttpVerbs = new string?[]
         {
index f5fdb6c..92e78b8 100644 (file)
@@ -11,7 +11,7 @@ internal static partial class Interop
         internal const int LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
         internal const int LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800;
 
-        [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryExW", SetLastError = true, ExactSpelling = true)]
-        internal static extern IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags);
+        [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryExW", SetLastError = true, ExactSpelling = true)]
+        internal static partial IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags);
     }
 }
index eadda76..9d771af 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern void WebSocketAbortHandle([In] SafeHandle webSocketHandle);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial void WebSocketAbortHandle(SafeHandle webSocketHandle);
     }
 }
index b082e8d..c79f029 100644 (file)
@@ -9,10 +9,10 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern void WebSocketCompleteAction(
-            [In] SafeHandle webSocketHandle,
-            [In] IntPtr actionContext,
-            [In] uint bytesTransferred);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial void WebSocketCompleteAction(
+            SafeHandle webSocketHandle,
+            IntPtr actionContext,
+            uint bytesTransferred);
     }
 }
index 6aeb2d1..dac7cc8 100644 (file)
@@ -10,10 +10,10 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern int WebSocketCreateClientHandle(
-           [In] Property[] properties,
-           [In] uint propertyCount,
-           [Out] out SafeWebSocketHandle webSocketHandle);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial int WebSocketCreateClientHandle(
+           Property[] properties,
+           uint propertyCount,
+           out SafeWebSocketHandle webSocketHandle);
     }
 }
index 672336c..c901426 100644 (file)
@@ -9,10 +9,10 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern int WebSocketCreateServerHandle(
-            [In]Property[] properties,
-            [In] uint propertyCount,
-            [Out] out SafeWebSocketHandle webSocketHandle);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial int WebSocketCreateServerHandle(
+            Property[] properties,
+            uint propertyCount,
+            out SafeWebSocketHandle webSocketHandle);
     }
 }
index f56255f..8be9ebe 100644 (file)
@@ -11,7 +11,7 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern int WebSocketEndServerHandshake([In] SafeHandle webSocketHandle);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial int WebSocketEndServerHandshake(SafeHandle webSocketHandle);
     }
 }
index 7cacdd4..567705d 100644 (file)
@@ -10,15 +10,15 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern int WebSocketGetAction(
-            [In] SafeHandle webSocketHandle,
-            [In] ActionQueue actionQueue,
-            [In, Out] Buffer[] dataBuffers,
-            [In, Out] ref uint dataBufferCount,
-            [Out] out System.Net.WebSockets.WebSocketProtocolComponent.Action action,
-            [Out] out BufferType bufferType,
-            [Out] out IntPtr applicationContext,
-            [Out] out IntPtr actionContext);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial int WebSocketGetAction(
+            SafeHandle webSocketHandle,
+            ActionQueue actionQueue,
+            Buffer[] dataBuffers,
+            ref uint dataBufferCount,
+            out System.Net.WebSockets.WebSocketProtocolComponent.Action action,
+            out BufferType bufferType,
+            out IntPtr applicationContext,
+            out IntPtr actionContext);
     }
 }
index 41b917b..3d40348 100644 (file)
@@ -9,10 +9,10 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket)]
-        internal static extern int WebSocketReceive(
-            [In] SafeHandle webSocketHandle,
-            [In] IntPtr buffers,
-            [In] IntPtr applicationContext);
+        [GeneratedDllImport(Libraries.WebSocket)]
+        internal static partial int WebSocketReceive(
+            SafeHandle webSocketHandle,
+            IntPtr buffers,
+            IntPtr applicationContext);
     }
 }
index 993709e..2a6c8fd 100644 (file)
@@ -10,18 +10,18 @@ internal static partial class Interop
 {
     internal static partial class WebSocket
     {
-        [DllImport(Libraries.WebSocket, EntryPoint = "WebSocketSend", ExactSpelling = true)]
-        internal static extern int WebSocketSend_Raw(
-            [In] SafeHandle webSocketHandle,
-            [In] BufferType bufferType,
-            [In] ref Buffer buffer,
-            [In] IntPtr applicationContext);
+        [GeneratedDllImport(Libraries.WebSocket, EntryPoint = "WebSocketSend", ExactSpelling = true)]
+        internal static partial int WebSocketSend_Raw(
+            SafeHandle webSocketHandle,
+            BufferType bufferType,
+            ref Buffer buffer,
+            IntPtr applicationContext);
 
-        [DllImport(Libraries.WebSocket, EntryPoint = "WebSocketSend", ExactSpelling = true)]
-        internal static extern int WebSocketSendWithoutBody_Raw(
-            [In] SafeHandle webSocketHandle,
-            [In] BufferType bufferType,
-            [In] IntPtr buffer,
-            [In] IntPtr applicationContext);
+        [GeneratedDllImport(Libraries.WebSocket, EntryPoint = "WebSocketSend", ExactSpelling = true)]
+        internal static partial int WebSocketSendWithoutBody_Raw(
+            SafeHandle webSocketHandle,
+            BufferType bufferType,
+            IntPtr buffer,
+            IntPtr applicationContext);
     }
 }