Added Microsoft-specific winsock constructs to Ws2_32

pull/350/head
David Hall 2022-10-26 23:03:47 -06:00
parent e977b1eebf
commit 7d9101e977
6 changed files with 10690 additions and 6982 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,14 @@ using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
namespace Vanara.PInvoke;
/// <summary>Functions, structures and constants from ws2_32.h.</summary>
public static partial class Ws2_32
{
/// <summary/>
public static readonly uint SIO_NSP_NOTIFY_CHANGE = _WSAIOW(IOC_WS2, 25);
/// <summary>
/// An opaque data structure object from the service provider associated with socket s. This object stores the current configuration
/// information of the service provider. The exact format of this data structure is service provider specific.
@ -33,40 +36,10 @@ namespace Vanara.PInvoke
[CorrespondingType(typeof(BOOL))]
public const int SO_CONDITIONAL_ACCEPT = 0x3002;
/// <summary></summary>
public const int SO_CONNDATA = 0x7000;
/// <summary></summary>
public const int SO_CONNDATALEN = 0x7004;
/// <summary>
/// Returns the number of seconds a socket has been connected. This socket option is valid for connection oriented protocols only.
/// </summary>
[CorrespondingType(typeof(uint))]
public const int SO_CONNECT_TIME = 0x700C;
/// <summary></summary>
public const int SO_CONNOPT = 0x7001;
/// <summary></summary>
public const int SO_CONNOPTLEN = 0x7005;
/// <summary>Debugging is enabled.</summary>
[CorrespondingType(typeof(BOOL))]
public const int SO_DEBUG = 0x0001;
/// <summary></summary>
public const int SO_DISCDATA = 0x7002;
/// <summary></summary>
public const int SO_DISCDATALEN = 0x7006;
/// <summary></summary>
public const int SO_DISCOPT = 0x7003;
/// <summary></summary>
public const int SO_DISCOPTLEN = 0x7007;
/// <summary>If TRUE, the SO_LINGER option is disabled.</summary>
[CorrespondingType(typeof(BOOL))]
public const int SO_DONTLINGER = (int)~SO_LINGER;
@ -110,12 +83,6 @@ namespace Vanara.PInvoke
[CorrespondingType(typeof(uint))]
public const int SO_MAX_MSG_SIZE = 0x2003;
/// <summary></summary>
public const int SO_MAXDG = 0x7009;
/// <summary></summary>
public const int SO_MAXPATHDG = 0x700A;
/// <summary>
/// OOB data is being received in the normal data stream. (See section Windows Sockets 1.1 Blocking Routines and EINPROGRESS for a
/// discussion of this topic.)
@ -173,9 +140,6 @@ namespace Vanara.PInvoke
[CorrespondingType(typeof(int))]
public const int SO_TYPE = 0x1008;
/// <summary></summary>
public const int SO_UPDATE_ACCEPT_CONTEXT = 0x700B;
/// <summary></summary>
public const int SO_USELOOPBACK = 0x0040;
@ -188,9 +152,6 @@ namespace Vanara.PInvoke
/// <summary>Maximum queue length specifiable by listen.</summary>
public const int SOMAXCONN = 0x7fffffff;
/// <summary></summary>
public const int TCP_BSDURGENT = 0x7000;
/// <summary>Disables the Nagle algorithm for send coalescing.</summary>
[CorrespondingType(typeof(BOOL))]
public const int TCP_NODELAY = 0x0001;
@ -2713,4 +2674,3 @@ namespace Vanara.PInvoke
public override string ToString() => sa_family == ADDRESS_FAMILY.AF_INET ? ((SOCKADDR_IN)this).ToString() : ((SOCKADDR_IN6)this).ToString();
}
}
}

View File

@ -3,11 +3,52 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
namespace Vanara.PInvoke;
/// <summary>Functions, structures and constants from ws2_32.h.</summary>
public static partial class Ws2_32
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public static readonly uint SIO_ABSORB_RTRALERT = _WSAIOW(IOC_VENDOR, 5);
public static readonly uint SIO_ACQUIRE_PORT_RESERVATION = _WSAIOW(IOC_VENDOR, 100);
public static readonly uint SIO_APPLY_TRANSPORT_SETTING = _WSAIOW(IOC_VENDOR, 19);
public static readonly uint SIO_ASSOCIATE_PORT_RESERVATION = _WSAIOW(IOC_VENDOR, 102);
public static readonly uint SIO_CPU_AFFINITY = _WSAIOW(IOC_VENDOR, 21);
public static readonly uint SIO_DELETE_PEER_TARGET_NAME = _WSAIOW(IOC_VENDOR, 203);
public static readonly uint SIO_GET_TX_TIMESTAMP = _WSAIOW(IOC_VENDOR, 234);
public static readonly uint SIO_INDEX_ADD_MCAST = _WSAIOW(IOC_VENDOR, 10);
public static readonly uint SIO_INDEX_BIND = _WSAIOW(IOC_VENDOR, 8);
public static readonly uint SIO_INDEX_DEL_MCAST = _WSAIOW(IOC_VENDOR, 11);
public static readonly uint SIO_INDEX_MCASTIF = _WSAIOW(IOC_VENDOR, 9);
public static readonly uint SIO_KEEPALIVE_VALS = _WSAIOW(IOC_VENDOR, 4);
public static readonly uint SIO_LIMIT_BROADCASTS = _WSAIOW(IOC_VENDOR, 7);
public static readonly uint SIO_LOOPBACK_FAST_PATH = _WSAIOW(IOC_VENDOR, 16);
public static readonly uint SIO_PRIORITY_HINT = SIO_SET_PRIORITY_HINT;
public static readonly uint SIO_QUERY_RSS_SCALABILITY_INFO = _WSAIOR(IOC_VENDOR, 210);
public static readonly uint SIO_QUERY_SECURITY = _WSAIORW(IOC_VENDOR, 201);
public static readonly uint SIO_QUERY_TRANSPORT_SETTING = _WSAIOW(IOC_VENDOR, 20);
public static readonly uint SIO_QUERY_WFP_ALE_ENDPOINT_HANDLE = _WSAIOR(IOC_VENDOR, 205);
public static readonly uint SIO_QUERY_WFP_CONNECTION_REDIRECT_CONTEXT = _WSAIOW(IOC_VENDOR, 221);
public static readonly uint SIO_QUERY_WFP_CONNECTION_REDIRECT_RECORDS = _WSAIOW(IOC_VENDOR, 220);
public static readonly uint SIO_RCVALL = _WSAIOW(IOC_VENDOR, 1);
public static readonly uint SIO_RCVALL_IF = _WSAIOW(IOC_VENDOR, 14);
public static readonly uint SIO_RCVALL_IGMPMCAST = _WSAIOW(IOC_VENDOR, 3);
public static readonly uint SIO_RCVALL_MCAST = _WSAIOW(IOC_VENDOR, 2);
public static readonly uint SIO_RCVALL_MCAST_IF = _WSAIOW(IOC_VENDOR, 13);
public static readonly uint SIO_RELEASE_PORT_RESERVATION = _WSAIOW(IOC_VENDOR, 101);
public static readonly uint SIO_SET_PEER_TARGET_NAME = _WSAIOW(IOC_VENDOR, 202);
public static readonly uint SIO_SET_PRIORITY_HINT = _WSAIOW(IOC_VENDOR, 24);
public static readonly uint SIO_SET_SECURITY = _WSAIOW(IOC_VENDOR, 200);
public static readonly uint SIO_SET_WFP_CONNECTION_REDIRECT_RECORDS = _WSAIOW(IOC_VENDOR, 222);
public static readonly uint SIO_SOCKET_USAGE_NOTIFICATION = _WSAIOW(IOC_VENDOR, 204);
public static readonly uint SIO_TCP_INFO = _WSAIORW(IOC_VENDOR, 39);
public static readonly uint SIO_TCP_INITIAL_RTO = _WSAIOW(IOC_VENDOR, 17);
public static readonly uint SIO_TCP_SET_ACK_FREQUENCY = _WSAIOW(IOC_VENDOR, 23);
public static readonly uint SIO_TCP_SET_ICW = _WSAIOW(IOC_VENDOR, 22);
public static readonly uint SIO_TIMESTAMPING = _WSAIOW(IOC_VENDOR, 235);
public static readonly uint SIO_UCAST_IF = _WSAIOW(IOC_VENDOR, 6);
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// <summary>
/// The CONTROL_CHANNEL_TRIGGER_STATUS enumeration specifies the status from a query for the <c>REAL_TIME_NOTIFICATION_CAPABILITY</c>
/// transport setting for a TCP socket that is used with ControlChannelTrigger to receive background network notifications in a
@ -1128,4 +1169,3 @@ namespace Vanara.PInvoke
public Guid Guid;
}
}
}

View File

@ -0,0 +1,144 @@
global using PRIO_BUF = System.IntPtr;
global using RIO_BUFFERID = System.IntPtr;
global using RIO_CQ = System.IntPtr;
global using RIO_RQ = System.IntPtr;
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke;
public static partial class Ws2_32
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public const int RIO_MAX_CQ_SIZE = 0x8000000;
public static readonly RIO_CQ RIO_CORRUPT_CQ = (RIO_CQ)0xFFFFFFFF;
public static readonly RIO_BUFFERID RIO_INVALID_BUFFERID = (RIO_BUFFERID)0xFFFFFFFF;
public static readonly RIO_CQ RIO_INVALID_CQ = (RIO_CQ)0;
public static readonly RIO_RQ RIO_INVALID_RQ = (RIO_RQ)0;
public static readonly uint SIO_SET_COMPATIBILITY_MODE = _WSAIOW(IOC_VENDOR, 300);
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// <summary>A set of flags that modify the behavior of the <c>RIOSendEx</c> function.</summary>
[PInvokeData("mswsockdef.h", MSDNShortId = "NC:mswsock.LPFN_RIORECEIVE")]
[Flags]
public enum RIO_MSG
{
/// <summary>
/// The request should not trigger the <c>RIONotify</c> function when request completion is inserted into its completion queue.
/// </summary>
RIO_MSG_DONT_NOTIFY = 0x00000001,
/// <summary>
/// The request does not need to be executed immediately. This will insert the request into the request queue, but it may or may not
/// trigger the execution of the request. Sending data may be delayed until a send request is made on the <c>RIO_RQ</c> passed in the
/// <c>SocketQueue</c> parameter without the <c>RIO_MSG_DEFER</c> flag set. To trigger execution for all sends in a send queue, call
/// the <c>RIOSend</c> or <c>RIOSendEx</c> function without the <c>RIO_MSG_DEFER</c> flag set. <c>Note</c> The send request is
/// charged against the outstanding I/O capacity on the <c>RIO_RQ</c> passed in the <c>SocketQueue</c> parameter regardless of
/// whether <c>RIO_MSG_DEFER</c> is set.
/// </summary>
RIO_MSG_DEFER = 0x00000002,
/// <summary>
/// Causes the recv call to only complete when the buffer slice supplied is full, an error occurs, or the connection is terminated.
/// </summary>
RIO_MSG_WAITALL = 0x00000004,
/// <summary>
/// Previous requests added with <c>RIO_MSG_DEFER</c> flag will be committed. When the <c>RIO_MSG_COMMIT_ONLY</c> flag is set, no
/// other flags may be specified. When the <c>RIO_MSG_COMMIT_ONLY</c> flag is set, the <c>pData</c>, <c>pLocalAddress</c>,
/// <c>pRemoteAddress</c>, <c>pControlContext</c>, <c>pFlags</c>, and <c>RequestContext</c> parameters must be NULL and the
/// <c>DataBufferCount</c> parameter must be zero. This flag would normally be used occasionally after a number of requests were
/// issued with the <c>RIO_MSG_DEFER</c> flag set. This eliminates the need when using the <c>RIO_MSG_DEFER</c> flag to make the last
/// request without the <c>RIO_MSG_DEFER</c> flag, which causes the last request to complete much slower than other requests. Unlike
/// other calls to the <c>RIOSendEx</c> function, when the <c>RIO_MSG_COMMIT_ONLY</c> flag is set calls to the <c>RIOSendEx</c>
/// function do not need to be serialized. For a single <c>RIO_RQ</c>, the <c>RIOSendEx</c> function can be called with
/// <c>RIO_MSG_COMMIT_ONLY</c> on one thread while calling the <c>RIOSendEx</c> function on another thread.
/// </summary>
RIO_MSG_COMMIT_ONLY = 0x00000008,
}
/// <summary>
/// The <c>RIO_BUF</c> structure specifies a portion of a registered buffer used for sending or receiving network data with the Winsock
/// registered I/O extensions.
/// </summary>
/// <remarks>
/// <para>
/// The Winsock registered I/O extensions often operate on portions of registered buffers sometimes called buffer slices. The
/// <c>RIO_BUF</c> structure is used by an application that needs to use a small amount of registered memory for sending or receiving
/// network data. The application can often increase performance by registering one large buffer and then using small chunks of the
/// buffer as needed. The <c>RIO_BUF</c> structure may describe any contiguous segment of memory contained in a single buffer registration.
/// </para>
/// <para>
/// A pointer to a <c>RIO_BUF</c> structure is passed as the <c>pData</c> parameter to the RIOSend, RIOSendEx, RIOReceive, and
/// RIOReceiveEx functions to send or receive network data.
/// </para>
/// <para>
/// An application cannot resize a registered buffer simply by using a buffer slice with values larger than the original buffer that was
/// registered using the RIORegisterBuffer function.
/// </para>
/// <para>
/// The <c>RIO_BUF</c> structure is defined in the <c>Mswsockdef.h</c> header file which is automatically included in the
/// <c>Mswsock.h</c> header file. The <c>Mswsockdef.h</c> header file should never be used directly.
/// </para>
/// </remarks>
// https://learn.microsoft.com/en-us/windows/win32/api/mswsockdef/ns-mswsockdef-rio_buf typedef struct _RIO_BUF { RIO_BUFFERID BufferId;
// ULONG Offset; ULONG Length; } RIO_BUF, *PRIO_BUF;
[PInvokeData("mswsockdef.h", MSDNShortId = "NS:mswsockdef._RIO_BUF")]
[StructLayout(LayoutKind.Sequential)]
public struct RIO_BUF
{
/// <summary>The registered buffer descriptor for a Winsock registered I/O buffer used with send and receive requests.</summary>
public RIO_BUFFERID BufferId;
/// <summary>
/// The offset, in bytes, into the buffer specified by the <c>BufferId</c> member. An <c>Offset</c> value of zero points to the
/// beginning of the buffer
/// </summary>
public uint Offset;
/// <summary>A length, in bytes, of the buffer to use from the <c>Offset</c> member.</summary>
public uint Length;
}
/// <summary>
/// The <c>RIORESULT</c> structure contains data used to indicate request completion results used with the Winsock registered I/O extensions.
/// </summary>
/// <remarks>
/// <para>
/// The <c>RIORESULT</c> structure defines the data format used to indicate request completion by the Winsock registered I/O extensions.
/// An application requests completion indications by allocating an array of <c>RIORESULT</c> structures and passing the array of
/// <c>RIORESULT</c> structures to the RIODequeueCompletion function along with the element count. The application need not perform any
/// initialization of the <c>RIORESULT</c> structure elements before calling the <c>RIODequeueCompletion</c> function.
/// </para>
/// <para>
/// The <c>SocketContext</c> member of the <c>RIORESULT</c> structure can be used by an application to identify the RIO_CQ object or the
/// associated application object on which the Winsock registered I/O request was issued. The <c>RequestContext</c> member of the
/// <c>RIORESULT</c> structure can similarly be used to identify the particular Winsock registered I/O request that was completed.
/// </para>
/// <para>
/// The <c>RIORESULT</c> structure is defined in the <c>Mswsockdef.h</c> header file which is automatically included in the
/// <c>Mswsock.h</c> header file. The <c>Mswsockdef.h</c> header file should never be used directly.
/// </para>
/// </remarks>
// https://learn.microsoft.com/en-us/windows/win32/api/mswsockdef/ns-mswsockdef-rioresult typedef struct _RIORESULT { LONG Status; ULONG
// BytesTransferred; ULONGLONG SocketContext; ULONGLONG RequestContext; } RIORESULT, *PRIORESULT;
[PInvokeData("mswsockdef.h", MSDNShortId = "NS:mswsockdef._RIORESULT")]
[StructLayout(LayoutKind.Sequential)]
public struct RIORESULT
{
/// <summary>The completion status of the Winsock registered I/O request.</summary>
public int Status;
/// <summary>The number of bytes sent or received in the I/O request.</summary>
public uint BytesTransferred;
/// <summary>An application-provided context specified in call to the RIOCreateRequestQueue function.</summary>
public ulong SocketContext;
/// <summary>
/// An application-provided context specified with the registered I/O request to the RIOReceive, RIOReceiveEx, RIOSend, and RIOSendEx functions.
/// </summary>
public ulong RequestContext;
}
}

View File

@ -6,10 +6,45 @@ using Vanara.Extensions;
using Vanara.InteropServices;
#pragma warning disable IDE1006 // Naming Styles
namespace Vanara.PInvoke
{
namespace Vanara.PInvoke;
public static partial class Ws2_32
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public const uint IOC_UNIX = 0x00000000;
public const uint IOC_WS2 = 0x08000000;
public const uint IOC_PROTOCOL = 0x10000000;
public const uint IOC_VENDOR = 0x18000000;
public const uint IOC_WSK = 0x0F000000;
public static uint _WSAIO(uint x, uint y) => IOC_VOID|x|y;
public static uint _WSAIOR(uint x, uint y) => IOC_OUT|x|y;
public static uint _WSAIOW(uint x, uint y) => IOC_IN|x|y;
public static uint _WSAIORW(uint x, uint y) => IOC_INOUT|x|y;
public static readonly uint SIO_ASSOCIATE_HANDLE = _WSAIOW(IOC_WS2,1);
public static readonly uint SIO_ENABLE_CIRCULAR_QUEUEING = _WSAIO(IOC_WS2,2);
public static readonly uint SIO_FIND_ROUTE = _WSAIOR(IOC_WS2,3);
public static readonly uint SIO_FLUSH = _WSAIO(IOC_WS2,4);
public static readonly uint SIO_GET_BROADCAST_ADDRESS = _WSAIOR(IOC_WS2,5);
public static readonly uint SIO_GET_EXTENSION_FUNCTION_POINTER = _WSAIORW(IOC_WS2,6);
public static readonly uint SIO_GET_QOS = _WSAIORW(IOC_WS2,7);
public static readonly uint SIO_GET_GROUP_QOS = _WSAIORW(IOC_WS2,8);
public static readonly uint SIO_MULTIPOINT_LOOPBACK = _WSAIOW(IOC_WS2,9);
public static readonly uint SIO_MULTICAST_SCOPE = _WSAIOW(IOC_WS2,10);
public static readonly uint SIO_SET_QOS = _WSAIOW(IOC_WS2,11);
public static readonly uint SIO_SET_GROUP_QOS = _WSAIOW(IOC_WS2,12);
public static readonly uint SIO_TRANSLATE_HANDLE = _WSAIORW(IOC_WS2,13);
public static readonly uint SIO_ROUTING_INTERFACE_QUERY = _WSAIORW(IOC_WS2,20);
public static readonly uint SIO_ROUTING_INTERFACE_CHANGE = _WSAIOW(IOC_WS2,21);
public static readonly uint SIO_ADDRESS_LIST_QUERY = _WSAIOR(IOC_WS2,22);
public static readonly uint SIO_ADDRESS_LIST_CHANGE = _WSAIO(IOC_WS2,23);
public static readonly uint SIO_QUERY_TARGET_PNP_HANDLE = _WSAIOR(IOC_WS2,24);
public static readonly uint SIO_QUERY_RSS_PROCESSOR_INFO = _WSAIOR(IOC_WS2,37);
public static readonly uint SIO_ADDRESS_LIST_SORT = _WSAIORW(IOC_WS2,25);
public static readonly uint SIO_RESERVED_1 = _WSAIOW(IOC_WS2,26);
public static readonly uint SIO_RESERVED_2 = _WSAIOW(IOC_WS2,33);
public static readonly uint SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER = _WSAIORW(IOC_WS2, 36);
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// <summary>Flags that indicate options used in the GetAddrInfoW function.</summary>
[PInvokeData("ws2def.h", MSDNShortId = "a4896eac-68ae-4a08-8647-36be65fe4478")]
[Flags]
@ -2226,4 +2261,3 @@ namespace Vanara.PInvoke
private static uint _WSAIOW(uint x, uint y) => IOC_IN | (x) | (y);
}
}
}

View File

@ -4,8 +4,8 @@ using Vanara.Extensions;
using Vanara.InteropServices;
#pragma warning disable IDE1006 // Naming Styles
namespace Vanara.PInvoke
{
namespace Vanara.PInvoke;
public static partial class Ws2_32
{
/// <summary/>
@ -808,4 +808,3 @@ namespace Vanara.PInvoke
}
}
}
}