# HG changeset patch # User reimar # Date 1314212048 0 # Node ID 6c1d39323b6eec92014c77d0523f4e860645f39e # Parent 54c6c38fcaaa57544e9cf06aa70154d073169141 Fix udp-slave on Windows: Make sure WSAStartup is called before networking functions are used and fix inverted set_blocking behaviour. diff -r 54c6c38fcaaa -r 6c1d39323b6e udp_sync.c --- a/udp_sync.c Tue Aug 23 20:04:40 2011 +0000 +++ b/udp_sync.c Wed Aug 24 18:54:08 2011 +0000 @@ -57,11 +57,23 @@ // how far off is still considered equal #define UDP_TIMING_TOLERANCE 0.02 +static void startup(void) +{ +#if HAVE_WINSOCK2_H + static int wsa_started; + if (!wsa_started) { + WSADATA wd; + WSAStartup(0x0202, &wd); + wsa_started = 1; + } +#endif +} + static void set_blocking(int fd, int blocking) { long sock_flags; #if HAVE_WINSOCK2_H - sock_flags = blocking; + sock_flags = !blocking; ioctlsocket(fd, FIONBIO, &sock_flags); #else sock_flags = fcntl(fd, F_GETFL, 0); @@ -86,6 +98,7 @@ struct timeval tv = { .tv_sec = 30 }; struct sockaddr_in servaddr = { 0 }; + startup(); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) return -1; @@ -133,6 +146,7 @@ static const int one = 1; int ip_valid = 0; + startup(); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) exit_player(EXIT_ERROR);