pond3r/ggpo

WSANOTINITIALISED 10093 Error Code

hlimbo opened this issue · 1 comments

Dependencies Used

  • Visual Studio 2019
  • Windows 10
  • ggpo.lib
  • ggpo.dll
  • SDL2

Summary

When I attempt to build ggpo as a .dll and .lib file to use as a dependency for my own project, I end up receiving the following error below:

image

Looking at the code snippet below (udp.cpp):

void
Udp::SendTo(char *buffer, int len, int flags, struct sockaddr *dst, int destlen)
{
   struct sockaddr_in *to = (struct sockaddr_in *)dst;

   int res = sendto(_socket, buffer, len, flags, dst, destlen);
   if (res == SOCKET_ERROR) {
      DWORD err = WSAGetLastError();
      Log("unknown error in sendto (erro: %d  wsaerr: %d).\n", res, err);
      ASSERT(FALSE && "Unknown error in sendto");
   }
   char dst_ip[1024];
   Log("sent packet length %d to %s:%d (ret:%d).\n", len, inet_ntop(AF_INET, (void *)&to->sin_addr, dst_ip, ARRAY_SIZE(dst_ip)), ntohs(to->sin_port), res);
}

I end up getting a SOCKET_ERROR when the sendto(...) function is called. It turns out the error I get back is error code: 10093. Based on Microsoft's documentation, error code https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2, error code 10093 means that Win Sockets dependency hasn't been initialized yet.

Steps to Reproduce:

  • The following simplified code will reproduce the issue:
// assume callbacks, game state, non game state,  and port numbers are already defined somewhere else

const int NUM_PLAYERS = 2;
GGPOSession *ggpo = NULL;

GGPOSessionCallbacks cb = { 0 };
cb.begin_game      = vw_begin_game_callback;
cb.advance_frame	 = vw_advance_frame_callback;
cb.load_game_state = vw_load_game_state_callback;
cb.save_game_state = vw_save_game_state_callback;
cb.free_buffer     = vw_free_buffer;
cb.on_event        = vw_on_event_callback;
cb.log_game_state  = vw_log_game_state;

ggpo_start_session(&ggpo, &cb, "rollback_tech_demo", NUM_PLAYERS, sizeof(int), localPort);

ggpo_set_disconnect_timeout(ggpo, 3000);
ggpo_set_disconnect_notify_start(ggpo, 1000);

// Calls to ggpo_add_player() made but omitted to keep simple

int maxTimeIdleMillis = 6;
ggpo_idle(ggpo, maxTimeIdleMillis);

// sends input request over the network using UDP protocol internally
// Looks like this fails because Winsockets hasn't been initialized yet.
ggpo_add_local_input(ggpo, ngs.local_player_handle, &localInputsThisFrame, sizeof(localInputsThisFrame));

ggpo_synchronize_input(ggpo, (void *)allInputs, sizeof(int) * NUM_PLAYERS, &disconnectFlags);

ggpo_advance_frame(ggpo);

I have proposed a fix in a following PR: #69