1 /* $NetBSD: bufferevent.h,v 1.1.1.2 2015/01/29 06:38:27 spz Exp $ */
2 /* $NetBSD: bufferevent.h,v 1.1.1.2 2015/01/29 06:38:27 spz Exp $ */
4 * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
5 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef _EVENT2_BUFFEREVENT_H_
30 #define _EVENT2_BUFFEREVENT_H_
33 @file event2/bufferevent.h
35 Functions for buffering data for network sending or receiving. Bufferevents
36 are higher level than evbuffers: each has an underlying evbuffer for reading
37 and one for writing, and callbacks that are invoked under certain
40 A bufferevent provides input and output buffers that get filled and
41 drained automatically. The user of a bufferevent no longer deals
42 directly with the I/O, but instead is reading from input and writing
45 Once initialized, the bufferevent structure can be used repeatedly
46 with bufferevent_enable() and bufferevent_disable().
48 When reading is enabled, the bufferevent will try to read from the
49 file descriptor onto its input buffer, and call the read callback.
50 When writing is enabled, the bufferevent will try to write data onto its
51 file descriptor when the output buffer has enough data, and call the write
52 callback when the output buffer is sufficiently drained.
54 Bufferevents come in several flavors, including:
57 <dt>Socket-based bufferevents</dt>
58 <dd>A bufferevent that reads and writes data onto a network
59 socket. Created with bufferevent_socket_new().</dd>
61 <dt>Paired bufferevents</dt>
62 <dd>A pair of bufferevents that send and receive data to one
63 another without touching the network. Created with
64 bufferevent_pair_new().</dd>
66 <dt>Filtering bufferevents</dt>
67 <dd>A bufferevent that transforms data, and sends or receives it
68 over another underlying bufferevent. Created with
69 bufferevent_filter_new().</dd>
71 <dt>SSL-backed bufferevents</dt>
72 <dd>A bufferevent that uses the openssl library to send and
73 receive data over an encrypted connection. Created with
74 bufferevent_openssl_socket_new() or
75 bufferevent_openssl_filter_new().</dd>
83 #include <event2/event-config.h>
84 #ifdef _EVENT_HAVE_SYS_TYPES_H
85 #include <sys/types.h>
87 #ifdef _EVENT_HAVE_SYS_TIME_H
92 #include <event2/util.h>
94 /** @name Bufferevent event codes
96 These flags are passed as arguments to a bufferevent's event callback.
100 #define BEV_EVENT_READING 0x01 /**< error encountered while reading */
101 #define BEV_EVENT_WRITING 0x02 /**< error encountered while writing */
102 #define BEV_EVENT_EOF 0x10 /**< eof file reached */
103 #define BEV_EVENT_ERROR 0x20 /**< unrecoverable error encountered */
104 #define BEV_EVENT_TIMEOUT 0x40 /**< user-specified timeout reached */
105 #define BEV_EVENT_CONNECTED 0x80 /**< connect operation finished. */
109 An opaque type for handling buffered IO
111 @see event2/bufferevent.h
114 #ifdef _EVENT_IN_DOXYGEN
123 A read or write callback for a bufferevent.
125 The read callback is triggered when new data arrives in the input
126 buffer and the amount of readable data exceed the low watermark
127 which is 0 by default.
129 The write callback is triggered if the write buffer has been
130 exhausted or fell below its low watermark.
132 @param bev the bufferevent that triggered the callback
133 @param ctx the user-specified context for this bufferevent
135 typedef void (*bufferevent_data_cb
)(struct bufferevent
*bev
, void *ctx
);
138 An event/error callback for a bufferevent.
140 The event callback is triggered if either an EOF condition or another
141 unrecoverable error was encountered.
143 @param bev the bufferevent for which the error condition was reached
144 @param what a conjunction of flags: BEV_EVENT_READING or BEV_EVENT_WRITING
145 to indicate if the error was encountered on the read or write path,
146 and one of the following flags: BEV_EVENT_EOF, BEV_EVENT_ERROR,
147 BEV_EVENT_TIMEOUT, BEV_EVENT_CONNECTED.
149 @param ctx the user-specified context for this bufferevent
151 typedef void (*bufferevent_event_cb
)(struct bufferevent
*bev
, short what
, void *ctx
);
153 /** Options that can be specified when creating a bufferevent */
154 enum bufferevent_options
{
155 /** If set, we close the underlying file
156 * descriptor/bufferevent/whatever when this bufferevent is freed. */
157 BEV_OPT_CLOSE_ON_FREE
= (1<<0),
159 /** If set, and threading is enabled, operations on this bufferevent
160 * are protected by a lock */
161 BEV_OPT_THREADSAFE
= (1<<1),
163 /** If set, callbacks are run deferred in the event loop. */
164 BEV_OPT_DEFER_CALLBACKS
= (1<<2),
166 /** If set, callbacks are executed without locks being held on the
167 * bufferevent. This option currently requires that
168 * BEV_OPT_DEFER_CALLBACKS also be set; a future version of Libevent
169 * might remove the requirement.*/
170 BEV_OPT_UNLOCK_CALLBACKS
= (1<<3)
174 Create a new socket bufferevent over an existing socket.
176 @param base the event base to associate with the new bufferevent.
177 @param fd the file descriptor from which data is read and written to.
178 This file descriptor is not allowed to be a pipe(2).
179 It is safe to set the fd to -1, so long as you later
180 set it with bufferevent_setfd or bufferevent_socket_connect().
181 @param options Zero or more BEV_OPT_* flags
182 @return a pointer to a newly allocated bufferevent struct, or NULL if an
184 @see bufferevent_free()
186 struct bufferevent
*bufferevent_socket_new(struct event_base
*base
, evutil_socket_t fd
, int options
);
189 Launch a connect() attempt with a socket-based bufferevent.
191 When the connect succeeds, the eventcb will be invoked with
192 BEV_EVENT_CONNECTED set.
194 If the bufferevent does not already have a socket set, we allocate a new
195 socket here and make it nonblocking before we begin.
197 If no address is provided, we assume that the socket is already connecting,
198 and configure the bufferevent so that a BEV_EVENT_CONNECTED event will be
199 yielded when it is done connecting.
201 @param bufev an existing bufferevent allocated with
202 bufferevent_socket_new().
203 @param addr the address we should connect to
204 @param socklen The length of the address
205 @return 0 on success, -1 on failure.
207 int bufferevent_socket_connect(struct bufferevent
*, struct sockaddr
*, int);
211 Resolve the hostname 'hostname' and connect to it as with
212 bufferevent_socket_connect().
214 @param bufev An existing bufferevent allocated with bufferevent_socket_new()
215 @param evdns_base Optionally, an evdns_base to use for resolving hostnames
216 asynchronously. May be set to NULL for a blocking resolve.
217 @param family A preferred address family to resolve addresses to, or
218 AF_UNSPEC for no preference. Only AF_INET, AF_INET6, and AF_UNSPEC are
220 @param hostname The hostname to resolve; see below for notes on recognized
222 @param port The port to connect to on the resolved address.
223 @return 0 if successful, -1 on failure.
225 Recognized hostname formats are:
227 www.example.com (hostname)
228 1.2.3.4 (ipv4address)
230 [::1] ([ipv6address])
232 Performance note: If you do not provide an evdns_base, this function
233 may block while it waits for a DNS response. This is probably not
236 int bufferevent_socket_connect_hostname(struct bufferevent
*,
237 struct evdns_base
*, int, const char *, int);
240 Return the error code for the last failed DNS lookup attempt made by
241 bufferevent_socket_connect_hostname().
243 @param bev The bufferevent object.
244 @return DNS error code.
245 @see evutil_gai_strerror()
247 int bufferevent_socket_get_dns_error(struct bufferevent
*bev
);
250 Assign a bufferevent to a specific event_base.
252 NOTE that only socket bufferevents support this function.
254 @param base an event_base returned by event_init()
255 @param bufev a bufferevent struct returned by bufferevent_new()
256 or bufferevent_socket_new()
257 @return 0 if successful, or -1 if an error occurred
258 @see bufferevent_new()
260 int bufferevent_base_set(struct event_base
*base
, struct bufferevent
*bufev
);
263 Return the event_base used by a bufferevent
265 struct event_base
*bufferevent_get_base(struct bufferevent
*bev
);
268 Assign a priority to a bufferevent.
270 Only supported for socket bufferevents.
272 @param bufev a bufferevent struct
273 @param pri the priority to be assigned
274 @return 0 if successful, or -1 if an error occurred
276 int bufferevent_priority_set(struct bufferevent
*bufev
, int pri
);
280 Deallocate the storage associated with a bufferevent structure.
282 @param bufev the bufferevent structure to be freed.
284 void bufferevent_free(struct bufferevent
*bufev
);
288 Changes the callbacks for a bufferevent.
290 @param bufev the bufferevent object for which to change callbacks
291 @param readcb callback to invoke when there is data to be read, or NULL if
292 no callback is desired
293 @param writecb callback to invoke when the file descriptor is ready for
294 writing, or NULL if no callback is desired
295 @param eventcb callback to invoke when there is an event on the file
297 @param cbarg an argument that will be supplied to each of the callbacks
298 (readcb, writecb, and errorcb)
299 @see bufferevent_new()
301 void bufferevent_setcb(struct bufferevent
*bufev
,
302 bufferevent_data_cb readcb
, bufferevent_data_cb writecb
,
303 bufferevent_event_cb eventcb
, void *cbarg
);
306 Changes the file descriptor on which the bufferevent operates.
307 Not supported for all bufferevent types.
309 @param bufev the bufferevent object for which to change the file descriptor
310 @param fd the file descriptor to operate on
312 int bufferevent_setfd(struct bufferevent
*bufev
, evutil_socket_t fd
);
315 Returns the file descriptor associated with a bufferevent, or -1 if
316 no file descriptor is associated with the bufferevent.
318 evutil_socket_t
bufferevent_getfd(struct bufferevent
*bufev
);
321 Returns the underlying bufferevent associated with a bufferevent (if
322 the bufferevent is a wrapper), or NULL if there is no underlying bufferevent.
324 struct bufferevent
*bufferevent_get_underlying(struct bufferevent
*bufev
);
327 Write data to a bufferevent buffer.
329 The bufferevent_write() function can be used to write data to the file
330 descriptor. The data is appended to the output buffer and written to the
331 descriptor automatically as it becomes available for writing.
333 @param bufev the bufferevent to be written to
334 @param data a pointer to the data to be written
335 @param size the length of the data, in bytes
336 @return 0 if successful, or -1 if an error occurred
337 @see bufferevent_write_buffer()
339 int bufferevent_write(struct bufferevent
*bufev
,
340 const void *data
, size_t size
);
344 Write data from an evbuffer to a bufferevent buffer. The evbuffer is
345 being drained as a result.
347 @param bufev the bufferevent to be written to
348 @param buf the evbuffer to be written
349 @return 0 if successful, or -1 if an error occurred
350 @see bufferevent_write()
352 int bufferevent_write_buffer(struct bufferevent
*bufev
, struct evbuffer
*buf
);
356 Read data from a bufferevent buffer.
358 The bufferevent_read() function is used to read data from the input buffer.
360 @param bufev the bufferevent to be read from
361 @param data pointer to a buffer that will store the data
362 @param size the size of the data buffer, in bytes
363 @return the amount of data read, in bytes.
365 size_t bufferevent_read(struct bufferevent
*bufev
, void *data
, size_t size
);
368 Read data from a bufferevent buffer into an evbuffer. This avoids
371 @param bufev the bufferevent to be read from
372 @param buf the evbuffer to which to add data
373 @return 0 if successful, or -1 if an error occurred.
375 int bufferevent_read_buffer(struct bufferevent
*bufev
, struct evbuffer
*buf
);
378 Returns the input buffer.
380 The user MUST NOT set the callback on this buffer.
382 @param bufev the bufferevent from which to get the evbuffer
383 @return the evbuffer object for the input buffer
386 struct evbuffer
*bufferevent_get_input(struct bufferevent
*bufev
);
389 Returns the output buffer.
391 The user MUST NOT set the callback on this buffer.
393 When filters are being used, the filters need to be manually
394 triggered if the output buffer was manipulated.
396 @param bufev the bufferevent from which to get the evbuffer
397 @return the evbuffer object for the output buffer
400 struct evbuffer
*bufferevent_get_output(struct bufferevent
*bufev
);
403 Enable a bufferevent.
405 @param bufev the bufferevent to be enabled
406 @param event any combination of EV_READ | EV_WRITE.
407 @return 0 if successful, or -1 if an error occurred
408 @see bufferevent_disable()
410 int bufferevent_enable(struct bufferevent
*bufev
, short event
);
413 Disable a bufferevent.
415 @param bufev the bufferevent to be disabled
416 @param event any combination of EV_READ | EV_WRITE.
417 @return 0 if successful, or -1 if an error occurred
418 @see bufferevent_enable()
420 int bufferevent_disable(struct bufferevent
*bufev
, short event
);
423 Return the events that are enabled on a given bufferevent.
425 @param bufev the bufferevent to inspect
426 @return A combination of EV_READ | EV_WRITE
428 short bufferevent_get_enabled(struct bufferevent
*bufev
);
431 Set the read and write timeout for a bufferevent.
433 A bufferevent's timeout will fire the first time that the indicated
434 amount of time has elapsed since a successful read or write operation,
435 during which the bufferevent was trying to read or write.
437 (In other words, if reading or writing is disabled, or if the
438 bufferevent's read or write operation has been suspended because
439 there's no data to write, or not enough banwidth, or so on, the
440 timeout isn't active. The timeout only becomes active when we we're
441 willing to actually read or write.)
443 Calling bufferevent_enable or setting a timeout for a bufferevent
444 whose timeout is already pending resets its timeout.
446 If the timeout elapses, the corresponding operation (EV_READ or
447 EV_WRITE) becomes disabled until you re-enable it again. The
448 bufferevent's event callback is called with the
449 BEV_EVENT_TIMEOUT|BEV_EVENT_READING or
450 BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING.
452 @param bufev the bufferevent to be modified
453 @param timeout_read the read timeout, or NULL
454 @param timeout_write the write timeout, or NULL
456 int bufferevent_set_timeouts(struct bufferevent
*bufev
,
457 const struct timeval
*timeout_read
, const struct timeval
*timeout_write
);
460 Sets the watermarks for read and write events.
462 On input, a bufferevent does not invoke the user read callback unless
463 there is at least low watermark data in the buffer. If the read buffer
464 is beyond the high watermark, the bufferevent stops reading from the network.
466 On output, the user write callback is invoked whenever the buffered data
467 falls below the low watermark. Filters that write to this bufev will try
468 not to write more bytes to this buffer than the high watermark would allow,
469 except when flushing.
471 @param bufev the bufferevent to be modified
472 @param events EV_READ, EV_WRITE or both
473 @param lowmark the lower watermark to set
474 @param highmark the high watermark to set
477 void bufferevent_setwatermark(struct bufferevent
*bufev
, short events
,
478 size_t lowmark
, size_t highmark
);
481 Acquire the lock on a bufferevent. Has no effect if locking was not
482 enabled with BEV_OPT_THREADSAFE.
484 void bufferevent_lock(struct bufferevent
*bufev
);
487 Release the lock on a bufferevent. Has no effect if locking was not
488 enabled with BEV_OPT_THREADSAFE.
490 void bufferevent_unlock(struct bufferevent
*bufev
);
493 Flags that can be passed into filters to let them know how to
494 deal with the incoming data.
496 enum bufferevent_flush_mode
{
497 /** usually set when processing data */
500 /** want to checkpoint all data sent. */
503 /** encountered EOF on read or done sending data */
508 Triggers the bufferevent to produce more data if possible.
510 @param bufev the bufferevent object
511 @param iotype either EV_READ or EV_WRITE or both.
512 @param mode either BEV_NORMAL or BEV_FLUSH or BEV_FINISHED
513 @return -1 on failure, 0 if no data was produces, 1 if data was produced
515 int bufferevent_flush(struct bufferevent
*bufev
,
517 enum bufferevent_flush_mode mode
);
520 @name Filtering support
525 Values that filters can return.
527 enum bufferevent_filter_result
{
528 /** everything is okay */
531 /** the filter needs to read more data before output */
534 /** the filter encountered a critical error, no further data
539 /** A callback function to implement a filter for a bufferevent.
541 @param src An evbuffer to drain data from.
542 @param dst An evbuffer to add data to.
543 @param limit A suggested upper bound of bytes to write to dst.
544 The filter may ignore this value, but doing so means that
545 it will overflow the high-water mark associated with dst.
547 @param mode Whether we should write data as may be convenient
548 (BEV_NORMAL), or flush as much data as we can (BEV_FLUSH),
549 or flush as much as we can, possibly including an end-of-stream
551 @param ctx A user-supplied pointer.
553 @return BEV_OK if we wrote some data; BEV_NEED_MORE if we can't
554 produce any more output until we get some input; and BEV_ERROR
557 typedef enum bufferevent_filter_result (*bufferevent_filter_cb
)(
558 struct evbuffer
*src
, struct evbuffer
*dst
, ev_ssize_t dst_limit
,
559 enum bufferevent_flush_mode mode
, void *ctx
);
562 Allocate a new filtering bufferevent on top of an existing bufferevent.
564 @param underlying the underlying bufferevent.
565 @param input_filter The filter to apply to data we read from the underlying
567 @param output_filter The filer to apply to data we write to the underlying
569 @param options A bitfield of bufferevent options.
570 @param free_context A function to use to free the filter context when
571 this bufferevent is freed.
572 @param ctx A context pointer to pass to the filter functions.
575 bufferevent_filter_new(struct bufferevent
*underlying
,
576 bufferevent_filter_cb input_filter
,
577 bufferevent_filter_cb output_filter
,
579 void (*free_context
)(void *),
584 Allocate a pair of linked bufferevents. The bufferevents behave as would
585 two bufferevent_sock instances connected to opposite ends of a
586 socketpair(), except that no internal socketpair is allocated.
588 @param base The event base to associate with the socketpair.
589 @param options A set of options for this bufferevent
590 @param pair A pointer to an array to hold the two new bufferevent objects.
591 @return 0 on success, -1 on failure.
593 int bufferevent_pair_new(struct event_base
*base
, int options
,
594 struct bufferevent
*pair
[2]);
597 Given one bufferevent returned by bufferevent_pair_new(), returns the
598 other one if it still exists. Otherwise returns NULL.
600 struct bufferevent
*bufferevent_pair_get_partner(struct bufferevent
*bev
);
603 Abstract type used to configure rate-limiting on a bufferevent or a group
606 struct ev_token_bucket_cfg
;
609 A group of bufferevents which are configured to respect the same rate
612 struct bufferevent_rate_limit_group
;
614 /** Maximum configurable rate- or burst-limit. */
615 #define EV_RATE_LIMIT_MAX EV_SSIZE_MAX
618 Initialize and return a new object to configure the rate-limiting behavior
621 @param read_rate The maximum number of bytes to read per tick on
623 @param read_burst The maximum number of bytes to read in any single tick.
624 @param write_rate The maximum number of bytes to write per tick on
626 @param write_burst The maximum number of bytes to write in any single tick.
627 @param tick_len The length of a single tick. Defaults to one second.
628 Any fractions of a millisecond are ignored.
630 Note that all rate-limits hare are currently best-effort: future versions
631 of Libevent may implement them more tightly.
633 struct ev_token_bucket_cfg
*ev_token_bucket_cfg_new(
634 size_t read_rate
, size_t read_burst
,
635 size_t write_rate
, size_t write_burst
,
636 const struct timeval
*tick_len
);
638 /** Free all storage held in 'cfg'.
640 Note: 'cfg' is not currently reference-counted; it is not safe to free it
641 until no bufferevent is using it.
643 void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg
*cfg
);
646 Set the rate-limit of a the bufferevent 'bev' to the one specified in
647 'cfg'. If 'cfg' is NULL, disable any per-bufferevent rate-limiting on
650 Note that only some bufferevent types currently respect rate-limiting.
651 They are: socket-based bufferevents (normal and IOCP-based), and SSL-based
654 Return 0 on sucess, -1 on failure.
656 int bufferevent_set_rate_limit(struct bufferevent
*bev
,
657 struct ev_token_bucket_cfg
*cfg
);
660 Create a new rate-limit group for bufferevents. A rate-limit group
661 constrains the maximum number of bytes sent and received, in toto,
662 by all of its bufferevents.
664 @param base An event_base to run any necessary timeouts for the group.
665 Note that all bufferevents in the group do not necessarily need to share
667 @param cfg The rate-limit for this group.
669 Note that all rate-limits hare are currently best-effort: future versions
670 of Libevent may implement them more tightly.
672 Note also that only some bufferevent types currently respect rate-limiting.
673 They are: socket-based bufferevents (normal and IOCP-based), and SSL-based
676 struct bufferevent_rate_limit_group
*bufferevent_rate_limit_group_new(
677 struct event_base
*base
,
678 const struct ev_token_bucket_cfg
*cfg
);
680 Change the rate-limiting settings for a given rate-limiting group.
682 Return 0 on success, -1 on failure.
684 int bufferevent_rate_limit_group_set_cfg(
685 struct bufferevent_rate_limit_group
*,
686 const struct ev_token_bucket_cfg
*);
689 Change the smallest quantum we're willing to allocate to any single
690 bufferevent in a group for reading or writing at a time.
692 The rationale is that, because of TCP/IP protocol overheads and kernel
693 behavior, if a rate-limiting group is so tight on bandwidth that you're
694 only willing to send 1 byte per tick per bufferevent, you might instead
695 want to batch up the reads and writes so that you send N bytes per
696 1/N of the bufferevents (chosen at random) each tick, so you still wind
697 up send 1 byte per tick per bufferevent on average, but you don't send
698 so many tiny packets.
700 The default min-share is currently 64 bytes.
702 Returns 0 on success, -1 on faulre.
704 int bufferevent_rate_limit_group_set_min_share(
705 struct bufferevent_rate_limit_group
*, size_t);
708 Free a rate-limiting group. The group must have no members when
709 this function is called.
711 void bufferevent_rate_limit_group_free(struct bufferevent_rate_limit_group
*);
714 Add 'bev' to the list of bufferevents whose aggregate reading and writing
715 is restricted by 'g'. If 'g' is NULL, remove 'bev' from its current group.
717 A bufferevent may belong to no more than one rate-limit group at a time.
718 If 'bev' is already a member of a group, it will be removed from its old
719 group before being added to 'g'.
721 Return 0 on success and -1 on failure.
723 int bufferevent_add_to_rate_limit_group(struct bufferevent
*bev
,
724 struct bufferevent_rate_limit_group
*g
);
726 /** Remove 'bev' from its current rate-limit group (if any). */
727 int bufferevent_remove_from_rate_limit_group(struct bufferevent
*bev
);
730 @name Rate limit inspection
732 Return the current read or write bucket size for a bufferevent.
733 If it is not configured with a per-bufferevent ratelimit, return
734 EV_SSIZE_MAX. This function does not inspect the group limit, if any.
735 Note that it can return a negative value if the bufferevent has been
736 made to read or write more than its limit.
740 ev_ssize_t
bufferevent_get_read_limit(struct bufferevent
*bev
);
741 ev_ssize_t
bufferevent_get_write_limit(struct bufferevent
*bev
);
744 ev_ssize_t
bufferevent_get_max_to_read(struct bufferevent
*bev
);
745 ev_ssize_t
bufferevent_get_max_to_write(struct bufferevent
*bev
);
748 @name Group Rate limit inspection
750 Return the read or write bucket size for a bufferevent rate limit
751 group. Note that it can return a negative value if bufferevents in
752 the group have been made to read or write more than their limits.
756 ev_ssize_t
bufferevent_rate_limit_group_get_read_limit(
757 struct bufferevent_rate_limit_group
*);
758 ev_ssize_t
bufferevent_rate_limit_group_get_write_limit(
759 struct bufferevent_rate_limit_group
*);
763 @name Rate limit manipulation
765 Subtract a number of bytes from a bufferevent's read or write bucket.
766 The decrement value can be negative, if you want to manually refill
767 the bucket. If the change puts the bucket above or below zero, the
768 bufferevent will resume or suspend reading writing as appropriate.
769 These functions make no change in the buckets for the bufferevent's
772 Returns 0 on success, -1 on internal error.
776 int bufferevent_decrement_read_limit(struct bufferevent
*bev
, ev_ssize_t decr
);
777 int bufferevent_decrement_write_limit(struct bufferevent
*bev
, ev_ssize_t decr
);
781 @name Group rate limit manipulation
783 Subtract a number of bytes from a bufferevent rate-limiting group's
784 read or write bucket. The decrement value can be negative, if you
785 want to manually refill the bucket. If the change puts the bucket
786 above or below zero, the bufferevents in the group will resume or
787 suspend reading writing as appropriate.
789 Returns 0 on success, -1 on internal error.
793 int bufferevent_rate_limit_group_decrement_read(
794 struct bufferevent_rate_limit_group
*, ev_ssize_t
);
795 int bufferevent_rate_limit_group_decrement_write(
796 struct bufferevent_rate_limit_group
*, ev_ssize_t
);
801 * Inspect the total bytes read/written on a group.
803 * Set the variable pointed to by total_read_out to the total number of bytes
804 * ever read on grp, and the variable pointed to by total_written_out to the
805 * total number of bytes ever written on grp. */
806 void bufferevent_rate_limit_group_get_totals(
807 struct bufferevent_rate_limit_group
*grp
,
808 ev_uint64_t
*total_read_out
, ev_uint64_t
*total_written_out
);
811 * Reset the total bytes read/written on a group.
813 * Reset the number of bytes read or written on grp as given by
814 * bufferevent_rate_limit_group_reset_totals(). */
816 bufferevent_rate_limit_group_reset_totals(
817 struct bufferevent_rate_limit_group
*grp
);
823 #endif /* _EVENT2_BUFFEREVENT_H_ */