manoj 99/10/29 22:25:33
Modified: src/include buff.h src/main buff.c http_protocol.c src/modules/standard mod_cgi.c mod_echo.c Log: ap_bwrite now exports an errnoless interface. Revision Changes Path 1.8 +3 -2 apache-2.0/src/include/buff.h Index: buff.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/buff.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -u -r1.7 -r1.8 --- buff.h 1999/10/30 02:06:32 1.7 +++ buff.h 1999/10/30 05:25:28 1.8 @@ -78,7 +78,7 @@ non-blocking, unbuffered non-blocking, unbuffered, HTTP-chunked - In all the blocking modes, a bwrite(fb, buf, len) will return less + In all the blocking modes, a bwrite(fb, buf, len) will write less than len only in an error state. The error may be deferred until the next use of fb. @@ -186,7 +186,8 @@ ap_ssize_t *bytes_read); API_EXPORT(int) ap_bgets(char *s, int n, BUFF *fb); API_EXPORT(int) ap_blookc(BUFF *fb); -API_EXPORT(int) ap_bwrite(BUFF *fb, const void *buf, int nbyte); +API_EXPORT(ap_status_t) ap_bwrite(BUFF *fb, const void *buf, ap_size_t nbyte, + ap_ssize_t *bytes_written); API_EXPORT(ap_status_t) ap_bflush(BUFF *fb); API_EXPORT(int) ap_bputs(const char *x, BUFF *fb); API_EXPORT(int) ap_bvputs(BUFF *fb,...); 1.20 +24 -20 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.19 retrieving revision 1.20 diff -u -d -u -r1.19 -r1.20 --- buff.c 1999/10/30 02:06:32 1.19 +++ buff.c 1999/10/30 05:25:29 1.20 @@ -529,9 +529,16 @@ API_EXPORT(int) ap_bflsbuf(int c, BUFF *fb) { char ss[1]; + ap_ssize_t bytes_written; + ap_status_t rv; ss[0] = c; - return ap_bwrite(fb, ss, 1); + rv = ap_bwrite(fb, ss, 1, &bytes_written); + if (rv == APR_SUCCESS) { + return bytes_written; + } + errno = rv; + return -1; } /* @@ -767,19 +774,21 @@ * It is worth noting that if an error occurs, the buffer is in an unknown * state. */ -API_EXPORT(int) ap_bwrite(BUFF *fb, const void *buf, int nbyte) +API_EXPORT(ap_status_t) ap_bwrite(BUFF *fb, const void *buf, ap_size_t nbyte, + ap_ssize_t *bytes_written) { int amt; int total; ap_ssize_t n; - ap_status_t rv; if (fb->flags & (B_WRERR | B_EOUT)) { - errno = fb->saved_errno; - return -1; + *bytes_written = 0; + return fb->saved_errno; } - if (nbyte == 0) - return 0; + if (nbyte == 0) { + *bytes_written = 0; + return APR_SUCCESS; + } /* * Detect case where we're asked to write a large buffer, and combine our @@ -790,19 +799,12 @@ */ if (!(fb->flags & B_WR) || (nbyte > LARGE_WRITE_THRESHOLD && nbyte + fb->outcnt >= fb->bufsiz)) { - ap_ssize_t n; - if (fb->flags & B_CHUNK) { - rv = large_write_chunk(fb, buf, nbyte, &n); + return large_write_chunk(fb, buf, nbyte, bytes_written); } else { - rv = large_write(fb, buf, nbyte, &n); - } - if (rv == APR_SUCCESS) { - return n; + return large_write(fb, buf, nbyte, bytes_written); } - errno = rv; - return -1; } /* at this point we know that nbyte < fb->bufsize */ @@ -815,14 +817,16 @@ nbyte -= amt; (void) bflush_core(fb, &n); if (n < amt) { - return amt; + *bytes_written = amt; + return APR_SUCCESS; } total = amt; } /* now we know that nbyte < fb->bufsiz */ memcpy(fb->outbase + fb->outcnt, buf, nbyte); fb->outcnt += nbyte; - return total + nbyte; + *bytes_written = total + nbyte; + return APR_SUCCESS; } /* @@ -875,7 +879,7 @@ API_EXPORT(int) ap_bputs(const char *x, BUFF *fb) { int i, j = strlen(x); - i = ap_bwrite(fb, x, j); + (void) ap_bwrite(fb, x, j, &i); if (i != j) return -1; else @@ -897,7 +901,7 @@ if (x == NULL) break; j = strlen(x); - i = ap_bwrite(fb, x, j); + (void) ap_bwrite(fb, x, j, &i); if (i != j) { va_end(v); return -1; 1.28 +27 -21 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.27 retrieving revision 1.28 diff -u -d -u -r1.27 -r1.28 --- http_protocol.c 1999/10/30 02:06:33 1.27 +++ http_protocol.c 1999/10/30 05:25:30 1.28 @@ -2015,9 +2015,10 @@ { char buf[IOBUFSIZE]; long total_bytes_sent = 0; - register int w, o; + register int o; + ap_ssize_t w; ap_ssize_t n; - ap_status_t status; + ap_status_t rv; if (length == 0) return 0; @@ -2030,8 +2031,8 @@ n = o; do { - status = ap_read(fd, buf, &n); - } while (status == APR_EINTR && !ap_is_aborted(r->connection) && + rv = ap_read(fd, buf, &n); + } while (rv == APR_EINTR && !ap_is_aborted(r->connection) && (n < 1)); if (n < 1) { @@ -2041,15 +2042,15 @@ o = 0; while (n && !ap_is_aborted(r->connection)) { - w = ap_bwrite(r->connection->client, &buf[o], n); + rv = ap_bwrite(r->connection->client, &buf[o], n, &w); if (w > 0) { total_bytes_sent += w; n -= w; o += w; } - else if (w < 0) { + else if (rv != 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 send body completed"); ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; @@ -2076,7 +2077,8 @@ char buf[IOBUFSIZE]; long total_bytes_sent = 0; long zero_timeout = 0; - int w, o; + register int o; + ap_ssize_t w; ap_ssize_t n; ap_status_t rv; @@ -2120,15 +2122,15 @@ o = 0; while (n && !ap_is_aborted(r->connection)) { - w = ap_bwrite(r->connection->client, &buf[o], n); + rv = ap_bwrite(r->connection->client, &buf[o], n, &w); if (w > 0) { total_bytes_sent += w; n -= w; o += w; } - else if (w < 0) { + else if (rv != 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; @@ -2159,7 +2161,9 @@ size_t length) { size_t total_bytes_sent = 0; - int n, w; + int n; + ap_ssize_t w; + ap_status_t rv; if (length == 0) return 0; @@ -2175,19 +2179,19 @@ } while (n && !r->connection->aborted) { - w = ap_bwrite(r->connection->client, (char *) mm + offset, n); + rv = ap_bwrite(r->connection->client, (char *) mm + offset, n, &w); if (w > 0) { total_bytes_sent += w; n -= w; offset += w; } - else if (w < 0) { + else if (rv != APR_SUCCESS) { if (r->connection->aborted) break; - else if (errno == EAGAIN) + else if (rv == EAGAIN) continue; else { - ap_log_rerror(APLOG_MARK, APLOG_INFO, errno, r, + ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before send mmap completed"); ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; @@ -2242,15 +2246,16 @@ API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r) { - int n; + ap_ssize_t n; + ap_status_t rv; if (r->connection->aborted) return EOF; - n = ap_bwrite(r->connection->client, buf, nbyte); + rv = ap_bwrite(r->connection->client, buf, nbyte, &n); if (n < 0) { if (!r->connection->aborted) { - ap_log_rerror(APLOG_MARK, APLOG_INFO, errno, r, + ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before rwrite completed"); ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; @@ -2314,6 +2319,7 @@ int i, j, k; const char *x; BUFF *fb = r->connection->client; + ap_status_t rv; if (r->connection->aborted) return EOF; @@ -2324,11 +2330,11 @@ if (x == NULL) break; j = strlen(x); - i = ap_bwrite(fb, x, j); + rv = ap_bwrite(fb, x, j, &i); if (i != j) { va_end(args); if (!r->connection->aborted) { - ap_log_rerror(APLOG_MARK, APLOG_INFO, errno, r, + ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before rvputs completed"); ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; 1.16 +3 -1 apache-2.0/src/modules/standard/mod_cgi.c Index: mod_cgi.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_cgi.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -u -r1.15 -r1.16 --- mod_cgi.c 1999/10/25 12:45:39 1.15 +++ mod_cgi.c 1999/10/30 05:25:31 1.16 @@ -538,6 +538,7 @@ */ if (ap_should_client_block(r)) { int dbsize, len_read; + ap_ssize_t bytes_written; if (conf->logname) { dbuf = ap_pcalloc(r->pool, conf->bufbytes + 1); @@ -556,7 +557,8 @@ memcpy(dbuf + dbpos, argsbuffer, dbsize); dbpos += dbsize; } - if (ap_bwrite(script_out, argsbuffer, len_read) < len_read) { + (void) ap_bwrite(script_out, argsbuffer, len_read, &bytes_written); + if (bytes_written < len_read) { /* silly script stopped reading, soak up remaining message */ while (ap_get_client_block(r, argsbuffer, HUGE_STRING_LEN) > 0) { /* dump it */ 1.13 +1 -1 apache-2.0/src/modules/standard/mod_echo.c Index: mod_echo.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_echo.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -u -r1.12 -r1.13 --- mod_echo.c 1999/10/30 02:06:34 1.12 +++ mod_echo.c 1999/10/30 05:25:32 1.13 @@ -43,7 +43,7 @@ (void) ap_bread(c->client,buf,sizeof buf,&r); if(r <= 0) break; - w=ap_bwrite(c->client,buf,r); + (void) ap_bwrite(c->client,buf,r, &w); if(w != r) break; ap_bflush(c->client);