1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-30 03:26:23 -04:00

decompress_data: make the current state more explicit

Introduce and use the local variable state instead of determining the
current state from to_read. Localise to_read to the loop.
This commit is contained in:
Miciah Dashiel Butler Masters 2006-11-05 03:42:16 +00:00 committed by Miciah Dashiel Butler Masters
parent 157b08609f
commit e441361f2c

View File

@ -960,7 +960,8 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
* causes further malfunction of zlib :[ ... so we will make sure that * causes further malfunction of zlib :[ ... so we will make sure that
* we will always have at least PIPE_BUF / 2 + 1 in the pipe (returning * we will always have at least PIPE_BUF / 2 + 1 in the pipe (returning
* early otherwise)). */ * early otherwise)). */
int to_read = PIPE_BUF / 2, did_read = 0; enum { NORMAL, FINISHING } state = NORMAL;
int did_read = 0;
int *length_of_block; int *length_of_block;
unsigned char *output = NULL; unsigned char *output = NULL;
@ -972,7 +973,7 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
/* Going to finish this decoding bussiness. */ /* Going to finish this decoding bussiness. */
/* Some nicely big value - empty encoded output queue by reading /* Some nicely big value - empty encoded output queue by reading
* big chunks from it. */ * big chunks from it. */
to_read = BIG_READ; state = FINISHING;
} }
if (conn->content_encoding == ENCODING_NONE) { if (conn->content_encoding == ENCODING_NONE) {
@ -991,11 +992,15 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
} }
do { do {
int to_read;
int init = 0; int init = 0;
if (to_read == PIPE_BUF / 2) { if (state == NORMAL) {
/* ... we aren't finishing yet. */ /* ... we aren't finishing yet. */
int written = safe_write(conn->stream_pipes[1], data, int written;
to_read = PIPE_BUF / 2;
written = safe_write(conn->stream_pipes[1], data,
len > to_read ? to_read : len); len > to_read ? to_read : len);
if (written > 0) { if (written > 0) {
@ -1009,7 +1014,7 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
* non-keep-alive and chunked */ * non-keep-alive and chunked */
if (!http->length) { if (!http->length) {
/* That's all, folks - let's finish this. */ /* That's all, folks - let's finish this. */
to_read = BIG_READ; state = FINISHING;
} else if (!len) { } else if (!len) {
/* We've done for this round (but not done /* We've done for this round (but not done
* completely). Thus we will get out with * completely). Thus we will get out with
@ -1022,6 +1027,8 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
return output; return output;
} }
} }
} else {
to_read = BIG_READ;
} }
if (!conn->stream) { if (!conn->stream) {
@ -1030,7 +1037,7 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
if (!conn->stream) return NULL; if (!conn->stream) return NULL;
/* On "startup" pipe is treated with care, but if everything /* On "startup" pipe is treated with care, but if everything
* was already written to the pipe, caution isn't necessary */ * was already written to the pipe, caution isn't necessary */
if (to_read != BIG_READ) init = 1; if (state != FINISHING) init = 1;
} }
output = (unsigned char *) mem_realloc(output, *new_len + to_read); output = (unsigned char *) mem_realloc(output, *new_len + to_read);