[libsoup] websocket-connection: avoid sending data if we are closing the connection



commit 3212d89097fdaa1b72be82a671d6c982d79edeea
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.
    
    Change the code to be more robust and to not try to write in the socket
    if we are in the closed state.
    
    This fixes an assertion on the test 3.2 of autobahn:
    See https://github.com/crossbario/autobahn-testsuite
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774957

 libsoup/soup-websocket-connection.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c
index 66742a1..eff6ba6 100644
--- a/libsoup/soup-websocket-connection.c
+++ b/libsoup/soup-websocket-connection.c
@@ -348,6 +348,11 @@ send_message (SoupWebsocketConnection *self,
        guint8 *mask = 0;
        guint8 *at;
 
+       if (!(soup_websocket_connection_get_state (self) == SOUP_WEBSOCKET_STATE_OPEN)) {
+               g_debug ("Ignoring message since the connection is closed or is closing");
+               return;
+       }
+
        bytes = g_byte_array_sized_new (14 + length);
        outer = bytes->data;
        outer[0] = 0x80 | opcode;
@@ -851,6 +856,12 @@ on_web_socket_output (GObject *pollable_stream,
        gssize count;
        gsize len;
 
+       if (soup_websocket_connection_get_state (self) == SOUP_WEBSOCKET_STATE_CLOSED) {
+               g_debug ("Ignoring message since the connection is closed");
+               stop_output (self);
+               return TRUE;
+       }
+
        frame = g_queue_peek_head (&pv->outgoing);
 
        /* No more frames to send */


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