authorgravatar for kenta@lithdew.netlithdew <kenta@lithdew.net> 2021-05-05 16:09:08+09:00
committergravatar for kenta@lithdew.netlithdew <kenta@lithdew.net> 2021-05-05 16:09:08+09:00
logc75ae8b66d57d9e7c195121e1d8d8ff5ca98e73d
tree6edc6ae92d6471fd26c625af568a87078fb81f54
parent785a6c1aa9a7979a962db9d741a53897c423cb92

x/net: fix tcp tests for openbsd and add missing `fmt` import

On OpenBSD, connecting to a newly-allocated port on an unspecified IPv4 host address causes EINVAL. This was found by @mikdusan when running TCP tests on OpenBSD. This commit fixes TCP tests on OpenBSD by having all tests that allocate a new host-port pair to have the host IPv4/IPv6 address point to the host's loopback adapter (on localhost).

3 files changed, 13 insertions(+), 2 deletions(-)

lib/std/x/net/ip.zig+2
......@@ -6,6 +6,8 @@
66
77const std = @import("../../std.zig");
88
9const fmt = std.fmt;
10
911const IPv4 = std.x.os.IPv4;
1012const IPv6 = std.x.os.IPv6;
1113const Socket = std.x.os.Socket;
lib/std/x/net/tcp.zig+10-2
......@@ -282,7 +282,11 @@ test "tcp: create client/listener pair" {
282282 try listener.bind(ip.Address.initIPv4(IPv4.unspecified, 0));
283283 try listener.listen(128);
284284
285 const binded_address = try listener.getLocalAddress();
285 var binded_address = try listener.getLocalAddress();
286 switch (binded_address) {
287 .ipv4 => |*ipv4| ipv4.host = IPv4.localhost,
288 .ipv6 => |*ipv6| ipv6.host = IPv6.localhost,
289 }
286290
287291 const client = try tcp.Client.init(.ip, os.SOCK_CLOEXEC);
288292 defer client.deinit();
......@@ -302,7 +306,11 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
302306 try listener.bind(ip.Address.initIPv4(IPv4.unspecified, 0));
303307 try listener.listen(128);
304308
305 const binded_address = try listener.getLocalAddress();
309 var binded_address = try listener.getLocalAddress();
310 switch (binded_address) {
311 .ipv4 => |*ipv4| ipv4.host = IPv4.localhost,
312 .ipv6 => |*ipv6| ipv6.host = IPv6.localhost,
313 }
306314
307315 const client = try tcp.Client.init(.ip, os.SOCK_CLOEXEC);
308316 defer client.deinit();
lib/std/x/os/Socket.zig+1
......@@ -8,6 +8,7 @@ const std = @import("../../std.zig");
88const net = @import("net.zig");
99
1010const os = std.os;
11const fmt = std.fmt;
1112const mem = std.mem;
1213const time = std.time;
1314