[libsoup] websocket-connection: do not send new frames until the previous is not successfully sent



commit e7c827d5979ce6da64f8722254a315960bcf08c2
Author: Silvio Lazzeretti <silviola amazon com>
Date:   Wed Jan 24 11:23:34 2018 +0100

    websocket-connection: do not send new frames until the previous is not successfully sent
    
    If the sending of a frame fails with G_IO_ERROR_WOULD_BLOCK,
    we must send it again before sending more urgent ones.
    This change is relevant in case a SSL connection is being used
    because SSL expects the same message to be resent
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790436

 libsoup/soup-websocket-connection.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c
index 369c223..b93fab2 100644
--- a/libsoup/soup-websocket-connection.c
+++ b/libsoup/soup-websocket-connection.c
@@ -107,6 +107,7 @@ typedef struct {
        gsize sent;
        gsize amount;
        SoupWebsocketQueueFlags flags;
+       gboolean pending;
 } Frame;
 
 struct _SoupWebsocketConnectionPrivate {
@@ -971,6 +972,9 @@ on_web_socket_output (GObject *pollable_stream,
                if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
                        g_clear_error (&error);
                        count = 0;
+
+                       g_debug ("failed to send frame because it would block, marking as pending");
+                       frame->pending = TRUE;
                } else {
                        emit_error_and_close (self, error, TRUE);
                        return FALSE;
@@ -1034,12 +1038,12 @@ queue_frame (SoupWebsocketConnection *self,
        if (flags & SOUP_WEBSOCKET_QUEUE_URGENT) {
                GList *l;
 
-               /* Find out the first frame that is not urgent or partially sent */
+               /* Find out the first frame that is not urgent or partially sent or pending */
                for (l = g_queue_peek_head_link (&pv->outgoing); l != NULL; l = l->next) {
                        Frame *prev = l->data;
 
                        if (!(prev->flags & SOUP_WEBSOCKET_QUEUE_URGENT) &&
-                           prev->sent == 0)
+                           prev->sent == 0 && !prev->pending)
                                break;
                }
 


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