diff options
Diffstat (limited to 'ot_fullscrape.c')
-rw-r--r-- | ot_fullscrape.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/ot_fullscrape.c b/ot_fullscrape.c index d7d3518..fafd83c 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c | |||
@@ -36,9 +36,9 @@ | |||
36 | #define OT_SCRAPE_MAXENTRYLEN 256 | 36 | #define OT_SCRAPE_MAXENTRYLEN 256 |
37 | 37 | ||
38 | /* Forward declaration */ | 38 | /* Forward declaration */ |
39 | static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ); | 39 | static void fullscrape_make( int taskid, ot_tasktype mode); |
40 | #ifdef WANT_COMPRESSION_GZIP | 40 | #ifdef WANT_COMPRESSION_GZIP |
41 | static void fullscrape_make_gzip( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ); | 41 | static void fullscrape_make_gzip( int taskid, ot_tasktype mode); |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | /* Converter function from memory to human readable hex strings | 44 | /* Converter function from memory to human readable hex strings |
@@ -49,9 +49,6 @@ static char*to_hex(char*d,uint8_t*s){char*m="0123456789ABCDEF";char *t=d;char*e= | |||
49 | It grabs tasks from mutex_tasklist and delivers results back | 49 | It grabs tasks from mutex_tasklist and delivers results back |
50 | */ | 50 | */ |
51 | static void * fullscrape_worker( void * args ) { | 51 | static void * fullscrape_worker( void * args ) { |
52 | int iovec_entries; | ||
53 | struct iovec *iovector; | ||
54 | |||
55 | (void) args; | 52 | (void) args; |
56 | 53 | ||
57 | while( g_opentracker_running ) { | 54 | while( g_opentracker_running ) { |
@@ -59,12 +56,11 @@ static void * fullscrape_worker( void * args ) { | |||
59 | ot_taskid taskid = mutex_workqueue_poptask( &tasktype ); | 56 | ot_taskid taskid = mutex_workqueue_poptask( &tasktype ); |
60 | #ifdef WANT_COMPRESSION_GZIP | 57 | #ifdef WANT_COMPRESSION_GZIP |
61 | if (tasktype & TASK_FLAG_GZIP) | 58 | if (tasktype & TASK_FLAG_GZIP) |
62 | fullscrape_make_gzip( &iovec_entries, &iovector, tasktype ); | 59 | fullscrape_make_gzip( taskid, tasktype ); |
63 | else | 60 | else |
64 | #endif | 61 | #endif |
65 | fullscrape_make( &iovec_entries, &iovector, tasktype ); | 62 | fullscrape_make( taskid, tasktype ); |
66 | if( mutex_workqueue_pushresult( taskid, iovec_entries, iovector ) ) | 63 | mutex_workqueue_pushchunked( taskid, NULL ); |
67 | iovec_free( &iovec_entries, &iovector ); | ||
68 | } | 64 | } |
69 | return NULL; | 65 | return NULL; |
70 | } | 66 | } |
@@ -123,14 +119,13 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torre | |||
123 | return r; | 119 | return r; |
124 | } | 120 | } |
125 | 121 | ||
126 | static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ) { | 122 | static void fullscrape_make( int taskid, ot_tasktype mode ) { |
127 | int bucket; | 123 | int bucket; |
128 | char *r, *re; | 124 | char *r, *re; |
125 | struct iovec iovector = { NULL, 0 }; | ||
129 | 126 | ||
130 | /* Setup return vector... */ | 127 | /* Setup return vector... */ |
131 | *iovec_entries = 0; | 128 | r = iovector.iov_base = malloc( OT_SCRAPE_CHUNK_SIZE ); |
132 | *iovector = NULL; | ||
133 | r = iovec_increase( iovec_entries, iovector, OT_SCRAPE_CHUNK_SIZE ); | ||
134 | if( !r ) | 129 | if( !r ) |
135 | return; | 130 | return; |
136 | 131 | ||
@@ -152,8 +147,14 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas | |||
152 | r = fullscrape_write_one( mode, r, torrents+i, &torrents[i].hash ); | 147 | r = fullscrape_write_one( mode, r, torrents+i, &torrents[i].hash ); |
153 | 148 | ||
154 | if( r > re) { | 149 | if( r > re) { |
150 | iovector.iov_len = r - (char *)iovector.iov_base; | ||
151 | |||
152 | if (mutex_workqueue_pushchunked(taskid, &iovector) ) { | ||
153 | free(iovector.iov_base); | ||
154 | return mutex_bucket_unlock( bucket, 0 ); | ||
155 | } | ||
155 | /* Allocate a fresh output buffer at the end of our buffers list */ | 156 | /* Allocate a fresh output buffer at the end of our buffers list */ |
156 | r = iovec_fix_increase_or_free( iovec_entries, iovector, r, OT_SCRAPE_CHUNK_SIZE ); | 157 | r = iovector.iov_base = malloc( OT_SCRAPE_CHUNK_SIZE ); |
157 | if( !r ) | 158 | if( !r ) |
158 | return mutex_bucket_unlock( bucket, 0 ); | 159 | return mutex_bucket_unlock( bucket, 0 ); |
159 | 160 | ||
@@ -174,7 +175,9 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas | |||
174 | r += sprintf( r, "ee" ); | 175 | r += sprintf( r, "ee" ); |
175 | 176 | ||
176 | /* Release unused memory in current output buffer */ | 177 | /* Release unused memory in current output buffer */ |
177 | iovec_fixlast( iovec_entries, iovector, r ); | 178 | iovector.iov_len = r - (char *)iovector.iov_base; |
179 | if( mutex_workqueue_pushchunked(taskid, &iovector) ) | ||
180 | free(iovector.iov_base); | ||
178 | } | 181 | } |
179 | 182 | ||
180 | #ifdef WANT_COMPRESSION_GZIP | 183 | #ifdef WANT_COMPRESSION_GZIP |