1275970Scy/*
2275970Scy * Copyright (c) 2008-2012 Niels Provos and Nick Mathewson
3275970Scy *
4275970Scy * Redistribution and use in source and binary forms, with or without
5275970Scy * modification, are permitted provided that the following conditions
6275970Scy * are met:
7275970Scy * 1. Redistributions of source code must retain the above copyright
8275970Scy *    notice, this list of conditions and the following disclaimer.
9275970Scy * 2. Redistributions in binary form must reproduce the above copyright
10275970Scy *    notice, this list of conditions and the following disclaimer in the
11275970Scy *    documentation and/or other materials provided with the distribution.
12275970Scy * 3. The name of the author may not be used to endorse or promote products
13275970Scy *    derived from this software without specific prior written permission.
14275970Scy *
15275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25275970Scy */
26275970Scy#ifndef BUFFEREVENT_INTERNAL_H_INCLUDED_
27275970Scy#define BUFFEREVENT_INTERNAL_H_INCLUDED_
28275970Scy
29275970Scy#ifdef __cplusplus
30275970Scyextern "C" {
31275970Scy#endif
32275970Scy
33275970Scy#include "event2/event-config.h"
34275970Scy#include "event2/event_struct.h"
35275970Scy#include "evconfig-private.h"
36275970Scy#include "event2/util.h"
37275970Scy#include "defer-internal.h"
38275970Scy#include "evthread-internal.h"
39275970Scy#include "event2/thread.h"
40275970Scy#include "ratelim-internal.h"
41275970Scy#include "event2/bufferevent_struct.h"
42275970Scy
43275970Scy/* These flags are reasons that we might be declining to actually enable
44275970Scy   reading or writing on a bufferevent.
45275970Scy */
46275970Scy
47275970Scy/* On a all bufferevents, for reading: used when we have read up to the
48275970Scy   watermark value.
49275970Scy
50275970Scy   On a filtering bufferevent, for writing: used when the underlying
51275970Scy   bufferevent's write buffer has been filled up to its watermark
52275970Scy   value.
53275970Scy*/
54275970Scy#define BEV_SUSPEND_WM 0x01
55275970Scy/* On a base bufferevent: when we have emptied a bandwidth buckets */
56275970Scy#define BEV_SUSPEND_BW 0x02
57275970Scy/* On a base bufferevent: when we have emptied the group's bandwidth bucket. */
58275970Scy#define BEV_SUSPEND_BW_GROUP 0x04
59275970Scy/* On a socket bufferevent: can't do any operations while we're waiting for
60275970Scy * name lookup to finish. */
61275970Scy#define BEV_SUSPEND_LOOKUP 0x08
62275970Scy/* On a base bufferevent, for reading: used when a filter has choked this
63275970Scy * (underlying) bufferevent because it has stopped reading from it. */
64275970Scy#define BEV_SUSPEND_FILT_READ 0x10
65275970Scy
66275970Scytypedef ev_uint16_t bufferevent_suspend_flags;
67275970Scy
68275970Scystruct bufferevent_rate_limit_group {
69275970Scy	/** List of all members in the group */
70275970Scy	LIST_HEAD(rlim_group_member_list, bufferevent_private) members;
71275970Scy	/** Current limits for the group. */
72275970Scy	struct ev_token_bucket rate_limit;
73275970Scy	struct ev_token_bucket_cfg rate_limit_cfg;
74275970Scy
75275970Scy	/** True iff we don't want to read from any member of the group.until
76275970Scy	 * the token bucket refills.  */
77275970Scy	unsigned read_suspended : 1;
78275970Scy	/** True iff we don't want to write from any member of the group.until
79275970Scy	 * the token bucket refills.  */
80275970Scy	unsigned write_suspended : 1;
81275970Scy	/** True iff we were unable to suspend one of the bufferevents in the
82275970Scy	 * group for reading the last time we tried, and we should try
83275970Scy	 * again. */
84275970Scy	unsigned pending_unsuspend_read : 1;
85275970Scy	/** True iff we were unable to suspend one of the bufferevents in the
86275970Scy	 * group for writing the last time we tried, and we should try
87275970Scy	 * again. */
88275970Scy	unsigned pending_unsuspend_write : 1;
89275970Scy
90275970Scy	/*@{*/
91275970Scy	/** Total number of bytes read or written in this group since last
92275970Scy	 * reset. */
93275970Scy	ev_uint64_t total_read;
94275970Scy	ev_uint64_t total_written;
95275970Scy	/*@}*/
96275970Scy
97275970Scy	/** The number of bufferevents in the group. */
98275970Scy	int n_members;
99275970Scy
100275970Scy	/** The smallest number of bytes that any member of the group should
101275970Scy	 * be limited to read or write at a time. */
102275970Scy	ev_ssize_t min_share;
103275970Scy	ev_ssize_t configured_min_share;
104275970Scy
105275970Scy	/** Timeout event that goes off once a tick, when the bucket is ready
106275970Scy	 * to refill. */
107275970Scy	struct event master_refill_event;
108275970Scy
109275970Scy	/** Seed for weak random number generator. Protected by 'lock' */
110275970Scy	struct evutil_weakrand_state weakrand_seed;
111275970Scy
112275970Scy	/** Lock to protect the members of this group.  This lock should nest
113275970Scy	 * within every bufferevent lock: if you are holding this lock, do
114275970Scy	 * not assume you can lock another bufferevent. */
115275970Scy	void *lock;
116275970Scy};
117275970Scy
118275970Scy/** Fields for rate-limiting a single bufferevent. */
119275970Scystruct bufferevent_rate_limit {
120275970Scy	/* Linked-list elements for storing this bufferevent_private in a
121275970Scy	 * group.
122275970Scy	 *
123275970Scy	 * Note that this field is supposed to be protected by the group
124275970Scy	 * lock */
125275970Scy	LIST_ENTRY(bufferevent_private) next_in_group;
126275970Scy	/** The rate-limiting group for this bufferevent, or NULL if it is
127275970Scy	 * only rate-limited on its own. */
128275970Scy	struct bufferevent_rate_limit_group *group;
129275970Scy
130275970Scy	/* This bufferevent's current limits. */
131275970Scy	struct ev_token_bucket limit;
132275970Scy	/* Pointer to the rate-limit configuration for this bufferevent.
133275970Scy	 * Can be shared.  XXX reference-count this? */
134275970Scy	struct ev_token_bucket_cfg *cfg;
135275970Scy
136275970Scy	/* Timeout event used when one this bufferevent's buckets are
137275970Scy	 * empty. */
138275970Scy	struct event refill_bucket_event;
139275970Scy};
140275970Scy
141275970Scy/** Parts of the bufferevent structure that are shared among all bufferevent
142275970Scy * types, but not exposed in bufferevent_struct.h. */
143275970Scystruct bufferevent_private {
144275970Scy	/** The underlying bufferevent structure. */
145275970Scy	struct bufferevent bev;
146275970Scy
147275970Scy	/** Evbuffer callback to enforce watermarks on input. */
148275970Scy	struct evbuffer_cb_entry *read_watermarks_cb;
149275970Scy
150275970Scy	/** If set, we should free the lock when we free the bufferevent. */
151275970Scy	unsigned own_lock : 1;
152275970Scy
153275970Scy	/** Flag: set if we have deferred callbacks and a read callback is
154275970Scy	 * pending. */
155275970Scy	unsigned readcb_pending : 1;
156275970Scy	/** Flag: set if we have deferred callbacks and a write callback is
157275970Scy	 * pending. */
158275970Scy	unsigned writecb_pending : 1;
159275970Scy	/** Flag: set if we are currently busy connecting. */
160275970Scy	unsigned connecting : 1;
161275970Scy	/** Flag: set if a connect failed prematurely; this is a hack for
162275970Scy	 * getting around the bufferevent abstraction. */
163275970Scy	unsigned connection_refused : 1;
164275970Scy	/** Set to the events pending if we have deferred callbacks and
165275970Scy	 * an events callback is pending. */
166275970Scy	short eventcb_pending;
167275970Scy
168275970Scy	/** If set, read is suspended until one or more conditions are over.
169275970Scy	 * The actual value here is a bitfield of those conditions; see the
170275970Scy	 * BEV_SUSPEND_* flags above. */
171275970Scy	bufferevent_suspend_flags read_suspended;
172275970Scy
173275970Scy	/** If set, writing is suspended until one or more conditions are over.
174275970Scy	 * The actual value here is a bitfield of those conditions; see the
175275970Scy	 * BEV_SUSPEND_* flags above. */
176275970Scy	bufferevent_suspend_flags write_suspended;
177275970Scy
178275970Scy	/** Set to the current socket errno if we have deferred callbacks and
179275970Scy	 * an events callback is pending. */
180275970Scy	int errno_pending;
181275970Scy
182275970Scy	/** The DNS error code for bufferevent_socket_connect_hostname */
183275970Scy	int dns_error;
184275970Scy
185275970Scy	/** Used to implement deferred callbacks */
186275970Scy	struct event_callback deferred;
187275970Scy
188275970Scy	/** The options this bufferevent was constructed with */
189275970Scy	enum bufferevent_options options;
190275970Scy
191275970Scy	/** Current reference count for this bufferevent. */
192275970Scy	int refcnt;
193275970Scy
194275970Scy	/** Lock for this bufferevent.  Shared by the inbuf and the outbuf.
195275970Scy	 * If NULL, locking is disabled. */
196275970Scy	void *lock;
197275970Scy
198275970Scy	/** No matter how big our bucket gets, don't try to read more than this
199275970Scy	 * much in a single read operation. */
200275970Scy	ev_ssize_t max_single_read;
201275970Scy
202275970Scy	/** No matter how big our bucket gets, don't try to write more than this
203275970Scy	 * much in a single write operation. */
204275970Scy	ev_ssize_t max_single_write;
205275970Scy
206275970Scy	/** Rate-limiting information for this bufferevent */
207275970Scy	struct bufferevent_rate_limit *rate_limiting;
208275970Scy};
209275970Scy
210275970Scy/** Possible operations for a control callback. */
211275970Scyenum bufferevent_ctrl_op {
212275970Scy	BEV_CTRL_SET_FD,
213275970Scy	BEV_CTRL_GET_FD,
214275970Scy	BEV_CTRL_GET_UNDERLYING,
215275970Scy	BEV_CTRL_CANCEL_ALL
216275970Scy};
217275970Scy
218275970Scy/** Possible data types for a control callback */
219275970Scyunion bufferevent_ctrl_data {
220275970Scy	void *ptr;
221275970Scy	evutil_socket_t fd;
222275970Scy};
223275970Scy
224275970Scy/**
225275970Scy   Implementation table for a bufferevent: holds function pointers and other
226275970Scy   information to make the various bufferevent types work.
227275970Scy*/
228275970Scystruct bufferevent_ops {
229275970Scy	/** The name of the bufferevent's type. */
230275970Scy	const char *type;
231275970Scy	/** At what offset into the implementation type will we find a
232275970Scy	    bufferevent structure?
233275970Scy
234275970Scy	    Example: if the type is implemented as
235275970Scy	    struct bufferevent_x {
236275970Scy	       int extra_data;
237275970Scy	       struct bufferevent bev;
238275970Scy	    }
239275970Scy	    then mem_offset should be offsetof(struct bufferevent_x, bev)
240275970Scy	*/
241275970Scy	off_t mem_offset;
242275970Scy
243275970Scy	/** Enables one or more of EV_READ|EV_WRITE on a bufferevent.  Does
244275970Scy	    not need to adjust the 'enabled' field.  Returns 0 on success, -1
245275970Scy	    on failure.
246275970Scy	 */
247275970Scy	int (*enable)(struct bufferevent *, short);
248275970Scy
249275970Scy	/** Disables one or more of EV_READ|EV_WRITE on a bufferevent.  Does
250275970Scy	    not need to adjust the 'enabled' field.  Returns 0 on success, -1
251275970Scy	    on failure.
252275970Scy	 */
253275970Scy	int (*disable)(struct bufferevent *, short);
254275970Scy
255275970Scy	/** Detatches the bufferevent from related data structures. Called as
256275970Scy	 * soon as its reference count reaches 0. */
257275970Scy	void (*unlink)(struct bufferevent *);
258275970Scy
259275970Scy	/** Free any storage and deallocate any extra data or structures used
260275970Scy	    in this implementation. Called when the bufferevent is
261275970Scy	    finalized.
262275970Scy	 */
263275970Scy	void (*destruct)(struct bufferevent *);
264275970Scy
265275970Scy	/** Called when the timeouts on the bufferevent have changed.*/
266275970Scy	int (*adj_timeouts)(struct bufferevent *);
267275970Scy
268275970Scy	/** Called to flush data. */
269275970Scy	int (*flush)(struct bufferevent *, short, enum bufferevent_flush_mode);
270275970Scy
271275970Scy	/** Called to access miscellaneous fields. */
272275970Scy	int (*ctrl)(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *);
273275970Scy
274275970Scy};
275275970Scy
276275970Scyextern const struct bufferevent_ops bufferevent_ops_socket;
277275970Scyextern const struct bufferevent_ops bufferevent_ops_filter;
278275970Scyextern const struct bufferevent_ops bufferevent_ops_pair;
279275970Scy
280275970Scy#define BEV_IS_SOCKET(bevp) ((bevp)->be_ops == &bufferevent_ops_socket)
281275970Scy#define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter)
282275970Scy#define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair)
283275970Scy
284275970Scy#ifdef _WIN32
285275970Scyextern const struct bufferevent_ops bufferevent_ops_async;
286275970Scy#define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async)
287275970Scy#else
288275970Scy#define BEV_IS_ASYNC(bevp) 0
289275970Scy#endif
290275970Scy
291275970Scy/** Initialize the shared parts of a bufferevent. */
292275970Scyint bufferevent_init_common_(struct bufferevent_private *, struct event_base *, const struct bufferevent_ops *, enum bufferevent_options options);
293275970Scy
294275970Scy/** For internal use: temporarily stop all reads on bufev, until the conditions
295275970Scy * in 'what' are over. */
296275970Scyvoid bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what);
297275970Scy/** For internal use: clear the conditions 'what' on bufev, and re-enable
298275970Scy * reading if there are no conditions left. */
299275970Scyvoid bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what);
300275970Scy
301275970Scy/** For internal use: temporarily stop all writes on bufev, until the conditions
302275970Scy * in 'what' are over. */
303275970Scyvoid bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what);
304275970Scy/** For internal use: clear the conditions 'what' on bufev, and re-enable
305275970Scy * writing if there are no conditions left. */
306275970Scyvoid bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what);
307275970Scy
308275970Scy#define bufferevent_wm_suspend_read(b) \
309275970Scy	bufferevent_suspend_read_((b), BEV_SUSPEND_WM)
310275970Scy#define bufferevent_wm_unsuspend_read(b) \
311275970Scy	bufferevent_unsuspend_read_((b), BEV_SUSPEND_WM)
312275970Scy
313275970Scy/*
314275970Scy  Disable a bufferevent.  Equivalent to bufferevent_disable(), but
315275970Scy  first resets 'connecting' flag to force EV_WRITE down for sure.
316275970Scy
317275970Scy  XXXX this method will go away in the future; try not to add new users.
318275970Scy    See comment in evhttp_connection_reset_() for discussion.
319275970Scy
320275970Scy  @param bufev the bufferevent to be disabled
321275970Scy  @param event any combination of EV_READ | EV_WRITE.
322275970Scy  @return 0 if successful, or -1 if an error occurred
323275970Scy  @see bufferevent_disable()
324275970Scy */
325275970Scyint bufferevent_disable_hard_(struct bufferevent *bufev, short event);
326275970Scy
327275970Scy/** Internal: Set up locking on a bufferevent.  If lock is set, use it.
328275970Scy * Otherwise, use a new lock. */
329275970Scyint bufferevent_enable_locking_(struct bufferevent *bufev, void *lock);
330275970Scy/** Internal: Increment the reference count on bufev. */
331275970Scyvoid bufferevent_incref_(struct bufferevent *bufev);
332275970Scy/** Internal: Lock bufev and increase its reference count.
333275970Scy * unlocking it otherwise. */
334275970Scyvoid bufferevent_incref_and_lock_(struct bufferevent *bufev);
335275970Scy/** Internal: Decrement the reference count on bufev.  Returns 1 if it freed
336275970Scy * the bufferevent.*/
337275970Scyint bufferevent_decref_(struct bufferevent *bufev);
338275970Scy/** Internal: Drop the reference count on bufev, freeing as necessary, and
339275970Scy * unlocking it otherwise.  Returns 1 if it freed the bufferevent. */
340275970Scyint bufferevent_decref_and_unlock_(struct bufferevent *bufev);
341275970Scy
342275970Scy/** Internal: If callbacks are deferred and we have a read callback, schedule
343275970Scy * a readcb.  Otherwise just run the readcb. Ignores watermarks. */
344275970Scyvoid bufferevent_run_readcb_(struct bufferevent *bufev, int options);
345275970Scy/** Internal: If callbacks are deferred and we have a write callback, schedule
346275970Scy * a writecb.  Otherwise just run the writecb. Ignores watermarks. */
347275970Scyvoid bufferevent_run_writecb_(struct bufferevent *bufev, int options);
348275970Scy/** Internal: If callbacks are deferred and we have an eventcb, schedule
349275970Scy * it to run with events "what".  Otherwise just run the eventcb.
350275970Scy * See bufferevent_trigger_event for meaning of "options". */
351275970Scyvoid bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options);
352275970Scy
353275970Scy/** Internal: Run or schedule (if deferred or options contain
354275970Scy * BEV_TRIG_DEFER_CALLBACKS) I/O callbacks specified in iotype.
355275970Scy * Must already hold the bufev lock. Honors watermarks unless
356275970Scy * BEV_TRIG_IGNORE_WATERMARKS is in options. */
357275970Scystatic inline void bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options);
358275970Scy
359275970Scy/* Making this inline since all of the common-case calls to this function in
360275970Scy * libevent use constant arguments. */
361275970Scystatic inline void
362275970Scybufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options)
363275970Scy{
364275970Scy	if ((iotype & EV_READ) && ((options & BEV_TRIG_IGNORE_WATERMARKS) ||
365275970Scy	    evbuffer_get_length(bufev->input) >= bufev->wm_read.low))
366275970Scy		bufferevent_run_readcb_(bufev, options);
367275970Scy	if ((iotype & EV_WRITE) && ((options & BEV_TRIG_IGNORE_WATERMARKS) ||
368275970Scy	    evbuffer_get_length(bufev->output) <= bufev->wm_write.low))
369275970Scy		bufferevent_run_writecb_(bufev, options);
370275970Scy}
371275970Scy
372275970Scy/** Internal: Add the event 'ev' with timeout tv, unless tv is set to 0, in
373275970Scy * which case add ev with no timeout. */
374275970Scyint bufferevent_add_event_(struct event *ev, const struct timeval *tv);
375275970Scy
376275970Scy/* =========
377275970Scy * These next functions implement timeouts for bufferevents that aren't doing
378275970Scy * anything else with ev_read and ev_write, to handle timeouts.
379275970Scy * ========= */
380275970Scy/** Internal use: Set up the ev_read and ev_write callbacks so that
381275970Scy * the other "generic_timeout" functions will work on it.  Call this from
382275970Scy * the constructor function. */
383275970Scyvoid bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev);
384275970Scy/** Internal use: Add or delete the generic timeout events as appropriate.
385275970Scy * (If an event is enabled and a timeout is set, we add the event.  Otherwise
386275970Scy * we delete it.)  Call this from anything that changes the timeout values,
387275970Scy * that enabled EV_READ or EV_WRITE, or that disables EV_READ or EV_WRITE. */
388275970Scyint bufferevent_generic_adj_timeouts_(struct bufferevent *bev);
389275970Scy
390275970Scyenum bufferevent_options bufferevent_get_options_(struct bufferevent *bev);
391275970Scy
392275970Scy/** Internal use: We have just successfully read data into an inbuf, so
393275970Scy * reset the read timeout (if any). */
394275970Scy#define BEV_RESET_GENERIC_READ_TIMEOUT(bev)				\
395275970Scy	do {								\
396275970Scy		if (evutil_timerisset(&(bev)->timeout_read))		\
397275970Scy			event_add(&(bev)->ev_read, &(bev)->timeout_read); \
398275970Scy	} while (0)
399275970Scy/** Internal use: We have just successfully written data from an inbuf, so
400275970Scy * reset the read timeout (if any). */
401275970Scy#define BEV_RESET_GENERIC_WRITE_TIMEOUT(bev)				\
402275970Scy	do {								\
403275970Scy		if (evutil_timerisset(&(bev)->timeout_write))		\
404275970Scy			event_add(&(bev)->ev_write, &(bev)->timeout_write); \
405275970Scy	} while (0)
406275970Scy#define BEV_DEL_GENERIC_READ_TIMEOUT(bev)	\
407275970Scy		event_del(&(bev)->ev_read)
408275970Scy#define BEV_DEL_GENERIC_WRITE_TIMEOUT(bev)	\
409275970Scy		event_del(&(bev)->ev_write)
410275970Scy
411275970Scy
412275970Scy/** Internal: Given a bufferevent, return its corresponding
413275970Scy * bufferevent_private. */
414275970Scy#define BEV_UPCAST(b) EVUTIL_UPCAST((b), struct bufferevent_private, bev)
415275970Scy
416275970Scy#ifdef EVENT__DISABLE_THREAD_SUPPORT
417275970Scy#define BEV_LOCK(b) EVUTIL_NIL_STMT_
418275970Scy#define BEV_UNLOCK(b) EVUTIL_NIL_STMT_
419275970Scy#else
420275970Scy/** Internal: Grab the lock (if any) on a bufferevent */
421275970Scy#define BEV_LOCK(b) do {						\
422275970Scy		struct bufferevent_private *locking =  BEV_UPCAST(b);	\
423275970Scy		EVLOCK_LOCK(locking->lock, 0);				\
424275970Scy	} while (0)
425275970Scy
426275970Scy/** Internal: Release the lock (if any) on a bufferevent */
427275970Scy#define BEV_UNLOCK(b) do {						\
428275970Scy		struct bufferevent_private *locking =  BEV_UPCAST(b);	\
429275970Scy		EVLOCK_UNLOCK(locking->lock, 0);			\
430275970Scy	} while (0)
431275970Scy#endif
432275970Scy
433275970Scy
434275970Scy/* ==== For rate-limiting. */
435275970Scy
436275970Scyint bufferevent_decrement_write_buckets_(struct bufferevent_private *bev,
437275970Scy    ev_ssize_t bytes);
438275970Scyint bufferevent_decrement_read_buckets_(struct bufferevent_private *bev,
439275970Scy    ev_ssize_t bytes);
440275970Scyev_ssize_t bufferevent_get_read_max_(struct bufferevent_private *bev);
441275970Scyev_ssize_t bufferevent_get_write_max_(struct bufferevent_private *bev);
442275970Scy
443275970Scyint bufferevent_ratelim_init_(struct bufferevent_private *bev);
444275970Scy
445275970Scy#ifdef __cplusplus
446275970Scy}
447275970Scy#endif
448275970Scy
449275970Scy
450275970Scy#endif /* BUFFEREVENT_INTERNAL_H_INCLUDED_ */
451