]> git.pld-linux.org Git - packages/elinks.git/blob - elinks-decompress4.patch
- kill remaining fuzzy, fix format specifiers, some pl fixes
[packages/elinks.git] / elinks-decompress4.patch
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 @@
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 ret = 2048;
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;
26  
27 -       while (r == ret) {
28 -               if (!finishing) {
29 -                       int written = write(conn->stream_pipes[1], data, len);
30 +       do {
31 +               if (ret == 2048) {
32 +                       int written = write(conn->stream_pipes[1], data, len > ret ? ret : len);
33  
34                         /* When we're writing zero bytes already, we want to
35                          * zero ret properly for now, so that we'll go out for
36 @@ -700,37 +698,16 @@
37                          * zero bytes, but ret will be on its original value,
38                          * causing us to close the stream, and that's disaster
39                          * when more data are about to come yet. */
40 -                       if (written > 0 || (!written && !len)) {
41 -                               ret = written;
42 -                               data += ret;
43 -                               len -= ret;
44 +                       if (written > 0) {
45 +                               data += written;
46 +                               len -= written;
47                                 if (*length_of_block > 0)
48 -                                       *length_of_block -= ret;
49 +                                       *length_of_block -= written;
50                                 if (!info->length)
51 -                                       finishing = 1;
52 +                                       ret = 65536;
53 +                               else if (!len)
54 +                                       return output;
55                         }
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 */
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 -               }
75 -               if (ret < 4096) {
76 -                       /* Not enough data, try in next round. */
77 -                       return output;
78                 }
79  
80                 if (!conn->stream) {
81 @@ -743,8 +720,9 @@
82                 if (!output) break;
83  
84                 r = read_encoded(conn->stream, output + *new_len, ret);
85 +               
86                 if (r > 0) *new_len += r;
87 -       }
88 +       } while (len || r == ret);
89  
90         if (r < 0 && output) {
91                 mem_free(output);
This page took 0.037178 seconds and 3 git commands to generate.