From eb92b181e5dd6455e98d4827857ce7967417ff98 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Oto=20=C5=A0=C5=A5=C3=A1va?= Date: Mon, 20 May 2024 18:22:19 +0200 Subject: [PATCH] daemon/io: remove minor inefficiency The resolver would try to move the bytes in the wire buffer over even if the incoming data would not fit anyway. This should prevent that. --- daemon/io.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/daemon/io.c b/daemon/io.c index 5ed2ef78a..3adb0deca 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -269,12 +269,10 @@ static enum protolayer_iter_cb_result pl_tcp_unwrap( return protolayer_break(ctx, ret); } - /* Try to make space */ - while (len > wire_buf_free_space_length(&tcp->wire_buf)) { - if (wire_buf_data_length(&tcp->wire_buf) > 0 || - tcp->wire_buf.start == 0) + /* Check if space can be made */ + if (len > wire_buf_free_space_length(&tcp->wire_buf)) { + if (len > tcp->wire_buf.size - wire_buf_data_length(&tcp->wire_buf)) return protolayer_break(ctx, kr_error(EMSGSIZE)); - wire_buf_movestart(&tcp->wire_buf); } -- 2.47.3