[DGD] DGD 1.2p4 with networking package and outgoing connections

bart at wotf.org bart at wotf.org
Sat Dec 8 01:28:17 CET 2007


When using outgoing tcp connections, the mud freezes untill a timeout expires
when there is no reply at all to an outgoing connection attempt.

I made a small patch so that connections are opened in nonblocking mode.
Obviously, you won't get errors from connect() about failed connections
anymore with this patch, but since close() will be called for those cases, I
don't think that is much of a problem.

It seems to work well for me on FreeBSD and Linux, but maybe I am missing
something, so if someone else using 1.2p4 with networking package and better C
fu then me could take a look at this it would be appreciated.

--- host/unix/connect.c.orig    Tue Jun  7 19:45:59 2005
+++ host/unix/connect.c Fri Dec  7 23:56:29 2007
@@ -651,6 +651,7 @@
     register connection * conn;
     register int sock;
     int on;
+    long arg;
     struct sockaddr_in sin;

     sock=socket(addrtype, SOCK_STREAM, 0);
@@ -672,6 +673,15 @@
        return NULL;
     }
 #endif
+    if( (arg = fcntl(sock, F_GETFL, NULL)) < 0) {
+       perror("fcntl");
+       return NULL;
+    }
+    arg |= O_NONBLOCK;
+    if( fcntl(sock, F_SETFL, arg) < 0) {
+       perror("fcntl");
+       return NULL;
+    }
     memset(&sin, '\0', sizeof(sin));
     sin.sin_port = htons(port);
     sin.sin_family = addrtype;
@@ -679,7 +689,8 @@
        perror("inet_aton");
        return NULL;
     }
-    if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
+    if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0 &&
+                    errno != EINPROGRESS) {
        perror("connect");
        return NULL;
     }

--
Created with Open WebMail at http://www.bartsplace.net/
Read my weblog at http://soapbox.bartsplace.net/




More information about the DGD mailing list