| ... | ... | @@ -77,7 +77,11 @@ pub const Address = extern union { |
| 77 | 77 | }); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | | pub fn listen(adr: Address, options: ListenOptions) !Server { |
| 80 | pub fn listen(adr_: Address, options: ListenOptions) !Server { |
| 81 | var adr = adr_; |
| 82 | if (options.dualstack_if_possible and adr_.any.family == .INET and adr_.in.sa.addr.addr == 0) { |
| 83 | adr = .{ .in6 = .init(@bitCast(@as([16]u8, @splat(0))), @byteSwap(adr_.in.sa.port)) }; |
| 84 | } |
| 81 | 85 | const sockfd = try sys.socket( |
| 82 | 86 | adr.any.family, |
| 83 | 87 | sys.SOCK.STREAM | sys.SOCK.CLOEXEC, |
| ... | ... | @@ -89,6 +93,9 @@ pub const Address = extern union { |
| 89 | 93 | }; |
| 90 | 94 | errdefer s.stream.close(); |
| 91 | 95 | |
| 96 | if (options.dualstack_if_possible and adr_.any.family == .INET and adr_.in.sa.addr.addr == 0) { |
| 97 | try sys.setsockopt(sockfd, sys.IPPROTO.IPV6, sys.IPV6.V6ONLY, &std.mem.toBytes(@as(c_int, 0))); |
| 98 | } |
| 92 | 99 | if (options.reuse_address) { |
| 93 | 100 | try sys.setsockopt(sockfd, sys.SOL.SOCKET, sys.SO.REUSEADDR, &std.mem.toBytes(@as(c_int, 1))); |
| 94 | 101 | |
| ... | ... | @@ -110,6 +117,8 @@ pub const Address = extern union { |
| 110 | 117 | kernel_backlog: u31 = 511, |
| 111 | 118 | /// Sets SO_REUSEADDR and SO_REUSEPORT. |
| 112 | 119 | reuse_address: bool = false, |
| 120 | /// When listening on 0.0.0.0, listens on [::] instead and disables IPV6_V6ONLY. |
| 121 | dualstack_if_possible: bool = true, |
| 113 | 122 | }; |
| 114 | 123 | |
| 115 | 124 | pub fn tcpConnect(adr: Address) !Stream { |