mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-05 21:18:32 +08:00
Fixed mg_websocket_read()
This commit is contained in:
parent
9cca843a9b
commit
1a64d37fc7
@ -28,9 +28,11 @@ static int event_handler(struct mg_event *event) {
|
||||
while ((len = mg_websocket_read(event->conn, &bits, &data)) > 0) {
|
||||
// Echo message back to the client
|
||||
mg_websocket_write(event->conn, WEBSOCKET_OPCODE_TEXT, data, len);
|
||||
printf("got message: [%.*s]\n", len, data);
|
||||
if (memcmp(data, "exit", 4) == 0) {
|
||||
mg_websocket_write(event->conn,
|
||||
WEBSOCKET_OPCODE_CONNECTION_CLOSE, "", 0);
|
||||
free(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
stop = 1;
|
||||
}
|
||||
|
||||
// Not breaking the loop, process next websocket frame.
|
||||
return data_len;
|
||||
} else {
|
||||
// Buffering websocket request
|
||||
if ((n = pull(NULL, conn, conn->buf + conn->data_len,
|
||||
|
Loading…
Reference in New Issue
Block a user