add reuse
authorteodor <teodor>
Wed, 29 Sep 2004 16:00:35 +0000 (16:00 +0000)
committerteodor <teodor>
Wed, 29 Sep 2004 16:00:35 +0000 (16:00 +0000)
tcp.c

diff --git a/tcp.c b/tcp.c
index 525a57e..6833be2 100644 (file)
--- a/tcp.c
+++ b/tcp.c
@@ -95,7 +95,7 @@ setlinger( TC_Connection *cs ) {
 
 u_int32_t
 TC_ClientInitConnection(TC_Connection *cs, char *name, u_int32_t port) {
-       int flags;
+       int flags, val=1;
 
        cs = TC_fillConnection(cs, name, port);
 
@@ -104,6 +104,11 @@ TC_ClientInitConnection(TC_Connection *cs, char *name, u_int32_t port) {
                tlog(TL_CRIT|TL_EXIT,"socket4: %s:%d - %s",inet_ntoa(cs->serv_addr.sin_addr),
                        ntohs(cs->serv_addr.sin_port),strerror(errno));
 
+        if (setsockopt(cs->fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
+                tlog(TL_CRIT|TL_EXIT, "socketsockopt failed: %s", strerror(errno));
+                return CS_ERROR;
+        }
+
        if ((flags=fcntl(cs->fd,F_GETFL,0)) == -1)
                tlog(TL_ALARM,"fcntl F_GETFL - %s",strerror(errno));
        if (fcntl(cs->fd,F_SETFL,flags|O_NDELAY) < 0 )