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_OK 1000
27 #define WEBSOCKET_CODE_GOING_AWAY 1001
28 #define WEBSOCKET_CODE_PROTOCOL_ERROR 1002
29 #define WEBSOCKET_CODE_CANT_ACCEPT 1003
30 #define WEBSOCKET_CODE_RESERVED 1004
31 #define WEBSOCKET_CODE_NOT_SET 1005
32 #define WEBSOCKET_CODE_ABNORMAL 1006
33 #define WEBSOCKET_CODE_INVALID_UTF8 1007
34 #define WEBSOCKET_CODE_POLICY_VIOLATION 1008
35 #define WEBSOCKET_CODE_MESSAGE_TOO_LARGE 1009
36 #define WEBSOCKET_CODE_INTERNAL_ERROR 1011
39 ssize_t (*writev) (void *, const struct iovec *, int);
40 ssize_t (*readv) (void *, const struct iovec *, int);
41 void (*disconnect) (void *);
43 void (*on_ping) (void *); /* if not NULL, responsible of pong */
44 void (*on_pong) (void *);
45 void (*on_close) (void *, uint16_t code, size_t size);
46 void (*on_text) (void *, int last, size_t size);
47 void (*on_binary) (void *, int last, size_t size);
48 void (*on_continue) (void *, int last, size_t size);
49 int (*on_extension) (void *, int last, int rsv1, int rsv2, int rsv3, int opcode, size_t size);
54 void websock_close(struct websock *ws);
55 void websock_close_code(struct websock *ws, uint16_t code);
57 void websock_ping(struct websock *ws);
58 void websock_pong(struct websock *ws);
59 void websock_text(struct websock *ws, const char *text, size_t length);
60 void websock_binary(struct websock *ws, const void *data, size_t length);
62 ssize_t websock_read(struct websock *ws, void *buffer, size_t size);
63 void websock_drop(struct websock *ws);
65 int websock_dispatch(struct websock *ws);
67 struct websock *websock_create_v13(const struct websock_itf *itf, void *closure);
68 void websock_destroy(struct websock *ws);