From: teodor Date: Wed, 29 Sep 2004 16:47:01 +0000 (+0000) Subject: poll=>select X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=2cad3c3c44259c9875f46da0054019974a67bf6a;hp=c71811ceb4e5647304eed264043d40b2fddf7517;p=tedtools.git poll=>select --- diff --git a/tcp.c b/tcp.c index 6833be2..7867f6d 100644 --- a/tcp.c +++ b/tcp.c @@ -214,32 +214,38 @@ TC_ServerInitConnect( TC_Connection *cs ) { u_int32_t TC_ServerConnect( TC_Connection *cs ) { - struct pollfd pfd; + fd_set fdwr, fdexcept; int ret; + struct timeval timeout; if ( cs->state != CS_INPROCESS ) return cs->state; - pfd.fd = cs->fd; - pfd.events = POLLOUT; - pfd.revents = 0; - ret = poll( &pfd, 1, 0 ); + 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 ) ; if ( ret<0 ) { - tlog( TL_CRIT, "TC_ServerConnect: poll: %s", + tlog( TL_CRIT, "TC_ServerConnect: select: %s", strerror(errno)); cs->state = CS_ERROR; return CS_ERROR; } else if ( ret == 0 ) return CS_INPROCESS; - if ( (pfd.revents & (POLLHUP | POLLNVAL | POLLERR)) ) { - tlog( TL_CRIT, "TC_ServerConnect: poll return connect error for %s:%d", + if ( FD_ISSET(cs->fd, &fdexcept) ) { + tlog( TL_CRIT, "TC_ServerConnect: select 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 ( ! (pfd.revents & POLLOUT) ) + if ( ! FD_ISSET(cs->fd, &fdwr) ) return CS_INPROCESS;