Debian Codegraph @

crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_server.h

raw symbols SCIP
1 #ifndef AWS_EVENT_STREAM_RPC_SERVER_H
2 #define AWS_EVENT_STREAM_RPC_SERVER_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7
8 #include <aws/event-stream/event_stream_rpc.h>
9
10 AWS_PUSH_SANE_WARNING_LEVEL
11
12 struct aws_channel;
13 struct aws_event_stream_rpc_server_connection;
14
15 struct aws_event_stream_rpc_server_continuation_token;
16
17 /**
18 * Invoked when a connection receives a message on an existing stream. message_args contains the
19 * message data.
20 */
21 typedef void(aws_event_stream_rpc_server_stream_continuation_fn)(
22 struct aws_event_stream_rpc_server_continuation_token *token,
23 const struct aws_event_stream_rpc_message_args *message_args,
24 void *user_data);
25
26 /**
27 * Invoked when a continuation has either been closed with the TERMINATE_STREAM flag, or when the connection
28 * shutsdown and deletes the continuation.
29 */
30 typedef void(aws_event_stream_rpc_server_stream_continuation_closed_fn)(
31 struct aws_event_stream_rpc_server_continuation_token *token,
32 void *user_data);
33
34 struct aws_event_stream_rpc_server_stream_continuation_options {
35 aws_event_stream_rpc_server_stream_continuation_fn *on_continuation;
36 aws_event_stream_rpc_server_stream_continuation_closed_fn *on_continuation_closed;
37 void *user_data;
38 };
39
40 /**
41 * Invoked when a non-stream level message is received on a connection.
42 */
43 typedef void(aws_event_stream_rpc_server_connection_protocol_message_fn)(
44 struct aws_event_stream_rpc_server_connection *connection,
45 const struct aws_event_stream_rpc_message_args *message_args,
46 void *user_data);
47
48 /**
49 * Invoked when a new stream has been received on the connection. If you return AWS_OP_SUCCESS (0),
50 * You must fill in the fields for continuation options or the program will assert and exit.
51 *
52 * A failure path MUST leave the ref count of the continuation alone.
53 *
54 * A success path should probably take a ref which will leave the continuation (assuming no other interference)
55 * at two AFTER creation is complete: 1 for the connection's continuation table, and one for the callback
56 * recipient which is presumably tracking it as well.
57 */
58 typedef int(aws_event_stream_rpc_server_on_incoming_stream_fn)(
59 struct aws_event_stream_rpc_server_connection *connection,
60 struct aws_event_stream_rpc_server_continuation_token *token,
61 struct aws_byte_cursor operation_name,
62 struct aws_event_stream_rpc_server_stream_continuation_options *continuation_options,
63 void *user_data);
64
65 struct aws_event_stream_rpc_connection_options {
66 aws_event_stream_rpc_server_on_incoming_stream_fn *on_incoming_stream;
67 aws_event_stream_rpc_server_connection_protocol_message_fn *on_connection_protocol_message;
68 void *user_data;
69 };
70
71 /**
72 * Invoked when a new connection is received on a server listener. If you return AWS_OP_SUCCESS,
73 * You must fill in the fields for connection_options or the program will assert and exit.
74 *
75 * If error_code is non-zero, an error occurred upon setting up the channel and connection will be NULL. Otherwise,
76 * connection is non-null. If you intend to seat a pointer to connection, you MUST call
77 * aws_event_stream_rpc_server_connection_acquire() and when you're finished with the connection you MUST call
78 * aws_event_stream_server_connection_release().
79 */
80 typedef int(aws_event_stream_rpc_server_on_new_connection_fn)(
81 struct aws_event_stream_rpc_server_connection *connection,
82 int error_code,
83 struct aws_event_stream_rpc_connection_options *connection_options,
84 void *user_data);
85
86 /**
87 * Invoked when a successfully created connection is shutdown. error_code will indicate the reason for the shutdown.
88 */
89 typedef void(aws_event_stream_rpc_server_on_connection_shutdown_fn)(
90 struct aws_event_stream_rpc_server_connection *connection,
91 int error_code,
92 void *user_data);
93
94 /**
95 * Invoked whenever a message has been flushed to the channel.
96 */
97 typedef void(aws_event_stream_rpc_server_message_flush_fn)(int error_code, void *user_data);
98
99 struct aws_server_bootstrap;
100 struct aws_event_stream_rpc_server_listener;
101
102 /**
103 * (Optional). Invoked when the listener has been successfully shutdown (after the last ref count release).
104 */
105 typedef void(aws_event_stream_rpc_server_on_listener_destroy_fn)(
106 struct aws_event_stream_rpc_server_listener *server,
107 void *user_data);
108
109 struct aws_event_stream_rpc_server_listener_options {
110 /** host name to use for the listener. This depends on your socket type. */
111 const char *host_name;
112 /** port to use for your listener, assuming for the appropriate socket type. */
113 uint32_t port;
114 const struct aws_socket_options *socket_options;
115 /** optional: tls options for using when setting up your server. */
116 const struct aws_tls_connection_options *tls_options;
117 struct aws_server_bootstrap *bootstrap;
118 aws_event_stream_rpc_server_on_new_connection_fn *on_new_connection;
119 aws_event_stream_rpc_server_on_connection_shutdown_fn *on_connection_shutdown;
120 aws_event_stream_rpc_server_on_listener_destroy_fn *on_destroy_callback;
121 void *user_data;
122 };
123
124 AWS_EXTERN_C_BEGIN
125
126 /**
127 * Creates a listener with a ref count of 1. You are responsible for calling
128 * aws_event_stream_rpc_server_listener_release() when you're finished with the listener. Returns NULL if an error
129 * occurs.
130 */
131 AWS_EVENT_STREAM_API struct aws_event_stream_rpc_server_listener *aws_event_stream_rpc_server_new_listener(
132 struct aws_allocator *allocator,
133 struct aws_event_stream_rpc_server_listener_options *options);
134 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_listener_acquire(
135 struct aws_event_stream_rpc_server_listener *listener);
136 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_listener_release(
137 struct aws_event_stream_rpc_server_listener *listener);
138
139 /**
140 * Get the local port which the listener's socket is bound to.
141 */
142 AWS_EVENT_STREAM_API
143 uint32_t aws_event_stream_rpc_server_listener_get_bound_port(
144 const struct aws_event_stream_rpc_server_listener *listener);
145
146 /**
147 * Bypasses server, and creates a connection on an already existing channel. No connection lifetime callbacks will be
148 * invoked on the returned connection. Returns NULL if an error occurs. If and only if, you use this API, the returned
149 * connection is already ref counted and you must call aws_event_stream_rpc_server_connection_release() even if you did
150 * not explictly call aws_event_stream_rpc_server_connection_acquire()
151 */
152 AWS_EVENT_STREAM_API struct aws_event_stream_rpc_server_connection *
153 aws_event_stream_rpc_server_connection_from_existing_channel(
154 struct aws_event_stream_rpc_server_listener *server,
155 struct aws_channel *channel,
156 const struct aws_event_stream_rpc_connection_options *connection_options);
157 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_connection_acquire(
158 struct aws_event_stream_rpc_server_connection *connection);
159 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_connection_release(
160 struct aws_event_stream_rpc_server_connection *connection);
161
162 AWS_EVENT_STREAM_API void *aws_event_stream_rpc_server_connection_get_user_data(
163 struct aws_event_stream_rpc_server_connection *connection);
164 /**
165 * returns true if the connection is open. False otherwise.
166 */
167 AWS_EVENT_STREAM_API bool aws_event_stream_rpc_server_connection_is_open(
168 struct aws_event_stream_rpc_server_connection *connection);
169
170 /**
171 * Closes the connection (including all continuations on the connection), and releases the connection ref count.
172 * shutdown_error_code is the error code to use when shutting down the channel. Use AWS_ERROR_SUCCESS for non-error
173 * cases.
174 */
175 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_connection_close(
176 struct aws_event_stream_rpc_server_connection *connection,
177 int shutdown_error_code);
178
179 /**
180 * Sends a protocol message on the connection (not application data). If the message is valid and successfully written
181 * to the channel, flush_fn will be invoked.
182 */
183 AWS_EVENT_STREAM_API int aws_event_stream_rpc_server_connection_send_protocol_message(
184 struct aws_event_stream_rpc_server_connection *connection,
185 const struct aws_event_stream_rpc_message_args *message_args,
186 aws_event_stream_rpc_server_message_flush_fn *flush_fn,
187 void *user_data);
188
189 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_continuation_acquire(
190 struct aws_event_stream_rpc_server_continuation_token *continuation);
191 AWS_EVENT_STREAM_API void aws_event_stream_rpc_server_continuation_release(
192 struct aws_event_stream_rpc_server_continuation_token *continuation);
193
194 /**
195 * returns true if the continuation is still in an open state.
196 */
197 AWS_EVENT_STREAM_API bool aws_event_stream_rpc_server_continuation_is_closed(
198 struct aws_event_stream_rpc_server_continuation_token *continuation);
199
200 /**
201 * Sends an application message on the continuation. If the message is valid and successfully written
202 * to the channel, flush_fn will be invoked.
203 */
204 AWS_EVENT_STREAM_API int aws_event_stream_rpc_server_continuation_send_message(
205 struct aws_event_stream_rpc_server_continuation_token *continuation,
206 const struct aws_event_stream_rpc_message_args *message_args,
207 aws_event_stream_rpc_server_message_flush_fn *flush_fn,
208 void *user_data);
209
210 AWS_EXTERN_C_END
211 AWS_POP_SANE_WARNING_LEVEL
212
213 #endif /* AWS_EVENT_STREAM_RPC_SERVER_H */