From: teodor Date: Wed, 29 Sep 2004 17:07:01 +0000 (+0000) Subject: poll<=select X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=d1d1db673bb3d51dd1abf275338b15543abeb64b;p=tedtools.git poll<=select --- diff --git a/tcp.c b/tcp.c index 7867f6d..6833be2 100644 --- a/tcp.c +++ b/tcp.c @@ -214,38 +214,32 @@ TC_ServerInitConnect( TC_Connection *cs ) { 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;