Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ accept(2) — Ultrix-11 3.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

bind(2)

connect(2)

listen(2)

select(2)

socket(2)

accept(2)

NAME

accept − accept a connection on a socket

SYNTAX

include <sys/types.h>
#include <sys/socket.h>

int  ns = accept(s, addr, addrlen)
int s, *addrlen;
struct sockaddr *addr;

DESCRIPTION

The accept system call extracts the first connection on the queue of pending connections, creates a new socket with the same properties of s and allocates a new file descriptor ns for the socket.  The specified s is a socket that was created with the socket call, that was bound to an address with the bind call, and that is listening for connections after a listen call.  If no pending connections are present on the queue and if the socket is not marked as non-blocking, the accept call blocks the caller until a connection is present.  If the socket is marked non-blocking and if no pending connections are present on the queue, the accept call returns an error.  The accepted socket ns may not be used to accept more connections.  The original socket s remains open. 

The specified addr is a result parameter which is filled in with the address of the connecting entity, as known to the communications layer.  The exact format of addr is determined by the domain in which the communication is occurring.  The specified addrlen argument is a value-result parameter.  It should initially contain the amount of space pointed to by addr.  On return, it will contain the actual length (in bytes) of the address returned.  This call is used with connection-based socket types, currently with SOCK_STREAM. 

It is possible to select a socket for the purposes of doing an accept by selecting it for read. 

RETURN VALUE

If successful, returns a non-negative integer, a descriptor for the accepted socket.  If unsuccessful, returns a −1, and the global variable errno indicates the error code. 

DIAGNOSTICS

The accdpt call will fail if:

[EBADF] The descriptor is invalid. 

[ENOTSOCK] The descriptor references a file, not a socket. 

[EOPNOTSUPP] The referenced socket is not of type SOCK_STREAM. 

[EFAULT] The specified addr is not in a writable part of the user address space. 

[EWOULDBLOCK] The socket is marked non-blocking and no connections are present to be accepted. 

SEE ALSO

bind(2), connect(2), listen(2), select(2), socket(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026