]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/io: remove minor inefficiency
authorOto Šťáva <oto.stava@nic.cz>
Mon, 20 May 2024 16:22:19 +0000 (18:22 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Tue, 4 Jun 2024 11:04:59 +0000 (13:04 +0200)
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

index 5ed2ef78a064f026a37aab80b544b076ab8aee20..3adb0deca250dd7f0c196b4fd417c2817ea75362 100644 (file)
@@ -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);
                }