2
* eagain_bucket.c : a serf bucket that handles slowing down data
3
* for specific readers that would have unwanted
4
* behavior if they read everything too fast
5
* ====================================================================
6
* Licensed to the Apache Software Foundation (ASF) under one
7
* or more contributor license agreements. See the NOTICE file
8
* distributed with this work for additional information
9
* regarding copyright ownership. The ASF licenses this file
10
* to you under the Apache License, Version 2.0 (the
11
* "License"); you may not use this file except in compliance
12
* with the License. You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing,
17
* software distributed under the License is distributed on an
18
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
* KIND, either express or implied. See the License for the
20
* specific language governing permissions and limitations
22
* ====================================================================
26
#include <serf_bucket_util.h>
28
#include "svn_private_config.h"
32
typedef struct eagain_baton_t
39
eagain_bucket_read(serf_bucket_t *bucket,
44
eagain_baton_t *eab = bucket->data;
46
if (eab->remaining > 0)
49
if (requested > eab->remaining || requested == SERF_READ_ALL_AVAIL)
51
*len = eab->remaining;
58
eab->data += requested;
59
eab->remaining -= requested;
71
eagain_bucket_readline(serf_bucket_t *bucket,
77
/* ### for now, we know callers won't use this function. */
78
svn_error_clear(svn_error__malfunction(TRUE, __FILE__, __LINE__,
85
eagain_bucket_peek(serf_bucket_t *bucket,
89
const eagain_baton_t *eab = bucket->data;
91
*data = eab->data ? eab->data : "";
92
*len = eab->remaining;
98
static const serf_bucket_type_t delay_bucket_vtable = {
101
eagain_bucket_readline,
102
serf_default_read_iovec,
103
serf_default_read_for_sendfile,
104
serf_default_read_bucket,
106
serf_default_destroy_and_data,
111
svn_ra_serf__create_bucket_with_eagain(const char *data,
113
serf_bucket_alloc_t *allocator)
117
eab = serf_bucket_mem_alloc(allocator, sizeof(*eab));
119
eab->remaining = len;
121
return serf_bucket_create(&delay_bucket_vtable, allocator, eab);