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