apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@apache.org
Subject cvs commit: apr/network_io/win32 sendrecv.c
Date Sun, 19 Aug 2001 02:05:05 GMT
stoddard    01/08/18 19:05:05

  Modified:    network_io/win32 sendrecv.c
  Log:
  Put the WSABUFs on the stack in apr_sendv to save a malloc/free call.
  
  Revision  Changes    Path
  1.43      +16 -16    apr/network_io/win32/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sendrecv.c,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- sendrecv.c	2001/07/12 18:58:57	1.42
  +++ sendrecv.c	2001/08/19 02:05:04	1.43
  @@ -69,8 +69,8 @@
    * bytes.
    */
   #define MAX_SEGMENT_SIZE 65536
  +#define WSABUF_ON_STACK 50
   
  -
   APR_DECLARE(apr_status_t) apr_send(apr_socket_t *sock, const char *buf,
                                      apr_size_t *len)
   {
  @@ -123,33 +123,33 @@
                                       const struct iovec *vec,
                                       apr_int32_t nvec, apr_size_t *nbytes)
   {
  +    apr_status_t rc = APR_SUCCESS;
       apr_ssize_t rv;
       int i;
  -    int lasterror;
       DWORD dwBytes = 0;
  -
  -    /* Todo: Put the WSABUF array on the stack. */
  -    LPWSABUF pWsaData = (LPWSABUF) malloc(sizeof(WSABUF) * nvec);
  -
  -    if (!pWsaData)
  -        return APR_ENOMEM;
  +    WSABUF wsabuf[WSABUF_ON_STACK];
  +    LPWSABUF pWsaBuf = wsabuf;
   
  +    if (nvec > WSABUF_ON_STACK) {
  +        pWsaBuf = (LPWSABUF) malloc(sizeof(WSABUF) * nvec);
  +        if (!pWsaBuf)
  +            return APR_ENOMEM;
  +    }
       for (i = 0; i < nvec; i++) {
  -        pWsaData[i].buf = vec[i].iov_base;
  -        pWsaData[i].len = vec[i].iov_len;
  +        pWsaBuf[i].buf = vec[i].iov_base;
  +        pWsaBuf[i].len = vec[i].iov_len;
       }
   
  -    rv = WSASend(sock->sock, pWsaData, nvec, &dwBytes, 0, NULL, NULL);
  +    rv = WSASend(sock->sock, pWsaBuf, nvec, &dwBytes, 0, NULL, NULL);
       if (rv == SOCKET_ERROR) {
  -        lasterror = apr_get_netos_error();
  -        free(pWsaData);
  -        return lasterror;
  +        rc = apr_get_netos_error();
       }
   
  -    free(pWsaData);
  +    if (nvec > WSABUF_ON_STACK) 
  +        free(pWsaBuf);
   
       *nbytes = dwBytes;
  -    return APR_SUCCESS;
  +    return rc;
   }
   
   
  
  
  

Mime
View raw message