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