manoj       99/10/26 15:25:03

  Modified:    src      CHANGES
               src/main buff.c http_connection.c http_protocol.c
  Log:
  ap_bflush and ap_bclose now return ap_status_t error codes instead of
  returning -1 and setting errno.
  
  Revision  Changes    Path
  1.13      +3 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -d -u -r1.12 -r1.13
  --- CHANGES   1999/10/23 21:20:15     1.12
  +++ CHANGES   1999/10/26 22:25:00     1.13
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0-dev
   
  +  *) ap_bflush and ap_bclose now return ap_status_t error codes instead
  +     of returning -1 and setting errno. [Manoj Kasichainula]
  +
     *) mod_speling runs in 2.0-dev now: a bug in readdir_r handling and
        interface adaption to APR functions did it. [Martin Kraemer]
   
  
  
  
  1.17      +36 -37    apache-2.0/src/main/buff.c
  
  Index: buff.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/buff.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -d -u -r1.16 -r1.17
  --- buff.c    1999/10/26 20:43:46     1.16
  +++ buff.c    1999/10/26 22:25:01     1.17
  @@ -718,32 +718,36 @@
   }
   
   
  -static int bflush_core(BUFF *fb)
  +static ap_status_t bflush_core(BUFF *fb, ap_ssize_t *bytes_written)
   {
  -    int total;
  -    ap_ssize_t bytes_written;
  +    ap_status_t rv;
  +    ap_ssize_t n;
   
       if (fb->flags & B_CHUNK) {
        end_chunk(fb, 0);
       }
  -    total = 0;
  +    *bytes_written = 0;
       while (fb->outcnt > 0) {
  -     (void) write_with_errors(fb, fb->outbase + total, fb->outcnt,
  -                                 &bytes_written);
  -     if (bytes_written <= 0) {       /* error or eof */
  -         if (total) {
  -             memmove(fb->outbase, fb->outbase + total, fb->outcnt);
  -             return total;
  +     rv = write_with_errors(fb, fb->outbase + *bytes_written, fb->outcnt,
  +                                 &n);
  +     if (n <= 0) {       /* error or eof */
  +         if (*bytes_written) {
  +             memmove(fb->outbase, fb->outbase + *bytes_written, fb->outcnt);
  +#ifdef MIDWAY_ERROR_RETURNS_ERROR_BLAH_BLAH_BLAH
  +                return rv;
  +#else
  +             return APR_SUCCESS;
  +#endif
            }
  -         return -1;
  +         return rv;
        }
  -     fb->outcnt -= bytes_written;
  -     total += bytes_written;
  +     fb->outcnt -= n;
  +     *bytes_written += n;
       }
       if (fb->flags & B_CHUNK) {
        start_chunk(fb);
       }
  -    return total;
  +    return APR_SUCCESS;
   }
   
   
  @@ -758,6 +762,8 @@
   {
       int amt;
       int total;
  +    ap_ssize_t n;
  +    ap_status_t rv;
   
       if (fb->flags & (B_WRERR | B_EOUT)) {
        errno = fb->saved_errno;
  @@ -775,7 +781,6 @@
    */
       if (!(fb->flags & B_WR)
        || (nbyte > LARGE_WRITE_THRESHOLD && nbyte + fb->outcnt >= fb->bufsiz)) 
{
  -        ap_status_t rv;
           ap_ssize_t n;
   
        if (fb->flags & B_CHUNK) {
  @@ -799,7 +804,8 @@
        fb->outcnt += amt;
        buf = (const char *) buf + amt;
        nbyte -= amt;
  -     if (bflush_core(fb) < amt) {
  +        (void) bflush_core(fb, &n);
  +     if (n < amt) {
            return amt;
        }
        total = amt;
  @@ -812,18 +818,18 @@
   
   /*
    * Flushes the buffered stream.
  - * Returns 0 on success or -1 on error
    */
  -API_EXPORT(int) ap_bflush(BUFF *fb)
  +API_EXPORT(ap_status_t) ap_bflush(BUFF *fb)
   {
  -    int ret;
  -
  -    if ((fb->flags & (B_WRERR | B_EOUT | B_WR)) != B_WR)
  -     return -1;
  -
  -    ret = bflush_core(fb);
  +    ap_ssize_t n;       /* Placeholder; not ever used */
   
  -    return ret;
  +    if ((fb->flags & (B_EOUT | B_WR)) != B_WR) {
  +        return APR_EINVAL;
  +    }
  +    if ((fb->flags & B_WRERR) != 0) {
  +        return fb->saved_errno;
  +    }
  +    return bflush_core(fb, &n);
   }
   
   /*
  @@ -832,23 +838,16 @@
    * Sets the EOF flag to indicate no futher data can be read,
    * and the EOUT flag to indicate no further data can be written.
    */
  -API_EXPORT(int) ap_bclose(BUFF *fb)
  +API_EXPORT(ap_status_t) ap_bclose(BUFF *fb)
   {
  -    int rc1, rc2;
  +    ap_status_t rc1, rc2;
   
       if (fb->flags & B_WR)
        rc1 = ap_bflush(fb);
       else
  -     rc1 = 0;
  +     rc1 = APR_SUCCESS;
       ap_kill_cleanup(fb->pool, fb, bcleanup);
       rc2 = iol_close(fb->iol);
  -    if (rc2 == APR_SUCCESS) {
  -        rc2 = 0;
  -    }
  -    else {
  -        errno = rc2;
  -        rc2 = -1;
  -    }
   
       fb->inptr = fb->inbase;
       fb->incnt = 0;
  @@ -856,7 +855,7 @@
   
       fb->flags |= B_EOF | B_EOUT;
   
  -    if (rc1 != 0)
  +    if (rc1 != APR_SUCCESS)
        return rc1;
       return rc2;
   }
  @@ -921,7 +920,7 @@
   
       fb->outcnt += b->vbuff.curpos - (char *)&fb->outbase[fb->outcnt];
       if (fb->outcnt == fb->bufsiz) {
  -     if (ap_bflush(fb)) {
  +     if (ap_bflush(fb) != APR_SUCCESS) {
            return -1;
        }
       }
  
  
  
  1.23      +1 -1      apache-2.0/src/main/http_connection.c
  
  Index: http_connection.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_connection.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -d -u -r1.22 -r1.23
  --- http_connection.c 1999/10/24 05:59:18     1.22
  +++ http_connection.c 1999/10/26 22:25:02     1.23
  @@ -146,7 +146,7 @@
   
       /* Send any leftover data to the client, but never try to again */
   
  -    if (ap_bflush(r->connection->client) == -1) {
  +    if (ap_bflush(r->connection->client) != APR_SUCCESS) {
        ap_bclose(r->connection->client);
        return;
       }
  
  
  
  1.26      +5 -2      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.25
  retrieving revision 1.26
  diff -u -d -u -r1.25 -r1.26
  --- http_protocol.c   1999/10/26 22:15:16     1.25
  +++ http_protocol.c   1999/10/26 22:25:02     1.26
  @@ -2339,13 +2339,16 @@
   
   API_EXPORT(int) ap_rflush(request_rec *r)
   {
  -    if (ap_bflush(r->connection->client) < 0) {
  +    ap_status_t rv;
  +
  +    if ((rv = ap_bflush(r->connection->client)) != APR_SUCCESS) {
           if (!ap_is_aborted(r->connection)) {
  -            ap_log_rerror(APLOG_MARK, APLOG_INFO, errno, r,
  +            ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
                   "client stopped connection before rflush completed");
               ap_bsetflag(r->connection->client, B_EOUT, 1);
               r->connection->aborted = 1;
           }
  +        errno = rv;
           return EOF;
       }
       return 0;
  
  
  

Reply via email to