summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-11-25 18:59:46 +0000
committererdgeist <>2007-11-25 18:59:46 +0000
commit9d86780a74522a7a29097f18ba736965440b1bac (patch)
treead4b70c29705a6e6ea45c988158b06f91b172fa2
parent09a662dfce63641aea2d873a4c3f3a85daaedb5b (diff)
Fixed call to deflate() with wrong flag in endgame
-rw-r--r--ot_fullscrape.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/ot_fullscrape.c b/ot_fullscrape.c
index d85aa9d..b632cb9 100644
--- a/ot_fullscrape.c
+++ b/ot_fullscrape.c
@@ -32,10 +32,10 @@
32 32
33#ifdef WANT_COMPRESSION_GZIP 33#ifdef WANT_COMPRESSION_GZIP
34#define IF_COMPRESSION( TASK ) if( mode & TASK_FLAG_GZIP ) TASK 34#define IF_COMPRESSION( TASK ) if( mode & TASK_FLAG_GZIP ) TASK
35#define WANT_COMPRESSION_GZIP_PARAM( param1, param2 ) , param1, param2 35#define WANT_COMPRESSION_GZIP_PARAM( param1, param2, param3 ) , param1, param2, param3
36#else 36#else
37#define IF_COMPRESSION( TASK ) 37#define IF_COMPRESSION( TASK )
38#define WANT_COMPRESSION_GZIP_PARAM( param1, param2 ) 38#define WANT_COMPRESSION_GZIP_PARAM( param1, param2, param3 )
39#endif 39#endif
40 40
41/* Forward declaration */ 41/* Forward declaration */
@@ -78,7 +78,7 @@ void fullscrape_deliver( int64 socket, ot_tasktype tasktype ) {
78} 78}
79 79
80static int fullscrape_increase( int *iovec_entries, struct iovec **iovector, 80static int fullscrape_increase( int *iovec_entries, struct iovec **iovector,
81 char **r, char **re WANT_COMPRESSION_GZIP_PARAM( z_stream *strm, ot_tasktype mode ) ) { 81 char **r, char **re WANT_COMPRESSION_GZIP_PARAM( z_stream *strm, ot_tasktype mode, int zaction ) ) {
82 /* Allocate a fresh output buffer at the end of our buffers list */ 82 /* Allocate a fresh output buffer at the end of our buffers list */
83 if( !( *r = iovec_fix_increase_or_free( iovec_entries, iovector, *r, OT_SCRAPE_CHUNK_SIZE ) ) ) { 83 if( !( *r = iovec_fix_increase_or_free( iovec_entries, iovector, *r, OT_SCRAPE_CHUNK_SIZE ) ) ) {
84 84
@@ -93,13 +93,16 @@ static int fullscrape_increase( int *iovec_entries, struct iovec **iovector,
93 *re = *r + OT_SCRAPE_CHUNK_SIZE - OT_SCRAPE_MAXENTRYLEN; 93 *re = *r + OT_SCRAPE_CHUNK_SIZE - OT_SCRAPE_MAXENTRYLEN;
94 94
95 /* When compressing, we have all the bytes in output buffer */ 95 /* When compressing, we have all the bytes in output buffer */
96 IF_COMPRESSION( { \ 96#ifdef WANT_COMPRESSION_GZIP
97 *re -= OT_SCRAPE_MAXENTRYLEN; \ 97 if( mode & TASK_FLAG_GZIP ) {
98 strm->next_out = (ot_byte*)*r; \ 98 *re -= OT_SCRAPE_MAXENTRYLEN;
99 strm->avail_out = OT_SCRAPE_CHUNK_SIZE; \ 99 strm->next_out = (ot_byte*)*r;
100 deflate( strm, Z_NO_FLUSH ); \ 100 strm->avail_out = OT_SCRAPE_CHUNK_SIZE;
101 *r = (char*)strm->next_out; \ 101 if( deflate( strm, zaction ) < Z_OK )
102 } ) 102 fprintf( stderr, "deflate() failed while in fullscrape_increase().\n" );
103 *r = (char*)strm->next_out;
104 }
105#endif
103 106
104 return 0; 107 return 0;
105} 108}
@@ -180,14 +183,16 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
180 if( mode & TASK_FLAG_GZIP ) { 183 if( mode & TASK_FLAG_GZIP ) {
181 strm.next_in = (ot_byte*)compress_buffer; 184 strm.next_in = (ot_byte*)compress_buffer;
182 strm.avail_in = r - compress_buffer; 185 strm.avail_in = r - compress_buffer;
183 deflate( &strm, Z_NO_FLUSH ); 186 if( deflate( &strm, Z_NO_FLUSH ) < Z_OK )
187 fprintf( stderr, "deflate() failed while in fullscrape_make().\n" );
184 r = (char*)strm.next_out; 188 r = (char*)strm.next_out;
185 } 189 }
186#endif 190#endif
187 191
188 /* Check if there still is enough buffer left */ 192 /* Check if there still is enough buffer left */
189 while( ( r > re ) && fullscrape_increase( iovec_entries, iovector, &r, &re WANT_COMPRESSION_GZIP_PARAM( &strm, mode ) ) ) 193 while( r >= re )
190 return mutex_bucket_unlock( bucket ); 194 if( fullscrape_increase( iovec_entries, iovector, &r, &re WANT_COMPRESSION_GZIP_PARAM( &strm, mode, Z_NO_FLUSH ) ) )
195 return mutex_bucket_unlock( bucket );
191 196
192 IF_COMPRESSION( r = compress_buffer; ) 197 IF_COMPRESSION( r = compress_buffer; )
193 } 198 }
@@ -203,11 +208,13 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
203 if( mode & TASK_FLAG_GZIP ) { 208 if( mode & TASK_FLAG_GZIP ) {
204 strm.next_in = (ot_byte*)compress_buffer; 209 strm.next_in = (ot_byte*)compress_buffer;
205 strm.avail_in = r - compress_buffer; 210 strm.avail_in = r - compress_buffer;
206 deflate( &strm, Z_FINISH ); 211 if( deflate( &strm, Z_FINISH ) < Z_OK )
212 fprintf( stderr, "deflate() failed while in fullscrape_make()'s endgame.\n" );
207 r = (char*)strm.next_out; 213 r = (char*)strm.next_out;
208 214
209 while( ( r > re ) && fullscrape_increase( iovec_entries, iovector, &r, &re WANT_COMPRESSION_GZIP_PARAM( &strm, mode ) ) ) 215 while( r >= re )
210 return mutex_bucket_unlock( bucket ); 216 if( fullscrape_increase( iovec_entries, iovector, &r, &re WANT_COMPRESSION_GZIP_PARAM( &strm, mode, Z_FINISH ) ) )
217 return mutex_bucket_unlock( bucket );
211 deflateEnd(&strm); 218 deflateEnd(&strm);
212 } 219 }
213#endif 220#endif