]>
Commit | Line | Data |
---|---|---|
4a5ed3ca | 1 | --- elinks-0.4.0/src/protocol/http/http.c Sat Dec 7 23:15:31 2002 |
2 | +++ elinks-0.4.0.new/src/protocol/http/http.c Tue Dec 24 21:26:46 2002 | |
3 | @@ -680,8 +680,8 @@ | |
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; | |
8 | - int r = 0, *length_of_block; | |
9 | + int ret = 2048; | |
10 | + int r, *length_of_block; | |
11 | /* If true, all stuff was written to pipe and only uncompression is | |
12 | * wanted now. */ | |
13 | int finishing = 0; | |
14 | @@ -705,10 +705,9 @@ | |
15 | if (set_nonblocking_fd(conn->stream_pipes[1]) < 0) return NULL; | |
16 | } | |
17 | ||
18 | - while (r == ret) { | |
19 | + do { | |
20 | if (!finishing) { | |
21 | - int written = write(conn->stream_pipes[1], data, len); | |
22 | - | |
23 | + int written = write(conn->stream_pipes[1], data, len > 2048 ? 2048 : len); | |
24 | /* When we're writing zero bytes already, we want to | |
25 | * zero ret properly for now, so that we'll go out for | |
26 | * some more data. Otherwise, read_encoded() will yield | |
27 | @@ -716,22 +715,16 @@ | |
28 | * causing us to close the stream, and that's disaster | |
29 | * when more data are about to come yet. */ | |
30 | if (written > 0 || (!written && !len)) { | |
31 | - ret = written; | |
32 | - data += ret; | |
33 | - len -= ret; | |
34 | - if (*length_of_block > 0) | |
35 | - *length_of_block -= ret; | |
36 | + data += written; | |
37 | + len -= written; | |
38 | + *length_of_block -= written; | |
39 | if (!info->length) | |
40 | finishing = 1; | |
41 | - } | |
42 | - | |
43 | - if (len) { | |
44 | - /* We assume that this is because full pipe. */ | |
45 | - /* FIXME: We should probably handle errors as | |
46 | - * well. --pasky */ | |
47 | - ret = 4096; /* pipe capacity */ | |
48 | + else if (!len) | |
49 | + return output; | |
50 | } | |
51 | } | |
52 | + | |
53 | /* finishing could be changed above ;) */ | |
54 | if (finishing) { | |
55 | /* Granularity of the final decompression. When we were | |
56 | @@ -743,10 +736,6 @@ | |
57 | * displaying feeling better? --pasky */ | |
58 | ret = 65536; | |
59 | } | |
60 | - if (ret < 4096) { | |
61 | - /* Not enough data, try in next round. */ | |
62 | - return output; | |
63 | - } | |
64 | ||
65 | if (!conn->stream) { | |
66 | conn->stream = open_encoded(conn->stream_pipes[0], | |
67 | @@ -757,9 +746,9 @@ | |
68 | output = (unsigned char *) mem_realloc(output, *new_len + ret); | |
69 | if (!output) break; | |
70 | ||
71 | - r = read_encoded(conn->stream, output + *new_len, ret); | |
72 | + r = read_encoded(conn->stream, output + *new_len, ret); | |
73 | if (r > 0) *new_len += r; | |
74 | - } | |
75 | + } while (len || r == ret); | |
76 | ||
77 | if (r < 0 && output) { | |
78 | mem_free(output); |