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;
69 #if !SERF_VERSION_AT_LEAST(1, 4, 0)
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__,
86 eagain_bucket_peek(serf_bucket_t *bucket,
90 const eagain_baton_t *eab = bucket->data;
92 *data = eab->data ? eab->data : "";
93 *len = eab->remaining;
99 static const serf_bucket_type_t delay_bucket_vtable = {
102 #if SERF_VERSION_AT_LEAST(1, 4, 0)
103 serf_default_readline,
105 eagain_bucket_readline,
107 serf_default_read_iovec,
108 serf_default_read_for_sendfile,
109 serf_default_read_bucket,
111 serf_default_destroy_and_data,
116 svn_ra_serf__create_bucket_with_eagain(const char *data,
118 serf_bucket_alloc_t *allocator)
122 eab = serf_bucket_mem_alloc(allocator, sizeof(*eab));
124 eab->remaining = len;
126 return serf_bucket_create(&delay_bucket_vtable, allocator, eab);