| ... | @@ -3471,31 +3471,10 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void { | ... | @@ -3471,31 +3471,10 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void { |
| 3471 | | 3471 | |
| 3472 | pub const AcceptError = std.Io.net.Server.AcceptError; | 3472 | pub const AcceptError = std.Io.net.Server.AcceptError; |
| 3473 | | 3473 | |
| 3474 | /// Accept a connection on a socket. | | |
| 3475 | /// If `sockfd` is opened in non blocking mode, the function will | | |
| 3476 | /// return error.WouldBlock when EAGAIN is received. | | |
| 3477 | pub fn accept( | 3474 | pub fn accept( |
| 3478 | /// This argument is a socket that has been created with `socket`, bound to a local address | | |
| 3479 | /// with `bind`, and is listening for connections after a `listen`. | | |
| 3480 | sock: socket_t, | 3475 | sock: socket_t, |
| 3481 | /// This argument is a pointer to a sockaddr structure. This structure is filled in with the | | |
| 3482 | /// address of the peer socket, as known to the communications layer. The exact format of the | | |
| 3483 | /// address returned addr is determined by the socket's address family (see `socket` and the | | |
| 3484 | /// respective protocol man pages). | | |
| 3485 | addr: ?*sockaddr, | 3476 | addr: ?*sockaddr, |
| 3486 | /// This argument is a value-result argument: the caller must initialize it to contain the | | |
| 3487 | /// size (in bytes) of the structure pointed to by addr; on return it will contain the actual size | | |
| 3488 | /// of the peer address. | | |
| 3489 | /// | | |
| 3490 | /// The returned address is truncated if the buffer provided is too small; in this case, `addr_size` | | |
| 3491 | /// will return a value greater than was supplied to the call. | | |
| 3492 | addr_size: ?*socklen_t, | 3477 | addr_size: ?*socklen_t, |
| 3493 | /// The following values can be bitwise ORed in flags to obtain different behavior: | | |
| 3494 | /// * `SOCK.NONBLOCK` - Set the `NONBLOCK` file status flag on the open file description (see `open`) | | |
| 3495 | /// referred to by the new file descriptor. Using this flag saves extra calls to `fcntl` to achieve | | |
| 3496 | /// the same result. | | |
| 3497 | /// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the | | |
| 3498 | /// description of the `CLOEXEC` flag in `open` for reasons why this may be useful. | | |
| 3499 | flags: u32, | 3478 | flags: u32, |
| 3500 | ) AcceptError!socket_t { | 3479 | ) AcceptError!socket_t { |
| 3501 | const have_accept4 = !(builtin.target.os.tag.isDarwin() or native_os == .windows or native_os == .haiku); | 3480 | const have_accept4 = !(builtin.target.os.tag.isDarwin() or native_os == .windows or native_os == .haiku); |
| ... | @@ -3504,29 +3483,11 @@ pub fn accept( | ... | @@ -3504,29 +3483,11 @@ pub fn accept( |
| 3504 | const accepted_sock: socket_t = while (true) { | 3483 | const accepted_sock: socket_t = while (true) { |
| 3505 | const rc = if (have_accept4) | 3484 | const rc = if (have_accept4) |
| 3506 | system.accept4(sock, addr, addr_size, flags) | 3485 | system.accept4(sock, addr, addr_size, flags) |
| 3507 | else if (native_os == .windows) | | |
| 3508 | windows.accept(sock, addr, addr_size) | | |
| 3509 | else | 3486 | else |
| 3510 | system.accept(sock, addr, addr_size); | 3487 | system.accept(sock, addr, addr_size); |
| 3511 | | 3488 | |
| 3512 | if (native_os == .windows) { | 3489 | if (native_os == .windows) { |
| 3513 | if (rc == windows.ws2_32.INVALID_SOCKET) { | 3490 | @compileError("use std.Io instead"); |
| 3514 | switch (windows.ws2_32.WSAGetLastError()) { | | |
| 3515 | .NOTINITIALISED => unreachable, // not initialized WSA | | |
| 3516 | .ECONNRESET => return error.ConnectionResetByPeer, | | |
| 3517 | .EFAULT => unreachable, | | |
| 3518 | .ENOTSOCK => return error.FileDescriptorNotASocket, | | |
| 3519 | .EINVAL => return error.SocketNotListening, | | |
| 3520 | .EMFILE => return error.ProcessFdQuotaExceeded, | | |
| 3521 | .ENETDOWN => return error.NetworkDown, | | |
| 3522 | .ENOBUFS => return error.FileDescriptorNotASocket, | | |
| 3523 | .EOPNOTSUPP => return error.OperationNotSupported, | | |
| 3524 | .EWOULDBLOCK => return error.WouldBlock, | | |
| 3525 | else => |err| return windows.unexpectedWSAError(err), | | |
| 3526 | } | | |
| 3527 | } else { | | |
| 3528 | break rc; | | |
| 3529 | } | | |
| 3530 | } else { | 3491 | } else { |
| 3531 | switch (errno(rc)) { | 3492 | switch (errno(rc)) { |
| 3532 | .SUCCESS => break @intCast(rc), | 3493 | .SUCCESS => break @intCast(rc), |