drain
Function parameters
Parameters
- w:*Writer
- data:[]const []const u8
- splat:usize
Type definitions in this namespace
Types
Initiates a TLS handshake and establishes a TLSv1.2 or TLSv1.3 session.
Functions
Error sets in this namespace
Error Sets
The `Reader` supplied to `init` requires a buffer capacity
Values
- min_buffer_len
- The `Reader` supplied to `init` requires a buffer capacity
Source
Implementation
fn drain(w: *Writer, data: []const []const u8, splat: usize) Writer.Error!usize {
const c: *Client = @alignCast(@fieldParentPtr("writer", w));
const output = c.output;
const ciphertext_buf = try output.writableSliceGreedy(min_buffer_len);
var ciphertext_end: usize = 0;
var total_clear: usize = 0;
done: {
{
const buf = w.buffered();
const prepared = prepareCiphertextRecord(c, ciphertext_buf[ciphertext_end..], buf, .application_data);
total_clear += prepared.cleartext_len;
ciphertext_end += prepared.ciphertext_end;
if (prepared.cleartext_len < buf.len) break :done;
}
for (data[0 .. data.len - 1]) |buf| {
const prepared = prepareCiphertextRecord(c, ciphertext_buf[ciphertext_end..], buf, .application_data);
total_clear += prepared.cleartext_len;
ciphertext_end += prepared.ciphertext_end;
if (prepared.cleartext_len < buf.len) break :done;
}
const buf = data[data.len - 1];
for (0..splat) |_| {
const prepared = prepareCiphertextRecord(c, ciphertext_buf[ciphertext_end..], buf, .application_data);
total_clear += prepared.cleartext_len;
ciphertext_end += prepared.ciphertext_end;
if (prepared.cleartext_len < buf.len) break :done;
}
}
output.advance(ciphertext_end);
return w.consume(total_clear);
}