1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-22 09:38:01 +02:00

Update Socket.bf

Allow specifying winsock version.
Added Uninit to cleanup winsock.

These are useful for other network libraries to reuse.
This commit is contained in:
Damian Day 2021-08-17 01:24:42 +01:00 committed by GitHub
parent f0cca6dc40
commit 3ce62c2d22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ namespace System.Net
{ {
class Socket class Socket
{ {
const uint16 WINSOCK_VERSION = 0x0202;
const int32 WSAENETRESET = 10052; const int32 WSAENETRESET = 10052;
const int32 WSAECONNABORTED = 10053; const int32 WSAECONNABORTED = 10053;
const int32 WSAECONNRESET = 10054; const int32 WSAECONNRESET = 10054;
@ -169,6 +170,9 @@ namespace System.Net
#if BF_PLATFORM_WINDOWS #if BF_PLATFORM_WINDOWS
[Import("wsock32.lib"), CLink, CallingConvention(.Stdcall)] [Import("wsock32.lib"), CLink, CallingConvention(.Stdcall)]
static extern int32 WSAStartup(uint16 versionRequired, WSAData* wsaData); static extern int32 WSAStartup(uint16 versionRequired, WSAData* wsaData);
[Import("wsock32.lib"), CLink, CallingConvention(.Stdcall)]
static extern int32 WSACleanup();
[Import("wsock32.lib"), CLink, CallingConvention(.Stdcall)] [Import("wsock32.lib"), CLink, CallingConvention(.Stdcall)]
static extern int32 WSAGetLastError(); static extern int32 WSAGetLastError();
@ -230,11 +234,22 @@ namespace System.Net
#endif #endif
} }
public static void Init() public static int32 Init(uint16 versionRequired = WINSOCK_VERSION)
{ {
#if BF_PLATFORM_WINDOWS #if BF_PLATFORM_WINDOWS
WSAData wsaData = default; WSAData wsaData = default;
WSAStartup(0x202, &wsaData); return WSAStartup(versionRequired, &wsaData);
#else
return 0;
#endif
}
public static int32 Uninit()
{
#if BF_PLATFORM_WINDOWS
return WSACleanup();
#else
return 0;
#endif #endif
} }