Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 1 | |
Andy Green | 775c0dd | 2010-10-29 14:15:22 +0100 | [diff] [blame] | 2 | enum libwebsocket_callback_reasons { |
| 3 | LWS_CALLBACK_ESTABLISHED, |
| 4 | LWS_CALLBACK_CLOSED, |
| 5 | LWS_CALLBACK_SEND, |
| 6 | LWS_CALLBACK_RECEIVE, |
Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 7 | }; |
| 8 | |
Andy Green | 775c0dd | 2010-10-29 14:15:22 +0100 | [diff] [blame] | 9 | struct libwebsocket; |
Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 10 | |
Andy Green | 775c0dd | 2010-10-29 14:15:22 +0100 | [diff] [blame] | 11 | extern int libwebsocket_create_server(int port, |
| 12 | int (*callback)(struct libwebsocket *, |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame^] | 13 | enum libwebsocket_callback_reasons, void *, size_t)); |
Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 14 | |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame^] | 15 | /* |
| 16 | * IMPORTANT NOTICE! |
| 17 | * |
| 18 | * The send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE |
| 19 | * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len). |
| 20 | * |
| 21 | * This allows us to add protocol info before and after the data, and send as |
| 22 | * one packet on the network without payload copying, for maximum efficiency. |
| 23 | * |
| 24 | * So for example you need this kind of code to use libwebsocket_write with a |
| 25 | * 128-byte payload |
| 26 | * |
| 27 | * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING]; |
| 28 | * |
| 29 | * // fill your part of the buffer... for example here it's all zeros |
| 30 | * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128); |
| 31 | * |
| 32 | * libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128); |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #define LWS_SEND_BUFFER_PRE_PADDING 12 |
| 37 | #define LWS_SEND_BUFFER_POST_PADDING 1 |
| 38 | |
| 39 | extern int libwebsocket_write(struct libwebsocket *, unsigned char *buf, size_t len, int is_binary); |