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 {...@@ -1366,6 +1366,10 @@ pub const StreamServer = struct {
13661366
1367 /// Firewall rules forbid connection.1367 /// Firewall rules forbid connection.
1368 BlockedByFirewall,1368 BlockedByFirewall,
1369
1370 /// Permission to create a socket of the specified type and/or
1371 /// protocol is denied.
1372 PermissionDenied,
1369 } || os.UnexpectedError;1373 } || os.UnexpectedError;
13701374
1371 pub const Connection = struct {1375 pub const Connection = struct {
lib/std/net/test.zig+1-1
...@@ -81,7 +81,7 @@ test "resolve DNS" {...@@ -81,7 +81,7 @@ test "resolve DNS" {
81test "listen on a port, send bytes, receive bytes" {81test "listen on a port, send bytes, receive bytes" {
82 if (!std.io.is_async) return error.SkipZigTest;82 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()) {
85 // TODO build abstractions for other operating systems85 // TODO build abstractions for other operating systems
86 return error.SkipZigTest;86 return error.SkipZigTest;
87 }87 }
lib/std/os.zig+9-1
...@@ -2156,6 +2156,9 @@ pub const SocketError = error{...@@ -2156,6 +2156,9 @@ pub const SocketError = error{
21562156
2157 /// The protocol type or the specified protocol is not supported within this domain.2157 /// The protocol type or the specified protocol is not supported within this domain.
2158 ProtocolNotSupported,2158 ProtocolNotSupported,
2159
2160 /// The socket type is not supported by the protocol.
2161 SocketTypeNotSupported,
2159} || UnexpectedError;2162} || UnexpectedError;
21602163
2161pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {2164pub 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 {...@@ -2164,7 +2167,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
2164 socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC)2167 socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC)
2165 else2168 else
2166 socket_type;2169 socket_type;
2167 const rc = system.socket(domain, socket_type, protocol);2170 const rc = system.socket(domain, filtered_sock_type, protocol);
2168 switch (errno(rc)) {2171 switch (errno(rc)) {
2169 0 => {2172 0 => {
2170 const fd = @intCast(fd_t, rc);2173 const fd = @intCast(fd_t, rc);
...@@ -2181,6 +2184,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {...@@ -2181,6 +2184,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
2181 ENOBUFS => return error.SystemResources,2184 ENOBUFS => return error.SystemResources,
2182 ENOMEM => return error.SystemResources,2185 ENOMEM => return error.SystemResources,
2183 EPROTONOSUPPORT => return error.ProtocolNotSupported,2186 EPROTONOSUPPORT => return error.ProtocolNotSupported,
2187 EPROTOTYPE => return error.SocketTypeNotSupported,
2184 else => |err| return unexpectedErrno(err),2188 else => |err| return unexpectedErrno(err),
2185 }2189 }
2186}2190}
...@@ -2290,6 +2294,10 @@ pub const AcceptError = error{...@@ -2290,6 +2294,10 @@ pub const AcceptError = error{
2290 /// This error occurs when no global event loop is configured,2294 /// This error occurs when no global event loop is configured,
2291 /// and accepting from the socket would block.2295 /// and accepting from the socket would block.
2292 WouldBlock,2296 WouldBlock,
2297
2298 /// Permission to create a socket of the specified type and/or
2299 /// protocol is denied.
2300 PermissionDenied,
2293} || UnexpectedError;2301} || UnexpectedError;
22942302
2295/// Accept a connection on a socket.2303/// Accept a connection on a socket.