diff options
Diffstat (limited to 'compress.c')
-rw-r--r-- | compress.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/compress.c b/compress.c index e8539baf0..3e41b3d82 100644 --- a/compress.c +++ b/compress.c | |||
@@ -12,7 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "includes.h" | 14 | #include "includes.h" |
15 | RCSID("$OpenBSD: compress.c,v 1.13 2001/02/08 19:30:51 itojun Exp $"); | 15 | RCSID("$OpenBSD: compress.c,v 1.14 2001/04/05 10:39:01 markus Exp $"); |
16 | 16 | ||
17 | #include "log.h" | 17 | #include "log.h" |
18 | #include "buffer.h" | 18 | #include "buffer.h" |
@@ -21,6 +21,8 @@ RCSID("$OpenBSD: compress.c,v 1.13 2001/02/08 19:30:51 itojun Exp $"); | |||
21 | 21 | ||
22 | static z_stream incoming_stream; | 22 | static z_stream incoming_stream; |
23 | static z_stream outgoing_stream; | 23 | static z_stream outgoing_stream; |
24 | static int compress_init_send_called = 0; | ||
25 | static int compress_init_recv_called = 0; | ||
24 | 26 | ||
25 | /* | 27 | /* |
26 | * Initializes compression; level is compression level from 1 to 9 | 28 | * Initializes compression; level is compression level from 1 to 9 |
@@ -28,14 +30,24 @@ static z_stream outgoing_stream; | |||
28 | */ | 30 | */ |
29 | 31 | ||
30 | void | 32 | void |
31 | buffer_compress_init(int level) | 33 | buffer_compress_init_send(int level) |
32 | { | 34 | { |
35 | if (compress_init_send_called == 1) | ||
36 | deflateEnd(&incoming_stream); | ||
37 | compress_init_send_called = 1; | ||
33 | debug("Enabling compression at level %d.", level); | 38 | debug("Enabling compression at level %d.", level); |
34 | if (level < 1 || level > 9) | 39 | if (level < 1 || level > 9) |
35 | fatal("Bad compression level %d.", level); | 40 | fatal("Bad compression level %d.", level); |
36 | inflateInit(&incoming_stream); | ||
37 | deflateInit(&outgoing_stream, level); | 41 | deflateInit(&outgoing_stream, level); |
38 | } | 42 | } |
43 | void | ||
44 | buffer_compress_init_recv(void) | ||
45 | { | ||
46 | if (compress_init_recv_called == 1) | ||
47 | inflateEnd(&incoming_stream); | ||
48 | compress_init_recv_called = 1; | ||
49 | inflateInit(&incoming_stream); | ||
50 | } | ||
39 | 51 | ||
40 | /* Frees any data structures allocated for compression. */ | 52 | /* Frees any data structures allocated for compression. */ |
41 | 53 | ||
@@ -50,8 +62,10 @@ buffer_compress_uninit(void) | |||
50 | incoming_stream.total_out, incoming_stream.total_in, | 62 | incoming_stream.total_out, incoming_stream.total_in, |
51 | incoming_stream.total_out == 0 ? 0.0 : | 63 | incoming_stream.total_out == 0 ? 0.0 : |
52 | (double) incoming_stream.total_in / incoming_stream.total_out); | 64 | (double) incoming_stream.total_in / incoming_stream.total_out); |
53 | inflateEnd(&incoming_stream); | 65 | if (compress_init_recv_called == 1) |
54 | deflateEnd(&outgoing_stream); | 66 | inflateEnd(&incoming_stream); |
67 | if (compress_init_send_called == 1) | ||
68 | deflateEnd(&outgoing_stream); | ||
55 | } | 69 | } |
56 | 70 | ||
57 | /* | 71 | /* |