u_int32_t
TC_ServerConnect( TC_Connection *cs ) {
- fd_set fdwr, fdexcept;
+ struct pollfd pfd;
int ret;
- struct timeval timeout;
if ( cs->state != CS_INPROCESS )
return cs->state;
- FD_ZERO( &fdwr );
- FD_ZERO( &fdexcept );
-
- FD_SET(cs->fd, &fdwr);
- FD_SET(cs->fd, &fdexcept);
-
- memset( &timeout, 0, sizeof(struct timeval));
-
- ret = select( cs->fd+1, NULL, &fdwr, &fdexcept, &timeout ) ;
+ pfd.fd = cs->fd;
+ pfd.events = POLLOUT;
+ pfd.revents = 0;
+ ret = poll( &pfd, 1, 0 );
if ( ret<0 ) {
- tlog( TL_CRIT, "TC_ServerConnect: select: %s",
+ tlog( TL_CRIT, "TC_ServerConnect: poll: %s",
strerror(errno));
cs->state = CS_ERROR;
return CS_ERROR;
} else if ( ret == 0 )
return CS_INPROCESS;
- if ( FD_ISSET(cs->fd, &fdexcept) ) {
- tlog( TL_CRIT, "TC_ServerConnect: select return connect error for %s:%d",
+ if ( (pfd.revents & (POLLHUP | POLLNVAL | POLLERR)) ) {
+ tlog( TL_CRIT, "TC_ServerConnect: poll return connect error for %s:%d",
inet_ntoa(cs->serv_addr.sin_addr), ntohs(cs->serv_addr.sin_port));
cs->state = CS_ERROR;
return CS_ERROR;
}
- if ( ! FD_ISSET(cs->fd, &fdwr) )
+ if ( ! (pfd.revents & POLLOUT) )
return CS_INPROCESS;