Better handling of websocket frames

pull/69/head
Lauri Kasanen 4 years ago
parent 4f25657d4a
commit 3dca11e031

@ -44,11 +44,11 @@ static void do_proxy(ws_ctx_t *ws_ctx, int target) {
int maxfd, client = ws_ctx->sockfd; int maxfd, client = ws_ctx->sockfd;
unsigned int opcode, left, ret; unsigned int opcode, left, ret;
unsigned int tout_start, tout_end, cout_start, cout_end; unsigned int tout_start, tout_end, cout_start, cout_end;
unsigned int tin_start, tin_end; unsigned int tin_end;
ssize_t len, bytes; ssize_t len, bytes;
tout_start = tout_end = cout_start = cout_end = tout_start = tout_end = cout_start = cout_end =
tin_start = tin_end = 0; tin_end = 0;
maxfd = client > target ? client+1 : target+1; maxfd = client > target ? client+1 : target+1;
while (1) { while (1) {
@ -165,7 +165,7 @@ static void do_proxy(ws_ctx_t *ws_ctx, int target) {
} }
if (FD_ISSET(client, &rlist)) { if (FD_ISSET(client, &rlist)) {
bytes = ws_recv(ws_ctx, ws_ctx->tin_buf + tin_end, BUFSIZE-1); bytes = ws_recv(ws_ctx, ws_ctx->tin_buf + tin_end, BUFSIZE-1-tin_end);
if (pipe_error) { break; } if (pipe_error) { break; }
if (bytes <= 0) { if (bytes <= 0) {
handler_emsg("client closed connection\n"); handler_emsg("client closed connection\n");
@ -180,13 +180,13 @@ static void do_proxy(ws_ctx_t *ws_ctx, int target) {
printf("\n"); printf("\n");
*/ */
if (ws_ctx->hybi) { if (ws_ctx->hybi) {
len = decode_hybi(ws_ctx->tin_buf + tin_start, len = decode_hybi(ws_ctx->tin_buf,
tin_end-tin_start, tin_end,
ws_ctx->tout_buf, BUFSIZE-1, ws_ctx->tout_buf, BUFSIZE-1,
&opcode, &left); &opcode, &left);
} else { } else {
len = decode_hixie(ws_ctx->tin_buf + tin_start, len = decode_hixie(ws_ctx->tin_buf,
tin_end-tin_start, tin_end,
ws_ctx->tout_buf, BUFSIZE-1, ws_ctx->tout_buf, BUFSIZE-1,
&opcode, &left); &opcode, &left);
} }
@ -208,10 +208,13 @@ static void do_proxy(ws_ctx_t *ws_ctx, int target) {
break; break;
} }
if (left) { if (left) {
tin_start = tin_end - left; const unsigned tin_start = tin_end - left;
//printf("partial frame from client"); //handler_emsg("partial frame from client, %u left, start %u end %u, lens %lu %lu\n",
// left, tin_start, tin_end, bytes, len);
memmove(ws_ctx->tin_buf, ws_ctx->tin_buf + tin_start, left);
tin_end = left;
} else { } else {
tin_start = 0; //handler_emsg("handled %lu/%lu bytes\n", bytes, len);
tin_end = 0; tin_end = 0;
} }

Loading…
Cancel
Save