-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22b7820
commit a47321b
Showing
6 changed files
with
107 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
const std = @import("std"); | ||
|
||
// TODO: why isn't this working? | ||
//const stdext = @import("stdext"); | ||
const stdext= @import("../src-stdext/stdext.zig"); | ||
const readwrite = stdext.readwrite; | ||
const ReaderWriter = readwrite.ReaderWriter; | ||
|
||
pub fn init() anyerror!void { | ||
std.debug.warn("[DEBUG] nossl init\n", .{}); | ||
} | ||
|
||
pub const SslConn = struct { | ||
rw: ReaderWriter, | ||
pub fn init(file: std.fs.File, serverName: []const u8) !SslConn { | ||
return error.NoSslConfigured; | ||
} | ||
pub fn deinit(self: SslConn) void { } | ||
pub fn read(self: SslConn, data: []u8) !usize { | ||
@panic("nossl has been configured"); | ||
} | ||
pub fn write(self: SslConn, data: []const u8) !usize { | ||
@panic("nossl has been configured"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const std = @import("std"); | ||
const ssl = @import("ssl"); | ||
|
||
pub const NetStream = union(enum) { | ||
File: *const std.fs.File, | ||
Ssl: *ssl.SslConn, | ||
|
||
pub const Reader = std.io.Reader(*@This(), FnErrorSet(@TypeOf(read)), read); | ||
pub const Writer = std.io.Writer(*@This(), FnErrorSet(@TypeOf(write)), write); | ||
|
||
pub fn initFile(file: *const std.fs.File) NetStream { | ||
return .{ .File = file }; | ||
} | ||
pub fn initSsl(conn: *ssl.SslConn) NetStream { | ||
return .{ .Ssl = conn }; | ||
} | ||
|
||
pub fn reader(self: *@This()) Reader { | ||
return .{ .context = self }; | ||
} | ||
|
||
pub fn writer(self: *@This()) Writer { | ||
return .{ .context = self }; | ||
} | ||
|
||
pub fn read(self: *@This(), dest: []u8) !usize { | ||
switch (self.*) { | ||
.File => |s| return s.read(dest), | ||
.Ssl => |s| return s.read(dest), | ||
} | ||
} | ||
|
||
pub fn write(self: *@This(), bytes: []const u8) !usize { | ||
switch (self.*) { | ||
.File => |s| return try s.write(bytes), | ||
.Ssl => |s| return try s.write(bytes), | ||
} | ||
} | ||
}; | ||
|
||
/// TODO: move this | ||
/// Returns the error set for the given function type | ||
fn FnErrorSet(comptime FnType: type) type { | ||
const Return = @typeInfo(FnType).Fn.return_type.?; | ||
return @typeInfo(Return).ErrorUnion.error_set; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters