26 #ifndef _BUFFEREVENT_INTERNAL_H_
27 #define _BUFFEREVENT_INTERNAL_H_
33 #include "event2/event-config.h"
35 #include "defer-internal.h"
36 #include "evthread-internal.h"
38 #include "ratelim-internal.h"
52 #define BEV_SUSPEND_WM 0x01
54 #define BEV_SUSPEND_BW 0x02
56 #define BEV_SUSPEND_BW_GROUP 0x04
59 #define BEV_SUSPEND_LOOKUP 0x08
62 #define BEV_SUSPEND_FILT_READ 0x10
64 typedef ev_uint16_t bufferevent_suspend_flags;
92 ev_uint64_t total_written;
130 struct event refill_bucket_event;
195 enum bufferevent_ctrl_op {
198 BEV_CTRL_GET_UNDERLYING
258 #define BEV_IS_SOCKET(bevp) ((bevp)->be_ops == &bufferevent_ops_socket)
259 #define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter)
260 #define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair)
264 #define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async)
266 #define BEV_IS_ASYNC(bevp) 0
274 void bufferevent_suspend_read(
struct bufferevent *bufev, bufferevent_suspend_flags what);
277 void bufferevent_unsuspend_read(
struct bufferevent *bufev, bufferevent_suspend_flags what);
281 void bufferevent_suspend_write(
struct bufferevent *bufev, bufferevent_suspend_flags what);
284 void bufferevent_unsuspend_write(
struct bufferevent *bufev, bufferevent_suspend_flags what);
286 #define bufferevent_wm_suspend_read(b) \
287 bufferevent_suspend_read((b), BEV_SUSPEND_WM)
288 #define bufferevent_wm_unsuspend_read(b) \
289 bufferevent_unsuspend_read((b), BEV_SUSPEND_WM)
307 int bufferevent_enable_locking(
struct bufferevent *bufev,
void *lock);
309 void bufferevent_incref(
struct bufferevent *bufev);
312 void _bufferevent_incref_and_lock(
struct bufferevent *bufev);
318 int _bufferevent_decref_and_unlock(
struct bufferevent *bufev);
322 void _bufferevent_run_readcb(
struct bufferevent *bufev);
325 void _bufferevent_run_writecb(
struct bufferevent *bufev);
328 void _bufferevent_run_eventcb(
struct bufferevent *bufev,
short what);
332 int _bufferevent_add_event(
struct event *ev,
const struct timeval *tv);
341 void _bufferevent_init_generic_timeout_cbs(
struct bufferevent *bev);
344 int _bufferevent_del_generic_timeout_cbs(
struct bufferevent *bev);
349 int _bufferevent_generic_adj_timeouts(
struct bufferevent *bev);
353 #define BEV_RESET_GENERIC_READ_TIMEOUT(bev) \
355 if (evutil_timerisset(&(bev)->timeout_read)) \
356 event_add(&(bev)->ev_read, &(bev)->timeout_read); \
360 #define BEV_RESET_GENERIC_WRITE_TIMEOUT(bev) \
362 if (evutil_timerisset(&(bev)->timeout_write)) \
363 event_add(&(bev)->ev_write, &(bev)->timeout_write); \
365 #define BEV_DEL_GENERIC_READ_TIMEOUT(bev) \
366 event_del(&(bev)->ev_read)
367 #define BEV_DEL_GENERIC_WRITE_TIMEOUT(bev) \
368 event_del(&(bev)->ev_write)
373 #define BEV_UPCAST(b) EVUTIL_UPCAST((b), struct bufferevent_private, bev)
375 #ifdef _EVENT_DISABLE_THREAD_SUPPORT
376 #define BEV_LOCK(b) _EVUTIL_NIL_STMT
377 #define BEV_UNLOCK(b) _EVUTIL_NIL_STMT
380 #define BEV_LOCK(b) do { \
381 struct bufferevent_private *locking = BEV_UPCAST(b); \
382 EVLOCK_LOCK(locking->lock, 0); \
386 #define BEV_UNLOCK(b) do { \
387 struct bufferevent_private *locking = BEV_UPCAST(b); \
388 EVLOCK_UNLOCK(locking->lock, 0); \
int errno_pending
Set to the current socket errno if we have deferred callbacks and an events callback is pending...
Definition: bufferevent-internal.h:172
int(* enable)(struct bufferevent *, short)
Enables one or more of EV_READ|EV_WRITE on a bufferevent.
Definition: bufferevent-internal.h:230
unsigned connection_refused
Flag: set if a connect failed prematurely; this is a hack for getting around the bufferevent abstract...
Definition: bufferevent-internal.h:155
int(* adj_timeouts)(struct bufferevent *)
Called when the timeouts on the bufferevent have changed.
Definition: bufferevent-internal.h:244
A single evbuffer callback for an evbuffer.
Definition: evbuffer-internal.h:60
ev_ssize_t min_share
The smallest number of bytes that any member of the group should be limited to read or write at a tim...
Definition: bufferevent-internal.h:100
unsigned read_suspended
True iff we don't want to read from any member of the group.until the token bucket refills...
Definition: bufferevent-internal.h:75
struct deferred_cb deferred
Used to implement deferred callbacks.
Definition: bufferevent-internal.h:178
Definition: bufferevent-internal.h:66
const char * type
The name of the bufferevent's type.
Definition: bufferevent-internal.h:213
struct bufferevent_rate_limit * rate_limiting
Rate-limiting information for this bufferevent.
Definition: bufferevent-internal.h:191
unsigned pending_unsuspend_write
True iff we were unable to suspend one of the bufferevents in the group for writing the last time we ...
Definition: bufferevent-internal.h:86
void * lock
Lock for this bufferevent.
Definition: bufferevent-internal.h:188
Structure to represent a single event.
Definition: event_struct.h:87
int refcnt
Current reference count for this bufferevent.
Definition: bufferevent-internal.h:184
ev_uint64_t total_read
Total number of bytes read or written in this group since last reset.
Definition: bufferevent-internal.h:91
unsigned connecting
Flag: set if we are currently busy connecting.
Definition: bufferevent-internal.h:152
struct event master_refill_event
Timeout event that goes off once a tick, when the bucket is ready to refill.
Definition: bufferevent-internal.h:103
unsigned own_lock
If set, we should free the lock when we free the bufferevent.
Definition: bufferevent-internal.h:143
Data structures for bufferevents.
bufferevent_suspend_flags write_suspended
If set, writing is suspended until one or more conditions are over.
Definition: bufferevent-internal.h:168
int dns_error
The DNS error code for bufferevent_socket_connect_hostname.
Definition: bufferevent-internal.h:175
Functions for multi-threaded applications using Libevent.
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:278
unsigned readcb_pending
Flag: set if we have deferred callbacks and a read callback is pending.
Definition: bufferevent-internal.h:147
int n_members
The number of bufferevents in the group.
Definition: bufferevent-internal.h:96
unsigned writecb_pending
Flag: set if we have deferred callbacks and a write callback is pending.
Definition: bufferevent-internal.h:150
Parts of the bufferevent structure that are shared among all bufferevent types, but not exposed in bu...
Definition: bufferevent-internal.h:135
A token bucket is an internal structure that tracks how many bytes we are currently willing to read o...
Definition: ratelim-internal.h:38
Configuration info for a token bucket or set of token buckets.
Definition: ratelim-internal.h:48
void(* destruct)(struct bufferevent *)
Free any storage and deallocate any extra data or structures used in this implementation.
Definition: bufferevent-internal.h:241
void * lock
Lock to protect the members of this group.
Definition: bufferevent-internal.h:107
off_t mem_offset
At what offset into the implementation type will we find a bufferevent structure? ...
Definition: bufferevent-internal.h:224
Possible data types for a control callback.
Definition: bufferevent-internal.h:202
Common convenience functions for cross-platform portability and related socket manipulations.
enum bufferevent_options options
The options this bufferevent was constructed with.
Definition: bufferevent-internal.h:181
short eventcb_pending
Set to the events pending if we have deferred callbacks and an events callback is pending...
Definition: bufferevent-internal.h:158
int(* flush)(struct bufferevent *, short, enum bufferevent_flush_mode)
Called to flush data.
Definition: bufferevent-internal.h:247
TAILQ_HEAD(rlim_group_member_list, bufferevent_private) members
List of all members in the group.
bufferevent_suspend_flags read_suspended
If set, read is suspended until one or more conditions are over.
Definition: bufferevent-internal.h:163
struct evbuffer_cb_entry * read_watermarks_cb
Evbuffer callback to enforce watermarks on input.
Definition: bufferevent-internal.h:140
struct ev_token_bucket rate_limit
Current limits for the group.
Definition: bufferevent-internal.h:70
struct bufferevent_rate_limit_group * group
The rate-limiting group for this bufferevent, or NULL if it is only rate-limited on its own...
Definition: bufferevent-internal.h:120
A deferred_cb is a callback that can be scheduled to run as part of an event_base's event_loop...
Definition: defer-internal.h:42
bufferevent_flush_mode
Flags that can be passed into filters to let them know how to deal with the incoming data...
Definition: bufferevent.h:490
unsigned pending_unsuspend_read
True iff we were unable to suspend one of the bufferevents in the group for reading the last time we ...
Definition: bufferevent-internal.h:82
int(* ctrl)(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *)
Called to access miscellaneous fields.
Definition: bufferevent-internal.h:250
Shared implementation of a bufferevent.
Definition: bufferevent_struct.h:70
bufferevent_options
Options that can be specified when creating a bufferevent.
Definition: bufferevent.h:148
Definition: event-internal.h:167
Implementation table for a bufferevent: holds function pointers and other information to make the var...
Definition: bufferevent-internal.h:211
int(* disable)(struct bufferevent *, short)
Disables one or more of EV_READ|EV_WRITE on a bufferevent.
Definition: bufferevent-internal.h:236
struct bufferevent bev
The underlying bufferevent structure.
Definition: bufferevent-internal.h:137
Fields for rate-limiting a single bufferevent.
Definition: bufferevent-internal.h:111
unsigned write_suspended
True iff we don't want to write from any member of the group.until the token bucket refills...
Definition: bufferevent-internal.h:78