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 {...@@ -222,7 +222,7 @@ pub const Address = extern union {
222 };222 };
223223
224 // this enables us to have the proper length of the socket in getOsSockLen224 // 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
227 if (path.len > sock_addr.path.len) return error.NameTooLong;227 if (path.len > sock_addr.path.len) return error.NameTooLong;
228 mem.copy(u8, &sock_addr.path, path);228 mem.copy(u8, &sock_addr.path, path);
...@@ -347,9 +347,9 @@ pub const Address = extern union {...@@ -347,9 +347,9 @@ pub const Address = extern union {
347 switch (self.any.family) {347 switch (self.any.family) {
348 os.AF_INET => return @sizeOf(os.sockaddr_in),348 os.AF_INET => return @sizeOf(os.sockaddr_in),
349 os.AF_INET6 => return @sizeOf(os.sockaddr_in6),349 os.AF_INET6 => return @sizeOf(os.sockaddr_in6),
350 os.AF_UNIX => blk: {350 os.AF_UNIX => {
351 const path_len = std.mem.len(self.un.path.len);351 const path_len = std.mem.len(u8, &self.un.path);
352 break :blk @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);352 return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
353 },353 },
354 else => unreachable,354 else => unreachable,
355 }355 }
...@@ -365,16 +365,13 @@ pub fn connectUnixSocket(path: []const u8) !fs.File {...@@ -365,16 +365,13 @@ pub fn connectUnixSocket(path: []const u8) !fs.File {
365 );365 );
366 errdefer os.close(sockfd);366 errdefer os.close(sockfd);
367367
368 var sock_addr = os.sockaddr_un{368 var addr = try std.net.Address.initUnix(path);
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);
375369
376 const size = @intCast(u32, @sizeOf(os.sockaddr_un) - sock_addr.path.len + path.len);370 try os.connect(
377 try os.connect(sockfd, &sock_addr, size);371 sockfd,
372 &addr.any,
373 addr.getOsSockLen(),
374 );
378375
379 return fs.File.openHandle(sockfd);376 return fs.File.openHandle(sockfd);
380}377}
...@@ -1306,7 +1303,8 @@ pub const StreamServer = struct {...@@ -1306,7 +1303,8 @@ pub const StreamServer = struct {
1306 pub fn listen(self: *StreamServer, address: Address) !void {1303 pub fn listen(self: *StreamServer, address: Address) !void {
1307 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;1304 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
1308 const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;1305 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);
1310 self.sockfd = sockfd;1308 self.sockfd = sockfd;
1311 errdefer {1309 errdefer {
1312 os.close(sockfd);1310 os.close(sockfd);