Skip to content

Commit

Permalink
Merge pull request #44 from paullouisageneau/fix-win-wsanotinitialized
Browse files Browse the repository at this point in the history
Fix WSANOTINITIALISED on Windows if app does not call WSAStartup
  • Loading branch information
paullouisageneau authored Dec 19, 2024
2 parents b8d3600 + a27e0fa commit 4c0abd3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ thread_return_t THREAD_CALL client_thread_entry(void *arg) {
}

client_t *client_create(void) {
PLUM_LOG_DEBUG("Creating client...");
PLUM_LOG_DEBUG("Creating client");

#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData)) {
PLUM_LOG_FATAL("WSAStartup failed");
return NULL;
}
#endif

client_t *client = malloc(sizeof(client_t));
if (!client) {
Expand All @@ -100,7 +108,7 @@ client_t *client_create(void) {
}

void client_destroy(client_t *client) {
PLUM_LOG_DEBUG("Destroying client...");
PLUM_LOG_DEBUG("Destroying client");

if (client->is_started) {
client_interrupt(client, true); // stop
Expand All @@ -112,6 +120,12 @@ void client_destroy(client_t *client) {

free(client->mappings);
free(client);

#ifdef _WIN32
WSACleanup();
#endif

PLUM_LOG_VERBOSE("Destroyed client");
}

int client_start(client_t *client) {
Expand Down

0 comments on commit 4c0abd3

Please sign in to comment.