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