poll=>select
authorteodor <teodor>
Wed, 29 Sep 2004 16:47:01 +0000 (16:47 +0000)
committerteodor <teodor>
Wed, 29 Sep 2004 16:47:01 +0000 (16:47 +0000)
tcp.c

diff --git a/tcp.c b/tcp.c
index 6833be2..7867f6d 100644 (file)
--- 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;