Debian Codegraph @

c/include/proton/listener.h

raw
1 #ifndef PROTON_LISTENER_H
2 #define PROTON_LISTENER_H 1
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23 #include <proton/import_export.h>
24 #include <proton/types.h>
25 #include <proton/event.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /**
32 * @file
33 *
34 * @copybrief listener
35 *
36 * @addtogroup listener
37 * @{
38 *
39 * @note Thread safety: Listener has the same thread-safety rules as a
40 * @ref core object. Calls to a single listener must be serialized
41 * with the exception of pn_listener_close().
42 */
43
44 /**
45 * Create a listener to pass to pn_proactor_listen()
46 *
47 * You can use pn_listener_attachments() to set application data that can be
48 * accessed when accepting connections.
49 */
50 PNP_EXTERN pn_listener_t *pn_listener(void);
51
52 /**
53 * Free a listener. You don't need to call this unless you create a listener
54 * with pn_listen() but never pass it to pn_proactor_listen()
55 */
56 PNP_EXTERN void pn_listener_free(pn_listener_t *l);
57
58 /**
59 * Accept an incoming connection request using @p transport and @p connection,
60 * which can be configured before the call.
61 *
62 * Call after a @ref PN_LISTENER_ACCEPT event.
63 *
64 * Errors are returned as @ref PN_TRANSPORT_CLOSED events by pn_proactor_wait().
65 *
66 * @note If you provide a transport, pn_listener_accept2() will call
67 * pn_transport_set_server() to mark it as a server. However if you use
68 * pn_sasl() you *must* call call pn_transport_set_server() yourself *before*
69 * calling pn_sasl() to set up a server SASL configuration.
70 *
71 * @param[in] listener the listener
72 * @param[in] connection If NULL a new connection is created.
73 * Memory management is the same as for pn_proactor_connect2()
74 * @param[in] transport If NULL a new transport is created.
75 * Memory management is the same as for pn_proactor_connect2()
76 */
77 PNP_EXTERN void pn_listener_accept2(pn_listener_t *listener, pn_connection_t *connection, pn_transport_t *transport);
78
79 /**
80 * **Deprecated** - Use ::pn_listener_accept2().
81 */
82 PNP_EXTERN void pn_listener_accept(pn_listener_t* listener, pn_connection_t *connection);
83
84 /**
85 * Get the error condition for a listener.
86 */
87 PNP_EXTERN pn_condition_t *pn_listener_condition(pn_listener_t *l);
88
89 /**
90 * Get the application context associated with this listener object.
91 *
92 * The application context for a connection may be set using
93 * ::pn_listener_set_context.
94 *
95 * @param[in] listener the listener whose context is to be returned.
96 * @return the application context for the listener object
97 */
98 PNP_EXTERN void *pn_listener_get_context(pn_listener_t *listener);
99
100 /**
101 * Set a new application context for a listener object.
102 *
103 * The application context for a listener object may be retrieved
104 * using ::pn_listener_get_context.
105 *
106 * @param[in] listener the listener object
107 * @param[in] context the application context
108 */
109 PNP_EXTERN void pn_listener_set_context(pn_listener_t *listener, void *context);
110
111 /**
112 * Get the attachments that are associated with a listener object.
113 */
114 PNP_EXTERN pn_record_t *pn_listener_attachments(pn_listener_t *listener);
115
116 /**
117 * Close the listener.
118 * The PN_LISTENER_CLOSE event is generated when the listener has stopped listening.
119 *
120 * @note Thread safe. Must not be called after the PN_LISTENER_CLOSE event has
121 * been handled as the listener may be freed .
122 */
123 PNP_EXTERN void pn_listener_close(pn_listener_t *l);
124
125 /**
126 * The proactor associated with a listener.
127 */
128 PNP_EXTERN pn_proactor_t *pn_listener_proactor(pn_listener_t *c);
129
130 /**
131 * Return the listener associated with an event.
132 *
133 * @return NULL if the event is not associated with a listener.
134 */
135 PNP_EXTERN pn_listener_t *pn_event_listener(pn_event_t *event);
136
137 /**
138 * Accept an incoming connection request as a raw connection.
139 *
140 * Call after a @ref PN_LISTENER_ACCEPT event.
141 *
142 * Errors are returned as @ref PN_RAW_CONNECTION_DISCONNECTED by pn_proactor_wait().
143 *
144 * @param[in] listener the listener
145 * @param[in] raw_connection the application must create a raw connection with pn_raw_connection()
146 * this parameter cannot be null.If NULL a new connection is created.
147 *
148 * The proactor that owns the @p listener *takes ownership* of @p raw_connection and will
149 * automatically call pn_raw_connection_free() after the final @ref
150 * PN_RAW_CONNECTION_DISCONNECTED event is handled, or when pn_proactor_free() is
151 * called.
152 *
153 */
154 PNP_EXTERN void pn_listener_raw_accept(pn_listener_t *listener, pn_raw_connection_t *raw_connection);
155
156 /**
157 *@}
158 */
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* listener.h */