| ... | ... | @@ -222,7 +222,7 @@ pub const Address = extern union { |
| 222 | 222 | }; |
| 223 | 223 | |
| 224 | 224 | // 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); |
| 226 | 226 | |
| 227 | 227 | if (path.len > sock_addr.path.len) return error.NameTooLong; |
| 228 | 228 | mem.copy(u8, &sock_addr.path, path); |
| ... | ... | @@ -347,9 +347,9 @@ pub const Address = extern union { |
| 347 | 347 | switch (self.any.family) { |
| 348 | 348 | os.AF_INET => return @sizeOf(os.sockaddr_in), |
| 349 | 349 | 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); |
| 353 | 353 | }, |
| 354 | 354 | else => unreachable, |
| 355 | 355 | } |
| ... | ... | @@ -365,16 +365,13 @@ pub fn connectUnixSocket(path: []const u8) !fs.File { |
| 365 | 365 | ); |
| 366 | 366 | errdefer os.close(sockfd); |
| 367 | 367 | |
| 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); |
| 375 | 369 | |
| 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 | ); |
| 378 | 375 | |
| 379 | 376 | return fs.File.openHandle(sockfd); |
| 380 | 377 | } |
| ... | ... | @@ -1306,7 +1303,8 @@ pub const StreamServer = struct { |
| 1306 | 1303 | pub fn listen(self: *StreamServer, address: Address) !void { |
| 1307 | 1304 | const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0; |
| 1308 | 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 | 1308 | self.sockfd = sockfd; |
| 1311 | 1309 | errdefer { |
| 1312 | 1310 | os.close(sockfd); |