xref: /aosp_15_r20/external/libevent/include/event2/bufferevent_compat.h (revision 663afb9b963571284e0f0a60f257164ab54f64bf)
1*663afb9bSAndroid Build Coastguard Worker /*
2*663afb9bSAndroid Build Coastguard Worker  * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
3*663afb9bSAndroid Build Coastguard Worker  * Copyright (c) 2000-2007 Niels Provos <[email protected]>
4*663afb9bSAndroid Build Coastguard Worker  * All rights reserved.
5*663afb9bSAndroid Build Coastguard Worker  *
6*663afb9bSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
7*663afb9bSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
8*663afb9bSAndroid Build Coastguard Worker  * are met:
9*663afb9bSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
10*663afb9bSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
11*663afb9bSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
12*663afb9bSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
13*663afb9bSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
14*663afb9bSAndroid Build Coastguard Worker  * 3. The name of the author may not be used to endorse or promote products
15*663afb9bSAndroid Build Coastguard Worker  *    derived from this software without specific prior written permission.
16*663afb9bSAndroid Build Coastguard Worker  *
17*663afb9bSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18*663afb9bSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19*663afb9bSAndroid Build Coastguard Worker  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*663afb9bSAndroid Build Coastguard Worker  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21*663afb9bSAndroid Build Coastguard Worker  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22*663afb9bSAndroid Build Coastguard Worker  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23*663afb9bSAndroid Build Coastguard Worker  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24*663afb9bSAndroid Build Coastguard Worker  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25*663afb9bSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26*663afb9bSAndroid Build Coastguard Worker  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*663afb9bSAndroid Build Coastguard Worker  */
28*663afb9bSAndroid Build Coastguard Worker #ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
29*663afb9bSAndroid Build Coastguard Worker #define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
30*663afb9bSAndroid Build Coastguard Worker 
31*663afb9bSAndroid Build Coastguard Worker #include <event2/visibility.h>
32*663afb9bSAndroid Build Coastguard Worker 
33*663afb9bSAndroid Build Coastguard Worker #define evbuffercb bufferevent_data_cb
34*663afb9bSAndroid Build Coastguard Worker #define everrorcb bufferevent_event_cb
35*663afb9bSAndroid Build Coastguard Worker 
36*663afb9bSAndroid Build Coastguard Worker /**
37*663afb9bSAndroid Build Coastguard Worker   Create a new bufferevent for an fd.
38*663afb9bSAndroid Build Coastguard Worker 
39*663afb9bSAndroid Build Coastguard Worker   This function is deprecated.  Use bufferevent_socket_new and
40*663afb9bSAndroid Build Coastguard Worker   bufferevent_set_callbacks instead.
41*663afb9bSAndroid Build Coastguard Worker 
42*663afb9bSAndroid Build Coastguard Worker   Libevent provides an abstraction on top of the regular event callbacks.
43*663afb9bSAndroid Build Coastguard Worker   This abstraction is called a buffered event.  A buffered event provides
44*663afb9bSAndroid Build Coastguard Worker   input and output buffers that get filled and drained automatically.  The
45*663afb9bSAndroid Build Coastguard Worker   user of a buffered event no longer deals directly with the I/O, but
46*663afb9bSAndroid Build Coastguard Worker   instead is reading from input and writing to output buffers.
47*663afb9bSAndroid Build Coastguard Worker 
48*663afb9bSAndroid Build Coastguard Worker   Once initialized, the bufferevent structure can be used repeatedly with
49*663afb9bSAndroid Build Coastguard Worker   bufferevent_enable() and bufferevent_disable().
50*663afb9bSAndroid Build Coastguard Worker 
51*663afb9bSAndroid Build Coastguard Worker   When read enabled the bufferevent will try to read from the file descriptor
52*663afb9bSAndroid Build Coastguard Worker   and call the read callback.  The write callback is executed whenever the
53*663afb9bSAndroid Build Coastguard Worker   output buffer is drained below the write low watermark, which is 0 by
54*663afb9bSAndroid Build Coastguard Worker   default.
55*663afb9bSAndroid Build Coastguard Worker 
56*663afb9bSAndroid Build Coastguard Worker   If multiple bases are in use, bufferevent_base_set() must be called before
57*663afb9bSAndroid Build Coastguard Worker   enabling the bufferevent for the first time.
58*663afb9bSAndroid Build Coastguard Worker 
59*663afb9bSAndroid Build Coastguard Worker   @deprecated This function is deprecated because it uses the current
60*663afb9bSAndroid Build Coastguard Worker     event base, and as such can be error prone for multithreaded programs.
61*663afb9bSAndroid Build Coastguard Worker     Use bufferevent_socket_new() instead.
62*663afb9bSAndroid Build Coastguard Worker 
63*663afb9bSAndroid Build Coastguard Worker   @param fd the file descriptor from which data is read and written to.
64*663afb9bSAndroid Build Coastguard Worker 	 This file descriptor is not allowed to be a pipe(2).
65*663afb9bSAndroid Build Coastguard Worker   @param readcb callback to invoke when there is data to be read, or NULL if
66*663afb9bSAndroid Build Coastguard Worker 	 no callback is desired
67*663afb9bSAndroid Build Coastguard Worker   @param writecb callback to invoke when the file descriptor is ready for
68*663afb9bSAndroid Build Coastguard Worker 	 writing, or NULL if no callback is desired
69*663afb9bSAndroid Build Coastguard Worker   @param errorcb callback to invoke when there is an error on the file
70*663afb9bSAndroid Build Coastguard Worker 	 descriptor
71*663afb9bSAndroid Build Coastguard Worker   @param cbarg an argument that will be supplied to each of the callbacks
72*663afb9bSAndroid Build Coastguard Worker 	 (readcb, writecb, and errorcb)
73*663afb9bSAndroid Build Coastguard Worker   @return a pointer to a newly allocated bufferevent struct, or NULL if an
74*663afb9bSAndroid Build Coastguard Worker 	  error occurred
75*663afb9bSAndroid Build Coastguard Worker   @see bufferevent_base_set(), bufferevent_free()
76*663afb9bSAndroid Build Coastguard Worker   */
77*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
78*663afb9bSAndroid Build Coastguard Worker struct bufferevent *bufferevent_new(evutil_socket_t fd,
79*663afb9bSAndroid Build Coastguard Worker     evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
80*663afb9bSAndroid Build Coastguard Worker 
81*663afb9bSAndroid Build Coastguard Worker 
82*663afb9bSAndroid Build Coastguard Worker /**
83*663afb9bSAndroid Build Coastguard Worker   Set the read and write timeout for a buffered event.
84*663afb9bSAndroid Build Coastguard Worker 
85*663afb9bSAndroid Build Coastguard Worker   @param bufev the bufferevent to be modified
86*663afb9bSAndroid Build Coastguard Worker   @param timeout_read the read timeout
87*663afb9bSAndroid Build Coastguard Worker   @param timeout_write the write timeout
88*663afb9bSAndroid Build Coastguard Worker  */
89*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
90*663afb9bSAndroid Build Coastguard Worker void bufferevent_settimeout(struct bufferevent *bufev,
91*663afb9bSAndroid Build Coastguard Worker     int timeout_read, int timeout_write);
92*663afb9bSAndroid Build Coastguard Worker 
93*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_READ		BEV_EVENT_READING
94*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_WRITE		BEV_EVENT_WRITING
95*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_EOF		BEV_EVENT_EOF
96*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_ERROR		BEV_EVENT_ERROR
97*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_TIMEOUT	BEV_EVENT_TIMEOUT
98*663afb9bSAndroid Build Coastguard Worker 
99*663afb9bSAndroid Build Coastguard Worker /** macro for getting access to the input buffer of a bufferevent */
100*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_INPUT(x)	bufferevent_get_input(x)
101*663afb9bSAndroid Build Coastguard Worker /** macro for getting access to the output buffer of a bufferevent */
102*663afb9bSAndroid Build Coastguard Worker #define EVBUFFER_OUTPUT(x)	bufferevent_get_output(x)
103*663afb9bSAndroid Build Coastguard Worker 
104*663afb9bSAndroid Build Coastguard Worker #endif
105