authorgravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-04-04 14:21:49-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-08 03:37:05-04:00
logfde05b10b3c29b914e4d2ef034dcd8a78800ef6e
tree21d746228b487dc2273f6a6d4754450b27f47e72
parent55a8b7e1fa4d36f5283d1f8655d3baecfefeffa3

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


1 files changed, 11 insertions(+), 9 deletions(-)

lib/std/crypto/tls/Client.zig+11-9
......@@ -923,20 +923,22 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
923923 if (partial_cleartext.len > 0) {
924924 const amt = @intCast(u15, vp.put(partial_cleartext));
925925 c.partial_cleartext_idx += amt;
926 if (amt < partial_cleartext.len) {
927 // We still have cleartext left so we cannot issue another read() call yet.
928 assert(vp.total == amt);
929 return amt;
926
927 if (c.partial_ciphertext_end == c.partial_ciphertext_idx) {
928 // The buffer is now empty.
929 c.partial_cleartext_idx = 0;
930 c.partial_ciphertext_idx = 0;
931 c.partial_ciphertext_end = 0;
930932 }
933
931934 if (c.received_close_notify) {
932935 c.partial_ciphertext_end = 0;
933936 assert(vp.total == amt);
934937 return amt;
935 }
936 if (c.partial_ciphertext_end == c.partial_ciphertext_idx) {
937 c.partial_cleartext_idx = 0;
938 c.partial_ciphertext_idx = 0;
939 c.partial_ciphertext_end = 0;
938 } else if (amt <= partial_cleartext.len) {
939 // We don't need more data, so don't call read.
940 assert(vp.total == amt);
941 return amt;
940942 }
941943 }
942944