stream: add backlog option to stream services, forward to listen()
[strongswan.git] / src / libstrongswan / networking / streams / stream_manager.h
1 /*
2 * Copyright (C) 2013 Martin Willi
3 * Copyright (C) 2013 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup stream_manager stream_manager
18 * @{ @ingroup streams
19 */
20
21 #ifndef STREAM_MANAGER_H_
22 #define STREAM_MANAGER_H_
23
24 typedef struct stream_manager_t stream_manager_t;
25
26 #include <networking/streams/stream_service.h>
27
28 /**
29 * Manages client-server connections and services using stream_t backends.
30 */
31 struct stream_manager_t {
32
33 /**
34 * Create a client-server connection to a service.
35 *
36 * @param uri URI of service to connect to
37 * @return stream instance, NULL on error
38 */
39 stream_t* (*connect)(stream_manager_t *this, char *uri);
40
41 /**
42 * Start a new service under an URI, accept()ing client connections.
43 *
44 * @param uri URI of service to provide
45 * @param backlog size of the backlog queue, as passed to listen()
46 * @param cb callback function invoked for each client connection
47 * @param data user data to pass to callback
48 * @return TRUE if service started, FALSE on failure
49 */
50 bool (*start_service)(stream_manager_t *this, char *uri, int backlog,
51 stream_service_cb_t cb, void *data);
52
53 /**
54 * Stop a service previously create with start_service().
55 *
56 * @param uri URI of service to stop
57 */
58 void (*stop_service)(stream_manager_t *this, char *uri);
59
60 /**
61 * Register a stream backend to the manager.
62 *
63 * @param prefix prefix of URIs to use the backend for
64 * @param create constructor function for the stream
65 */
66 void (*add_stream)(stream_manager_t *this, char *prefix,
67 stream_constructor_t create);
68
69 /**
70 * Unregister stream backends from the manager.
71 *
72 * @param create constructor function passed to add_stream()
73 */
74 void (*remove_stream)(stream_manager_t *this, stream_constructor_t create);
75
76 /**
77 * Register a stream service backend to the manager.
78 *
79 * @param prefix prefix of URIs to use the backend for
80 * @param create constructor function for the stream service
81 */
82 void (*add_service)(stream_manager_t *this, char *prefix,
83 stream_service_constructor_t create);
84
85 /**
86 * Unregister stream service backends from the manager.
87 *
88 * @param create constructor function passed to add_service()
89 */
90 void (*remove_service)(stream_manager_t *this,
91 stream_service_constructor_t create);
92
93 /**
94 * Destroy a stream_manager_t.
95 */
96 void (*destroy)(stream_manager_t *this);
97 };
98
99 /**
100 * Create a stream_manager instance.
101 */
102 stream_manager_t *stream_manager_create();
103
104 #endif /** STREAM_MANAGER_H_ @}*/