authorgravatar for git@l4.pmLuna <git@l4.pm> 2019-11-10 14:17:39-03:00
committergravatar for git@l4.pmLuna <git@l4.pm> 2019-11-10 14:17:39-03:00
logd99ecef9433d677b4f834d466d7057b0f35e4dbf
tree9ea518aeb280793470ea3757baf3d0a63f05b4a8
parent2d02920a905e20b7f43991657cdc028e444b9df7

replace panic to unreachable

- remove error.UnsupportedOS from StreamServer.listen

1 files changed, 4 insertions(+), 10 deletions(-)

lib/std/net.zig+4-10
......@@ -340,8 +340,8 @@ pub const Address = extern union {
340340 try std.fmt.format(context, Errors, output, "]:{}", port);
341341 },
342342 os.AF_UNIX => {
343 if (@typeOf(self.un) == void) {
344 @panic("unsupported OS");
343 if (!has_unix_sockets) {
344 unreachable;
345345 }
346346
347347 try std.fmt.format(context, Errors, output, "{}", self.un.path);
......@@ -361,8 +361,8 @@ pub const Address = extern union {
361361 os.AF_INET => return @sizeOf(os.sockaddr_in),
362362 os.AF_INET6 => return @sizeOf(os.sockaddr_in6),
363363 os.AF_UNIX => {
364 if (@typeOf(self.un) == void) {
365 @panic("unsupported OS");
364 if (!has_unix_sockets) {
365 unreachable;
366366 }
367367
368368 const path_len = std.mem.len(u8, &self.un.path);
......@@ -1321,12 +1321,6 @@ pub const StreamServer = struct {
13211321 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
13221322 const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;
13231323 const proto = if (address.any.family == os.AF_UNIX) @as(u32, 0) else os.IPPROTO_TCP;
1324 if (address.any.family == os.AF_UNIX and @typeOf(address.un) == void) {
1325 return error{
1326 /// When the OS does not have support for AF_UNIX sockets.
1327 UnsupportedOS,
1328 }.UnsupportedOS;
1329 }
13301324
13311325 const sockfd = try os.socket(address.any.family, sock_flags, proto);
13321326 self.sockfd = sockfd;