1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
;
;
/* TODO: Document lifetime stuff */
/* TODO: Document CLOSE frame behavior (when auto-sent during close, when auto-closed) */
/* TODO: Document auto-pong behavior */
/**
* A websocket connection.
*/
;
/**
* Opcode describing the type of a websocket frame.
* RFC-6455 Section 5.2
*/
;
/**
* Called when websocket setup is complete.
* An error_code of zero indicates that setup was completely successful.
* Called exactly once on the websocket's event-loop thread.
*
* websocket: if successful, a valid pointer to the websocket, otherwise NULL.
* error_code: the operation was completely successful if this value is zero.
* handshake_response_status: The response status code of the HTTP handshake, 101 if successful,
* -1 if the connection failed before a response was received.
* handshake_response_header_array: Headers from the HTTP handshake response.
* May be NULL if num_handshake_response_headers is 0.
* Copy if necessary, this memory becomes invalid once the callback completes.
* num_handshake_response_headers: Number of entries in handshake_response_header_array.
* May be 0 if the response did not complete, or was invalid.
*/
typedef void;
/**
* Called when the websocket has finished shutting down.
* Called once on the websocket's event-loop thread if setup succeeded.
* If setup failed, this is never called.
*/
typedef void;
/**
* Data about an incoming frame.
* See RFC-6455 Section 5.2.
*/
;
/**
* Called when a new frame arrives.
* Invoked once per frame on the websocket's event-loop thread.
* Each incoming-frame-begin call will eventually be followed by an incoming-frame-complete call,
* before the next frame begins and before the websocket shuts down.
*
* Return true to proceed normally. If false is returned, the websocket will read no further data,
* the frame will complete with an error-code, and the connection will close.
*/
typedef bool;
/**
* Called repeatedly as payload data arrives.
* Invoked 0 or more times on the websocket's event-loop thread.
* Payload data will not be valid after this call, so copy if necessary.
* The payload data is always unmasked at this point.
*
* Return true to proceed normally. If false is returned, the websocket will read no further data,
* the frame will complete with an error-code, and the connection will close.
*/
typedef bool;
/**
* Called when done processing an incoming frame.
* If error_code is non-zero, an error occurred and the payload may not have been completely received.
* Invoked once per frame on the websocket's event-loop thread.
*
* Return true to proceed normally. If false is returned, the websocket will read no further data
* and the connection will close.
*/
typedef bool;
/**
* Options for creating a websocket client connection.
*/
;
/**
* Called repeatedly as the websocket's payload is streamed out.
* The user should write payload data to out_buf, up to available capacity.
* The websocket will mask this data for you, if necessary.
* Invoked repeatedly on the websocket's event-loop thread.
*
* Return true to proceed normally. If false is returned, the websocket will send no further data,
* the frame will complete with an error-code, and the connection will close.
*/
typedef bool;
/**
* Called when a aws_websocket_send_frame() operation completes.
* error_code will be zero if the operation was successful.
* "Success" does not guarantee that the peer actually received or processed the frame.
* Invoked exactly once per sent frame on the websocket's event-loop thread.
*/
typedef void;
/**
* Options for sending a websocket frame.
* This structure is copied immediately by aws_websocket_send().
* For descriptions of opcode, fin, rsv, and payload_length see in RFC-6455 Section 5.2.
*/
;
/**
* Return true if opcode is for a data frame, false if opcode if for a control frame.
*/
bool ;
/**
* Asynchronously establish a client websocket connection.
* The on_connection_setup callback is invoked when the operation has finished creating a connection, or failed.
*/
int ;
/**
* Users must release the websocket when they are done with it.
* The websocket's memory cannot be reclaimed until this is done.
* If the websocket connection was not already shutting down, it will be shut down.
* Callbacks may continue firing after this is called, with "shutdown" being the final callback.
* This function may be called from any thread.
*/
void ;
/**
* Close the websocket connection.
* It is safe to call this, even if the connection is already closed or closing.
* The websocket will attempt to send a CLOSE frame during normal shutdown.
* If `free_scarce_resources_immediately` is true, the connection will be torn down as quickly as possible.
* This function may be called from any thread.
*/
void ;
/**
* Send a websocket frame.
* The `options` struct is copied.
* A callback will be invoked when the operation completes.
* This function may be called from any thread.
*/
int ;
/**
* Manually increment the read window.
* The read window shrinks as payload data is received, and reading stops when its size reaches 0.
* Note that the read window can also be controlled from the aws_websocket_on_incoming_frame_payload_fn(),
* callback, by manipulating the `out_increment_window` argument.
* This function may be called from any thread.
*/
void ;
/**
* Convert the websocket into a mid-channel handler.
* The websocket will stop being usable via its public API and become just another handler in the channel.
* The caller will likely install a channel handler to the right.
* This must not be called in the middle of an incoming frame (between "frame begin" and "frame complete" callbacks).
* This MUST be called from the websocket's thread.
*
* If successful:
* - Other than aws_websocket_release(), all calls to aws_websocket_x() functions are ignored.
* - The websocket will no longer invoke any "incoming frame" callbacks.
* - aws_io_messages written by a downstream handler will be wrapped in binary data frames and sent upstream.
* The data may be split/combined as it is sent along.
* - aws_io_messages read from upstream handlers will be scanned for binary data frames.
* The payloads of these frames will be sent downstream.
* The payloads may be split/combined as they are sent along.
* - An incoming close frame will automatically result in channel-shutdown.
* - aws_websocket_release() must still be called or the websocket and its channel will never be cleaned up.
* - The websocket will still invoke its "on connection shutdown" callback when channel shutdown completes.
*
* If unsuccessful, NULL is returned and the websocket is unchanged.
*/
int ;
/**
* Returns the websocket's underlying I/O channel.
*/
struct aws_channel *;
/**
* Generate value for a Sec-WebSocket-Key header and write it into `dst` buffer.
* The buffer should have at least AWS_WEBSOCKET_MAX_HANDSHAKE_KEY_LENGTH space available.
*
* This value is the base64 encoding of a random 16-byte value.
* RFC-6455 Section 4.1
*/
int ;
/**
* Create request with all required fields for a websocket upgrade request.
* The method and path are set, and the the following headers are added:
*
* Host: <host>
* Upgrade: websocket
* Connection: Upgrade
* Sec-WebSocket-Key: <base64 encoding of 16 random bytes>
* Sec-WebSocket-Version: 13
*/
struct aws_http_message *;
/* AWS_HTTP_WEBSOCKET_H */