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