1 /*	$NetBSD: bufferevent_compat.h,v 1.1.1.1 2013/04/11 16:43:34 christos Exp $	*/
2 /*
3  * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
4  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
17  *
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.
28  */
29 #ifndef _EVENT2_BUFFEREVENT_COMPAT_H_
30 #define _EVENT2_BUFFEREVENT_COMPAT_H_
31 
32 #define evbuffercb bufferevent_data_cb
33 #define everrorcb bufferevent_event_cb
34 
35 /**
36   Create a new bufferevent for an fd.
37 
38   This function is deprecated.  Use bufferevent_socket_new and
39   bufferevent_set_callbacks instead.
40 
41   Libevent provides an abstraction on top of the regular event callbacks.
42   This abstraction is called a buffered event.  A buffered event provides
43   input and output buffers that get filled and drained automatically.  The
44   user of a buffered event no longer deals directly with the I/O, but
45   instead is reading from input and writing to output buffers.
46 
47   Once initialized, the bufferevent structure can be used repeatedly with
48   bufferevent_enable() and bufferevent_disable().
49 
50   When read enabled the bufferevent will try to read from the file descriptor
51   and call the read callback.  The write callback is executed whenever the
52   output buffer is drained below the write low watermark, which is 0 by
53   default.
54 
55   If multiple bases are in use, bufferevent_base_set() must be called before
56   enabling the bufferevent for the first time.
57 
58   @deprecated This function is deprecated because it uses the current
59     event base, and as such can be error prone for multithreaded programs.
60     Use bufferevent_socket_new() instead.
61 
62   @param fd the file descriptor from which data is read and written to.
63 	 This file descriptor is not allowed to be a pipe(2).
64   @param readcb callback to invoke when there is data to be read, or NULL if
65 	 no callback is desired
66   @param writecb callback to invoke when the file descriptor is ready for
67 	 writing, or NULL if no callback is desired
68   @param errorcb callback to invoke when there is an error on the file
69 	 descriptor
70   @param cbarg an argument that will be supplied to each of the callbacks
71 	 (readcb, writecb, and errorcb)
72   @return a pointer to a newly allocated bufferevent struct, or NULL if an
73 	  error occurred
74   @see bufferevent_base_set(), bufferevent_free()
75   */
76 struct bufferevent *bufferevent_new(evutil_socket_t fd,
77     evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
78 
79 
80 /**
81   Set the read and write timeout for a buffered event.
82 
83   @param bufev the bufferevent to be modified
84   @param timeout_read the read timeout
85   @param timeout_write the write timeout
86  */
87 void bufferevent_settimeout(struct bufferevent *bufev,
88     int timeout_read, int timeout_write);
89 
90 #define EVBUFFER_READ		BEV_EVENT_READING
91 #define EVBUFFER_WRITE		BEV_EVENT_WRITING
92 #define EVBUFFER_EOF		BEV_EVENT_EOF
93 #define EVBUFFER_ERROR		BEV_EVENT_ERROR
94 #define EVBUFFER_TIMEOUT	BEV_EVENT_TIMEOUT
95 
96 /** macro for getting access to the input buffer of a bufferevent */
97 #define EVBUFFER_INPUT(x)	bufferevent_get_input(x)
98 /** macro for getting access to the output buffer of a bufferevent */
99 #define EVBUFFER_OUTPUT(x)	bufferevent_get_output(x)
100 
101 #endif
102