httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@hyperreal.org
Subject cvs commit: apache-2.0/mpm/src/os/win32 iol_socket.c
Date Thu, 19 Aug 1999 15:13:51 GMT
stoddard    99/08/19 08:13:51

  Modified:    mpm/src/os/win32 iol_socket.c
  Log:
  New send, recv and writev implementations. These are a bit faster. Leaving the old routines
in the file for now to experiment with.
  
  Revision  Changes    Path
  1.3       +136 -2    apache-2.0/mpm/src/os/win32/iol_socket.c
  
  Index: iol_socket.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/os/win32/iol_socket.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iol_socket.c	1999/08/18 15:09:37	1.2
  +++ iol_socket.c	1999/08/19 15:13:50	1.3
  @@ -208,7 +208,7 @@
   };
   
   #elif defined(IOL_SOCK_WIN32)
  -
  +/*
   static int win32_send(ap_iol *viol, const char *buf, int len)
   {
       int rv;
  @@ -268,7 +268,6 @@
   
       return len;
   }
  -
   static int win32_recv( ap_iol *viol, const char *buf, int len)
   {
       int rv;
  @@ -334,6 +333,7 @@
   
       return len;
   }
  +
   static int win32_writev(ap_iol *viol, const struct iovec *vec, int num)
   {
       int i;
  @@ -404,6 +404,140 @@
   
       free(pWsaData);
       return len;
  +}
  +*/
  +static int win32_send(ap_iol *viol, const char *buf, int len)
  +{
  +    int rv;
  +    int lasterror;    
  +    int timeout;
  +    iol_socket *iol = (iol_socket *)viol;
  +    WSABUF wsaData;
  +
  +    wsaData.len = len;
  +    wsaData.buf = (const char*) buf;
  +
  +    timeout = iol->timeout * 1000;  /* setsockopt requires timeout in milliseconds */
  +
  +    rv = setsockopt(iol->fd, SOL_SOCKET, SO_SNDTIMEO,
  +               (char*) &timeout, sizeof(timeout));
  +    if (rv != NO_ERROR) {
  +        printf("win32send: setsockopt failed.\n");
  +        return -1;
  +    }
  +    do {
  +        rv = WSASend(iol->fd, &wsaData, 1, &len, 0, NULL, NULL);
  +        if (rv != SOCKET_ERROR) {
  +            return len;
  +        }
  +        else {
  +            lasterror = WSAGetLastError();
  +        } 
  +    } while (rv == SOCKET_ERROR && lasterror == WSAEINTR);
  +
  +    /* TEST CODE
  +     * If lasterror ==WSATIMEDOUT, then the connection timed out 
  +     */
  +    if (rv == SOCKET_ERROR && lasterror == WSAETIMEDOUT) {
  +        printf("wsasend: Connection timed out\n");
  +    } else {
  +        printf("Connection failed. lasterror = %d\n", lasterror);
  +    }
  +
  +    return -1;
  +}
  +static int win32_recv( ap_iol *viol, const char *buf, int len)
  +{
  +    int rv;
  +    int lasterror;
  +    int timeout;
  +    iol_socket *iol = (iol_socket *)viol;
  +
  +    WSABUF wsaData;
  +    DWORD dwBytesRecv;
  +    DWORD flags = 0;
  +
  +    wsaData.len = len;
  +    wsaData.buf = buf;
  +
  +    timeout = iol->timeout * 1000;  /* setsockopt requires timeout in milliseconds */
  +
  +    rv = setsockopt(iol->fd, SOL_SOCKET, SO_RCVTIMEO,
  +               (char*) &timeout, sizeof(timeout));
  +    if (rv != NO_ERROR) {
  +        printf("win32recv: setsockopt failed. errno = %d\n", WSAGetLastError());
  +        return -1;
  +    }
  +    do {
  +        rv = WSARecv(iol->fd, &wsaData, 1, &dwBytesRecv, &flags, NULL, NULL);
  +        if (rv != SOCKET_ERROR) {
  +            return (int) dwBytesRecv;
  +        }
  +        else {
  +            lasterror = WSAGetLastError();
  +        }
  +    } while (rv == SOCKET_ERROR && lasterror == WSAEINTR);
  +
  +    /* TEST CODE
  +     * If lasterror ==WSATIMEDOUT, then the connection timed out 
  +     */
  +    if (rv == SOCKET_ERROR && lasterror == WSAETIMEDOUT) {
  +        printf("wsarecv: Connection timed out\n");
  +    } else {
  +        printf("Connection failed. lasterror = %d\n", lasterror);
  +    }
  +
  +    return -1;
  +}
  +
  +static int win32_writev(ap_iol *viol, const struct iovec *vec, int num)
  +{
  +    int i;
  +    int rv;
  +    int lasterror;
  +    int len = 0;
  +    int timeout;
  +    iol_socket *iol = (iol_socket *)viol;
  +
  +    LPWSABUF pWsaData = malloc(sizeof(WSABUF) * num);
  +    if (!pWsaData)
  +        return -1;
  +
  +    for (i = 0; i < num; i++) {
  +        pWsaData[i].buf = vec[i].iov_base;
  +        pWsaData[i].len = vec[i].iov_len;
  +    }
  +
  +    timeout = iol->timeout * 1000;  /* setsockopt requires timeout in milliseconds */
  +
  +    rv = setsockopt(iol->fd, SOL_SOCKET, SO_SNDTIMEO,
  +               (char*) &timeout, sizeof(timeout));
  +    if (rv != NO_ERROR) {
  +        printf("win32recv: setsockopt failed. errno = %d\n", WSAGetLastError());
  +        return -1;
  +    }
  +
  +    do {
  +        rv = WSASend(iol->fd, pWsaData, num, &len, 0, NULL, NULL);
  +        if (rv != SOCKET_ERROR) {
  +            free(pWsaData);
  +            return len;
  +        } 
  +        else {
  +            lasterror = WSAGetLastError();
  +        }
  +    } while (rv == SOCKET_ERROR && lasterror == WSAEINTR);
  +
  +    /* TEST CODE
  +     * If lasterror ==WSATIMEDOUT, then the connection timed out 
  +     */
  +    if (rv == SOCKET_ERROR && lasterror == WSAETIMEDOUT) {
  +        printf("wsarecv: Connection timed out\n");
  +    } else {
  +        printf("Connection failed. lasterror = %d\n", lasterror);
  +    }
  +    free(pWsaData);
  +    return -1;
   }
   static const ap_iol_methods socket_methods = {
       win32_close,
  
  
  

Mime
View raw message