49
53
while (ctx->done != NULL) {
50
54
next_list = ctx->done->next;
52
serf_bucket_destroy(ctx->done->bucket);
56
if (ctx->bucket_owner) {
57
serf_bucket_destroy(ctx->done->bucket);
53
59
serf_bucket_mem_free(allocator, ctx->done);
55
61
ctx->done = next_list;
59
SERF_DECLARE(serf_bucket_t *) serf_bucket_aggregate_create(
65
void serf_bucket_aggregate_cleanup(
66
serf_bucket_t *bucket, serf_bucket_alloc_t *allocator)
68
aggregate_context_t *ctx = bucket->data;
70
cleanup_aggregate(ctx, allocator);
73
static aggregate_context_t *create_aggregate(serf_bucket_alloc_t *allocator)
75
aggregate_context_t *ctx;
77
ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
83
ctx->hold_open = NULL;
84
ctx->hold_open_baton = NULL;
85
ctx->bucket_owner = 1;
90
serf_bucket_t *serf_bucket_aggregate_create(
60
91
serf_bucket_alloc_t *allocator)
62
93
aggregate_context_t *ctx;
64
ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
95
ctx = create_aggregate(allocator);
69
97
return serf_bucket_create(&serf_bucket_type_aggregate, allocator, ctx);
100
serf_bucket_t *serf__bucket_stream_create(
101
serf_bucket_alloc_t *allocator,
102
serf_bucket_aggregate_eof_t fn,
105
serf_bucket_t *bucket = serf_bucket_aggregate_create(allocator);
106
aggregate_context_t *ctx = bucket->data;
108
serf_bucket_aggregate_hold_open(bucket, fn, baton);
110
ctx->bucket_owner = 0;
72
116
static void serf_aggregate_destroy_and_data(serf_bucket_t *bucket)
74
118
aggregate_context_t *ctx = bucket->data;
75
119
bucket_list_t *next_ctx;
77
121
while (ctx->list) {
78
serf_bucket_destroy(ctx->list->bucket);
122
if (ctx->bucket_owner) {
123
serf_bucket_destroy(ctx->list->bucket);
79
125
next_ctx = ctx->list->next;
80
126
serf_bucket_mem_free(bucket->allocator, ctx->list);
81
127
ctx->list = next_ctx;
85
131
serf_default_destroy_and_data(bucket);
88
SERF_DECLARE(void) serf_bucket_aggregate_become(serf_bucket_t *bucket)
134
void serf_bucket_aggregate_become(serf_bucket_t *bucket)
90
136
aggregate_context_t *ctx;
92
ctx = serf_bucket_mem_alloc(bucket->allocator, sizeof(*ctx));
138
ctx = create_aggregate(bucket->allocator);
98
140
bucket->type = &serf_bucket_type_aggregate;
99
141
bucket->data = ctx;
105
SERF_DECLARE(void) serf_bucket_aggregate_prepend(
147
void serf_bucket_aggregate_prepend(
106
148
serf_bucket_t *aggregate_bucket,
107
149
serf_bucket_t *prepend_bucket)
117
159
ctx->list = new_list;
120
SERF_DECLARE(void) serf_bucket_aggregate_append(
162
void serf_bucket_aggregate_append(
121
163
serf_bucket_t *aggregate_bucket,
122
164
serf_bucket_t *append_bucket)
136
178
if (ctx->list == NULL) {
137
179
ctx->list = new_list;
138
ctx->last = new_list;
180
ctx->last = new_list;
141
183
ctx->last->next = new_list;
142
ctx->last = ctx->last->next;
184
ctx->last = ctx->last->next;
146
SERF_DECLARE(void) serf_bucket_aggregate_prepend_iovec(
188
void serf_bucket_aggregate_hold_open(serf_bucket_t *aggregate_bucket,
189
serf_bucket_aggregate_eof_t fn,
192
aggregate_context_t *ctx = aggregate_bucket->data;
194
ctx->hold_open_baton = baton;
197
void serf_bucket_aggregate_prepend_iovec(
147
198
serf_bucket_t *aggregate_bucket,
148
199
struct iovec *vecs,
236
292
/* If we have no more in our list, return EOF. */
237
293
if (!ctx->list) {
294
if (ctx->hold_open) {
295
return ctx->hold_open(ctx->hold_open_baton, bucket);
241
302
/* At this point, it safe to read the next bucket - if we can. */