authorgravatar for cato@cato.ninjaCato <cato@cato.ninja> 2020-05-03 10:40:07+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-03 15:35:36-04:00
log9b788b765c1557a414710872fa9c11fce1f8c504
tree38a57d5b2a68e3330a0b642f79c2977b732c45b8
parentc8b4cc2ff9cf15a42f95b2302e02431a0004f5c8

Pass filtered_sock_type to system.socket. Cover PermissionDenied error


3 files changed, 14 insertions(+), 2 deletions(-)

lib/std/net.zig+4
......@@ -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+1-1
......@@ -81,7 +81,7 @@ test "resolve DNS" {
8181test "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+9-1
......@@ -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
21612164pub 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.