1290001Sglebius/*
2290001Sglebius * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
3290001Sglebius * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
4290001Sglebius * All rights reserved.
5290001Sglebius *
6290001Sglebius * Redistribution and use in source and binary forms, with or without
7290001Sglebius * modification, are permitted provided that the following conditions
8290001Sglebius * are met:
9290001Sglebius * 1. Redistributions of source code must retain the above copyright
10290001Sglebius *    notice, this list of conditions and the following disclaimer.
11290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright
12290001Sglebius *    notice, this list of conditions and the following disclaimer in the
13290001Sglebius *    documentation and/or other materials provided with the distribution.
14290001Sglebius * 3. The name of the author may not be used to endorse or promote products
15290001Sglebius *    derived from this software without specific prior written permission.
16290001Sglebius *
17290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27290001Sglebius */
28290001Sglebius#ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
29290001Sglebius#define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
30290001Sglebius
31290001Sglebius#define evbuffercb bufferevent_data_cb
32290001Sglebius#define everrorcb bufferevent_event_cb
33290001Sglebius
34290001Sglebius/**
35290001Sglebius  Create a new bufferevent for an fd.
36290001Sglebius
37290001Sglebius  This function is deprecated.  Use bufferevent_socket_new and
38290001Sglebius  bufferevent_set_callbacks instead.
39290001Sglebius
40290001Sglebius  Libevent provides an abstraction on top of the regular event callbacks.
41290001Sglebius  This abstraction is called a buffered event.  A buffered event provides
42290001Sglebius  input and output buffers that get filled and drained automatically.  The
43290001Sglebius  user of a buffered event no longer deals directly with the I/O, but
44290001Sglebius  instead is reading from input and writing to output buffers.
45290001Sglebius
46290001Sglebius  Once initialized, the bufferevent structure can be used repeatedly with
47290001Sglebius  bufferevent_enable() and bufferevent_disable().
48290001Sglebius
49290001Sglebius  When read enabled the bufferevent will try to read from the file descriptor
50290001Sglebius  and call the read callback.  The write callback is executed whenever the
51290001Sglebius  output buffer is drained below the write low watermark, which is 0 by
52290001Sglebius  default.
53290001Sglebius
54290001Sglebius  If multiple bases are in use, bufferevent_base_set() must be called before
55290001Sglebius  enabling the bufferevent for the first time.
56290001Sglebius
57290001Sglebius  @deprecated This function is deprecated because it uses the current
58290001Sglebius    event base, and as such can be error prone for multithreaded programs.
59290001Sglebius    Use bufferevent_socket_new() instead.
60290001Sglebius
61290001Sglebius  @param fd the file descriptor from which data is read and written to.
62290001Sglebius	 This file descriptor is not allowed to be a pipe(2).
63290001Sglebius  @param readcb callback to invoke when there is data to be read, or NULL if
64290001Sglebius	 no callback is desired
65290001Sglebius  @param writecb callback to invoke when the file descriptor is ready for
66290001Sglebius	 writing, or NULL if no callback is desired
67290001Sglebius  @param errorcb callback to invoke when there is an error on the file
68290001Sglebius	 descriptor
69290001Sglebius  @param cbarg an argument that will be supplied to each of the callbacks
70290001Sglebius	 (readcb, writecb, and errorcb)
71290001Sglebius  @return a pointer to a newly allocated bufferevent struct, or NULL if an
72290001Sglebius	  error occurred
73290001Sglebius  @see bufferevent_base_set(), bufferevent_free()
74290001Sglebius  */
75290001Sglebiusstruct bufferevent *bufferevent_new(evutil_socket_t fd,
76290001Sglebius    evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
77290001Sglebius
78290001Sglebius
79290001Sglebius/**
80290001Sglebius  Set the read and write timeout for a buffered event.
81290001Sglebius
82290001Sglebius  @param bufev the bufferevent to be modified
83290001Sglebius  @param timeout_read the read timeout
84290001Sglebius  @param timeout_write the write timeout
85290001Sglebius */
86290001Sglebiusvoid bufferevent_settimeout(struct bufferevent *bufev,
87290001Sglebius    int timeout_read, int timeout_write);
88290001Sglebius
89290001Sglebius#define EVBUFFER_READ		BEV_EVENT_READING
90290001Sglebius#define EVBUFFER_WRITE		BEV_EVENT_WRITING
91290001Sglebius#define EVBUFFER_EOF		BEV_EVENT_EOF
92290001Sglebius#define EVBUFFER_ERROR		BEV_EVENT_ERROR
93290001Sglebius#define EVBUFFER_TIMEOUT	BEV_EVENT_TIMEOUT
94290001Sglebius
95290001Sglebius/** macro for getting access to the input buffer of a bufferevent */
96290001Sglebius#define EVBUFFER_INPUT(x)	bufferevent_get_input(x)
97290001Sglebius/** macro for getting access to the output buffer of a bufferevent */
98290001Sglebius#define EVBUFFER_OUTPUT(x)	bufferevent_get_output(x)
99290001Sglebius
100290001Sglebius#endif
101