You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@locus.apache.org on 2000/04/14 19:38:15 UTC

cvs commit: apache-2.0/src/main http_protocol.c

stoddard    00/04/14 10:38:14

  Modified:    src/main http_protocol.c
  Log:
  Allow for the possibility of receiving data regardless of the pipe
  error condition or receiving EOF on the pipe read. This patch
  assumes that a read returning APR_SUCCESS with 0 bytes read is equivalent
  to an EOF.
  
  Submitted by:	Dean Gaudet
  Reviewed by:	Bill Stoddard
  
  Revision  Changes    Path
  1.62      +36 -28    apache-2.0/src/main/http_protocol.c
  
  Index: http_protocol.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- http_protocol.c	2000/04/14 15:58:56	1.61
  +++ http_protocol.c	2000/04/14 17:38:14	1.62
  @@ -2152,7 +2152,9 @@
       register int o;
       ap_ssize_t w;
       ap_ssize_t n;
  +    ap_ssize_t bytes_read;
       ap_status_t rv;
  +    ap_status_t read_rv;
   
       if (length == 0) {
           return 0;
  @@ -2165,33 +2167,10 @@
   
       ap_bsetopt(fb, BO_TIMEOUT, &zero_timeout);
       while (!ap_is_aborted(r->connection)) {
  -        rv = ap_bread(fb, buf, sizeof(buf), &n);
  -        if (n == 0) {
  -            if (rv == APR_SUCCESS) {    /* eof */
  -                (void) ap_rflush(r);
  -                break;
  -            }
  -            if (rv != APR_EAGAIN) {
  -                r->connection->aborted = 1;
  -                break;
  -            }
  -            /* next read will block, so flush the client now */
  -            if (ap_rflush(r) == EOF) {
  -                break;
  -            }
  -
  -            ap_bsetopt(fb, BO_TIMEOUT, &r->server->timeout);
  -            rv = ap_bread(fb, buf, sizeof(buf), &n);
  -            if (n == 0) {
  -                if (rv == APR_SUCCESS) {        /* eof */
  -                    (void) ap_rflush(r);
  -                }
  -                r->connection->aborted = 1;
  -                break;
  -            }
  -            ap_bsetopt(fb, BO_TIMEOUT, &zero_timeout);
  -        }
  -        
  +        read_rv = ap_bread(fb, buf, sizeof(buf), &n);
  +    got_read:
  +        bytes_read = n;
  +        /* Regardless of read errors, EOF, etc, bytes may have been read */
           o = 0;
           while (n && !ap_is_aborted(r->connection)) {
               rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
  @@ -2203,12 +2182,41 @@
               else if (rv != APR_SUCCESS) {
                   if (!ap_is_aborted(r->connection)) {
                       ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
  -                        "client stopped connection before rflush completed");
  +                                  "client stopped connection before rflush completed");
                       ap_bsetflag(r->connection->client, B_EOUT, 1);
                       r->connection->aborted = 1;
                   }
                   break;
               }
  +        }
  +        if (read_rv == APR_SUCCESS) {
  +            /* Assume a sucessful read of 0 bytes is an EOF 
  +             * Note: I don't think this is ultimately the right thing.
  +             * Read functions should explicitly return EOF. 
  +             * wgs
  +             */
  +            if (bytes_read == 0) {
  +                (void) ap_rflush(r);
  +                break;
  +            }
  +        }
  +        else if (read_rv == APR_EOF) {
  +            (void) ap_rflush(r);
  +            break;
  +        }
  +        else if (read_rv != APR_EAGAIN) {
  +            r->connection->aborted = 1;
  +            break;
  +        }
  +        else {
  +            /* next read will block, so flush the client now */
  +            if (ap_rflush(r) == EOF) {
  +                break;
  +            }
  +            ap_bsetopt(fb, BO_TIMEOUT, &r->server->timeout);
  +            read_rv = ap_bread(fb, buf, sizeof(buf), &n);
  +            ap_bsetopt(fb, BO_TIMEOUT, &zero_timeout);
  +            goto got_read;
           }
       }
       SET_BYTES_SENT(r);