Skip to content

Commit a664129

Browse files
truemedianandrewrk
authored andcommitted
tls.Client: don't read if we don't need more data
1 parent 4ebf483 commit a664129

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/std/crypto/tls/Client.zig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)