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