From 8ab96ec74b2f4e080162628a164604dbc35a5ec5 Mon Sep 17 00:00:00 2001 From: Marko Mikulicic Date: Mon, 14 Sep 2015 12:58:08 +0100 Subject: [PATCH] Implement binary and incremental clubby client PUBLISHED_FROM=ba371b8a3d9dd8afcb771144beb8e5c344c7d6c7 --- mongoose.c | 2 +- mongoose.h | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 77a0b3d9..980904df 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3686,7 +3686,7 @@ static void mg_send_ws_header(struct mg_connection *nc, int op, size_t len, int header_len; unsigned char header[10]; - header[0] = 0x80 + (op & 0x0f); + header[0] = (op & WEBSOCKET_DONT_FIN ? 0x0 : 0x80) + (op & 0x0f); if (len < 126) { header[1] = len; header_len = 2; diff --git a/mongoose.h b/mongoose.h index b5707516..1a7777bf 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1307,7 +1307,7 @@ void mg_send_websocket_handshake(struct mg_connection *nc, const char *uri, /* * Send websocket frame to the remote end. * - * `op` specifies frame's type , one of: + * `op_and_flags` specifies frame's type, one of: * * - WEBSOCKET_OP_CONTINUE * - WEBSOCKET_OP_TEXT @@ -1315,17 +1315,22 @@ void mg_send_websocket_handshake(struct mg_connection *nc, const char *uri, * - WEBSOCKET_OP_CLOSE * - WEBSOCKET_OP_PING * - WEBSOCKET_OP_PONG + * + * Orred with one of the flags: + * + * - WEBSOCKET_DONT_FIN: Don't set the FIN flag on the frame to be sent. + * * `data` and `data_len` contain frame data. */ -void mg_send_websocket_frame(struct mg_connection *nc, int op, const void *data, - size_t data_len); +void mg_send_websocket_frame(struct mg_connection *nc, int op_and_flags, + const void *data, size_t data_len); /* * Send multiple websocket frames. * * Like `mg_send_websocket_frame()`, but composes a frame from multiple buffers. */ -void mg_send_websocket_framev(struct mg_connection *nc, int op, +void mg_send_websocket_framev(struct mg_connection *nc, int op_and_flags, const struct mg_str *strings, int num_strings); /* @@ -1334,7 +1339,7 @@ void mg_send_websocket_framev(struct mg_connection *nc, int op, * Like `mg_send_websocket_frame()`, but allows to create formatted message * with `printf()`-like semantics. */ -void mg_printf_websocket_frame(struct mg_connection *nc, int op, +void mg_printf_websocket_frame(struct mg_connection *nc, int op_and_flags, const char *fmt, ...); /* @@ -1376,6 +1381,20 @@ void mg_printf_html_escape(struct mg_connection *, const char *, ...); #define WEBSOCKET_OP_PING 9 #define WEBSOCKET_OP_PONG 10 +/* + * If set causes the FIN flag to not be set on outbound + * frames. This enables sending multiple fragments of a single + * logical message. + * + * The WebSocket protocol mandates that if the FIN flag of a data + * frame is not set, the next frame must be a WEBSOCKET_OP_CONTINUE. + * The last frame must have the FIN bit set. + * + * Note that mongoose will automatically defragment incoming messages, + * so this flag is used only on outbound messages. + */ +#define WEBSOCKET_DONT_FIN 0x100 + /* * Parse a HTTP message. *