commit 8b26ecdf140c13b804dbfa1bb3a98b7be01e8cf5
parent d5a32c2dabfa764631c54b9b891c14a3e5cd4b70
Author: Joris Vink <joris@coders.se>
Date: Mon, 30 Jan 2017 22:21:57 +0100
more websocket improvements.
- send a CLOSE opcode if we haven't yet when removing a ws client.
- ignore unsolicited PONG.
Diffstat:
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -143,6 +143,7 @@ TAILQ_HEAD(netbuf_head, netbuf);
#define CONN_IDLE_TIMER_ACT 0x10
#define CONN_READ_BLOCK 0x20
#define CONN_CLOSE_EMPTY 0x40
+#define CONN_WS_CLOSE_SENT 0x80
#define KORE_IDLE_TIMER_MAX 20000
diff --git a/src/websocket.c b/src/websocket.c
@@ -144,6 +144,8 @@ kore_websocket_send(struct connection *c, u_int8_t op, const void *data,
websocket_frame_build(frame, op, data, len);
net_send_queue(c, frame->data, frame->offset);
kore_buf_free(frame);
+
+ net_send_flush(c);
}
void
@@ -315,8 +317,9 @@ websocket_recv_frame(struct netbuf *nb)
ret = KORE_RESULT_OK;
switch (op) {
- case WEBSOCKET_OP_CONT:
case WEBSOCKET_OP_PONG:
+ break;
+ case WEBSOCKET_OP_CONT:
ret = KORE_RESULT_ERROR;
kore_log(LOG_ERR, "%p: we do not support op 0x%02x yet", c, op);
break;
@@ -328,7 +331,10 @@ websocket_recv_frame(struct netbuf *nb)
}
break;
case WEBSOCKET_OP_CLOSE:
- kore_websocket_send(c, WEBSOCKET_OP_CLOSE, NULL, 0);
+ if (!(c->flags & CONN_WS_CLOSE_SENT)) {
+ c->flags |= CONN_WS_CLOSE_SENT;
+ kore_websocket_send(c, WEBSOCKET_OP_CLOSE, NULL, 0);
+ }
kore_connection_disconnect(c);
break;
case WEBSOCKET_OP_PING:
@@ -347,6 +353,11 @@ websocket_recv_frame(struct netbuf *nb)
static void
websocket_disconnect(struct connection *c)
{
+ if (!(c->flags & CONN_WS_CLOSE_SENT)) {
+ c->flags |= CONN_WS_CLOSE_SENT;
+ kore_websocket_send(c, WEBSOCKET_OP_CLOSE, NULL, 0);
+ }
+
if (c->ws_disconnect != NULL)
kore_runtime_wsdisconnect(c->ws_disconnect, c);
}