2010-10-31 12:42:52 +00:00
|
|
|
#ifndef __LIBWEBSOCKET_H__
|
|
|
|
#define __LIBWEBSOCKET_H__
|
|
|
|
|
2010-10-28 22:36:01 +01:00
|
|
|
|
2010-10-29 14:15:22 +01:00
|
|
|
enum libwebsocket_callback_reasons {
|
|
|
|
LWS_CALLBACK_ESTABLISHED,
|
|
|
|
LWS_CALLBACK_CLOSED,
|
|
|
|
LWS_CALLBACK_SEND,
|
|
|
|
LWS_CALLBACK_RECEIVE,
|
2010-10-31 11:57:17 +00:00
|
|
|
LWS_CALLBACK_HTTP
|
|
|
|
};
|
|
|
|
|
|
|
|
enum libwebsocket_write_protocol {
|
|
|
|
LWS_WRITE_TEXT,
|
|
|
|
LWS_WRITE_BINARY,
|
|
|
|
LWS_WRITE_HTTP
|
2010-10-28 22:36:01 +01:00
|
|
|
};
|
|
|
|
|
2010-10-29 14:15:22 +01:00
|
|
|
struct libwebsocket;
|
2010-10-28 22:36:01 +01:00
|
|
|
|
2010-10-29 14:15:22 +01:00
|
|
|
extern int libwebsocket_create_server(int port,
|
2010-10-31 13:11:57 +00:00
|
|
|
int (*callback)(struct libwebsocket *wsi,
|
|
|
|
enum libwebsocket_callback_reasons reason,
|
2010-11-03 11:13:06 +00:00
|
|
|
void *user, void *in, size_t len),
|
2010-11-08 17:03:03 +00:00
|
|
|
int protocol, size_t user_space,
|
|
|
|
const char * ssl_cert_filepath,
|
|
|
|
const char * ssl_private_key_filepath,
|
|
|
|
int gid, int uid);
|
2010-10-28 22:36:01 +01:00
|
|
|
|
2010-10-30 12:15:07 +01:00
|
|
|
/*
|
|
|
|
* IMPORTANT NOTICE!
|
|
|
|
*
|
2010-10-31 11:57:17 +00:00
|
|
|
* When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY)
|
|
|
|
* the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE
|
2010-10-30 12:15:07 +01:00
|
|
|
* buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len).
|
|
|
|
*
|
|
|
|
* This allows us to add protocol info before and after the data, and send as
|
|
|
|
* one packet on the network without payload copying, for maximum efficiency.
|
|
|
|
*
|
|
|
|
* So for example you need this kind of code to use libwebsocket_write with a
|
|
|
|
* 128-byte payload
|
|
|
|
*
|
2010-10-31 12:42:52 +00:00
|
|
|
* char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING];
|
2010-10-30 12:15:07 +01:00
|
|
|
*
|
2010-10-31 12:42:52 +00:00
|
|
|
* // fill your part of the buffer... for example here it's all zeros
|
|
|
|
* memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128);
|
2010-10-30 12:15:07 +01:00
|
|
|
*
|
2010-10-31 12:42:52 +00:00
|
|
|
* libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128);
|
2010-10-30 12:15:07 +01:00
|
|
|
*
|
2010-10-31 11:57:17 +00:00
|
|
|
* When sending LWS_WRITE_HTTP, there is no protocol addition and you can just
|
|
|
|
* use the whole buffer without taking care of the above.
|
2010-10-30 12:15:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define LWS_SEND_BUFFER_PRE_PADDING 12
|
|
|
|
#define LWS_SEND_BUFFER_POST_PADDING 1
|
|
|
|
|
2010-10-31 11:57:17 +00:00
|
|
|
extern int
|
|
|
|
libwebsocket_write(struct libwebsocket *, unsigned char *buf, size_t len,
|
|
|
|
enum libwebsocket_write_protocol protocol);
|
|
|
|
extern const char *
|
|
|
|
libwebsocket_get_uri(struct libwebsocket *wsi);
|
2010-10-31 12:42:52 +00:00
|
|
|
|
2010-10-31 11:57:17 +00:00
|
|
|
extern int
|
|
|
|
libwebsockets_serve_http_file(struct libwebsocket *wsi, const char * file,
|
|
|
|
const char * content_type);
|
2010-10-31 12:42:52 +00:00
|
|
|
|
|
|
|
#endif
|