Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
7
8internal static class Interop
9{
10 internal static class Kernel32
11 {
12 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryExW", ExactSpelling = true, SetLastError = true)]
13 internal static extern IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags);
14 }
15
16 internal static class Winsock
17 {
18 internal struct AddressInfo
19 {
21
23
24 internal int ai_socktype;
25
26 internal int ai_protocol;
27
29
30 internal unsafe sbyte* ai_canonname;
31
32 internal unsafe byte* ai_addr;
33
34 internal unsafe AddressInfo* ai_next;
35 }
36
37 [StructLayout(LayoutKind.Sequential, Size = 408)]
38 private struct WSAData
39 {
40 }
41
42 internal struct AddressInfoEx
43 {
45
47
48 internal int ai_socktype;
49
50 internal int ai_protocol;
51
53
55
56 internal unsafe byte* ai_addr;
57
58 internal IntPtr ai_blob;
59
61
63
64 internal unsafe AddressInfoEx* ai_next;
65 }
66
67 private static int s_initialized;
68
69 [DllImport("ws2_32.dll", ExactSpelling = true, SetLastError = true)]
70 internal static extern SocketError closesocket([In] IntPtr socketHandle);
71
72 [DllImport("ws2_32.dll", SetLastError = true)]
73 internal unsafe static extern SocketError gethostname(byte* name, int namelen);
74
75 [DllImport("ws2_32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, SetLastError = true, ThrowOnUnmappableChar = true)]
76 internal unsafe static extern SocketError GetNameInfoW(byte* pSockaddr, int SockaddrLength, char* pNodeBuffer, int NodeBufferSize, char* pServiceBuffer, int ServiceBufferSize, int Flags);
77
78 [DllImport("ws2_32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, ThrowOnUnmappableChar = true)]
79 internal unsafe static extern int GetAddrInfoW([In] string pNameName, [In] string pServiceName, [In] AddressInfo* pHints, [Out] AddressInfo** ppResult);
80
81 [DllImport("ws2_32.dll", ExactSpelling = true, SetLastError = true)]
82 internal unsafe static extern void FreeAddrInfoW(AddressInfo* info);
83
84 internal static void EnsureInitialized()
85 {
86 if (s_initialized == 0)
87 {
88 Initialize();
89 }
90 unsafe static void Initialize()
91 {
92 Unsafe.SkipInit(out WSAData wSAData);
93 SocketError socketError = WSAStartup(514, &wSAData);
94 if (socketError != 0)
95 {
96 throw new SocketException((int)socketError);
97 }
98 if (Interlocked.CompareExchange(ref s_initialized, 1, 0) != 0)
99 {
100 socketError = WSACleanup();
101 }
102 }
103 }
104
105 [DllImport("ws2_32.dll")]
106 private unsafe static extern SocketError WSAStartup(short wVersionRequested, WSAData* lpWSAData);
107
108 [DllImport("ws2_32.dll")]
109 private static extern SocketError WSACleanup();
110
111 [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
112 internal static extern IntPtr WSASocketW([In] AddressFamily addressFamily, [In] SocketType socketType, [In] int protocolType, [In] IntPtr protocolInfo, [In] int group, [In] int flags);
113
114 [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
115 internal unsafe static extern int GetAddrInfoExW([In] string pName, [In] string pServiceName, [In] int dwNamespace, [In] IntPtr lpNspId, [In] AddressInfoEx* pHints, [Out] AddressInfoEx** ppResult, [In] IntPtr timeout, [In] NativeOverlapped* lpOverlapped, [In] delegate* unmanaged<int, int, NativeOverlapped*, void> lpCompletionRoutine, [Out] IntPtr* lpNameHandle);
116
117 [DllImport("ws2_32.dll", ExactSpelling = true)]
118 internal unsafe static extern int GetAddrInfoExCancel([In] IntPtr* lpHandle);
119
120 [DllImport("ws2_32.dll", ExactSpelling = true)]
121 internal unsafe static extern void FreeAddrInfoExW(AddressInfoEx* pAddrInfo);
122 }
123}
static void SetLastError(int errorCode)
static IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags)
static unsafe int GetAddrInfoW([In] string pNameName, [In] string pServiceName, [In] AddressInfo *pHints, [Out] AddressInfo **ppResult)
static unsafe SocketError GetNameInfoW(byte *pSockaddr, int SockaddrLength, char *pNodeBuffer, int NodeBufferSize, char *pServiceBuffer, int ServiceBufferSize, int Flags)
static unsafe void FreeAddrInfoExW(AddressInfoEx *pAddrInfo)
static IntPtr WSASocketW([In] AddressFamily addressFamily, [In] SocketType socketType, [In] int protocolType, [In] IntPtr protocolInfo, [In] int group, [In] int flags)
static SocketError WSACleanup()
static int s_initialized
Definition Interop.cs:67
static SocketError closesocket([In] IntPtr socketHandle)
static unsafe SocketError gethostname(byte *name, int namelen)
static unsafe int GetAddrInfoExW([In] string pName, [In] string pServiceName, [In] int dwNamespace, [In] IntPtr lpNspId, [In] AddressInfoEx *pHints, [Out] AddressInfoEx **ppResult, [In] IntPtr timeout, [In] NativeOverlapped *lpOverlapped, [In] delegate *unmanaged< int, int, NativeOverlapped *, void > lpCompletionRoutine, [Out] IntPtr *lpNameHandle)
static void EnsureInitialized()
Definition Interop.cs:84
static unsafe SocketError WSAStartup(short wVersionRequested, WSAData *lpWSAData)
static unsafe void FreeAddrInfoW(AddressInfo *info)
static unsafe int GetAddrInfoExCancel([In] IntPtr *lpHandle)
static int CompareExchange(ref int location1, int value, int comparand)
AddressInfoHints ai_flags
Definition Interop.cs:44
unsafe AddressInfoEx * ai_next
Definition Interop.cs:64
unsafe AddressInfo * ai_next
Definition Interop.cs:34
unsafe sbyte * ai_canonname
Definition Interop.cs:30
AddressFamily ai_family
Definition Interop.cs:22
unsafe byte * ai_addr
Definition Interop.cs:32
AddressInfoHints ai_flags
Definition Interop.cs:20