Commit 1a64d37f authored by Sergey Lyubka's avatar Sergey Lyubka

Fixed mg_websocket_read()

parent 9cca843a
...@@ -28,9 +28,11 @@ static int event_handler(struct mg_event *event) { ...@@ -28,9 +28,11 @@ static int event_handler(struct mg_event *event) {
while ((len = mg_websocket_read(event->conn, &bits, &data)) > 0) { while ((len = mg_websocket_read(event->conn, &bits, &data)) > 0) {
// Echo message back to the client // Echo message back to the client
mg_websocket_write(event->conn, WEBSOCKET_OPCODE_TEXT, data, len); mg_websocket_write(event->conn, WEBSOCKET_OPCODE_TEXT, data, len);
printf("got message: [%.*s]\n", len, data);
if (memcmp(data, "exit", 4) == 0) { if (memcmp(data, "exit", 4) == 0) {
mg_websocket_write(event->conn, mg_websocket_write(event->conn,
WEBSOCKET_OPCODE_CONNECTION_CLOSE, "", 0); WEBSOCKET_OPCODE_CONNECTION_CLOSE, "", 0);
free(data);
break; break;
} }
} }
......
...@@ -4090,14 +4090,7 @@ int mg_websocket_read(struct mg_connection *conn, int *bits, char **data) { ...@@ -4090,14 +4090,7 @@ int mg_websocket_read(struct mg_connection *conn, int *bits, char **data) {
} }
} }
// Exit the loop if callback signalled to exit,
// or "connection close" opcode received.
if ((*bits & 0x0f) == WEBSOCKET_OPCODE_CONNECTION_CLOSE) {
return data_len; return data_len;
stop = 1;
}
// Not breaking the loop, process next websocket frame.
} else { } else {
// Buffering websocket request // Buffering websocket request
if ((n = pull(NULL, conn, conn->buf + conn->data_len, if ((n = pull(NULL, conn, conn->buf + conn->data_len,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment