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)...@@ -923,20 +923,22 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
923 if (partial_cleartext.len > 0) {923 if (partial_cleartext.len > 0) {
924 const amt = @intCast(u15, vp.put(partial_cleartext));924 const amt = @intCast(u15, vp.put(partial_cleartext));
925 c.partial_cleartext_idx += amt;925 c.partial_cleartext_idx += amt;
926 if (amt < partial_cleartext.len) {926
927 // We still have cleartext left so we cannot issue another read() call yet.927 if (c.partial_ciphertext_end == c.partial_ciphertext_idx) {
928 assert(vp.total == amt);928 // The buffer is now empty.
929 return amt;929 c.partial_cleartext_idx = 0;
930 c.partial_ciphertext_idx = 0;
931 c.partial_ciphertext_end = 0;
930 }932 }
933
931 if (c.received_close_notify) {934 if (c.received_close_notify) {
932 c.partial_ciphertext_end = 0;935 c.partial_ciphertext_end = 0;
933 assert(vp.total == amt);936 assert(vp.total == amt);
934 return amt;937 return amt;
935 }938 } else if (amt <= partial_cleartext.len) {
936 if (c.partial_ciphertext_end == c.partial_ciphertext_idx) {939 // We don't need more data, so don't call read.
937 c.partial_cleartext_idx = 0;940 assert(vp.total == amt);
938 c.partial_ciphertext_idx = 0;941 return amt;
939 c.partial_ciphertext_end = 0;
940 }942 }
941 }943 }
942944