accept (HLCALL 0x3E09) - accept a connection on a socket.
ld a, (listen_sockfd) ; get the listening socket handle ld hl, ACCEPT call HLCALL
#include <sys/types.h> #include <sys/socket.h> int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
The argument s is a socket that has been created with socket, bound to an address with bind, and is listening for connections after a listen. The accept() call extracts the first connection request on the queue of pending connections, creates a new socket with the same properties of s, and allocates a new file descriptor for the socket. If no pending connections are present on the queue, accept() blocks the caller until a connection is present. The accepted socket may not be used to accept more connections. The original socket s remains open.
The argument addr is a result parameter that is filled in with the address of the connecting entity as known to the communications layer, which for the Spectranet is only sockaddr_in. Assembly language programmers may use the getsockinfo call to fill a block of memory with the address information.
It is possible to poll a socket for the purposes of doing an accept() by selecting it for read.
On success, the C accept() call returns 0, and on error, -1. The assembly language call returns with the carry flag reset on success, and carry set on error with the A register set to the error code.