TC_Connection *
TC_fillConnection(TC_Connection *sc, char *name, u_int32_t port) {
if ( !sc )
- sc = (TC_Connection *)t0malloc(sizeof(TC_Connection));
- else
- memset(sc, 0, sizeof(TC_Connection));
+ sc = (TC_Connection *)tmalloc(sizeof(TC_Connection));
+ memset(sc, 0, sizeof(TC_Connection));
sc->serv_addr.sin_family = AF_INET;
sc->serv_addr.sin_addr.s_addr = (name) ? inet_addr(name) : htonl(INADDR_ANY);
sc->serv_addr.sin_port = htons(port);
if (fcntl(cs->fd,F_SETFL,flags|O_NDELAY) < 0 )
tlog(TL_ALARM,"fcntl O_NDELAY - %s",strerror(errno));
+ flags=1;
+ if (setsockopt(cs->fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags)) < 0)
+ tlog(TL_ALARM, "socketsockopt failed: %s (%d)", strerror(errno), errno);
+
if ( connect(cs->fd, (struct sockaddr *) &(cs->serv_addr),
sizeof(struct sockaddr_in)) < 0 ) {
if ( errno == EINPROGRESS || errno == EALREADY ) {
return CS_INPROCESS;
} else if (errno != EISCONN && errno != EALREADY &&
errno != EWOULDBLOCK && errno != EAGAIN) {
- tlog(TL_DEBUG,"open4: %s:%d - %s",
+ tlog(TL_DEBUG,"connect: %s:%d - %s",
inet_ntoa(cs->serv_addr.sin_addr), ntohs(cs->serv_addr.sin_port),
strerror(errno));
shutdown(cs->fd,SHUT_RDWR);
int ret,i, fdnum=0;
if ( number==0 || cs ==NULL ) {
+ if (timeout<0)
+ timeout=1000;
usleep( timeout * 1000.0 );
return 0;
}
}
cs[i]->readyio=0;
}
+
+ if ( fdnum==0 ) {
+ tfree(pfd);
+ if (timeout<0)
+ timeout=1000;
+ usleep( timeout * 1000.0 );
+ return 0;
+ }
ret = poll( pfd, fdnum, timeout );
if ( ret<0 ) {
tlog( TL_CRIT, "TC_ReadyIO: poll: %s",