zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fde05b10b3c29b914e4d2ef034dcd8a78800ef6e (tree)
parent 55a8b7e1fa4d36f5283d1f8655d3baecfefeffa3
Author: Nameless <truemedian@gmail.com>
Date:   Tue,  4 Apr 2023 14:21:49 -0500

tls.Client: don't read if we don't need more data

Diffstat:
Mlib/std/crypto/tls/Client.zig | 20+++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig @@ -923,20 +923,22 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) if (partial_cleartext.len > 0) { const amt = @intCast(u15, vp.put(partial_cleartext)); c.partial_cleartext_idx += amt; - if (amt < partial_cleartext.len) { - // We still have cleartext left so we cannot issue another read() call yet. - assert(vp.total == amt); - return amt; + + if (c.partial_ciphertext_end == c.partial_ciphertext_idx) { + // The buffer is now empty. + c.partial_cleartext_idx = 0; + c.partial_ciphertext_idx = 0; + c.partial_ciphertext_end = 0; } + if (c.received_close_notify) { c.partial_ciphertext_end = 0; assert(vp.total == amt); return amt; - } - if (c.partial_ciphertext_end == c.partial_ciphertext_idx) { - c.partial_cleartext_idx = 0; - c.partial_ciphertext_idx = 0; - c.partial_ciphertext_end = 0; + } else if (amt <= partial_cleartext.len) { + // We don't need more data, so don't call read. + assert(vp.total == amt); + return amt; } }