Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue of winsocks not being initialized #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/include/ggponet.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ typedef struct GGPONetworkStats {
} timesync;
} GGPONetworkStats;

// Windows specific API to initialize windows sockets for network programming
GGPO_API GGPOErrorCode __cdecl ggpo_initialize_winsock();

// Windows specific API to deinitialize windows sockets for network programming
GGPO_API GGPOErrorCode __cdecl ggpo_deinitialize_winsock();

/*
* ggpo_start_session --
*
Expand Down
34 changes: 34 additions & 0 deletions src/lib/ggpo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ ggpo_logv(GGPOSession *ggpo, const char *fmt, va_list args)
}
}

GGPOErrorCode
ggpo_initialize_winsock()
{
#ifdef WIN32
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData;
int err = WSAStartup(wVersionRequested, &wsaData);

if (err != 0) {
// Can comment out following lines for debugging purposes
//printf("WSAStartup failed with error: %d\n", err);
//DWORD lastError = WSAGetLastError();
//printf("last error code: %d\n", lastError);
ASSERT(FALSE && "Error initializing winsockets");
}
#endif

return GGPO_ERRORCODE_SUCCESS;
}

GGPOErrorCode
ggpo_deinitialize_winsock()
{
#ifdef WIN32
// https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsacleanup
int result = WSACleanup();
if (result != 0) {
ASSERT(FALSE && "Error de-initializing winsockets");
}
#endif

return GGPO_ERRORCODE_SUCCESS;
}

GGPOErrorCode
ggpo_start_session(GGPOSession **session,
GGPOSessionCallbacks *cb,
Expand Down