httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/test client.c
Date Fri, 28 Apr 2000 18:48:16 GMT
trawick     00/04/28 11:48:16

  Modified:    src/lib/apr/include apr_errno.h
               src/lib/apr/misc/unix errorcodes.c
               src/lib/apr/misc/win32 errorcodes.c
               src/lib/apr/test client.c
  Log:
  apr_errno.h:
  APR_OS_START_ERROR needs to be at least 2000 for OS/390 and needs
  to be much higher than 10000 for Win32; 20000 seems nice and round
  and large enough to keep folks happy for a while; without this change,
  Win32 ap_strerror() is broken for common socket error codes
  
  unix/errorcodes.c:
  fix bug in stuffbuffer(); it chopped off the last char of the message
  
  win32/errorcodes.c:
  fix same bug in stuffbuffer()
  when Windows doesn't return a msg, provide a default one
  
  test/client.c:
  call ap_strerror() in a couple of places for easy testing
  get rid of the loop around ap_connect(); no current ap_connect()
  closes the socket or anything else required to make this work
  
  Revision  Changes    Path
  1.30      +1 -1      apache-2.0/src/lib/apr/include/apr_errno.h
  
  Index: apr_errno.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_errno.h,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- apr_errno.h	2000/04/25 22:33:43	1.29
  +++ apr_errno.h	2000/04/28 18:48:11	1.30
  @@ -74,7 +74,7 @@
    * APR_OS_START_SYSERR should be used for system error values on 
    *     each platform.  
    */
  -#define APR_OS_START_ERROR     1000
  +#define APR_OS_START_ERROR     20000
   #define APR_OS_START_STATUS    (APR_OS_START_ERROR + 500)
   #define APR_OS_START_USEERR    (APR_OS_START_STATUS + 500)
   #define APR_OS_START_CANONERR  (APR_OS_START_USEERR + 500)
  
  
  
  1.12      +6 -8      apache-2.0/src/lib/apr/misc/unix/errorcodes.c
  
  Index: errorcodes.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/errorcodes.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- errorcodes.c	2000/04/28 02:35:40	1.11
  +++ errorcodes.c	2000/04/28 18:48:12	1.12
  @@ -55,17 +55,12 @@
   #include "misc.h"
   
   /*
  - * stuffbuffer - Stuff contents of string 's' into buffer 'buf' 
  - * w/o overflowing 'buf' then NULL terminate.
  + * stuffbuffer - like ap_cpystrn() but returns the address of the
  + * dest buffer instead of the address of the terminating '\0'
    */
   static char *stuffbuffer(char *buf, ap_size_t bufsize, const char *s)
   {
  -    ap_size_t len = strlen(s);
  -    if (len > bufsize)
  -        len = bufsize;
  -    memcpy(buf, s, len);
  -    if (len)
  -        buf[len-1] = '\0';
  +    ap_cpystrn(buf,s,bufsize);
       return buf;
   }
   
  @@ -209,6 +204,9 @@
           return stuffbuffer(buf, bufsize, "APR does not understand this error code");
       }
       else {
  +        /* TODO - recognize when the system has hstrerror() and call it here for
  +         * Unix since on Unix this would be a resolver error code
  +         */
   	return apr_os_strerror(buf, bufsize, statcode - APR_OS_START_SYSERR);
       }
   }
  
  
  
  1.9       +23 -21    apache-2.0/src/lib/apr/misc/win32/errorcodes.c
  
  Index: errorcodes.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/win32/errorcodes.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- errorcodes.c	2000/04/26 15:33:37	1.8
  +++ errorcodes.c	2000/04/28 18:48:13	1.9
  @@ -60,17 +60,12 @@
    */
   
   /*
  - * stuffbuffer - Stuff contents of string 's' into buffer 'buf' 
  - * w/o overflowing 'buf' then NULL terminate.
  + * stuffbuffer - like ap_cpystrn() but returns the address of the
  + * dest buffer instead of the address of the terminating '\0'
    */
   static char *stuffbuffer(char *buf, ap_size_t bufsize, const char *s)
   {
  -    ap_size_t len = strlen(s);
  -    if (len > bufsize)
  -        len = bufsize;
  -    memcpy(buf, s, len);
  -    if (len)
  -        buf[len-1] = '\0';
  +    ap_cpystrn(buf,s,bufsize);
       return buf;
   }
   
  @@ -154,8 +149,6 @@
       DWORD len;
       DWORD i;
   
  -    buf = "";
  -
       len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
                           NULL,
                           errcode,
  @@ -164,18 +157,27 @@
                           bufsize,
                           NULL);
   
  -    /* FormatMessage put the message in the buffer, but it may
  -     * have embedded a newline (\r\n), and possible more than one.
  -     * Remove the newlines replacing them with a space. This is not 
  -     * as visually perfect as moving all the remaining message over, 
  -     * but more efficient.
  -     */
  -    i = len;
  -    while (i) {
  -        i--;
  -        if ((buf[i] == '\r') || (buf[i] == '\n'))
  -            buf[i] = ' ';
  +    if (len) {
  +        /* FormatMessage put the message in the buffer, but it may
  +         * have embedded a newline (\r\n), and possible more than one.
  +         * Remove the newlines replacing them with a space. This is not 
  +         * as visually perfect as moving all the remaining message over, 
  +         * but more efficient.
  +         */
  +        i = len;
  +        while (i) {
  +            i--;
  +            if ((buf[i] == '\r') || (buf[i] == '\n'))
  +                buf[i] = ' ';
  +        }
  +    }
  +    else {
  +        /* Windows didn't provide us with a message.  Even stuff like
  +         * WSAECONNREFUSED won't get a message.
  +         */
  +        ap_cpystrn(buf, "Unrecognized error code", bufsize);
       }
  +
       return buf;
   }
   
  
  
  
  1.11      +6 -5      apache-2.0/src/lib/apr/test/client.c
  
  Index: client.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/client.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- client.c	2000/04/16 16:59:39	1.10
  +++ client.c	2000/04/28 18:48:14	1.11
  @@ -68,6 +68,7 @@
       ap_status_t stat;
       char datasend[STRLEN] = "Send data test";
       char datarecv[STRLEN];
  +    char msgbuf[80];
       char *local_ipaddr, *remote_ipaddr;
       char *dest = "127.0.0.1";
       ap_uint32_t local_port, remote_port;
  @@ -124,13 +125,12 @@
   
       fprintf(stdout, "\tClient:  Connecting to socket.......");
   
  -    do {
  -      stat = ap_connect(sock, dest);
  -    } while (stat == APR_ECONNREFUSED);
  +    stat = ap_connect(sock, dest);
   
       if (stat != APR_SUCCESS) {
           ap_close_socket(sock);
  -        fprintf(stderr, "Could not connect  %d\n", stat);
  +        fprintf(stderr, "Could not connect: %s (%d)\n", 
  +		ap_strerror(stat, msgbuf, sizeof(msgbuf)), stat);
           fflush(stderr);
           exit(-1);
       }
  @@ -166,7 +166,8 @@
   
       if ((stat = ap_recv(sock, datarecv, &length)) != APR_SUCCESS) {
           ap_close_socket(sock);
  -        fprintf(stderr, "Problem receiving data: %d\n", stat);
  +        fprintf(stderr, "Problem receiving data: %s (%d)\n", 
  +		ap_strerror(stat, msgbuf, sizeof(msgbuf)), stat);
           exit(-1);
       }
       if (strcmp(datarecv, "Recv data test")) {
  
  
  

Mime
View raw message