| ... | @@ -217,7 +217,10 @@ pub const Address = extern union { | ... | @@ -217,7 +217,10 @@ pub const Address = extern union { |
| 217 | /// If more than this many connections pool in the kernel, clients will start | 217 | /// If more than this many connections pool in the kernel, clients will start |
| 218 | /// seeing "Connection refused". | 218 | /// seeing "Connection refused". |
| 219 | kernel_backlog: u31 = 128, | 219 | kernel_backlog: u31 = 128, |
| | 220 | /// Sets SO_REUSEADDR and SO_REUSEPORT on POSIX. |
| | 221 | /// Sets SO_REUSEADDR on Windows, which is roughly equivalent. |
| 220 | reuse_address: bool = false, | 222 | reuse_address: bool = false, |
| | 223 | /// Deprecated. Does nothing. |
| 221 | reuse_port: bool = false, | 224 | reuse_port: bool = false, |
| 222 | force_nonblocking: bool = false, | 225 | force_nonblocking: bool = false, |
| 223 | }; | 226 | }; |
| ... | @@ -242,15 +245,15 @@ pub const Address = extern union { | ... | @@ -242,15 +245,15 @@ pub const Address = extern union { |
| 242 | posix.SO.REUSEADDR, | 245 | posix.SO.REUSEADDR, |
| 243 | &mem.toBytes(@as(c_int, 1)), | 246 | &mem.toBytes(@as(c_int, 1)), |
| 244 | ); | 247 | ); |
| 245 | } | 248 | switch (builtin.os.tag) { |
| 246 | | 249 | .windows => {}, |
| 247 | if (options.reuse_port) { | 250 | else => try posix.setsockopt( |
| 248 | try posix.setsockopt( | 251 | sockfd, |
| 249 | sockfd, | 252 | posix.SOL.SOCKET, |
| 250 | posix.SOL.SOCKET, | 253 | posix.SO.REUSEPORT, |
| 251 | posix.SO.REUSEPORT, | 254 | &mem.toBytes(@as(c_int, 1)), |
| 252 | &mem.toBytes(@as(c_int, 1)), | 255 | ), |
| 253 | ); | 256 | } |
| 254 | } | 257 | } |
| 255 | | 258 | |
| 256 | var socklen = address.getOsSockLen(); | 259 | var socklen = address.getOsSockLen(); |