From: Oto Šťáva Date: Mon, 20 May 2024 16:22:19 +0000 (+0200) Subject: daemon/io: remove minor inefficiency X-Git-Tag: v6.0.8~14^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb92b181e5dd6455e98d4827857ce7967417ff98;p=thirdparty%2Fknot-resolver.git 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. --- 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); }