authorgravatar for git@l4.pmLuna <git@l4.pm> 2019-11-09 14:53:48-03:00
committergravatar for git@l4.pmLuna <git@l4.pm> 2019-11-09 14:53:48-03:00
log348c0232a5612eb9bdb445e80e6e201d24911dcc
tree669495f6669382d9c07df20f5c999db55a114b06
parent05ae21b78ed58e621fd2c10456a3f100a8107e3a

miscellaneous fixes

- make connextUnixSocket use std.net.Address - fix StreamServer.listen giving wrong protocol for unix sockets

1 files changed, 12 insertions(+), 14 deletions(-)

lib/std/net.zig+12-14
......@@ -222,7 +222,7 @@ pub const Address = extern union {
222222 };
223223
224224 // this enables us to have the proper length of the socket in getOsSockLen
225 mem.zero(&sock_addr.path);
225 mem.set(u8, &sock_addr.path, 0);
226226
227227 if (path.len > sock_addr.path.len) return error.NameTooLong;
228228 mem.copy(u8, &sock_addr.path, path);
......@@ -347,9 +347,9 @@ pub const Address = extern union {
347347 switch (self.any.family) {
348348 os.AF_INET => return @sizeOf(os.sockaddr_in),
349349 os.AF_INET6 => return @sizeOf(os.sockaddr_in6),
350 os.AF_UNIX => blk: {
351 const path_len = std.mem.len(self.un.path.len);
352 break :blk @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
350 os.AF_UNIX => {
351 const path_len = std.mem.len(u8, &self.un.path);
352 return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
353353 },
354354 else => unreachable,
355355 }
......@@ -365,16 +365,13 @@ pub fn connectUnixSocket(path: []const u8) !fs.File {
365365 );
366366 errdefer os.close(sockfd);
367367
368 var sock_addr = os.sockaddr_un{
369 .family = os.AF_UNIX,
370 .path = undefined,
371 };
372
373 if (path.len > sock_addr.path.len) return error.NameTooLong;
374 mem.copy(u8, &sock_addr.path, path);
368 var addr = try std.net.Address.initUnix(path);
375369
376 const size = @intCast(u32, @sizeOf(os.sockaddr_un) - sock_addr.path.len + path.len);
377 try os.connect(sockfd, &sock_addr, size);
370 try os.connect(
371 sockfd,
372 &addr.any,
373 addr.getOsSockLen(),
374 );
378375
379376 return fs.File.openHandle(sockfd);
380377}
......@@ -1306,7 +1303,8 @@ pub const StreamServer = struct {
13061303 pub fn listen(self: *StreamServer, address: Address) !void {
13071304 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
13081305 const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;
1309 const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
1306 const proto = if (address.any.family == os.AF_UNIX) u32(0) else os.IPPROTO_TCP;
1307 const sockfd = try os.socket(address.any.family, sock_flags, proto);
13101308 self.sockfd = sockfd;
13111309 errdefer {
13121310 os.close(sockfd);