blob: b23f588ff3cc1ffe1ef5e3c705299680b892308f [file] [log] [blame]
Andy Greenff95d7a2010-10-28 22:36:01 +01001
Andy Green775c0dd2010-10-29 14:15:22 +01002enum libwebsocket_callback_reasons {
3 LWS_CALLBACK_ESTABLISHED,
4 LWS_CALLBACK_CLOSED,
5 LWS_CALLBACK_SEND,
6 LWS_CALLBACK_RECEIVE,
Andy Greenff95d7a2010-10-28 22:36:01 +01007};
8
Andy Green775c0dd2010-10-29 14:15:22 +01009struct libwebsocket;
Andy Greenff95d7a2010-10-28 22:36:01 +010010
Andy Green775c0dd2010-10-29 14:15:22 +010011extern int libwebsocket_create_server(int port,
12 int (*callback)(struct libwebsocket *,
Andy Green4ea60062010-10-30 12:15:07 +010013 enum libwebsocket_callback_reasons, void *, size_t));
Andy Greenff95d7a2010-10-28 22:36:01 +010014
Andy Green4ea60062010-10-30 12:15:07 +010015/*
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
39extern int libwebsocket_write(struct libwebsocket *, unsigned char *buf, size_t len, int is_binary);