libevent  2.2.1
Event notification library
listener.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef EVENT2_LISTENER_H_INCLUDED_
28 #define EVENT2_LISTENER_H_INCLUDED_
29 
30 #include <event2/visibility.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <event2/event.h>
37 
38 struct sockaddr;
39 struct evconnlistener;
40 
51 typedef void (*evconnlistener_cb)(struct evconnlistener *, evutil_socket_t, struct sockaddr *, int socklen, void *);
52 
59 typedef void (*evconnlistener_errorcb)(struct evconnlistener *, void *);
60 
63 #define LEV_OPT_LEAVE_SOCKETS_BLOCKING (1u<<0)
64 
66 #define LEV_OPT_CLOSE_ON_FREE (1u<<1)
67 
68 #define LEV_OPT_CLOSE_ON_EXEC (1u<<2)
69 
71 #define LEV_OPT_REUSEABLE (1u<<3)
72 
74 #define LEV_OPT_THREADSAFE (1u<<4)
75 
77 #define LEV_OPT_DISABLED (1u<<5)
78 
91 #define LEV_OPT_DEFERRED_ACCEPT (1u<<6)
92 
100 #define LEV_OPT_REUSEABLE_PORT (1u<<7)
101 
112 #define LEV_OPT_BIND_IPV6ONLY (1u<<8)
113 
121 #define LEV_OPT_BIND_IPV4_AND_IPV6 (1u<<9)
122 
140 EVENT2_EXPORT_SYMBOL
141 struct evconnlistener *evconnlistener_new(struct event_base *base,
142  evconnlistener_cb cb, void *ptr, unsigned flags, int backlog,
143  evutil_socket_t fd);
159 EVENT2_EXPORT_SYMBOL
160 struct evconnlistener *evconnlistener_new_bind(struct event_base *base,
161  evconnlistener_cb cb, void *ptr, unsigned flags, int backlog,
162  const struct sockaddr *sa, int socklen);
166 EVENT2_EXPORT_SYMBOL
167 void evconnlistener_free(struct evconnlistener *lev);
171 EVENT2_EXPORT_SYMBOL
172 int evconnlistener_enable(struct evconnlistener *lev);
176 EVENT2_EXPORT_SYMBOL
177 int evconnlistener_disable(struct evconnlistener *lev);
178 
180 EVENT2_EXPORT_SYMBOL
181 struct event_base *evconnlistener_get_base(struct evconnlistener *lev);
182 
184 EVENT2_EXPORT_SYMBOL
185 evutil_socket_t evconnlistener_get_fd(struct evconnlistener *lev);
186 
189 EVENT2_EXPORT_SYMBOL
190 void evconnlistener_set_cb(struct evconnlistener *lev,
191  evconnlistener_cb cb, void *arg);
192 
194 EVENT2_EXPORT_SYMBOL
195 void evconnlistener_set_error_cb(struct evconnlistener *lev,
196  evconnlistener_errorcb errorcb);
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif
event_base
Structure to hold information and state for a Libevent dispatch loop.
Definition: event.h:219
evconnlistener_get_fd
EVENT2_EXPORT_SYMBOL evutil_socket_t evconnlistener_get_fd(struct evconnlistener *lev)
Return the socket that an evconnlistner is listening on.
evconnlistener_new
EVENT2_EXPORT_SYMBOL struct evconnlistener * evconnlistener_new(struct event_base *base, evconnlistener_cb cb, void *ptr, unsigned flags, int backlog, evutil_socket_t fd)
Allocate a new evconnlistener object to listen for incoming TCP connections on a given file descripto...
event.h
Core functions for waiting for and receiving events, and using event bases.
evconnlistener_new_bind
EVENT2_EXPORT_SYMBOL struct evconnlistener * evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb, void *ptr, unsigned flags, int backlog, const struct sockaddr *sa, int socklen)
Allocate a new evconnlistener object to listen for incoming TCP connections on a given address.
evconnlistener_errorcb
void(* evconnlistener_errorcb)(struct evconnlistener *, void *)
A callback that we invoke when a listener encounters a non-retriable error.
Definition: listener.h:59
evconnlistener_disable
EVENT2_EXPORT_SYMBOL int evconnlistener_disable(struct evconnlistener *lev)
Stop listening for connections on an evconnlistener.
evconnlistener_free
EVENT2_EXPORT_SYMBOL void evconnlistener_free(struct evconnlistener *lev)
Disable and deallocate an evconnlistener.
evconnlistener_set_cb
EVENT2_EXPORT_SYMBOL void evconnlistener_set_cb(struct evconnlistener *lev, evconnlistener_cb cb, void *arg)
Change the callback on the listener to cb and its user_data to arg.
evconnlistener_get_base
EVENT2_EXPORT_SYMBOL struct event_base * evconnlistener_get_base(struct evconnlistener *lev)
Return an evconnlistener's associated event_base.
evconnlistener_enable
EVENT2_EXPORT_SYMBOL int evconnlistener_enable(struct evconnlistener *lev)
Re-enable an evconnlistener that has been disabled.
evconnlistener_set_error_cb
EVENT2_EXPORT_SYMBOL void evconnlistener_set_error_cb(struct evconnlistener *lev, evconnlistener_errorcb errorcb)
Set an evconnlistener's error callback.
evutil_socket_t
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:310