]>
Commit | Line | Data |
---|---|---|
e6166caa | 1 | --- elinks/src/protocol/http/http.c Sun Dec 22 12:52:20 2002 |
2 | +++ elinks.2/src/protocol/http/http.c Tue Dec 24 22:15:59 2002 | |
3 | @@ -665,16 +665,14 @@ | |
4a5ed3ca | 4 | /* Number of uncompressed bytes that could be safely get from |
5 | * read_encoded(). We can't want to read too much, because if gzread | |
6 | * "clears" the buffer next time it will return -1. */ | |
7 | - int ret = 0; | |
4a5ed3ca | 8 | + int ret = 2048; |
e6166caa | 9 | int r = 0, *length_of_block; |
10 | - /* If true, all stuff was written to pipe and only uncompression is | |
11 | - * wanted now. */ | |
12 | - int finishing = 0; | |
13 | unsigned char *output = NULL; | |
14 | ||
15 | length_of_block = (info->length == LEN_CHUNKED ? &info->chunk_remaining | |
16 | : &info->length); | |
17 | - if (!*length_of_block) finishing = 1; | |
18 | + if (!*length_of_block) | |
19 | + ret = 65536; | |
20 | ||
21 | if (conn->content_encoding == ENCODING_NONE) { | |
22 | *new_len = len; | |
23 | @@ -690,9 +688,9 @@ | |
24 | || set_nonblocking_fd(conn->stream_pipes[1]) < 0)) | |
25 | return NULL; | |
4a5ed3ca | 26 | |
27 | - while (r == ret) { | |
e6166caa | 28 | - if (!finishing) { |
4a5ed3ca | 29 | - int written = write(conn->stream_pipes[1], data, len); |
e6166caa | 30 | + do { |
31 | + if (ret == 2048) { | |
32 | + int written = write(conn->stream_pipes[1], data, len > ret ? ret : len); | |
33 | ||
4a5ed3ca | 34 | /* When we're writing zero bytes already, we want to |
35 | * zero ret properly for now, so that we'll go out for | |
e6166caa | 36 | @@ -700,37 +698,16 @@ |
37 | * zero bytes, but ret will be on its original value, | |
4a5ed3ca | 38 | * causing us to close the stream, and that's disaster |
39 | * when more data are about to come yet. */ | |
e6166caa | 40 | - if (written > 0 || (!written && !len)) { |
4a5ed3ca | 41 | - ret = written; |
42 | - data += ret; | |
43 | - len -= ret; | |
e6166caa | 44 | + if (written > 0) { |
4a5ed3ca | 45 | + data += written; |
46 | + len -= written; | |
e6166caa | 47 | if (*length_of_block > 0) |
48 | - *length_of_block -= ret; | |
49 | + *length_of_block -= written; | |
4a5ed3ca | 50 | if (!info->length) |
e6166caa | 51 | - finishing = 1; |
52 | + ret = 65536; | |
53 | + else if (!len) | |
54 | + return output; | |
55 | } | |
4a5ed3ca | 56 | - |
57 | - if (len) { | |
58 | - /* We assume that this is because full pipe. */ | |
59 | - /* FIXME: We should probably handle errors as | |
60 | - * well. --pasky */ | |
61 | - ret = 4096; /* pipe capacity */ | |
e6166caa | 62 | - } |
63 | - } | |
64 | - /* finishing could be changed above ;) */ | |
65 | - if (finishing) { | |
66 | - /* Granularity of the final decompression. When we were | |
67 | - * taking the decompressed content, we only took the | |
68 | - * amount which we inserted there. When finishing, we | |
69 | - * have to drain the rest from the beast. */ | |
70 | - /* TODO: We should probably double the ret before trying | |
71 | - * to read as well..? Would maybe make the progressive | |
72 | - * displaying feeling better? --pasky */ | |
73 | - ret = 65536; | |
74 | - } | |
4a5ed3ca | 75 | - if (ret < 4096) { |
76 | - /* Not enough data, try in next round. */ | |
77 | - return output; | |
e6166caa | 78 | } |
4a5ed3ca | 79 | |
80 | if (!conn->stream) { | |
e6166caa | 81 | @@ -743,8 +720,9 @@ |
4a5ed3ca | 82 | if (!output) break; |
83 | ||
e6166caa | 84 | r = read_encoded(conn->stream, output + *new_len, ret); |
85 | + | |
4a5ed3ca | 86 | if (r > 0) *new_len += r; |
87 | - } | |
88 | + } while (len || r == ret); | |
89 | ||
90 | if (r < 0 && output) { | |
91 | mem_free(output); |