libevent
2.2.1
Event notification library
|
Go to the documentation of this file.
27 #ifndef EVENT2_BUFFEREVENT_H_INCLUDED_
28 #define EVENT2_BUFFEREVENT_H_INCLUDED_
78 #include <event2/visibility.h>
84 #include <event2/event-config.h>
85 #ifdef EVENT__HAVE_SYS_TYPES_H
86 #include <sys/types.h>
88 #ifdef EVENT__HAVE_SYS_TIME_H
101 #define BEV_EVENT_READING 0x01
102 #define BEV_EVENT_WRITING 0x02
103 #define BEV_EVENT_EOF 0x10
104 #define BEV_EVENT_ERROR 0x20
105 #define BEV_EVENT_TIMEOUT 0x40
106 #define BEV_EVENT_CONNECTED 0x80
115 #ifdef EVENT_IN_DOXYGEN_
235 struct evdns_base *evdns_base,
int family,
const char *hostname,
int port);
264 struct evdns_base *evdns_base,
const struct evutil_addrinfo *hints_in,
const char *hostname,
int port);
421 const void *data,
size_t size);
548 const struct timeval *timeout_read,
const struct timeval *timeout_write);
573 size_t lowmark,
size_t highmark);
587 size_t *lowmark,
size_t *highmark);
761 void (*free_context)(
void *),
790 struct ev_token_bucket_cfg;
796 struct bufferevent_rate_limit_group;
799 #define EV_RATE_LIMIT_MAX EV_SSIZE_MAX
819 size_t read_rate,
size_t read_burst,
820 size_t write_rate,
size_t write_burst,
821 const struct timeval *tick_len);
844 struct ev_token_bucket_cfg *cfg);
866 const struct ev_token_bucket_cfg *cfg);
874 struct bufferevent_rate_limit_group *,
875 const struct ev_token_bucket_cfg *);
895 struct bufferevent_rate_limit_group *,
size_t);
916 struct bufferevent_rate_limit_group *g);
964 ev_ssize_t bufferevent_get_read_limit(
struct bufferevent *bev);
966 ev_ssize_t bufferevent_get_write_limit(
struct bufferevent *bev);
970 ev_ssize_t bufferevent_get_max_to_read(
struct bufferevent *bev);
972 ev_ssize_t bufferevent_get_max_to_write(
struct bufferevent *bev);
975 const struct ev_token_bucket_cfg *bufferevent_get_token_bucket_cfg(
const struct bufferevent * bev);
987 ev_ssize_t bufferevent_rate_limit_group_get_read_limit(
988 struct bufferevent_rate_limit_group *);
990 ev_ssize_t bufferevent_rate_limit_group_get_write_limit(
991 struct bufferevent_rate_limit_group *);
1008 EVENT2_EXPORT_SYMBOL
1009 int bufferevent_decrement_read_limit(
struct bufferevent *bev, ev_ssize_t decr);
1010 EVENT2_EXPORT_SYMBOL
1011 int bufferevent_decrement_write_limit(
struct bufferevent *bev, ev_ssize_t decr);
1027 EVENT2_EXPORT_SYMBOL
1028 int bufferevent_rate_limit_group_decrement_read(
1029 struct bufferevent_rate_limit_group *, ev_ssize_t);
1030 EVENT2_EXPORT_SYMBOL
1031 int bufferevent_rate_limit_group_decrement_write(
1032 struct bufferevent_rate_limit_group *, ev_ssize_t);
1042 EVENT2_EXPORT_SYMBOL
1044 struct bufferevent_rate_limit_group *grp,
1045 ev_uint64_t *total_read_out, ev_uint64_t *total_written_out);
1052 EVENT2_EXPORT_SYMBOL
1055 struct bufferevent_rate_limit_group *grp);
EVENT2_EXPORT_SYMBOL int bufferevent_flush(struct bufferevent *bufev, short iotype, enum bufferevent_flush_mode mode)
Triggers the bufferevent to produce more data if possible.
EVENT2_EXPORT_SYMBOL void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg *cfg)
Free all storage held in 'cfg'.
@ BEV_OPT_CLOSE_ON_FREE
If set, we close the underlying file descriptor/bufferevent/whatever when this bufferevent is freed.
Definition: bufferevent.h:161
EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_pair_get_partner(struct bufferevent *bev)
Given one bufferevent returned by bufferevent_pair_new(), returns the other one if it still exists.
EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect_hostname(struct bufferevent *bufev, struct evdns_base *evdns_base, int family, const char *hostname, int port)
Resolve the hostname 'hostname' and connect to it as with bufferevent_socket_connect().
EVENT2_EXPORT_SYMBOL int bufferevent_setfd(struct bufferevent *bufev, evutil_socket_t fd)
Changes the file descriptor on which the bufferevent operates.
EVENT2_EXPORT_SYMBOL struct evbuffer * bufferevent_get_output(struct bufferevent *bufev)
Returns the output buffer.
@ BEV_TRIG_IGNORE_WATERMARKS
trigger the callback regardless of the watermarks
Definition: bufferevent.h:663
EVENT2_EXPORT_SYMBOL int bufferevent_priority_set(struct bufferevent *bufev, int pri)
Assign a priority to a bufferevent.
EVENT2_EXPORT_SYMBOL int bufferevent_set_timeouts(struct bufferevent *bufev, const struct timeval *timeout_read, const struct timeval *timeout_write)
Set the read and write timeout for a bufferevent.
EVENT2_EXPORT_SYMBOL struct ev_token_bucket_cfg * ev_token_bucket_cfg_new(size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval *tick_len)
Initialize and return a new object to configure the rate-limiting behavior of bufferevents.
bufferevent_flush_mode
Flags that can be passed into filters to let them know how to deal with the incoming data.
Definition: bufferevent.h:633
EVENT2_EXPORT_SYMBOL struct bufferevent_rate_limit_group * bufferevent_rate_limit_group_new(struct event_base *base, const struct ev_token_bucket_cfg *cfg)
Create a new rate-limit group for bufferevents.
EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_reset_totals(struct bufferevent_rate_limit_group *grp)
Reset the total bytes read/written on a group.
EVENT2_EXPORT_SYMBOL int bufferevent_socket_get_dns_error(struct bufferevent *bev)
Return the error code for the last failed DNS lookup attempt made by bufferevent_socket_connect_hostn...
EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_get_underlying(struct bufferevent *bufev)
Returns the underlying bufferevent associated with a bufferevent (if the bufferevent is a wrapper),...
EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_free(struct bufferevent_rate_limit_group *)
Free a rate-limiting group.
EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect_hostname_hints(struct bufferevent *bufev, struct evdns_base *evdns_base, const struct evutil_addrinfo *hints_in, const char *hostname, int port)
Resolve the hostname 'hostname' and connect to it as with bufferevent_socket_connect().
EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_get_max_single_read(struct bufferevent *bev)
Get the current size limit for single read operation.
EVENT2_EXPORT_SYMBOL void bufferevent_getcb(struct bufferevent *bufev, bufferevent_data_cb *readcb_ptr, bufferevent_data_cb *writecb_ptr, bufferevent_event_cb *eventcb_ptr, void **cbarg_ptr)
Retrieves the callbacks for a bufferevent.
EVENT2_EXPORT_SYMBOL int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev)
Assign a bufferevent to a specific event_base.
Structure to hold information and state for a Libevent dispatch loop.
Definition: event.h:219
EVENT2_EXPORT_SYMBOL int bufferevent_enable(struct bufferevent *bufev, short event)
Enable a bufferevent.
bufferevent_trigger_options
Flags for bufferevent_trigger(_event) that modify when and how to trigger the callback.
Definition: bufferevent.h:661
Structure to represent a single event.
Definition: event.h:276
@ BEV_OPT_THREADSAFE
If set, and threading is enabled, operations on this bufferevent are protected by a lock.
Definition: bufferevent.h:165
EVENT2_EXPORT_SYMBOL int bufferevent_getwatermark(struct bufferevent *bufev, short events, size_t *lowmark, size_t *highmark)
Retrieves the watermarks for read or write events.
@ BEV_FLUSH
want to checkpoint all data sent.
Definition: bufferevent.h:638
EVENT2_EXPORT_SYMBOL int bufferevent_read_buffer(struct bufferevent *bufev, struct evbuffer *buf)
Read data from a bufferevent buffer into an evbuffer.
EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_filter_new(struct bufferevent *underlying, bufferevent_filter_cb input_filter, bufferevent_filter_cb output_filter, int options, void(*free_context)(void *), void *ctx)
Allocate a new filtering bufferevent on top of an existing bufferevent.
EVENT2_EXPORT_SYMBOL struct evbuffer * bufferevent_get_input(struct bufferevent *bufev)
Returns the input buffer.
enum bufferevent_filter_result(* bufferevent_filter_cb)(struct evbuffer *src, struct evbuffer *dst, ev_ssize_t dst_limit, enum bufferevent_flush_mode mode, void *ctx)
A callback function to implement a filter for a bufferevent.
Definition: bufferevent.h:738
EVENT2_EXPORT_SYMBOL struct event_base * bufferevent_get_base(struct bufferevent *bev)
Return the event_base used by a bufferevent.
EVENT2_EXPORT_SYMBOL void bufferevent_incref(struct bufferevent *bufev)
Public interface to manually increase the reference count of a bufferevent this is useful in situatio...
An opaque type for handling buffered IO.
Definition: bufferevent.h:114
EVENT2_EXPORT_SYMBOL void bufferevent_lock(struct bufferevent *bufev)
Acquire the lock on a bufferevent.
EVENT2_EXPORT_SYMBOL int bufferevent_set_rate_limit(struct bufferevent *bev, struct ev_token_bucket_cfg *cfg)
Set the rate-limit of a the bufferevent 'bev' to the one specified in 'cfg'.
EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_get_max_single_write(struct bufferevent *bev)
Get the current size limit for single write operation.
EVENT2_EXPORT_SYMBOL int bufferevent_set_max_single_read(struct bufferevent *bev, size_t size)
Set the size limit for single read operation.
An evbuffer is an opaque data type for efficiently buffering data to be sent or received on the netwo...
Definition: buffer.h:97
EVENT2_EXPORT_SYMBOL short bufferevent_get_enabled(struct bufferevent *bufev)
Return the events that are enabled on a given bufferevent.
EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect(struct bufferevent *bufev, const struct sockaddr *addr, int socklen)
Launch a connect() attempt with a socket-based bufferevent.
EVENT2_EXPORT_SYMBOL evutil_socket_t bufferevent_getfd(struct bufferevent *bufev)
Returns the file descriptor associated with a bufferevent, or -1 if no file descriptor is associated ...
EVENT2_EXPORT_SYMBOL void bufferevent_unlock(struct bufferevent *bufev)
Release the lock on a bufferevent.
EVENT2_EXPORT_SYMBOL int bufferevent_remove_from_rate_limit_group(struct bufferevent *bev)
Remove 'bev' from its current rate-limit group (if any).
EVENT2_EXPORT_SYMBOL int bufferevent_get_priority(const struct bufferevent *bufev)
Return the priority of a bufferevent.
EVENT2_EXPORT_SYMBOL void bufferevent_setwatermark(struct bufferevent *bufev, short events, size_t lowmark, size_t highmark)
Sets the watermarks for read and write events.
EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_get_totals(struct bufferevent_rate_limit_group *grp, ev_uint64_t *total_read_out, ev_uint64_t *total_written_out)
Inspect the total bytes read/written on a group.
EVENT2_EXPORT_SYMBOL void bufferevent_trigger(struct bufferevent *bufev, short iotype, int options)
Triggers bufferevent data callbacks.
void(* bufferevent_event_cb)(struct bufferevent *bev, short what, void *ctx)
An event/error callback for a bufferevent.
Definition: bufferevent.h:155
void(* bufferevent_data_cb)(struct bufferevent *bev, void *ctx)
A read or write callback for a bufferevent.
Definition: bufferevent.h:136
EVENT2_EXPORT_SYMBOL void bufferevent_trigger_event(struct bufferevent *bufev, short what, int options)
Triggers the bufferevent event callback.
@ BEV_FINISHED
encountered EOF on read or done sending data
Definition: bufferevent.h:641
EVENT2_EXPORT_SYMBOL size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size)
Read data from a bufferevent buffer.
EVENT2_EXPORT_SYMBOL int bufferevent_decref(struct bufferevent *bufev)
Public interface to manually decrement the reference count of a bufferevent.
@ BEV_NEED_MORE
the filter needs to read more data before output
Definition: bufferevent.h:713
@ BEV_OPT_UNLOCK_CALLBACKS
If set, callbacks are executed without locks being held on the bufferevent.
Definition: bufferevent.h:174
EVENT2_EXPORT_SYMBOL int bufferevent_replacefd(struct bufferevent *bufev, evutil_socket_t fd)
Replaces the file descriptor on which the bufferevent operates.
EVENT2_EXPORT_SYMBOL void bufferevent_setcb(struct bufferevent *bufev, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void *cbarg)
Changes the callbacks for a bufferevent.
@ BEV_NORMAL
usually set when processing data
Definition: bufferevent.h:635
EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_cfg(struct bufferevent_rate_limit_group *, const struct ev_token_bucket_cfg *)
Change the rate-limiting settings for a given rate-limiting group.
EVENT2_EXPORT_SYMBOL int bufferevent_pair_new(struct event_base *base, int options, struct bufferevent *pair[2])
Allocate a pair of linked bufferevents.
@ BEV_OPT_DEFER_CALLBACKS
If set, callbacks are run deferred in the event loop.
Definition: bufferevent.h:168
EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_min_share(struct bufferevent_rate_limit_group *, size_t)
Change the smallest quantum we're willing to allocate to any single bufferevent in a group for readin...
EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, int options)
Create a new socket bufferevent over an existing socket.
EVENT2_EXPORT_SYMBOL void bufferevent_free(struct bufferevent *bufev)
Deallocate the storage associated with a bufferevent structure.
bufferevent_options
Options that can be specified when creating a bufferevent.
Definition: bufferevent.h:158
@ BEV_ERROR
the filter encountered a critical error, no further data can be processed.
Definition: bufferevent.h:717
@ BEV_OK
everything is okay
Definition: bufferevent.h:710
Common convenience functions for cross-platform portability and related socket manipulations.
EVENT2_EXPORT_SYMBOL int bufferevent_add_to_rate_limit_group(struct bufferevent *bev, struct bufferevent_rate_limit_group *g)
Add 'bev' to the list of bufferevents whose aggregate reading and writing is restricted by 'g'.
A definition of struct addrinfo for systems that lack it.
Definition: util.h:731
EVENT2_EXPORT_SYMBOL int bufferevent_set_max_single_write(struct bufferevent *bev, size_t size)
Set the size limit for single write operation.
bufferevent_filter_result
Values that filters can return.
Definition: bufferevent.h:708
EVENT2_EXPORT_SYMBOL int bufferevent_write(struct bufferevent *bufev, const void *data, size_t size)
Write data to a bufferevent buffer.
EVENT2_EXPORT_SYMBOL int bufferevent_disable(struct bufferevent *bufev, short event)
Disable a bufferevent.
EVENT2_EXPORT_SYMBOL int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf)
Write data from an evbuffer to a bufferevent buffer.
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:325
@ BEV_TRIG_DEFER_CALLBACKS
defer even if the callbacks are not
Definition: bufferevent.h:666