#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;
memcpy( &(nc->serv_addr), &cli_addr, clilen );
nc->state = CS_CONNECTED;
+ setlinger(nc);
return nc;
}
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 ) {