1*0a6a1f1dSLionel Sambuc /* $NetBSD: bufferevent_struct.h,v 1.1.1.2 2015/01/29 06:38:26 spz Exp $ */ 2*0a6a1f1dSLionel Sambuc /* $NetBSD: bufferevent_struct.h,v 1.1.1.2 2015/01/29 06:38:26 spz Exp $ */ 3e985b929SDavid van Moolenbroek /* 4e985b929SDavid van Moolenbroek * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 5e985b929SDavid van Moolenbroek * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 6e985b929SDavid van Moolenbroek * 7e985b929SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without 8e985b929SDavid van Moolenbroek * modification, are permitted provided that the following conditions 9e985b929SDavid van Moolenbroek * are met: 10e985b929SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright 11e985b929SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer. 12e985b929SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright 13e985b929SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the 14e985b929SDavid van Moolenbroek * documentation and/or other materials provided with the distribution. 15e985b929SDavid van Moolenbroek * 3. The name of the author may not be used to endorse or promote products 16e985b929SDavid van Moolenbroek * derived from this software without specific prior written permission. 17e985b929SDavid van Moolenbroek * 18e985b929SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19e985b929SDavid van Moolenbroek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20e985b929SDavid van Moolenbroek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21e985b929SDavid van Moolenbroek * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22e985b929SDavid van Moolenbroek * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23e985b929SDavid van Moolenbroek * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24e985b929SDavid van Moolenbroek * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25e985b929SDavid van Moolenbroek * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26e985b929SDavid van Moolenbroek * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27e985b929SDavid van Moolenbroek * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28e985b929SDavid van Moolenbroek */ 29e985b929SDavid van Moolenbroek #ifndef _EVENT2_BUFFEREVENT_STRUCT_H_ 30e985b929SDavid van Moolenbroek #define _EVENT2_BUFFEREVENT_STRUCT_H_ 31e985b929SDavid van Moolenbroek 32e985b929SDavid van Moolenbroek /** @file event2/bufferevent_struct.h 33e985b929SDavid van Moolenbroek 34e985b929SDavid van Moolenbroek Data structures for bufferevents. Using these structures may hurt forward 35e985b929SDavid van Moolenbroek compatibility with later versions of Libevent: be careful! 36e985b929SDavid van Moolenbroek 37e985b929SDavid van Moolenbroek @deprecated Use of bufferevent_struct.h is completely deprecated; these 38e985b929SDavid van Moolenbroek structures are only exposed for backward compatibility with programs 39e985b929SDavid van Moolenbroek written before Libevent 2.0 that used them. 40e985b929SDavid van Moolenbroek */ 41e985b929SDavid van Moolenbroek 42e985b929SDavid van Moolenbroek #ifdef __cplusplus 43e985b929SDavid van Moolenbroek extern "C" { 44e985b929SDavid van Moolenbroek #endif 45e985b929SDavid van Moolenbroek 46e985b929SDavid van Moolenbroek #include <event2/event-config.h> 47e985b929SDavid van Moolenbroek #ifdef _EVENT_HAVE_SYS_TYPES_H 48e985b929SDavid van Moolenbroek #include <sys/types.h> 49e985b929SDavid van Moolenbroek #endif 50e985b929SDavid van Moolenbroek #ifdef _EVENT_HAVE_SYS_TIME_H 51e985b929SDavid van Moolenbroek #include <sys/time.h> 52e985b929SDavid van Moolenbroek #endif 53e985b929SDavid van Moolenbroek 54e985b929SDavid van Moolenbroek /* For int types. */ 55e985b929SDavid van Moolenbroek #include <event2/util.h> 56e985b929SDavid van Moolenbroek /* For struct event */ 57e985b929SDavid van Moolenbroek #include <event2/event_struct.h> 58e985b929SDavid van Moolenbroek 59e985b929SDavid van Moolenbroek struct event_watermark { 60e985b929SDavid van Moolenbroek size_t low; 61e985b929SDavid van Moolenbroek size_t high; 62e985b929SDavid van Moolenbroek }; 63e985b929SDavid van Moolenbroek 64e985b929SDavid van Moolenbroek /** 65e985b929SDavid van Moolenbroek Shared implementation of a bufferevent. 66e985b929SDavid van Moolenbroek 67e985b929SDavid van Moolenbroek This type is exposed only because it was exposed in previous versions, 68e985b929SDavid van Moolenbroek and some people's code may rely on manipulating it. Otherwise, you 69e985b929SDavid van Moolenbroek should really not rely on the layout, size, or contents of this structure: 70e985b929SDavid van Moolenbroek it is fairly volatile, and WILL change in future versions of the code. 71e985b929SDavid van Moolenbroek **/ 72e985b929SDavid van Moolenbroek struct bufferevent { 73e985b929SDavid van Moolenbroek /** Event base for which this bufferevent was created. */ 74e985b929SDavid van Moolenbroek struct event_base *ev_base; 75e985b929SDavid van Moolenbroek /** Pointer to a table of function pointers to set up how this 76e985b929SDavid van Moolenbroek bufferevent behaves. */ 77e985b929SDavid van Moolenbroek const struct bufferevent_ops *be_ops; 78e985b929SDavid van Moolenbroek 79e985b929SDavid van Moolenbroek /** A read event that triggers when a timeout has happened or a socket 80e985b929SDavid van Moolenbroek is ready to read data. Only used by some subtypes of 81e985b929SDavid van Moolenbroek bufferevent. */ 82e985b929SDavid van Moolenbroek struct event ev_read; 83e985b929SDavid van Moolenbroek /** A write event that triggers when a timeout has happened or a socket 84e985b929SDavid van Moolenbroek is ready to write data. Only used by some subtypes of 85e985b929SDavid van Moolenbroek bufferevent. */ 86e985b929SDavid van Moolenbroek struct event ev_write; 87e985b929SDavid van Moolenbroek 88e985b929SDavid van Moolenbroek /** An input buffer. Only the bufferevent is allowed to add data to 89e985b929SDavid van Moolenbroek this buffer, though the user is allowed to drain it. */ 90e985b929SDavid van Moolenbroek struct evbuffer *input; 91e985b929SDavid van Moolenbroek 92e985b929SDavid van Moolenbroek /** An input buffer. Only the bufferevent is allowed to drain data 93e985b929SDavid van Moolenbroek from this buffer, though the user is allowed to add it. */ 94e985b929SDavid van Moolenbroek struct evbuffer *output; 95e985b929SDavid van Moolenbroek 96e985b929SDavid van Moolenbroek struct event_watermark wm_read; 97e985b929SDavid van Moolenbroek struct event_watermark wm_write; 98e985b929SDavid van Moolenbroek 99e985b929SDavid van Moolenbroek bufferevent_data_cb readcb; 100e985b929SDavid van Moolenbroek bufferevent_data_cb writecb; 101e985b929SDavid van Moolenbroek /* This should be called 'eventcb', but renaming it would break 102e985b929SDavid van Moolenbroek * backward compatibility */ 103e985b929SDavid van Moolenbroek bufferevent_event_cb errorcb; 104e985b929SDavid van Moolenbroek void *cbarg; 105e985b929SDavid van Moolenbroek 106e985b929SDavid van Moolenbroek struct timeval timeout_read; 107e985b929SDavid van Moolenbroek struct timeval timeout_write; 108e985b929SDavid van Moolenbroek 109e985b929SDavid van Moolenbroek /** Events that are currently enabled: currently EV_READ and EV_WRITE 110e985b929SDavid van Moolenbroek are supported. */ 111e985b929SDavid van Moolenbroek short enabled; 112e985b929SDavid van Moolenbroek }; 113e985b929SDavid van Moolenbroek 114e985b929SDavid van Moolenbroek #ifdef __cplusplus 115e985b929SDavid van Moolenbroek } 116e985b929SDavid van Moolenbroek #endif 117e985b929SDavid van Moolenbroek 118e985b929SDavid van Moolenbroek #endif /* _EVENT2_BUFFEREVENT_STRUCT_H_ */ 119