costin 01/12/12 13:52:41 Modified: jk/native2/common jk_requtil.c Log: Moved the 'read chunk from the web server' code to jk_requtil, it can be used by any worker/protocol. Removed any internal use of ajp buffers. Revision Changes Path 1.3 +47 -0 jakarta-tomcat-connectors/jk/native2/common/jk_requtil.c Index: jk_requtil.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_requtil.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- jk_requtil.c 2001/12/04 23:56:07 1.2 +++ jk_requtil.c 2001/12/12 21:52:40 1.3 @@ -68,6 +68,8 @@ #include "jk_env.h" #include "jk_requtil.h" +#define CHUNK_BUFFER_PAD (12) + const char *response_trans_headers[] = { "Content-Type", "Content-Language", @@ -352,6 +354,51 @@ return NULL; } return ch; +} + + +/* + * Read data from the web server. + * + * Socket API didn't garanty all the data will be kept in a single + * read, so we must loop up to all awaited data are received + */ +int jk_requtil_readFully(jk_ws_service_t *s, + unsigned char *buf, + unsigned len) +{ + unsigned rdlen = 0; + unsigned padded_len = len; + + if (s->is_chunked && s->no_more_chunks) { + return 0; + } + if (s->is_chunked) { + /* Corner case: buf must be large enough to hold next + * chunk size (if we're on or near a chunk border). + * Pad the length to a reasonable value, otherwise the + * read fails and the remaining chunks are tossed. + */ + padded_len = (len < CHUNK_BUFFER_PAD) ? + len : len - CHUNK_BUFFER_PAD; + } + + while(rdlen < padded_len) { + unsigned this_time = 0; + if(!s->read(s, buf + rdlen, len - rdlen, &this_time)) { + return -1; + } + + if(0 == this_time) { + if (s->is_chunked) { + s->no_more_chunks = 1; /* read no more */ + } + break; + } + rdlen += this_time; + } + + return (int)rdlen; } /** Initialize the request
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>