]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Workaround for non-blocking TCP sockets.
authornitroxis <nitroxis@wtwrp.de>
Sat, 18 Jan 2014 01:58:47 +0000 (02:58 +0100)
committernitroxis <nitroxis@wtwrp.de>
Sat, 18 Jan 2014 01:58:47 +0000 (02:58 +0100)
irc.c
lhnet.c

diff --git a/irc.c b/irc.c
index 3d003e112dd8c7d3bc92aebeb136efcd2ead4324..48ae7e310932479909d3f1971290cebe2cca9d0d 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -64,14 +64,22 @@ static int IRC_Connect(const char *addr)
                return 0;
        }
 
+#ifdef SUPPORTIPV6
+       if (!LHNETADDRESS_Resolve(&peeraddress, addr, 6667))
+       {
+               Con_Printf("[IRC] Bad server address: %s.\n", addr);
+               return 0;
+       }
+#else
        if (!LHNETADDRESS_FromString(&peeraddress, addr, 6667))
        {
                Con_Printf("[IRC] Bad server address: %s.\n", addr);
                return 0;
        }
+#endif
 
        // this should really be non-blocking, but it does not work.
-       if(!(irc_socket = LHNET_OpenSocket(&address, &peeraddress, 1, 1, 0)))
+       if(!(irc_socket = LHNET_OpenSocket(&address, &peeraddress, 1, 0, 0)))
        {
                Con_Printf("[IRC] Failed to open a socket.\n");
                return 0;
diff --git a/lhnet.c b/lhnet.c
index 9eae3d1d47d3881c516ad6fcce425b44fe5bb9bb..6781f2eccad93915ab074dbbe1cb39939ef2c2ff 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -1022,7 +1022,8 @@ lhnetsocket_t *LHNET_OpenSocket(lhnetaddress_t *address, lhnetaddress_t *peeradd
 #else
                                        char _true = 1;
 #endif
-                                       if (ioctlsocket(lhnetsocket->inetsocket, FIONBIO, use_blocking ? &_false : &_true) != -1)
+                                       if (1)
+                                       // if (ioctlsocket(lhnetsocket->inetsocket, FIONBIO, use_blocking ? &_false : &_true) != -1)
 #endif
                                        {
 #ifdef IPV6_V6ONLY
@@ -1059,25 +1060,34 @@ lhnetsocket_t *LHNET_OpenSocket(lhnetaddress_t *address, lhnetaddress_t *peeradd
                                                        {
                                                                if (LHNETSOCKET_TryConnect(lhnetsocket, peeraddress) != -1)
                                                                {
-                                                                       int i = 1;
-                                                                       // enable broadcast on this socket
-                                                                       setsockopt(lhnetsocket->inetsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i));
-#ifdef IP_TOS
-                                                                       {
-                                                                               // enable DSCP for ToS support
-                                                                               int tos = lhnet_default_dscp << 2;
-                                                                               setsockopt(lhnetsocket->inetsocket, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos));
-                                                                       }
+#ifdef MSG_DONTWAIT
+                                                                       if (1)
+#else
+                                                                       if (ioctlsocket(lhnetsocket->inetsocket, FIONBIO, use_blocking ? &_false : &_true) != -1)
 #endif
-                                                                       lhnetsocket->next = &lhnet_socketlist;
-                                                                       lhnetsocket->prev = lhnetsocket->next->prev;
-                                                                       lhnetsocket->next->prev = lhnetsocket;
-                                                                       lhnetsocket->prev->next = lhnetsocket;
+                                                                       {
+                                                                               int i = 1;
+                                                                               // enable broadcast on this socket
+                                                                               setsockopt(lhnetsocket->inetsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i));
+#ifdef IP_TOS
+                                                                               {
+                                                                                       // enable DSCP for ToS support
+                                                                                       int tos = lhnet_default_dscp << 2;
+                                                                                       setsockopt(lhnetsocket->inetsocket, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos));
+                                                                               }
+#endif
+                                                                               lhnetsocket->next = &lhnet_socketlist;
+                                                                               lhnetsocket->prev = lhnetsocket->next->prev;
+                                                                               lhnetsocket->next->prev = lhnetsocket;
+                                                                               lhnetsocket->prev->next = lhnetsocket;
 #ifdef WIN32
-                                                                       if (ioctlsocket(lhnetsocket->inetsocket, SIO_UDP_CONNRESET, &_false) == -1)
-                                                                               Con_DPrintf("LHNET_OpenSocket_Connectionless: ioctlsocket SIO_UDP_CONNRESET returned error: %s\n", LHNETPRIVATE_StrError());
+                                                                               if (ioctlsocket(lhnetsocket->inetsocket, SIO_UDP_CONNRESET, &_false) == -1)
+                                                                                       Con_DPrintf("LHNET_OpenSocket_Connectionless: ioctlsocket SIO_UDP_CONNRESET returned error: %s\n", LHNETPRIVATE_StrError());
 #endif
-                                                                       return lhnetsocket;
+                                                                               return lhnetsocket;
+                                                                       }
+                                                                       else
+                                                                               Con_Printf("LHNET_OpenSocket_Connectionless: ioctlsocket returned error: %s\n", LHNETPRIVATE_StrError());
                                                                }
                                                                else
                                                                {