| ... | ... | @@ -1360,14 +1360,22 @@ pub const StreamServer = struct { |
| 1360 | 1360 | BlockedByFirewall, |
| 1361 | 1361 | } || os.UnexpectedError; |
| 1362 | 1362 | |
| 1363 | | /// If this function succeeds, the returned `fs.File` is a caller-managed resource. |
| 1364 | | pub fn accept(self: *StreamServer) AcceptError!fs.File { |
| 1363 | pub const Connection = struct { |
| 1364 | file: fs.File, |
| 1365 | address: Address |
| 1366 | }; |
| 1367 | |
| 1368 | /// If this function succeeds, the returned `Connection` is a caller-managed resource. |
| 1369 | pub fn accept(self: *StreamServer) AcceptError!Connection { |
| 1365 | 1370 | const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0; |
| 1366 | 1371 | const accept_flags = nonblock | os.SOCK_CLOEXEC; |
| 1367 | 1372 | var accepted_addr: Address = undefined; |
| 1368 | 1373 | var adr_len: os.socklen_t = @sizeOf(Address); |
| 1369 | 1374 | if (os.accept4(self.sockfd.?, &accepted_addr.any, &adr_len, accept_flags)) |fd| { |
| 1370 | | return fs.File.openHandle(fd); |
| 1375 | return Connection{ |
| 1376 | .file = fs.File.openHandle(fd), |
| 1377 | .address = accepted_addr, |
| 1378 | }; |
| 1371 | 1379 | } else |err| switch (err) { |
| 1372 | 1380 | // We only give SOCK_NONBLOCK when I/O mode is async, in which case this error |
| 1373 | 1381 | // is handled by os.accept4. |