2 * Copyright 2016 iot.bzh
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * This work is a far adaptation of apache-websocket:
19 * origin: https://github.com/disconnect/apache-websocket
20 * commit: cfaef071223f11ba016bff7e1e4b7c9e5df45b50
21 * Copyright 2010-2012 self.disconnect (APACHE-2)
26 #define WEBSOCKET_CODE_UNSET 0
27 #define WEBSOCKET_CODE_OK 1000
28 #define WEBSOCKET_CODE_GOING_AWAY 1001
29 #define WEBSOCKET_CODE_PROTOCOL_ERROR 1002
30 #define WEBSOCKET_CODE_RESERVED 1004 /* Protocol 8: frame too large */
31 #define WEBSOCKET_CODE_INVALID_UTF8 1007
32 #define WEBSOCKET_CODE_POLICY_VIOLATION 1008
33 #define WEBSOCKET_CODE_MESSAGE_TOO_LARGE 1009
34 #define WEBSOCKET_CODE_INTERNAL_ERROR 1011
37 ssize_t (*writev) (void *, const struct iovec *, int);
38 ssize_t (*readv) (void *, const struct iovec *, int);
39 void (*disconnect) (void *);
41 void (*on_ping) (void *); /* if not NULL, responsible of pong */
42 void (*on_pong) (void *);
43 void (*on_close) (void *, uint16_t code, size_t size);
44 void (*on_text) (void *, int last, size_t size);
45 void (*on_binary) (void *, int last, size_t size);
46 void (*on_continue) (void *, int last, size_t size);
47 int (*on_extension) (void *, int last, int rsv1, int rsv2, int rsv3, int opcode, size_t size);
52 void websock_close(struct websock *ws);
53 void websock_close_code(struct websock *ws, uint16_t code);
55 void websock_ping(struct websock *ws);
56 void websock_pong(struct websock *ws);
57 void websock_text(struct websock *ws, const char *text, size_t length);
58 void websock_binary(struct websock *ws, const void *data, size_t length);
60 ssize_t websock_read(struct websock *ws, void *buffer, size_t size);
61 void websock_drop(struct websock *ws);
63 int websock_dispatch(struct websock *ws);
65 struct websock *websock_create_v13(const struct websock_itf *itf, void *closure);
66 void websock_destroy(struct websock *ws);