fn accept(sock: socket_t, addr: ?*sockaddr, addr_size: ?*socklen_t, flags: u32) AcceptError!socket_t
Accept a connection on a socket. If sockfd
is opened in non blocking mode, the function will return error.WouldBlock when EAGAIN is received.
Parameters
sock: socket_t,
This argument is a socket that has been created with socket
, bound to a local address with bind
, and is listening for connections after a listen
.
addr: ?*sockaddr,
This argument is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket, as known to the communications layer. The exact format of the address returned addr is determined by the socket’s address family (see socket
and the respective protocol man pages).
addr_size: ?*socklen_t,
This argument is a value-result argument: the caller must initialize it to contain the size (in bytes) of the structure pointed to by addr; on return it will contain the actual size of the peer address.
The returned address is truncated if the buffer provided is too small; in this case, addr_size
will return a value greater than was supplied to the call.
flags: u32,
The following values can be bitwise ORed in flags to obtain different behavior:
SOCK.NONBLOCK
- Set theO.NONBLOCK
file status flag on the open file description (seeopen
) referred to by the new file descriptor. Using this flag saves extra calls tofcntl
to achieve the same result.SOCK.CLOEXEC
- Set the close-on-exec (FD_CLOEXEC
) flag on the new file descriptor. See the description of theO.CLOEXEC
flag inopen
for reasons why this may be useful.