Accepts a connection on a socket.
Format
#include <socket.h>
int accept (int s, struct sockaddr *addr, int
*addrlen);
Routine Variants
This socket routine has a variant named __bsd44_accept. Enabled by
defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible
semantics. See Section A.7 for
more information.
Arguments
- s
- A socket descriptor that has been returned by socket,
subsequently bound to an address with bind, and that is listening
for connections after a listen.
- addr
- A result parameter that is filled in with the address of the
connecting entity, as known to the communications layer. The exact
format of the structure to which the address parameter points is
determined by the domain in which the communication is occurring.
This version of DEC C supports only the
Internet domain (AF_INET).
- addrlen
- A value-result parameter; it should initially contain the size
of the structure pointed to by addr. On return it will
contain the actual length, in bytes, of the structure that has
been filled in by the communication layer. See <socket.h> for a
description of the sockaddr structure.
Description
This routine completes the first connection on the queue of
pending connections, creates a new socket with the same properties
as s, and allocates and returns a new descriptor for the
socket. If no pending connections are present on the queue, and the
socket is not marked as nonblocking, accept blocks the caller until
a connection request is present. If the socket is marked nonblocking
by using a setsockopt call and no pending connections are present on
the queue, accept returns an error. The accepted socket may not be
used to accept connections. The original socket s remains
open (listening) for other connection requests. This call is used
with connection-based socket types, currently with SOCK_STREAM.
It is possible to select a socket for the purposes of performing an
accept by selecting it for read.
See also bind, connect, listen, select, and socket in this section.
Return Values
x | A nonnegative integer that is a
descriptor for the accepted socket. |
-
1 | Indicates an error; errno is set to one of the
following:
- EBADF - The socket descriptor is invalid.
- ENOTSOCK - The socket descriptor references a file, not a
socket.
- EOPNOTSUPP - The reference socket is not of type SOCK_
STREAM.
- EFAULT - The addr parameter is not in a writable
part of the user address space.
- EWOULDBLOCK - The socket is marked nonblocking and no
connections are present to be accepted.
|
Previous Page | Next Page | Table of Contents | Index