diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-12-29 15:45:51 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-01-02 16:57:16 -0700 |
| commit | e4a9b19a1490d5c41a4d8c10f47ba5639de48404 (patch) | |
| tree | 0ed259b5e272adab65c2f81dfa4c384ebe259096 /lib/std/net.zig | |
| parent | 7391df2be5143db8308ab7c5281842aea99cb1d7 (diff) | |
| download | zig-e4a9b19a1490d5c41a4d8c10f47ba5639de48404.tar.gz zig-e4a9b19a1490d5c41a4d8c10f47ba5639de48404.zip | |
std.crypto.tls.Client: rework the read function
Here's what I landed on for the TLS client. It's 16896 bytes
(max_ciphertext_record_len is 16640). I believe this is the theoretical
minimum size, give or take a few bytes.
These constraints are satisfied:
* a call to the readvAdvanced() function makes at most one call to the
underlying readv function
* iovecs are provided by the API, and used by the implementation for
underlying readv() calls to the socket
* the theoretical minimum number of memcpy() calls are issued in all
circumstances
* decryption is only performed once for any given TLS record
* large read buffers are fully exploited
This is accomplished by using the partial read buffer to storing both
cleartext and ciphertext.
Diffstat (limited to 'lib/std/net.zig')
| -rw-r--r-- | lib/std/net.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/std/net.zig b/lib/std/net.zig index 0112d5be8c..aa51176184 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -1672,6 +1672,17 @@ pub const Stream = struct { } } + pub fn readv(s: Stream, iovecs: []const os.iovec) ReadError!usize { + if (builtin.os.tag == .windows) { + // TODO improve this to use ReadFileScatter + if (iovecs.len == 0) return @as(usize, 0); + const first = iovecs[0]; + return os.windows.ReadFile(s.handle, first.iov_base[0..first.iov_len], null, io.default_mode); + } + + return os.readv(s.handle, iovecs); + } + /// Returns the number of bytes read. If the number read is smaller than /// `buffer.len`, it means the stream reached the end. Reaching the end of /// a stream is not an error condition. |
