aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-23 23:11:06 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-23 23:11:06 -0800
commitb5cec4b70491984b2efb86a529a0fea6b112660f (patch)
tree8add809792cbf0c1d872fa81e47b357d2b844fc3
parente895605e5fda235991cd2d938e17a9b92db4b477 (diff)
downloadbun-b5cec4b70491984b2efb86a529a0fea6b112660f.tar.gz
bun-b5cec4b70491984b2efb86a529a0fea6b112660f.tar.zst
bun-b5cec4b70491984b2efb86a529a0fea6b112660f.zip
[linux][http] return errno instead of unexpected
-rw-r--r--src/io/io_linux.zig33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig
index 5fab4f90e..50ff12358 100644
--- a/src/io/io_linux.zig
+++ b/src/io/io_linux.zig
@@ -1300,8 +1300,37 @@ pub fn write(
self.enqueue(completion);
}
+const SocketError = error{
+ AddressFamilyNotSupported,
+ ProtocolFamilyNotAvailable,
+ ProcessFdQuotaExceeded,
+ SystemFdQuotaExceeded,
+ SystemResources,
+ ProtocolNotSupported,
+ SocketTypeNotSupported,
+} || Errno;
+
+const Syscall = struct {
+ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!os.socket_t {
+ const rc = linux.socket(domain, socket_type, protocol);
+ return switch (linux.getErrno(rc)) {
+ .SUCCESS => @intCast(os.fd_t, rc),
+ .ACCES => return error.PermissionDenied,
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
+ .INVAL => return error.ProtocolFamilyNotAvailable,
+ .MFILE => return error.ProcessFdQuotaExceeded,
+ .NFILE => return error.SystemFdQuotaExceeded,
+ .NOBUFS => return error.SystemResources,
+ .NOMEM => return error.SystemResources,
+ .PROTONOSUPPORT => return error.ProtocolNotSupported,
+ .PROTOTYPE => return error.SocketTypeNotSupported,
+ else => |err| return asError(err),
+ };
+ }
+};
+
pub fn openSocket(family: u32, sock_type: u32, protocol: u32) !os.socket_t {
- return os.socket(family, sock_type, protocol);
+ return Syscall.socket(family, sock_type, protocol);
}
pub var global: IO = undefined;
@@ -1319,5 +1348,5 @@ fn buffer_limit(buffer_len: usize) usize {
.macos, .ios, .watchos, .tvos => std.math.maxInt(i32),
else => std.math.maxInt(isize),
};
- return std.math.min(limit, buffer_len);
+ return @minimum(limit, buffer_len);
}