manoj 99/10/25 23:15:59
Modified: src/main buff.c Log: More elimination of errno in buff. Now, everything under ap_bwrite is errno-free. ap_bwrite doesn't use errno, excpet for exporting its old interface. Revision Changes Path 1.15 +49 -41 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.14 retrieving revision 1.15 diff -u -d -u -r1.14 -r1.15 --- buff.c 1999/10/26 05:24:50 1.14 +++ buff.c 1999/10/26 06:15:59 1.15 @@ -606,16 +606,13 @@ /* write the contents of fb->outbase, and buf, stop at first partial write for a non-blocking buff - - return number of bytes of buf which were written - -1 for errors */ -static int large_write(BUFF *fb, const char *buf, int nbyte) +static ap_status_t large_write(BUFF *fb, const char *buf, ap_size_t nbyte, + ap_ssize_t *bytes_written) { struct iovec vec[2]; int nvec; ap_status_t rv; - ap_ssize_t bytes_written; ap_assert(nbyte > 0); if (fb->outcnt) { @@ -630,64 +627,64 @@ vec[0].iov_len = nbyte; nvec = 1; } - rv = writev_it_all(fb, vec, nvec, &bytes_written); - if (bytes_written == 0) { /* error or eof */ - if (rv == APR_SUCCESS) { - return 0; - } - errno = rv; - return -1; + rv = writev_it_all(fb, vec, nvec, bytes_written); + if (*bytes_written == 0) { /* error or eof */ + return rv; } - if (bytes_written < fb->outcnt) { + if (*bytes_written < fb->outcnt) { /* shift bytes forward in buffer */ - fb->outcnt -= bytes_written; - memmove(fb->outbase, fb->outbase + bytes_written, fb->outcnt); - return 0; + fb->outcnt -= *bytes_written; + memmove(fb->outbase, fb->outbase + *bytes_written, fb->outcnt); + *bytes_written = 0; + return APR_SUCCESS; } - bytes_written -= fb->outcnt; + *bytes_written -= fb->outcnt; fb->outcnt = 0; - return bytes_written; + return APR_SUCCESS; } -static int large_write_chunk(BUFF *fb, const char *buf, int nbyte) +static ap_status_t large_write_chunk(BUFF *fb, const char *buf, ap_size_t nbyte, + ap_ssize_t *bytes_written) { - int rv; - int amt; - int total; + ap_status_t rv; + ap_ssize_t total, n, amt; ap_assert(nbyte > 0); if (fb->chunk_overcommit) { amt = nbyte > fb->chunk_overcommit ? fb->chunk_overcommit : nbyte; - rv = large_write(fb, buf, amt); - if (rv <= 0) { - return rv; + rv = large_write(fb, buf, amt, &total); + if (total == 0) { /* error or eof */ + *bytes_written = total; + return rv; } - fb->chunk_overcommit -= rv; + fb->chunk_overcommit -= total; if (fb->chunk_overcommit == 0) { fb->outbase[0] = '\015'; fb->outbase[1] = '\012'; fb->outcnt = 2; start_chunk(fb); } - if (rv < amt || amt == nbyte) { - return rv; + if (total < amt || amt == nbyte) { + *bytes_written = total; + return APR_SUCCESS; } - nbyte -= rv; - buf += rv; + nbyte -= total; + buf += total; } ap_assert(fb->chunk_overcommit == 0 && fb->outchunk != -1); total = 0; do { amt = end_chunk(fb, nbyte); - rv = large_write(fb, buf, amt); - if (rv < amt) { - if (rv < 0) { - fb->chunk_overcommit = amt; - return total ? total : -1; - } - fb->chunk_overcommit = amt - rv; - return total + rv; + rv = large_write(fb, buf, amt, &n); + if (n < amt) { + fb->chunk_overcommit = amt - n; + *bytes_written = total + n; +#ifdef MIDWAY_ERROR_RETURNS_ERROR_BLAH_BLAH_BLAH + return rv; +#else + return *bytes_written ? APR_SUCCESS : rv; +#endif } fb->outbase[0] = '\015'; fb->outbase[1] = '\012'; @@ -697,7 +694,8 @@ buf += amt; total += amt; } while (nbyte); - return total; + *bytes_written = total; + return APR_SUCCESS; } /* A wrapper for write which deals with error conditions and @@ -777,10 +775,20 @@ */ 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) { - return large_write_chunk(fb, buf, nbyte); + rv = large_write_chunk(fb, buf, nbyte, &n); } - return large_write(fb, buf, nbyte); + else { + rv = large_write(fb, buf, nbyte, &n); + } + if (rv == APR_SUCCESS) { + return n; + } + errno = rv; + return -1; } /* at this point we know that nbyte < fb->bufsize */