Add flag to control Winsocket initialization (#3060)

When WAMR is embedded to other application, the lifecycle of the socket
might conflict with other usecases. E.g. if WAMR is deinitialized before any
other use of sockets, the application goes into the invalid state. The new
flag allows host application to take control over the socket initialization.
This commit is contained in:
Marcin Kolny
2024-01-21 23:33:26 +00:00
committed by GitHub
parent 1977ad23ef
commit 627debcefb
2 changed files with 15 additions and 0 deletions

View File

@ -32,6 +32,7 @@ static bool is_winsock_inited = false;
int
init_winsock()
{
#if WASM_ENABLE_HOST_SOCKET_INIT == 0
WSADATA wsaData;
if (!is_winsock_inited) {
@ -42,6 +43,7 @@ init_winsock()
is_winsock_inited = true;
}
#endif
return BHT_OK;
}
@ -49,9 +51,11 @@ init_winsock()
void
deinit_winsock()
{
#if WASM_ENABLE_HOST_SOCKET_INIT == 0
if (is_winsock_inited) {
WSACleanup();
}
#endif
}
int