From 57b0cdf152b7266e68bfa3e84635d4bdb64ef2cd Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 9 Oct 2017 15:34:06 +0100 Subject: io: simplify websocket ping reply handling We must ensure we don't get flooded with ping replies if the outbound channel is slow. Currently we do this by keeping the ping reply in a separate temporary buffer and only writing it if the encoutput buffer is completely empty. This is overly pessimistic, as it is reasonable to add a ping reply to the encoutput buffer even if it has previous data in it, as long as that previous data doesn't include a ping reply. To track this better, put the ping reply directly into the encoutput buffer, and then record the size of encoutput at this time in pong_remain. As we write encoutput to the underlying channel, we can decrement the pong_remain counter. Once it hits zero, we can accept further ping replies for transmission. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- include/io/channel-websock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/io/channel-websock.h b/include/io/channel-websock.h index ff32d86..3762707 100644 --- a/include/io/channel-websock.h +++ b/include/io/channel-websock.h @@ -60,8 +60,8 @@ struct QIOChannelWebsock { Buffer encoutput; Buffer rawinput; Buffer rawoutput; - Buffer ping_reply; size_t payload_remain; + size_t pong_remain; QIOChannelWebsockMask mask; guint io_tag; Error *io_err; -- cgit v1.1 From 8dfd5f96515ca20c4eb109cb0ee28e2bb32fc505 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 9 Oct 2017 16:54:07 +0100 Subject: io: get rid of bounce buffering in websock write path Currently most outbound I/O on the websock channel gets copied into the rawoutput buffer, and then immediately copied again into the encoutput buffer, with a header prepended. Now that qio_channel_websock_encode accepts a struct iovec, we can trivially remove this bounce buffering and write directly to encoutput. In doing so, we also now correctly validate the encoutput size against the QIO_CHANNEL_WEBSOCK_MAX_BUFFER limit. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- include/io/channel-websock.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/io/channel-websock.h b/include/io/channel-websock.h index 3762707..a7e5e92 100644 --- a/include/io/channel-websock.h +++ b/include/io/channel-websock.h @@ -59,7 +59,6 @@ struct QIOChannelWebsock { Buffer encinput; Buffer encoutput; Buffer rawinput; - Buffer rawoutput; size_t payload_remain; size_t pong_remain; QIOChannelWebsockMask mask; -- cgit v1.1