Skip to content

Commit

Permalink
Fix multi-part websocket sending. Note the changed flag constants!
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyPork committed Jan 24, 2017
1 parent cc6e7da commit 1a69994
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/cgiwebsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "httpd.h"

#define WEBSOCK_FLAG_NONE 0
#define WEBSOCK_FLAG_CONT (1<<0) //Set if the data is not the final data in the message; more follows
#define WEBSOCK_FLAG_MORE (1<<0) //Set if the data is not the final data in the message; more follows
#define WEBSOCK_FLAG_BIN (1<<1) //Set if the data is binary instead of text
#define WEBSOCK_FLAG_CONT (1<<2) // set if this is a continuation frame (after WEBSOCK_FLAG_CONT)



Expand Down
13 changes: 10 additions & 3 deletions util/cgiwebsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ static int ICACHE_FLASH_ATTR sendFrameHead(Websock *ws, int opcode, int len) {
int ICACHE_FLASH_ATTR cgiWebsocketSend(Websock *ws, char *data, int len, int flags) {
int r=0;
int fl=0;
if (flags&WEBSOCK_FLAG_BIN) fl=OPCODE_BINARY; else fl=OPCODE_TEXT;
if (!(flags&WEBSOCK_FLAG_CONT)) fl|=FLAG_FIN;
// Continuation frame has opcode 0
if (!(flags&WEBSOCK_FLAG_CONT)) {
if (flags & WEBSOCK_FLAG_BIN)
fl = OPCODE_BINARY;
else
fl = OPCODE_TEXT;
}
// add FIN to last frame
if (!(flags&WEBSOCK_FLAG_MORE)) fl|=FLAG_FIN;
sendFrameHead(ws, fl, len);
if (len!=0) r=httpdSend(ws->conn, data, len);
httpdFlushSendBuffer(ws->conn);
Expand Down Expand Up @@ -239,7 +246,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWebSocketRecv(HttpdConnData *connData, char
} else {
int flags=0;
if ((ws->priv->fr.flags&OPCODE_MASK)==OPCODE_BINARY) flags|=WEBSOCK_FLAG_BIN;
if ((ws->priv->fr.flags&FLAG_FIN)==0) flags|=WEBSOCK_FLAG_CONT;
if ((ws->priv->fr.flags&FLAG_FIN)==0) flags|=WEBSOCK_FLAG_MORE;
if (ws->recvCb) ws->recvCb(ws, data+i, sl, flags);
}
} else if ((ws->priv->fr.flags&OPCODE_MASK)==OPCODE_CLOSE) {
Expand Down

0 comments on commit 1a69994

Please sign in to comment.