Skip to content

Commit 9b788b7

Browse files
ninjacatoandrewrk
authored andcommitted
Pass filtered_sock_type to system.socket. Cover PermissionDenied error
1 parent c8b4cc2 commit 9b788b7

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/std/net.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,10 @@ pub const StreamServer = struct {
13661366

13671367
/// Firewall rules forbid connection.
13681368
BlockedByFirewall,
1369+
1370+
/// Permission to create a socket of the specified type and/or
1371+
/// protocol is denied.
1372+
PermissionDenied,
13691373
} || os.UnexpectedError;
13701374

13711375
pub const Connection = struct {

lib/std/net/test.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test "resolve DNS" {
8181
test "listen on a port, send bytes, receive bytes" {
8282
if (!std.io.is_async) return error.SkipZigTest;
8383

84-
if (std.builtin.os.tag != .linux) {
84+
if (std.builtin.os.tag != .linux and !std.builtin.os.tag.isDarwin()) {
8585
// TODO build abstractions for other operating systems
8686
return error.SkipZigTest;
8787
}

lib/std/os.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,9 @@ pub const SocketError = error{
21562156

21572157
/// The protocol type or the specified protocol is not supported within this domain.
21582158
ProtocolNotSupported,
2159+
2160+
/// The socket type is not supported by the protocol.
2161+
SocketTypeNotSupported,
21592162
} || UnexpectedError;
21602163

21612164
pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
@@ -2164,7 +2167,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
21642167
socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC)
21652168
else
21662169
socket_type;
2167-
const rc = system.socket(domain, socket_type, protocol);
2170+
const rc = system.socket(domain, filtered_sock_type, protocol);
21682171
switch (errno(rc)) {
21692172
0 => {
21702173
const fd = @intCast(fd_t, rc);
@@ -2181,6 +2184,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
21812184
ENOBUFS => return error.SystemResources,
21822185
ENOMEM => return error.SystemResources,
21832186
EPROTONOSUPPORT => return error.ProtocolNotSupported,
2187+
EPROTOTYPE => return error.SocketTypeNotSupported,
21842188
else => |err| return unexpectedErrno(err),
21852189
}
21862190
}
@@ -2290,6 +2294,10 @@ pub const AcceptError = error{
22902294
/// This error occurs when no global event loop is configured,
22912295
/// and accepting from the socket would block.
22922296
WouldBlock,
2297+
2298+
/// Permission to create a socket of the specified type and/or
2299+
/// protocol is denied.
2300+
PermissionDenied,
22932301
} || UnexpectedError;
22942302

22952303
/// Accept a connection on a socket.

0 commit comments

Comments
 (0)