Add setlinger to Accept
authorteodor <teodor>
Mon, 27 Sep 2004 16:23:54 +0000 (16:23 +0000)
committerteodor <teodor>
Mon, 27 Sep 2004 16:23:54 +0000 (16:23 +0000)
tcp.c

diff --git a/tcp.c b/tcp.c
index 76b0a19..525a57e 100644 (file)
--- a/tcp.c
+++ b/tcp.c
 #include "tlog.h"
 #include "tmalloc.h"
 
+static u_int32_t
+setlinger( TC_Connection *cs ) {
+       struct linger ling;
+       int     val = 0;
+       socklen_t size = sizeof(val); 
+
+       if (getsockopt(cs->fd, SOL_SOCKET,SO_ERROR,&val,&size) == -1) {
+               tlog(TL_ALARM,"getsockopt: %s:%d - %s(%d)",inet_ntoa(cs->serv_addr.sin_addr),
+                       ntohs(cs->serv_addr.sin_port), strerror(errno), errno);
+               shutdown(cs->fd,SHUT_RDWR);
+               close(cs->fd);
+               cs->fd = 0;
+               cs->state = CS_ERROR;
+               return CS_ERROR;
+       }
+
+       if ( val ) {
+               tlog(TL_ALARM,"getsockopt return: %s:%d - %s(%d)",inet_ntoa(cs->serv_addr.sin_addr),
+                       ntohs(cs->serv_addr.sin_port), strerror(val), val);
+               shutdown(cs->fd,SHUT_RDWR);
+               close(cs->fd);
+               cs->fd = 0;
+               cs->state = CS_ERROR;
+               return CS_ERROR;
+       }
+
+
+       ling.l_onoff = ling.l_linger = 0;
+       if (setsockopt(cs->fd, SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling))==-1) {
+               tlog(TL_ALARM,"setsockopt: LINGER %s:%d - %s",inet_ntoa(cs->serv_addr.sin_addr), ntohs(cs->serv_addr.sin_port),
+                       strerror(errno));
+               shutdown(cs->fd,SHUT_RDWR);
+               close(cs->fd);
+               cs->fd = 0;
+               cs->state = CS_ERROR;
+               return CS_ERROR;
+       }
+       cs->state = CS_CONNECTED;
+       return CS_CONNECTED;
+}
+
 u_int32_t
 TC_ClientInitConnection(TC_Connection *cs, char *name, u_int32_t port) {
        int flags;
@@ -103,6 +144,7 @@ TC_AcceptTcp(TC_Connection *cs) {
        memcpy( &(nc->serv_addr), &cli_addr, clilen );
        nc->state = CS_CONNECTED;
 
+       setlinger(nc);
        return nc;
 }
 
@@ -117,46 +159,6 @@ TC_fillConnection(TC_Connection *sc, char *name, u_int32_t port) {
        return sc; 
 }
 
-static u_int32_t
-setlinger( TC_Connection *cs ) {
-       struct linger ling;
-       int     val = 0;
-       socklen_t size = sizeof(val); 
-
-       if (getsockopt(cs->fd, SOL_SOCKET,SO_ERROR,&val,&size) == -1) {
-               tlog(TL_ALARM,"getsockopt: %s:%d - %s(%d)",inet_ntoa(cs->serv_addr.sin_addr),
-                       ntohs(cs->serv_addr.sin_port), strerror(errno), errno);
-               shutdown(cs->fd,SHUT_RDWR);
-               close(cs->fd);
-               cs->fd = 0;
-               cs->state = CS_ERROR;
-               return CS_ERROR;
-       }
-
-       if ( val ) {
-               tlog(TL_ALARM,"getsockopt return: %s:%d - %s(%d)",inet_ntoa(cs->serv_addr.sin_addr),
-                       ntohs(cs->serv_addr.sin_port), strerror(val), val);
-               shutdown(cs->fd,SHUT_RDWR);
-               close(cs->fd);
-               cs->fd = 0;
-               cs->state = CS_ERROR;
-               return CS_ERROR;
-       }
-
-
-       ling.l_onoff = ling.l_linger = 0;
-       if (setsockopt(cs->fd, SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling))==-1) {
-               tlog(TL_ALARM,"setsockopt: LINGER %s:%d - %s",inet_ntoa(cs->serv_addr.sin_addr), ntohs(cs->serv_addr.sin_port),
-                       strerror(errno));
-               shutdown(cs->fd,SHUT_RDWR);
-               close(cs->fd);
-               cs->fd = 0;
-               cs->state = CS_ERROR;
-               return CS_ERROR;
-       }
-       cs->state = CS_CONNECTED;
-       return CS_CONNECTED;
-}
 
 u_int32_t
 TC_ServerInitConnect( TC_Connection    *cs ) {