Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CreateSocket() [2/2]

static unsafe SocketError System.Net.Sockets.SocketPal.CreateSocket ( SocketInformation socketInformation,
out SafeSocketHandle socket,
ref AddressFamily addressFamily,
ref SocketType socketType,
ref ProtocolType protocolType )
inlinestatic

Definition at line 49 of file SocketPal.cs.

50 {
51 if (socketInformation.ProtocolInformation == null || socketInformation.ProtocolInformation.Length < sizeof(global::Interop.Winsock.WSAPROTOCOL_INFOW))
52 {
54 }
55 global::Interop.Winsock.EnsureInitialized();
56 fixed (byte* ptr = socketInformation.ProtocolInformation)
57 {
58 IntPtr preexistingHandle = global::Interop.Winsock.WSASocketW(AddressFamily.Unknown, SocketType.Unknown, ProtocolType.Unknown, (IntPtr)ptr, 0u, global::Interop.Winsock.SocketConstructorFlags.WSA_FLAG_OVERLAPPED | global::Interop.Winsock.SocketConstructorFlags.WSA_FLAG_NO_HANDLE_INHERIT);
59 socket = new SafeSocketHandle(preexistingHandle, ownsHandle: true);
60 if (socket.IsInvalid)
61 {
62 SocketError lastSocketError = GetLastSocketError();
63 if (System.Net.NetEventSource.Log.IsEnabled())
64 {
65 System.Net.NetEventSource.Error(null, $"WSASocketW failed with error {lastSocketError}", "CreateSocket");
66 }
67 socket.Dispose();
68 return lastSocketError;
69 }
70 if (!global::Interop.Kernel32.SetHandleInformation(socket, global::Interop.Kernel32.HandleFlags.HANDLE_FLAG_INHERIT, global::Interop.Kernel32.HandleFlags.None))
71 {
73 if (System.Net.NetEventSource.Log.IsEnabled())
74 {
75 System.Net.NetEventSource.Error(null, $"SetHandleInformation failed with error {lastSocketError2}", "CreateSocket");
76 }
77 socket.Dispose();
78 return lastSocketError2;
79 }
80 if (System.Net.NetEventSource.Log.IsEnabled())
81 {
82 System.Net.NetEventSource.Info(null, socket, "CreateSocket");
83 }
84 global::Interop.Winsock.WSAPROTOCOL_INFOW* ptr2 = (global::Interop.Winsock.WSAPROTOCOL_INFOW*)ptr;
85 addressFamily = ptr2->iAddressFamily;
86 socketType = ptr2->iSocketType;
87 protocolType = ptr2->iProtocol;
88 return SocketError.Success;
89 }
90 }
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static SocketError GetLastSocketError()
Definition SocketPal.cs:22
static string net_sockets_invalid_socketinformation
Definition SR.cs:114
Definition SR.cs:7

References System.Net.NetEventSource.Error(), System.Net.Sockets.SocketPal.GetLastSocketError(), System.Net.NetEventSource.Info(), System.Net.NetEventSource.Log, and System.SR.net_sockets_invalid_socketinformation.