--- a/src/server/public/nsapi.h Sun Oct 30 11:44:04 2016 +0100 +++ b/src/server/public/nsapi.h Mon Dec 26 14:00:10 2016 +0100 @@ -1110,6 +1110,48 @@ typedef struct _threadpool_job threadpool_job; typedef void*(*job_callback_f)(void *data); + +typedef struct WebSocket WebSocket; +typedef struct WSMessage WSMessage; + +struct WebSocket { + int (*on_open)(WebSocket *); + int (*on_error)(WebSocket *); + int (*on_message)(WebSocket *, WSMessage *msg); + int (*on_close)(WebSocket *); + void *userdata; +}; + +struct WSMessage { + /* + * message data (text or binary) + */ + char *data; + + /* + * data length + */ + size_t length; + + /* + * message type (opcode) + * 0x0: continuation + * 0x1: text + * 0x2: binary + * 0x3-7: reserved non-control frame + * 0x8: close + * 0x9: ping + * 0xa: pong + * 0xb-f: reserved control frame + */ + int type; + + /* + * if the message is incomplete, next points to the continuation message + */ + WSMessage *next; +}; + /* --- End type definitions --- */ /* --- Begin dispatch vector table definition --- */ @@ -1394,6 +1436,15 @@ NSAPI_PUBLIC char **http_hdrs2env(pblock *pb); +// new websocket API begin + +NSAPI_PUBLIC int http_handle_websocket(Session *sn, Request *rq, WebSocket *websocket); + +NSAPI_PUBLIC int websocket_send_text(SYS_NETFD csd, char *msg, size_t len); + +// websocket API end + + typedef void (*thrstartfunc)(void *); SYS_THREAD INTsysthread_start(int prio, int stksz, thrstartfunc fn, void *arg); NSAPI_PUBLIC void INTsysthread_sleep(int milliseconds);