[libsoup/wip/websocket-close-bug] websocket-connection: avoid sending data if we are closing the connection



commit 0f74a5fc0b808b3128ed5c771bec09075da4742c
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date:   Wed Nov 23 15:36:41 2016 +0100

    websocket-connection: avoid sending data if we are closing the connection
    
    We cannot trust the client to be nice and stop sending data when
    we are closing. If we receive a ping when closing the connection
    we need to avoid trying to send data after that.

 libsoup/soup-websocket-connection.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c
index 66742a1..099af2c 100644
--- a/libsoup/soup-websocket-connection.c
+++ b/libsoup/soup-websocket-connection.c
@@ -348,6 +348,12 @@ send_message (SoupWebsocketConnection *self,
        guint8 *mask = 0;
        guint8 *at;
 
+       if (soup_websocket_connection_get_state (self) == SOUP_WEBSOCKET_STATE_CLOSING ||
+           soup_websocket_connection_get_state (self) == SOUP_WEBSOCKET_STATE_CLOSED) {
+               g_warning ("Tried to send data when the connection is closed");
+               return;
+       }
+
        bytes = g_byte_array_sized_new (14 + length);
        outer = bytes->data;
        outer[0] = 0x80 | opcode;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]