dgaudet     97/06/16 12:32:55

  Modified:    src       buff.c buff.h http_main.c
               src/modules/proxy  proxy_cache.c proxy_ftp.c proxy_http.c
  Log:
  Clean up buff.c changes in NT port.  Replace fb->is_socket with B_SOCKET
  flag.  include http_main.h.  Create buff_write() and buff_read() static
  functions in buff.c to increase readability/maintainability.
  
  Revision  Changes    Path
  1.28      +50 -68    apache/src/buff.c
  
  Index: buff.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/buff.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -C3 -r1.27 -r1.28
  *** buff.c    1997/06/15 19:22:24     1.27
  --- buff.c    1997/06/16 19:32:49     1.28
  ***************
  *** 50,58 ****
     *
     */
    
  ! #include "conf.h"
  ! #include "alloc.h"
  ! #include "buff.h"
    
    #include <errno.h>
    #include <stdio.h>
  --- 50,57 ----
     *
     */
    
  ! #include "httpd.h"
  ! #include "http_main.h"
    
    #include <errno.h>
    #include <stdio.h>
  ***************
  *** 72,79 ****
    
    #define DEFAULT_BUFSIZE (4096)
    
  - extern int check_alarm(); /* didn't want to include http_main.h */
  - 
    /*
     * Buffered I/O routines.
     * These are a replacement for the stdio routines.
  --- 71,76 ----
  ***************
  *** 194,199 ****
  --- 191,238 ----
    
    #endif /* WIN32 */    
    
  + 
  + /* these are wrappers to make code below more readable */
  + #if !defined (__GNUC__)
  + #define inline
  + #endif
  + 
  + static inline int buff_read (BUFF *fb, void *buf, int nbyte)
  + {
  +     int rv;
  + 
  + #ifdef WIN32
  +     if (fb->flags & B_SOCKET) {
  +     rv = recvwithtimeout( fb->fd_in, buf, nbyte, 0 );
  +     if (rv == SOCKET_ERROR)
  +         errno = WSAGetLastError() - WSABASEERR;
  +     }
  +     else
  +     rv = read( fb->fd_in, buf, nbyte );
  + #else
  +     rv = read( fb->fd_in, buf, nbyte );
  + #endif /* WIN32 */
  +     return rv;
  + }
  + 
  + static inline int buff_write (BUFF *fb, const void *buf, int nbyte)
  + {
  +     int rv;
  + 
  + #ifdef WIN32
  +     if (fb->flags & B_SOCKET) {
  +     rv = sendwithtimeout( fb->fd, buf, nbyte, 0);
  +     if (rv == SOCKET_ERROR)
  +         errno = WSAGetLastError() - WSABASEERR;
  +     }
  +     else
  +     rv = write( fb->fd, buf, nbyte );
  + #else
  +     rv = write( fb->fd, buf, nbyte );
  + #endif /* WIN32 */
  +     return rv;
  + }
  + 
    static void
    doerror(BUFF *fb, int err)
    {
  ***************
  *** 213,219 ****
     * Create a new buffered stream
     */
    BUFF *
  ! bcreate(pool *p, int flags, int is_socket)
    {
        BUFF *fb;
    
  --- 252,258 ----
     * Create a new buffered stream
     */
    BUFF *
  ! bcreate(pool *p, int flags)
    {
        BUFF *fb;
    
  ***************
  *** 240,246 ****
    
        fb->fd = -1;
        fb->fd_in = -1;
  -     fb->is_socket = is_socket;
    
        return fb;
    }
  --- 279,284 ----
  ***************
  *** 423,440 ****
        }
        }
        do {
  ! #ifdef WIN32
  !         if(fb->is_socket)
  !         {
  !             rv = recvwithtimeout( fb->fd_in, buf, nbyte, 0 );
  !             if(rv == SOCKET_ERROR)
  !                 errno = WSAGetLastError() - WSABASEERR;
  !         }
  !         else
  !             rv = read( fb->fd_in, buf, nbyte );
  ! #else
  !     rv = read( fb->fd_in, buf, nbyte );
  ! #endif /* WIN32 */
        } while (rv == -1 && errno == EINTR && !(fb->flags & B_EOUT));
        return( rv );
    }
  --- 461,467 ----
        }
        }
        do {
  !     rv = buff_read (fb, buf, nbyte);
        } while (rv == -1 && errno == EINTR && !(fb->flags & B_EOUT));
        return( rv );
    }
  ***************
  *** 731,748 ****
        return -1;
    
        while (nbyte > 0) {
  ! #ifdef WIN32
  !         if(fb->is_socket)
  !         {
  !             i = sendwithtimeout( fb->fd, buf, nbyte, 0);
  !             if(i == SOCKET_ERROR)
  !                 errno = WSAGetLastError() - WSABASEERR;
  !         }
  !         else
  !             i = write( fb->fd, buf, nbyte );
  ! #else
  !     i = write( fb->fd, buf, nbyte );
  ! #endif /* WIN32 */
        if( i < 0 ) {
            if( errno != EAGAIN && errno != EINTR ) {
                return -1;
  --- 758,764 ----
        return -1;
    
        while (nbyte > 0) {
  !     i = buff_write( fb, buf, nbyte );
        if( i < 0 ) {
            if( errno != EAGAIN && errno != EINTR ) {
                return -1;
  ***************
  *** 780,797 ****
    
        if (!(fb->flags & B_CHUNK))
        {
  ! #ifdef WIN32
  !         if(fb->is_socket)
  !         {
  !             i = sendwithtimeout(fb->fd, buf, nbyte, 0 );
  !             if(i == SOCKET_ERROR)
  !                 errno = WSAGetLastError() - WSABASEERR;
  !         }
  !         else
  !             i = write(fb->fd, buf, nbyte);
  ! #else
  !     i = write(fb->fd, buf, nbyte);
  ! #endif /* WIN32 */
            return(i);
        }
    
  --- 796,802 ----
    
        if (!(fb->flags & B_CHUNK))
        {
  !     i = buff_write(fb, buf, nbyte);
            return(i);
        }
    
  ***************
  *** 916,934 ****
                    -1 : fb->outcnt;
        } else {
            do {
  ! #ifdef WIN32
  !                 if(fb->is_socket)
  !                 {
  !                     i = sendwithtimeout(fb->fd, fb->outbase, fb->outcnt, 0 
);
  !                     if(i == SOCKET_ERROR)
  !                         errno = WSAGetLastError() - WSABASEERR;
  !                 }
  !                 else
  !                     i = write(fb->fd, fb->outbase, fb->outcnt);
  ! 
  ! #else
  !             i = write(fb->fd, fb->outbase, fb->outcnt);
  ! #endif /* WIN32 */
            } while (i == -1 && errno == EINTR && !(fb->flags & B_EOUT));
        }
        if (i <= 0) {
  --- 921,927 ----
                    -1 : fb->outcnt;
        } else {
            do {
  !             i = buff_write(fb, fb->outbase, fb->outcnt);
            } while (i == -1 && errno == EINTR && !(fb->flags & B_EOUT));
        }
        if (i <= 0) {
  ***************
  *** 1011,1028 ****
        {
        /* the buffer must be full */
        do {
  ! #ifdef WIN32
  !                 if(fb->is_socket)
  !                 {
  !                     i = sendwithtimeout(fb->fd, fb->outbase, fb->outcnt, 0 
);
  !                     if(i == SOCKET_ERROR)
  !                         errno = WSAGetLastError() - WSABASEERR;
  !                 }
  !                 else
  !                     i = write(fb->fd, fb->outbase, fb->outcnt);
  ! #else
  !             i = write(fb->fd, fb->outbase, fb->outcnt);
  ! #endif /* WIN32 */
        } while (i == -1 && errno == EINTR && !(fb->flags & B_EOUT));
        if (i == 0) {
            errno = EAGAIN;
  --- 1004,1010 ----
        {
        /* the buffer must be full */
        do {
  !         i = buff_write(fb, fb->outbase, fb->outcnt);
        } while (i == -1 && errno == EINTR && !(fb->flags & B_EOUT));
        if (i == 0) {
            errno = EAGAIN;
  
  
  
  1.14      +3 -2      apache/src/buff.h
  
  Index: buff.h
  ===================================================================
  RCS file: /export/home/cvs/apache/src/buff.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -C3 -r1.13 -r1.14
  *** buff.h    1997/06/15 19:22:24     1.13
  --- buff.h    1997/06/16 19:32:50     1.14
  ***************
  *** 70,75 ****
  --- 70,77 ----
    #define B_CHUNK (64)
    /* bflush() if a read would block */
    #define B_SAFEREAD (128)
  + /* buffer is a socket */
  + #define B_SOCKET (256)
    
    typedef struct buff_struct BUFF;
    
  ***************
  *** 94,107 ****
    /* could also put pointers to the basic I/O routines here */
        int fd;                /* the file descriptor */
        int fd_in;             /* input file descriptor, if different */
  -     int is_socket;         /* whether fd/fd_in are sockets */
    };
    
    /* Options to bset/getopt */
    #define BO_BYTECT (1)
    
    /* Stream creation and modification */
  ! extern BUFF *bcreate(pool *p, int flags, int is_socket);
    extern void bpushfd(BUFF *fb, int fd_in, int fd_out);
    extern int bsetopt(BUFF *fb, int optname, const void *optval);
    extern int bgetopt(BUFF *fb, int optname, void *optval);
  --- 96,108 ----
    /* could also put pointers to the basic I/O routines here */
        int fd;                /* the file descriptor */
        int fd_in;             /* input file descriptor, if different */
    };
    
    /* Options to bset/getopt */
    #define BO_BYTECT (1)
    
    /* Stream creation and modification */
  ! extern BUFF *bcreate(pool *p, int flags);
    extern void bpushfd(BUFF *fb, int fd_in, int fd_out);
    extern int bsetopt(BUFF *fb, int optname, const void *optval);
    extern int bgetopt(BUFF *fb, int optname, void *optval);
  
  
  
  1.153     +3 -3      apache/src/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/http_main.c,v
  retrieving revision 1.152
  retrieving revision 1.153
  diff -C3 -r1.152 -r1.153
  *** http_main.c       1997/06/16 17:53:13     1.152
  --- http_main.c       1997/06/16 19:32:50     1.153
  ***************
  *** 2194,2200 ****
        (void)update_child_status(child_num, SERVER_BUSY_READ,
                                  (request_rec*)NULL);
    
  !     conn_io = bcreate(ptrans, B_RDWR, 1);
        dupped_csd = csd;
    #if defined(NEED_DUPPED_CSD)
        if ((dupped_csd = dup(csd)) < 0) {
  --- 2194,2200 ----
        (void)update_child_status(child_num, SERVER_BUSY_READ,
                                  (request_rec*)NULL);
    
  !     conn_io = bcreate(ptrans, B_RDWR | B_SOCKET);
        dupped_csd = csd;
    #if defined(NEED_DUPPED_CSD)
        if ((dupped_csd = dup(csd)) < 0) {
  ***************
  *** 2671,2677 ****
            exit(1);
        }
        server_conf->port =ntohs(((struct sockaddr_in *)&sa_server)->sin_port);
  !     cio = bcreate(ptrans, B_RDWR, 1);
    #ifdef MPE
    /* HP MPE 5.5 inetd only passes the incoming socket as stdin (fd 0), whereas
       HPUX inetd passes the incoming socket as stdin (fd 0) and stdout (fd 1).
  --- 2671,2677 ----
            exit(1);
        }
        server_conf->port =ntohs(((struct sockaddr_in *)&sa_server)->sin_port);
  !     cio = bcreate(ptrans, B_RDWR | B_SOCKET);
    #ifdef MPE
    /* HP MPE 5.5 inetd only passes the incoming socket as stdin (fd 0), whereas
       HPUX inetd passes the incoming socket as stdin (fd 0) and stdout (fd 1).
  ***************
  *** 2903,2909 ****
        (void)update_child_status(child_num, SERVER_BUSY_READ,
                                  (request_rec*)NULL);
    
  !     conn_io = bcreate(pchild, B_RDWR, 1);
        dupped_csd = csd;
    #if defined(NEED_DUPPED_CSD)
        if ((dupped_csd = dup(csd)) < 0) {
  --- 2903,2909 ----
        (void)update_child_status(child_num, SERVER_BUSY_READ,
                                  (request_rec*)NULL);
    
  !     conn_io = bcreate(pchild, B_RDWR | B_SOCKET);
        dupped_csd = csd;
    #if defined(NEED_DUPPED_CSD)
        if ((dupped_csd = dup(csd)) < 0) {
  
  
  
  1.16      +2 -2      apache/src/modules/proxy/proxy_cache.c
  
  Index: proxy_cache.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_cache.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -C3 -r1.15 -r1.16
  *** proxy_cache.c     1997/06/16 17:58:34     1.15
  --- proxy_cache.c     1997/06/16 19:32:53     1.16
  ***************
  *** 511,517 ****
        if (cfd != -1)
        {
            note_cleanups_for_fd(r->pool, cfd);
  !         cachefp = bcreate(r->pool, B_RD | B_WR, 0);
            bpushfd(cachefp, cfd, cfd);
        } else if (errno != ENOENT)
            proxy_log_uerror("open", c->filename,
  --- 511,517 ----
        if (cfd != -1)
        {
            note_cleanups_for_fd(r->pool, cfd);
  !         cachefp = bcreate(r->pool, B_RD | B_WR);
            bpushfd(cachefp, cfd, cfd);
        } else if (errno != ENOENT)
            proxy_log_uerror("open", c->filename,
  ***************
  *** 856,862 ****
        return DECLINED;
        }
        note_cleanups_for_fd(r->pool, i);
  !     c->fp = bcreate(r->pool, B_WR, 0);
        bpushfd(c->fp, -1, i);
    
        if (bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1)
  --- 856,862 ----
        return DECLINED;
        }
        note_cleanups_for_fd(r->pool, i);
  !     c->fp = bcreate(r->pool, B_WR);
        bpushfd(c->fp, -1, i);
    
        if (bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1)
  
  
  
  1.23      +3 -3      apache/src/modules/proxy/proxy_ftp.c
  
  Index: proxy_ftp.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_ftp.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -C3 -r1.22 -r1.23
  *** proxy_ftp.c       1997/06/15 19:22:48     1.22
  --- proxy_ftp.c       1997/06/16 19:32:53     1.23
  ***************
  *** 520,526 ****
        if (i == -1)
        return proxyerror(r, "Could not connect to remote machine");
    
  !     f = bcreate(pool, B_RDWR, 1);
        bpushfd(f, sock, sock);
    /* shouldn't we implement telnet control options here? */
    
  --- 520,526 ----
        if (i == -1)
        return proxyerror(r, "Could not connect to remote machine");
    
  !     f = bcreate(pool, B_RDWR | B_SOCKET);
        bpushfd(f, sock, sock);
    /* shouldn't we implement telnet control options here? */
    
  ***************
  *** 721,727 ****
                return proxyerror(r, "Could not connect to remote machine");
            }
            else {
  !             data = bcreate(pool, B_RDWR, 1); 
                bpushfd(data, dsock, dsock);
                pasvmode = 1;
            }
  --- 721,727 ----
                return proxyerror(r, "Could not connect to remote machine");
            }
            else {
  !             data = bcreate(pool, B_RDWR | B_SOCKET); 
                bpushfd(data, dsock, dsock);
                pasvmode = 1;
            }
  ***************
  *** 935,941 ****
            return BAD_GATEWAY;
            }
            note_cleanups_for_socket(pool, csd);
  !         data = bcreate(pool, B_RDWR, 1);
            bpushfd(data, csd, -1);
        kill_timeout(r);
        }
  --- 935,941 ----
            return BAD_GATEWAY;
            }
            note_cleanups_for_socket(pool, csd);
  !         data = bcreate(pool, B_RDWR | B_SOCKET);
            bpushfd(data, csd, -1);
        kill_timeout(r);
        }
  
  
  
  1.19      +1 -1      apache/src/modules/proxy/proxy_http.c
  
  Index: proxy_http.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_http.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -C3 -r1.18 -r1.19
  *** proxy_http.c      1997/06/15 19:22:48     1.18
  --- proxy_http.c      1997/06/16 19:32:53     1.19
  ***************
  *** 244,250 ****
    
        clear_connection(r->headers_in);        /* Strip connection-based 
headers */
    
  !     f = bcreate(pool, B_RDWR, 1);
        bpushfd(f, sock, sock);
    
        hard_timeout ("proxy send", r);
  --- 244,250 ----
    
        clear_connection(r->headers_in);        /* Strip connection-based 
headers */
    
  !     f = bcreate(pool, B_RDWR | B_SOCKET);
        bpushfd(f, sock, sock);
    
        hard_timeout ("proxy send", r);
  
  
  

Reply via email to