From: teodor Date: Wed, 29 Sep 2004 16:00:35 +0000 (+0000) Subject: add reuse X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=c71811ceb4e5647304eed264043d40b2fddf7517;p=tedtools.git add reuse --- diff --git a/tcp.c b/tcp.c index 525a57e..6833be2 100644 --- 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 )