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