1*2b15cb3dSCy Schubert /* 2*2b15cb3dSCy Schubert * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 3*2b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4*2b15cb3dSCy Schubert * 5*2b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 6*2b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 7*2b15cb3dSCy Schubert * are met: 8*2b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 9*2b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 10*2b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 11*2b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 12*2b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 13*2b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 14*2b15cb3dSCy Schubert * derived from this software without specific prior written permission. 15*2b15cb3dSCy Schubert * 16*2b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*2b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*2b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*2b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*2b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*2b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*2b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*2b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*2b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*2b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*2b15cb3dSCy Schubert */ 27*2b15cb3dSCy Schubert #ifndef EVBUFFER_INTERNAL_H_INCLUDED_ 28*2b15cb3dSCy Schubert #define EVBUFFER_INTERNAL_H_INCLUDED_ 29*2b15cb3dSCy Schubert 30*2b15cb3dSCy Schubert #ifdef __cplusplus 31*2b15cb3dSCy Schubert extern "C" { 32*2b15cb3dSCy Schubert #endif 33*2b15cb3dSCy Schubert 34*2b15cb3dSCy Schubert #include "event2/event-config.h" 35*2b15cb3dSCy Schubert #include "evconfig-private.h" 36*2b15cb3dSCy Schubert #include "event2/util.h" 37*2b15cb3dSCy Schubert #include "event2/event_struct.h" 38*2b15cb3dSCy Schubert #include "util-internal.h" 39*2b15cb3dSCy Schubert #include "defer-internal.h" 40*2b15cb3dSCy Schubert 41*2b15cb3dSCy Schubert /* Experimental cb flag: "never deferred." Implementation note: 42*2b15cb3dSCy Schubert * these callbacks may get an inaccurate view of n_del/n_added in their 43*2b15cb3dSCy Schubert * arguments. */ 44*2b15cb3dSCy Schubert #define EVBUFFER_CB_NODEFER 2 45*2b15cb3dSCy Schubert 46*2b15cb3dSCy Schubert #ifdef _WIN32 47*2b15cb3dSCy Schubert #include <winsock2.h> 48*2b15cb3dSCy Schubert #endif 49*2b15cb3dSCy Schubert #include <sys/queue.h> 50*2b15cb3dSCy Schubert 51*2b15cb3dSCy Schubert /* Minimum allocation for a chain. We define this so that we're burning no 52*2b15cb3dSCy Schubert * more than 5% of each allocation on overhead. It would be nice to lose even 53*2b15cb3dSCy Schubert * less space, though. */ 54*2b15cb3dSCy Schubert #if EVENT__SIZEOF_VOID_P < 8 55*2b15cb3dSCy Schubert #define MIN_BUFFER_SIZE 512 56*2b15cb3dSCy Schubert #else 57*2b15cb3dSCy Schubert #define MIN_BUFFER_SIZE 1024 58*2b15cb3dSCy Schubert #endif 59*2b15cb3dSCy Schubert 60*2b15cb3dSCy Schubert /** A single evbuffer callback for an evbuffer. This function will be invoked 61*2b15cb3dSCy Schubert * when bytes are added to or removed from the evbuffer. */ 62*2b15cb3dSCy Schubert struct evbuffer_cb_entry { 63*2b15cb3dSCy Schubert /** Structures to implement a doubly-linked queue of callbacks */ 64*2b15cb3dSCy Schubert LIST_ENTRY(evbuffer_cb_entry) next; 65*2b15cb3dSCy Schubert /** The callback function to invoke when this callback is called. 66*2b15cb3dSCy Schubert If EVBUFFER_CB_OBSOLETE is set in flags, the cb_obsolete field is 67*2b15cb3dSCy Schubert valid; otherwise, cb_func is valid. */ 68*2b15cb3dSCy Schubert union { 69*2b15cb3dSCy Schubert evbuffer_cb_func cb_func; 70*2b15cb3dSCy Schubert evbuffer_cb cb_obsolete; 71*2b15cb3dSCy Schubert } cb; 72*2b15cb3dSCy Schubert /** Argument to pass to cb. */ 73*2b15cb3dSCy Schubert void *cbarg; 74*2b15cb3dSCy Schubert /** Currently set flags on this callback. */ 75*2b15cb3dSCy Schubert ev_uint32_t flags; 76*2b15cb3dSCy Schubert }; 77*2b15cb3dSCy Schubert 78*2b15cb3dSCy Schubert struct bufferevent; 79*2b15cb3dSCy Schubert struct evbuffer_chain; 80*2b15cb3dSCy Schubert struct evbuffer { 81*2b15cb3dSCy Schubert /** The first chain in this buffer's linked list of chains. */ 82*2b15cb3dSCy Schubert struct evbuffer_chain *first; 83*2b15cb3dSCy Schubert /** The last chain in this buffer's linked list of chains. */ 84*2b15cb3dSCy Schubert struct evbuffer_chain *last; 85*2b15cb3dSCy Schubert 86*2b15cb3dSCy Schubert /** Pointer to the next pointer pointing at the 'last_with_data' chain. 87*2b15cb3dSCy Schubert * 88*2b15cb3dSCy Schubert * To unpack: 89*2b15cb3dSCy Schubert * 90*2b15cb3dSCy Schubert * The last_with_data chain is the last chain that has any data in it. 91*2b15cb3dSCy Schubert * If all chains in the buffer are empty, it is the first chain. 92*2b15cb3dSCy Schubert * If the buffer has no chains, it is NULL. 93*2b15cb3dSCy Schubert * 94*2b15cb3dSCy Schubert * The last_with_datap pointer points at _whatever 'next' pointer_ 95*2b15cb3dSCy Schubert * points at the last_with_datap chain. If the last_with_data chain 96*2b15cb3dSCy Schubert * is the first chain, or it is NULL, then the last_with_datap pointer 97*2b15cb3dSCy Schubert * is &buf->first. 98*2b15cb3dSCy Schubert */ 99*2b15cb3dSCy Schubert struct evbuffer_chain **last_with_datap; 100*2b15cb3dSCy Schubert 101*2b15cb3dSCy Schubert /** Total amount of bytes stored in all chains.*/ 102*2b15cb3dSCy Schubert size_t total_len; 103*2b15cb3dSCy Schubert 104*2b15cb3dSCy Schubert /** Number of bytes we have added to the buffer since we last tried to 105*2b15cb3dSCy Schubert * invoke callbacks. */ 106*2b15cb3dSCy Schubert size_t n_add_for_cb; 107*2b15cb3dSCy Schubert /** Number of bytes we have removed from the buffer since we last 108*2b15cb3dSCy Schubert * tried to invoke callbacks. */ 109*2b15cb3dSCy Schubert size_t n_del_for_cb; 110*2b15cb3dSCy Schubert 111*2b15cb3dSCy Schubert #ifndef EVENT__DISABLE_THREAD_SUPPORT 112*2b15cb3dSCy Schubert /** A lock used to mediate access to this buffer. */ 113*2b15cb3dSCy Schubert void *lock; 114*2b15cb3dSCy Schubert #endif 115*2b15cb3dSCy Schubert /** True iff we should free the lock field when we free this 116*2b15cb3dSCy Schubert * evbuffer. */ 117*2b15cb3dSCy Schubert unsigned own_lock : 1; 118*2b15cb3dSCy Schubert /** True iff we should not allow changes to the front of the buffer 119*2b15cb3dSCy Schubert * (drains or prepends). */ 120*2b15cb3dSCy Schubert unsigned freeze_start : 1; 121*2b15cb3dSCy Schubert /** True iff we should not allow changes to the end of the buffer 122*2b15cb3dSCy Schubert * (appends) */ 123*2b15cb3dSCy Schubert unsigned freeze_end : 1; 124*2b15cb3dSCy Schubert /** True iff this evbuffer's callbacks are not invoked immediately 125*2b15cb3dSCy Schubert * upon a change in the buffer, but instead are deferred to be invoked 126*2b15cb3dSCy Schubert * from the event_base's loop. Useful for preventing enormous stack 127*2b15cb3dSCy Schubert * overflows when we have mutually recursive callbacks, and for 128*2b15cb3dSCy Schubert * serializing callbacks in a single thread. */ 129*2b15cb3dSCy Schubert unsigned deferred_cbs : 1; 130*2b15cb3dSCy Schubert #ifdef _WIN32 131*2b15cb3dSCy Schubert /** True iff this buffer is set up for overlapped IO. */ 132*2b15cb3dSCy Schubert unsigned is_overlapped : 1; 133*2b15cb3dSCy Schubert #endif 134*2b15cb3dSCy Schubert /** Zero or more EVBUFFER_FLAG_* bits */ 135*2b15cb3dSCy Schubert ev_uint32_t flags; 136*2b15cb3dSCy Schubert 137*2b15cb3dSCy Schubert /** Used to implement deferred callbacks. */ 138*2b15cb3dSCy Schubert struct event_base *cb_queue; 139*2b15cb3dSCy Schubert 140*2b15cb3dSCy Schubert /** A reference count on this evbuffer. When the reference count 141*2b15cb3dSCy Schubert * reaches 0, the buffer is destroyed. Manipulated with 142*2b15cb3dSCy Schubert * evbuffer_incref and evbuffer_decref_and_unlock and 143*2b15cb3dSCy Schubert * evbuffer_free. */ 144*2b15cb3dSCy Schubert int refcnt; 145*2b15cb3dSCy Schubert 146*2b15cb3dSCy Schubert /** A struct event_callback handle to make all of this buffer's callbacks 147*2b15cb3dSCy Schubert * invoked from the event loop. */ 148*2b15cb3dSCy Schubert struct event_callback deferred; 149*2b15cb3dSCy Schubert 150*2b15cb3dSCy Schubert /** A doubly-linked-list of callback functions */ 151*2b15cb3dSCy Schubert LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks; 152*2b15cb3dSCy Schubert 153*2b15cb3dSCy Schubert /** The parent bufferevent object this evbuffer belongs to. 154*2b15cb3dSCy Schubert * NULL if the evbuffer stands alone. */ 155*2b15cb3dSCy Schubert struct bufferevent *parent; 156*2b15cb3dSCy Schubert }; 157*2b15cb3dSCy Schubert 158*2b15cb3dSCy Schubert /** A single item in an evbuffer. */ 159*2b15cb3dSCy Schubert struct evbuffer_chain { 160*2b15cb3dSCy Schubert /** points to next buffer in the chain */ 161*2b15cb3dSCy Schubert struct evbuffer_chain *next; 162*2b15cb3dSCy Schubert 163*2b15cb3dSCy Schubert /** total allocation available in the buffer field. */ 164*2b15cb3dSCy Schubert size_t buffer_len; 165*2b15cb3dSCy Schubert 166*2b15cb3dSCy Schubert /** unused space at the beginning of buffer or an offset into a 167*2b15cb3dSCy Schubert * file for sendfile buffers. */ 168*2b15cb3dSCy Schubert ev_off_t misalign; 169*2b15cb3dSCy Schubert 170*2b15cb3dSCy Schubert /** Offset into buffer + misalign at which to start writing. 171*2b15cb3dSCy Schubert * In other words, the total number of bytes actually stored 172*2b15cb3dSCy Schubert * in buffer. */ 173*2b15cb3dSCy Schubert size_t off; 174*2b15cb3dSCy Schubert 175*2b15cb3dSCy Schubert /** Set if special handling is required for this chain */ 176*2b15cb3dSCy Schubert unsigned flags; 177*2b15cb3dSCy Schubert #define EVBUFFER_FILESEGMENT 0x0001 /**< A chain used for a file segment */ 178*2b15cb3dSCy Schubert #define EVBUFFER_SENDFILE 0x0002 /**< a chain used with sendfile */ 179*2b15cb3dSCy Schubert #define EVBUFFER_REFERENCE 0x0004 /**< a chain with a mem reference */ 180*2b15cb3dSCy Schubert #define EVBUFFER_IMMUTABLE 0x0008 /**< read-only chain */ 181*2b15cb3dSCy Schubert /** a chain that mustn't be reallocated or freed, or have its contents 182*2b15cb3dSCy Schubert * memmoved, until the chain is un-pinned. */ 183*2b15cb3dSCy Schubert #define EVBUFFER_MEM_PINNED_R 0x0010 184*2b15cb3dSCy Schubert #define EVBUFFER_MEM_PINNED_W 0x0020 185*2b15cb3dSCy Schubert #define EVBUFFER_MEM_PINNED_ANY (EVBUFFER_MEM_PINNED_R|EVBUFFER_MEM_PINNED_W) 186*2b15cb3dSCy Schubert /** a chain that should be freed, but can't be freed until it is 187*2b15cb3dSCy Schubert * un-pinned. */ 188*2b15cb3dSCy Schubert #define EVBUFFER_DANGLING 0x0040 189*2b15cb3dSCy Schubert /** a chain that is a referenced copy of another chain */ 190*2b15cb3dSCy Schubert #define EVBUFFER_MULTICAST 0x0080 191*2b15cb3dSCy Schubert 192*2b15cb3dSCy Schubert /** number of references to this chain */ 193*2b15cb3dSCy Schubert int refcnt; 194*2b15cb3dSCy Schubert 195*2b15cb3dSCy Schubert /** Usually points to the read-write memory belonging to this 196*2b15cb3dSCy Schubert * buffer allocated as part of the evbuffer_chain allocation. 197*2b15cb3dSCy Schubert * For mmap, this can be a read-only buffer and 198*2b15cb3dSCy Schubert * EVBUFFER_IMMUTABLE will be set in flags. For sendfile, it 199*2b15cb3dSCy Schubert * may point to NULL. 200*2b15cb3dSCy Schubert */ 201*2b15cb3dSCy Schubert unsigned char *buffer; 202*2b15cb3dSCy Schubert }; 203*2b15cb3dSCy Schubert 204*2b15cb3dSCy Schubert /** callback for a reference chain; lets us know what to do with it when 205*2b15cb3dSCy Schubert * we're done with it. Lives at the end of an evbuffer_chain with the 206*2b15cb3dSCy Schubert * EVBUFFER_REFERENCE flag set */ 207*2b15cb3dSCy Schubert struct evbuffer_chain_reference { 208*2b15cb3dSCy Schubert evbuffer_ref_cleanup_cb cleanupfn; 209*2b15cb3dSCy Schubert void *extra; 210*2b15cb3dSCy Schubert }; 211*2b15cb3dSCy Schubert 212*2b15cb3dSCy Schubert /** File segment for a file-segment chain. Lives at the end of an 213*2b15cb3dSCy Schubert * evbuffer_chain with the EVBUFFER_FILESEGMENT flag set. */ 214*2b15cb3dSCy Schubert struct evbuffer_chain_file_segment { 215*2b15cb3dSCy Schubert struct evbuffer_file_segment *segment; 216*2b15cb3dSCy Schubert #ifdef _WIN32 217*2b15cb3dSCy Schubert /** If we're using CreateFileMapping, this is the handle to the view. */ 218*2b15cb3dSCy Schubert HANDLE view_handle; 219*2b15cb3dSCy Schubert #endif 220*2b15cb3dSCy Schubert }; 221*2b15cb3dSCy Schubert 222*2b15cb3dSCy Schubert /* Declared in event2/buffer.h; defined here. */ 223*2b15cb3dSCy Schubert struct evbuffer_file_segment { 224*2b15cb3dSCy Schubert void *lock; /**< lock prevent concurrent access to refcnt */ 225*2b15cb3dSCy Schubert int refcnt; /**< Reference count for this file segment */ 226*2b15cb3dSCy Schubert unsigned flags; /**< combination of EVBUF_FS_* flags */ 227*2b15cb3dSCy Schubert 228*2b15cb3dSCy Schubert /** What kind of file segment is this? */ 229*2b15cb3dSCy Schubert unsigned can_sendfile : 1; 230*2b15cb3dSCy Schubert unsigned is_mapping : 1; 231*2b15cb3dSCy Schubert 232*2b15cb3dSCy Schubert /** The fd that we read the data from. */ 233*2b15cb3dSCy Schubert int fd; 234*2b15cb3dSCy Schubert /** If we're using mmap, this is the raw mapped memory. */ 235*2b15cb3dSCy Schubert void *mapping; 236*2b15cb3dSCy Schubert #ifdef _WIN32 237*2b15cb3dSCy Schubert /** If we're using CreateFileMapping, this is the mapping */ 238*2b15cb3dSCy Schubert HANDLE mapping_handle; 239*2b15cb3dSCy Schubert #endif 240*2b15cb3dSCy Schubert /** If we're using mmap or IO, this is the content of the file 241*2b15cb3dSCy Schubert * segment. */ 242*2b15cb3dSCy Schubert char *contents; 243*2b15cb3dSCy Schubert /** Position of this segment within the file. */ 244*2b15cb3dSCy Schubert ev_off_t file_offset; 245*2b15cb3dSCy Schubert /** If we're using mmap, this is the offset within 'mapping' where 246*2b15cb3dSCy Schubert * this data segment begins. */ 247*2b15cb3dSCy Schubert ev_off_t mmap_offset; 248*2b15cb3dSCy Schubert /** The length of this segment. */ 249*2b15cb3dSCy Schubert ev_off_t length; 250*2b15cb3dSCy Schubert /** Cleanup callback function */ 251*2b15cb3dSCy Schubert evbuffer_file_segment_cleanup_cb cleanup_cb; 252*2b15cb3dSCy Schubert /** Argument to be pass to cleanup callback function */ 253*2b15cb3dSCy Schubert void *cleanup_cb_arg; 254*2b15cb3dSCy Schubert }; 255*2b15cb3dSCy Schubert 256*2b15cb3dSCy Schubert /** Information about the multicast parent of a chain. Lives at the 257*2b15cb3dSCy Schubert * end of an evbuffer_chain with the EVBUFFER_MULTICAST flag set. */ 258*2b15cb3dSCy Schubert struct evbuffer_multicast_parent { 259*2b15cb3dSCy Schubert /** source buffer the multicast parent belongs to */ 260*2b15cb3dSCy Schubert struct evbuffer *source; 261*2b15cb3dSCy Schubert /** multicast parent for this chain */ 262*2b15cb3dSCy Schubert struct evbuffer_chain *parent; 263*2b15cb3dSCy Schubert }; 264*2b15cb3dSCy Schubert 265*2b15cb3dSCy Schubert #define EVBUFFER_CHAIN_SIZE sizeof(struct evbuffer_chain) 266*2b15cb3dSCy Schubert /** Return a pointer to extra data allocated along with an evbuffer. */ 267*2b15cb3dSCy Schubert #define EVBUFFER_CHAIN_EXTRA(t, c) (t *)((struct evbuffer_chain *)(c) + 1) 268*2b15cb3dSCy Schubert 269*2b15cb3dSCy Schubert /** Assert that we are holding the lock on an evbuffer */ 270*2b15cb3dSCy Schubert #define ASSERT_EVBUFFER_LOCKED(buffer) \ 271*2b15cb3dSCy Schubert EVLOCK_ASSERT_LOCKED((buffer)->lock) 272*2b15cb3dSCy Schubert 273*2b15cb3dSCy Schubert #define EVBUFFER_LOCK(buffer) \ 274*2b15cb3dSCy Schubert do { \ 275*2b15cb3dSCy Schubert EVLOCK_LOCK((buffer)->lock, 0); \ 276*2b15cb3dSCy Schubert } while (0) 277*2b15cb3dSCy Schubert #define EVBUFFER_UNLOCK(buffer) \ 278*2b15cb3dSCy Schubert do { \ 279*2b15cb3dSCy Schubert EVLOCK_UNLOCK((buffer)->lock, 0); \ 280*2b15cb3dSCy Schubert } while (0) 281*2b15cb3dSCy Schubert #define EVBUFFER_LOCK2(buffer1, buffer2) \ 282*2b15cb3dSCy Schubert do { \ 283*2b15cb3dSCy Schubert EVLOCK_LOCK2((buffer1)->lock, (buffer2)->lock, 0, 0); \ 284*2b15cb3dSCy Schubert } while (0) 285*2b15cb3dSCy Schubert #define EVBUFFER_UNLOCK2(buffer1, buffer2) \ 286*2b15cb3dSCy Schubert do { \ 287*2b15cb3dSCy Schubert EVLOCK_UNLOCK2((buffer1)->lock, (buffer2)->lock, 0, 0); \ 288*2b15cb3dSCy Schubert } while (0) 289*2b15cb3dSCy Schubert 290*2b15cb3dSCy Schubert /** Increase the reference count of buf by one. */ 291*2b15cb3dSCy Schubert void evbuffer_incref_(struct evbuffer *buf); 292*2b15cb3dSCy Schubert /** Increase the reference count of buf by one and acquire the lock. */ 293*2b15cb3dSCy Schubert void evbuffer_incref_and_lock_(struct evbuffer *buf); 294*2b15cb3dSCy Schubert /** Pin a single buffer chain using a given flag. A pinned chunk may not be 295*2b15cb3dSCy Schubert * moved or freed until it is unpinned. */ 296*2b15cb3dSCy Schubert void evbuffer_chain_pin_(struct evbuffer_chain *chain, unsigned flag); 297*2b15cb3dSCy Schubert /** Unpin a single buffer chain using a given flag. */ 298*2b15cb3dSCy Schubert void evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag); 299*2b15cb3dSCy Schubert /** As evbuffer_free, but requires that we hold a lock on the buffer, and 300*2b15cb3dSCy Schubert * releases the lock before freeing it and the buffer. */ 301*2b15cb3dSCy Schubert void evbuffer_decref_and_unlock_(struct evbuffer *buffer); 302*2b15cb3dSCy Schubert 303*2b15cb3dSCy Schubert /** As evbuffer_expand, but does not guarantee that the newly allocated memory 304*2b15cb3dSCy Schubert * is contiguous. Instead, it may be split across two or more chunks. */ 305*2b15cb3dSCy Schubert int evbuffer_expand_fast_(struct evbuffer *, size_t, int); 306*2b15cb3dSCy Schubert 307*2b15cb3dSCy Schubert /** Helper: prepares for a readv/WSARecv call by expanding the buffer to 308*2b15cb3dSCy Schubert * hold enough memory to read 'howmuch' bytes in possibly noncontiguous memory. 309*2b15cb3dSCy Schubert * Sets up the one or two iovecs in 'vecs' to point to the free memory and its 310*2b15cb3dSCy Schubert * extent, and *chainp to point to the first chain that we'll try to read into. 311*2b15cb3dSCy Schubert * Returns the number of vecs used. 312*2b15cb3dSCy Schubert */ 313*2b15cb3dSCy Schubert int evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, 314*2b15cb3dSCy Schubert struct evbuffer_iovec *vecs, int n_vecs, struct evbuffer_chain ***chainp, 315*2b15cb3dSCy Schubert int exact); 316*2b15cb3dSCy Schubert 317*2b15cb3dSCy Schubert /* Helper macro: copies an evbuffer_iovec in ei to a win32 WSABUF in i. */ 318*2b15cb3dSCy Schubert #define WSABUF_FROM_EVBUFFER_IOV(i,ei) do { \ 319*2b15cb3dSCy Schubert (i)->buf = (ei)->iov_base; \ 320*2b15cb3dSCy Schubert (i)->len = (unsigned long)(ei)->iov_len; \ 321*2b15cb3dSCy Schubert } while (0) 322*2b15cb3dSCy Schubert /* XXXX the cast above is safe for now, but not if we allow mmaps on win64. 323*2b15cb3dSCy Schubert * See note in buffer_iocp's launch_write function */ 324*2b15cb3dSCy Schubert 325*2b15cb3dSCy Schubert /** Set the parent bufferevent object for buf to bev */ 326*2b15cb3dSCy Schubert void evbuffer_set_parent_(struct evbuffer *buf, struct bufferevent *bev); 327*2b15cb3dSCy Schubert 328*2b15cb3dSCy Schubert void evbuffer_invoke_callbacks_(struct evbuffer *buf); 329*2b15cb3dSCy Schubert 330*2b15cb3dSCy Schubert 331*2b15cb3dSCy Schubert int evbuffer_get_callbacks_(struct evbuffer *buffer, 332*2b15cb3dSCy Schubert struct event_callback **cbs, 333*2b15cb3dSCy Schubert int max_cbs); 334*2b15cb3dSCy Schubert 335*2b15cb3dSCy Schubert #ifdef __cplusplus 336*2b15cb3dSCy Schubert } 337*2b15cb3dSCy Schubert #endif 338*2b15cb3dSCy Schubert 339*2b15cb3dSCy Schubert #endif /* EVBUFFER_INTERNAL_H_INCLUDED_ */ 340