| author | |
| committer | |
| log | 0fb1388031ec98af77fe5e0ae8459c983010d1a8 |
| tree | a94917b63784d16ac21393921905c99c2fa7738c |
| parent | 16397241f6d85956f460f1b1049cf9ce0312bca4 |
| signature |
2 files changed, 20 insertions(+), 2 deletions(-)
lib/std/net.zig+2-2| ... | @@ -294,7 +294,7 @@ pub fn connectUnixSocket(path: []const u8) !fs.File { | ... | @@ -294,7 +294,7 @@ pub fn connectUnixSocket(path: []const u8) !fs.File { |
| 294 | if (path.len > @typeOf(sock_addr.un.path).len) return error.NameTooLong; | 294 | if (path.len > @typeOf(sock_addr.un.path).len) return error.NameTooLong; |
| 295 | mem.copy(u8, sock_addr.un.path[0..], path); | 295 | mem.copy(u8, sock_addr.un.path[0..], path); |
| 296 | const size = @intCast(u32, @sizeOf(os.sa_family_t) + path.len); | 296 | const size = @intCast(u32, @sizeOf(os.sa_family_t) + path.len); |
| 297 | try os.connect(sockfd, &sock_addr, size); | 297 | try os.connect(sockfd, sock_addr, size); |
| 298 | 298 | ||
| 299 | return fs.File.openHandle(sockfd); | 299 | return fs.File.openHandle(sockfd); |
| 300 | } | 300 | } |
| ... | @@ -561,7 +561,7 @@ fn linuxLookupName( | ... | @@ -561,7 +561,7 @@ fn linuxLookupName( |
| 561 | var prefixlen: i32 = 0; | 561 | var prefixlen: i32 = 0; |
| 562 | if (os.socket(addr.family, os.SOCK_DGRAM | os.SOCK_CLOEXEC, os.IPPROTO_UDP)) |fd| syscalls: { | 562 | if (os.socket(addr.family, os.SOCK_DGRAM | os.SOCK_CLOEXEC, os.IPPROTO_UDP)) |fd| syscalls: { |
| 563 | defer os.close(fd); | 563 | defer os.close(fd); |
| 564 | os.connect(fd, da, dalen) catch break :syscalls; | 564 | os.connect(fd, da.*, dalen) catch break :syscalls; |
| 565 | key |= DAS_USABLE; | 565 | key |= DAS_USABLE; |
| 566 | os.getsockname(fd, sa, &salen) catch break :syscalls; | 566 | os.getsockname(fd, sa, &salen) catch break :syscalls; |
| 567 | if (addr.family == os.AF_INET) { | 567 | if (addr.family == os.AF_INET) { |
lib/std/net/test.zig+18| ... | @@ -29,6 +29,24 @@ test "std.net.parseIp6" { | ... | @@ -29,6 +29,24 @@ test "std.net.parseIp6" { |
| 29 | std.testing.expect(mem.eql(u8, "[ff01::fb]:80", printed)); | 29 | std.testing.expect(mem.eql(u8, "[ff01::fb]:80", printed)); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | test "resolve DNS" { | ||
| 33 | if (std.builtin.os == .windows) { | ||
| 34 | // DNS resolution not implemented on Windows yet. | ||
| 35 | return error.SkipZigTest; | ||
| 36 | } | ||
| 37 | var buf: [1000 * 10]u8 = undefined; | ||
| 38 | const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; | ||
| 39 | |||
| 40 | const address_list = net.getAddressList(a, "example.com", 80) catch |err| switch (err) { | ||
| 41 | // The tests are required to work even when there is no Internet connection, | ||
| 42 | // so some of these errors we must accept and skip the test. | ||
| 43 | error.UnknownHostName => return error.SkipZigTest, | ||
| 44 | error.TemporaryNameServerFailure => return error.SkipZigTest, | ||
| 45 | else => return err, | ||
| 46 | }; | ||
| 47 | address_list.deinit(); | ||
| 48 | } | ||
| 49 | |||
| 32 | test "listen on a port, send bytes, receive bytes" { | 50 | test "listen on a port, send bytes, receive bytes" { |
| 33 | if (std.builtin.os != .linux) { | 51 | if (std.builtin.os != .linux) { |
| 34 | // TODO build abstractions for other operating systems | 52 | // TODO build abstractions for other operating systems |