httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@hyperreal.org
Subject cvs commit: apache-apr/apr/network_io/win32 networkio.h poll.c sockets.c
Date Tue, 15 Jun 1999 17:01:58 GMT
rbb         99/06/15 10:01:57

  Modified:    apr/network_io/win32 networkio.h poll.c sockets.c
  Log:
  Finally have all of the network code for Windows passing the testsock test
  case.  It doesn't use the best windows API, but these work, and that's more
  than I can say for the others.
  
  Revision  Changes    Path
  1.2       +6 -4      apache-apr/apr/network_io/win32/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/network_io/win32/networkio.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- networkio.h	1999/06/14 19:11:16	1.1
  +++ networkio.h	1999/06/15 17:01:55	1.2
  @@ -69,10 +69,12 @@
   
   struct pollfd_t {
       ap_context_t *cntxt;
  -    fd_set read;
  -    fd_set write;
  -    fd_set except;
  -    
  +    fd_set *read;
  +    int numread;
  +    fd_set *write;
  +    int numwrite;
  +    fd_set *except;
  +    int numexcept;    
   };
   
   #endif  /* ! NETWORK_IO_H */
  
  
  
  1.2       +38 -20    apache-apr/apr/network_io/win32/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/network_io/win32/poll.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- poll.c	1999/06/14 19:11:17	1.1
  +++ poll.c	1999/06/15 17:01:55	1.2
  @@ -69,9 +69,15 @@
           return APR_ENOMEM;
       }
       (*new)->cntxt = cont;
  -    FD_ZERO(&(*new)->read);
  -    FD_ZERO(&(*new)->write);
  -    FD_ZERO(&(*new)->except);
  +    (*new)->read = (fd_set *)ap_palloc(cont, sizeof(fd_set));
  +    (*new)->write = (fd_set *)ap_palloc(cont, sizeof(fd_set));
  +    (*new)->except = (fd_set *)ap_palloc(cont, sizeof(fd_set));
  +    FD_ZERO((*new)->read);
  +    (*new)->numread = 0;
  +    FD_ZERO((*new)->write);
  +    (*new)->numwrite = 0;
  +    FD_ZERO((*new)->except);
  +    (*new)->numexcept = 0;
       return APR_SUCCESS;
   }
   
  @@ -79,23 +85,17 @@
   			       struct socket_t *sock, ap_int16_t event)
   {
       if (event & APR_POLLIN) {
  -        FD_SET(sock->sock, &aprset->read);
  +        FD_SET(sock->sock, aprset->read);
  +        aprset->numread++;
       }
       if (event & APR_POLLPRI) {
  -        FD_SET(sock->sock, &aprset->read);
  +        FD_SET(sock->sock, aprset->read);
  +        aprset->numexcept++;
       }
       if (event & APR_POLLOUT) {
  -        FD_SET(sock->sock, &aprset->write);
  +        FD_SET(sock->sock, aprset->write);
  +        aprset->numwrite++;
       }
  -    if (event & APR_POLLERR) {
  -        FD_SET(sock->sock, &aprset->except);
  -    }
  -    if (event & APR_POLLHUP) {
  -        FD_SET(sock->sock, &aprset->except);
  -    }
  -    if (event & APR_POLLNVAL) {
  -        FD_SET(sock->sock, &aprset->except);
  -    }
       return APR_SUCCESS;
   }
   
  @@ -103,6 +103,9 @@
   {
       int rv;
       struct timeval *thetime;
  +    fd_set *newread = NULL;
  +    fd_set *newwrite = NULL;
  +    fd_set *newexcept = NULL;
   
       if (timeout == -1) {
           thetime = NULL;
  @@ -114,9 +117,24 @@
           timeout = timeout % 1000;
           thetime->tv_usec = timeout * 1000;
       }
  +
  +    if (aprset->numread != 0) {
  +        newread = aprset->read;
  +    }
  +    if (aprset->numwrite != 0) {
  +        newwrite = aprset->write;
  +    }
  +    if (aprset->numexcept != 0) {
  +        newexcept = aprset->except;
  +    }
   
  -    rv = select(500, &aprset->read, &aprset->read, &aprset->read,

  -                thetime);
  +    if (newread == NULL && newwrite == NULL && newexcept == NULL) {
  +        Sleep(100); /* Should sleep  for timeout, but that will be fixed next */
  +        return APR_TIMEUP;
  +    }
  +    else {
  +        rv = select(500, newread, newwrite, newexcept, thetime);
  +    }
   
       (*nsds) = rv;    
       if ((*nsds) < 0) {
  @@ -138,7 +156,7 @@
       data.len = 256;
       data.buf = (char *)ap_palloc(aprset->cntxt, 256);
   
  -    if (FD_ISSET(sock->sock, &aprset->read)) {
  +    if (FD_ISSET(sock->sock, aprset->read)) {
           revents |= APR_POLLIN;
           if (WSARecv(sock->sock, &data, 1, &dummy, &flags, NULL, 
                       NULL) == SOCKET_ERROR) {
  @@ -163,14 +181,14 @@
               }
           }
       }
  -    if (FD_ISSET(sock->sock, &aprset->write)) {
  +    if (FD_ISSET(sock->sock, aprset->write)) {
           revents |= APR_POLLOUT;
       }
       /* I am assuming that the except is for out of band data, not a failed
        * connection on a non-blocking socket.  Might be a bad assumption, but
        * it works for now. rbb.
        */
  -    if (FD_ISSET(sock->sock, &aprset->except)) {
  +    if (FD_ISSET(sock->sock, aprset->except)) {
           revents |= APR_POLLPRI;
       }
   
  
  
  
  1.2       +14 -8     apache-apr/apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/network_io/win32/sockets.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sockets.c	1999/06/14 19:11:17	1.1
  +++ sockets.c	1999/06/15 17:01:56	1.2
  @@ -91,7 +91,7 @@
       /* For right now, we are not using socket groups.  We may later.
        * No flags to use when creating a socket, so use 0 for that parameter as well.
        */
  -    (*new)->sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
  +    (*new)->sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
       (*new)->remote_hostname = NULL;
   
       (*new)->addr->sin_family = AF_INET;
  @@ -142,9 +142,7 @@
   
   ap_status_t ap_setport(struct socket_t *sock, ap_uint32_t port)
   {
  -    if (WSAHtons(sock->sock, (short)port, &sock->addr->sin_port) != 0) {
  -        return APR_EEXIST;
  -    }
  +    sock->addr->sin_port = htons((short)port);
       return APR_SUCCESS;
   }
   
  @@ -179,8 +177,8 @@
                    sizeof(struct sockaddr_in));
       (*new)->addr_len = sizeof(struct sockaddr_in);
   
  -    (*new)->sock = WSAAccept(sock->sock, (struct sockaddr *)(*new)->addr,
  -                        &(*new)->addr_len, NULL, 0);
  +    (*new)->sock = accept(sock->sock, (struct sockaddr *)(*new)->addr,
  +                        &(*new)->addr_len);
   
       if ((*new)->sock == INVALID_SOCKET) {
           return errno;
  @@ -201,6 +199,7 @@
   {
       struct hostent *hp;
       int lasterror;
  +    fd_set temp;
   
       if ((sock->sock == INVALID_SOCKET) || (!sock->addr)) {
           return APR_ENOTSOCK;
  @@ -224,14 +223,21 @@
       
       sock->addr->sin_family = AF_INET;
   
  -    if (WSAConnect(sock->sock, (const struct sockaddr *)sock->addr, sock->addr_len,
  -                    NULL, NULL, NULL, NULL) == 0) {
  +    if (connect(sock->sock, (const struct sockaddr *)sock->addr, 
  +                sock->addr_len) == 0) {
           sock->remote_hostname = strdup(hostname);
           return APR_SUCCESS;
       }
       else {
           lasterror = WSAGetLastError();
  +        if (lasterror == WSAEWOULDBLOCK) {
  +            FD_ZERO(&temp);
  +            FD_SET(sock->sock, &temp);
  +            if (select(sock->sock+1, NULL, &temp, NULL, NULL) == 1) {
  +                return APR_SUCCESS;
  +            }
           return APR_EEXIST;
  +        }
       }
   }
   
  
  
  

Mime
View raw message