From 4359536a175706f2288b2f769592c655a19b0918 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 9 Apr 2024 16:57:43 +0200 Subject: [PATCH] Allow to drop the first element of the send queue In case we're in disconnected state, allow the user to drop the first element of the send queue, even if it was already in progress to be written. Before this patch, the first element could not be retrieved at all, even after a disconnect. Signed-off-by: Steffen Jaeckel --- src/conn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/conn.c b/src/conn.c index 5abc23a..73a2737 100644 --- a/src/conn.c +++ b/src/conn.c @@ -1435,6 +1435,7 @@ char *xmpp_conn_send_queue_drop_element(xmpp_conn_t *conn, xmpp_queue_element_t which) { xmpp_send_queue_t *t; + int disconnected = conn->state == XMPP_STATE_DISCONNECTED; /* Fast return paths */ /* empty queue */ @@ -1443,7 +1444,7 @@ char *xmpp_conn_send_queue_drop_element(xmpp_conn_t *conn, /* one element in queue */ if (conn->send_queue_head == conn->send_queue_tail) { /* head is already sent out partially */ - if (conn->send_queue_head->wip) + if (conn->send_queue_head->wip && !disconnected) return NULL; /* the element is no USER element */ if (conn->send_queue_head->owner != XMPP_QUEUE_USER) @@ -1467,7 +1468,7 @@ char *xmpp_conn_send_queue_drop_element(xmpp_conn_t *conn, return NULL; /* head is already sent out partially */ - if (t == conn->send_queue_head && t->wip) + if (t == conn->send_queue_head && t->wip && !disconnected) t = t->next; /* search forward to find the first USER element */