Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2006:
[Freeciv-Dev] (PR#19481) 2.1.0-beta: LAN server scan not working on Wind
Home

[Freeciv-Dev] (PR#19481) 2.1.0-beta: LAN server scan not working on Wind

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#19481) 2.1.0-beta: LAN server scan not working on Windows
From: "Christian Prochaska" <cp.ml.freeciv.dev@xxxxxxxxxxxxxx>
Date: Sat, 12 Aug 2006 16:44:29 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=19481 >

> [cproc - Sa 12. Aug 2006, 02:51:46]:
> 
> Tested on Windows 2000 and Windows 98:
> 
> Windows 2000, 2.1.0-beta GTK+ & SDL client:
> 
> server_scan_begin() returns a pointer != NULL, but then in
> get_lan_server_list() the clients don't get out of the while(1) loop and
> "freeze"
> 
> Windows 98, 2.1.0-beta SDL client:
> 
> server_scan_begin() returns NULL
> 
> Metaserver scanning works fine with the 2.1.0-beta SDL client on both
> systems (switching to the metaserver tab in the 2.1.0-beta GTK+ client
> was not possible), and LAN server scanning works fine with the 2.0.8
> GTK+ client on Windows 2000. The gui-win32 client doesn't scan for lan
> servers, so I couldn't test the functionality with a 2.0.8 client on
> Windows 98. 
> 
> 

This patch fixes it for both Windows versions.

Index: client/servers.c
===================================================================
--- client/servers.c    (revision 12251)
+++ client/servers.c    (working copy)
@@ -422,13 +422,11 @@
   my_nonblock(s);
   
   if (connect(s, (struct sockaddr *) &addr.sockaddr, sizeof(addr)) == -1) {
-    if (
 #ifdef HAVE_WINSOCK
-       errno == WSAEINPROGRESS
+    if ((WSAGetLastError() == WSAEWOULDBLOCK) || (WSAGetLastError() == 
WSAEINPROGRESS)) {
 #else
-       errno == EINPROGRESS
+    if (errno == EINPROGRESS) {
 #endif
-       ) {
       /* With non-blocking sockets this is the expected result. */
       scan->meta.state = META_CONNECTING;
       scan->sock = s;
@@ -542,8 +540,10 @@
   unsigned char buffer[MAX_LEN_PACKET];
   struct ip_mreq mreq;
   const char *group;
+  size_t size;
+#ifndef HAVE_WINSOCK
   unsigned char ttl;
-  size_t size;
+#endif
 
   /* Create a socket for broadcasting to servers. */
   if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
@@ -563,13 +563,17 @@
   addr.sockaddr_in.sin_addr.s_addr = inet_addr(get_multicast_group());
   addr.sockaddr_in.sin_port = htons(SERVER_LAN_PORT);
 
+/* this setsockopt call fails on Windows 98, so we stick with the default
+ * value of 1 which should be fine in most cases */
+#ifndef HAVE_WINSOCK
   /* Set the Time-to-Live field for the packet  */
   ttl = SERVER_LAN_TTL;
-  if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&ttl, 
+  if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&ttl,
                  sizeof(ttl))) {
     freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return FALSE;
   }
+#endif
 
   if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, 
                  sizeof(opt))) {
Index: common/connection.c
===================================================================
--- common/connection.c (revision 12251)
+++ common/connection.c (working copy)
@@ -174,7 +174,11 @@
     return -1;
   }
 #ifdef NONBLOCKING_SOCKETS
+#ifdef HAVE_WINSOCK
+  else if (WSAGetLastError() == WSAEWOULDBLOCK) {
+#else
   else if (errno == EWOULDBLOCK || errno == EAGAIN) {
+#endif
     freelog(LOG_DEBUG, "EGAIN on socket read");
     return 0;
   }
@@ -240,7 +244,11 @@
       if((nput=my_writesocket(pc->sock, 
                              (const char *)buf->data+start, nblock)) == -1) {
 #ifdef NONBLOCKING_SOCKETS
+#ifdef HAVE_WINSOCK
+       if (WSAGetLastError() == WSAEWOULDBLOCK) {
+#else
        if (errno == EWOULDBLOCK || errno == EAGAIN) {
+#endif
          break;
        }
 #endif
Index: configure.ac
===================================================================
--- configure.ac        (revision 12251)
+++ configure.ac        (working copy)
@@ -337,6 +337,7 @@
   AC_DEFINE(ALWAYS_ROOT, 1, [Mingw32-specific setting - root])
   AC_DEFINE(WIN32_NATIVE, 1, [Mingw32-specific setting - native])
   AC_DEFINE(HAVE_WINSOCK, 1, [Mingw32-specific setting - winsock])
+  AC_DEFINE(NONBLOCKING_SOCKETS, 1, [nonblocking sockets support])
   LIBS="$LIBS -lwsock32"
 fi
 
Index: server/sernet.c
===================================================================
--- server/sernet.c     (revision 12251)
+++ server/sernet.c     (working copy)
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1128,7 +1128,9 @@
   int socksend, setting = 1;
   const char *group;
   size_t size;
+#ifndef HAVE_WINSOCK
   unsigned char ttl;
+#endif
 
   /* Create a socket to broadcast to client. */
   if ((socksend = socket(AF_INET,SOCK_DGRAM, 0)) < 0) {
@@ -1143,15 +1145,19 @@
   addr.sockaddr_in.sin_addr.s_addr = inet_addr(group);
   addr.sockaddr_in.sin_port = htons(SERVER_LAN_PORT + 1);
 
+/* this setsockopt call fails on Windows 98, so we stick with the default
+ * value of 1 which should be fine in most cases */
+#ifndef HAVE_WINSOCK
   /* Set the Time-to-Live field for the packet.  */
   ttl = SERVER_LAN_TTL;
-  if (setsockopt(socksend, IPPROTO_IP, IP_MULTICAST_TTL, 
+  if (setsockopt(socksend, IPPROTO_IP, IP_MULTICAST_TTL,
                  (const char*)&ttl, sizeof(ttl))) {
     freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return;
   }
+#endif
 
-  if (setsockopt(socksend, SOL_SOCKET, SO_BROADCAST, 
+  if (setsockopt(socksend, SOL_SOCKET, SO_BROADCAST,
                  (const char*)&setting, sizeof(setting))) {
     freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return;
Index: utility/netintf.c
===================================================================
--- utility/netintf.c   (revision 12251)
+++ utility/netintf.c   (working copy)
@@ -132,6 +132,10 @@
 void my_nonblock(int sockfd)
 {
 #ifdef NONBLOCKING_SOCKETS
+#ifdef HAVE_WINSOCK
+  unsigned long b = 1;
+  ioctlsocket(sockfd, FIONBIO, &b);
+#else
 #ifdef HAVE_FCNTL
   int f_set;
 
@@ -153,6 +157,7 @@
   }
 #endif
 #endif
+#endif
 #else
   freelog(LOG_DEBUG, "NONBLOCKING_SOCKETS not available");
 #endif

[Prev in Thread] Current Thread [Next in Thread]