| ... | ... | @@ -1,18 +1,13 @@ |
| 1 | 1 | stream: std.net.Stream, |
| 2 | | protocol: Protocol, |
| 3 | 2 | |
| 4 | 3 | read_buf: [buffer_size]u8, |
| 5 | 4 | read_start: u16, |
| 6 | 5 | read_end: u16, |
| 7 | 6 | |
| 8 | 7 | pub const buffer_size = std.crypto.tls.max_ciphertext_record_len; |
| 9 | | pub const Protocol = enum { plain }; |
| 10 | 8 | |
| 11 | 9 | pub fn rawReadAtLeast(conn: *Connection, buffer: []u8, len: usize) ReadError!usize { |
| 12 | | return switch (conn.protocol) { |
| 13 | | .plain => conn.stream.readAtLeast(buffer, len), |
| 14 | | // .tls => conn.tls_client.readAtLeast(conn.stream, buffer, len), |
| 15 | | } catch |err| { |
| 10 | return conn.stream.readAtLeast(buffer, len) catch |err| { |
| 16 | 11 | switch (err) { |
| 17 | 12 | error.ConnectionResetByPeer, error.BrokenPipe => return error.ConnectionResetByPeer, |
| 18 | 13 | else => return error.UnexpectedReadFailure, |
| ... | ... | @@ -91,20 +86,14 @@ pub fn reader(conn: *Connection) Reader { |
| 91 | 86 | } |
| 92 | 87 | |
| 93 | 88 | pub fn writeAll(conn: *Connection, buffer: []const u8) WriteError!void { |
| 94 | | return switch (conn.protocol) { |
| 95 | | .plain => conn.stream.writeAll(buffer), |
| 96 | | // .tls => return conn.tls_client.writeAll(conn.stream, buffer), |
| 97 | | } catch |err| switch (err) { |
| 89 | return conn.stream.writeAll(buffer) catch |err| switch (err) { |
| 98 | 90 | error.BrokenPipe, error.ConnectionResetByPeer => return error.ConnectionResetByPeer, |
| 99 | 91 | else => return error.UnexpectedWriteFailure, |
| 100 | 92 | }; |
| 101 | 93 | } |
| 102 | 94 | |
| 103 | 95 | pub fn write(conn: *Connection, buffer: []const u8) WriteError!usize { |
| 104 | | return switch (conn.protocol) { |
| 105 | | .plain => conn.stream.write(buffer), |
| 106 | | // .tls => return conn.tls_client.write(conn.stream, buffer), |
| 107 | | } catch |err| switch (err) { |
| 96 | return conn.stream.write(buffer) catch |err| switch (err) { |
| 108 | 97 | error.BrokenPipe, error.ConnectionResetByPeer => return error.ConnectionResetByPeer, |
| 109 | 98 | else => return error.UnexpectedWriteFailure, |
| 110 | 99 | }; |