Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/a/accept.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/a/accept.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/a/accept.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/a/accept.html on line 8
Accept a connection on a socket
#include <sys/types.h>
#include <sys/socket.h>
int accept( int s,
struct sockaddr * addr,
socklen_t * addrlen );
- s
- A socket that's been created with
socket().
- addr
- A result parameter that's filled in with the address of the connecting entity,
as known to the communications layer.
The exact format of the addr parameter is determined by
the domain in which the connection was made.
- addrlen
- A value-result parameter.
It should initially contain the amount of space pointed to by addr;
on return it contains the actual length (in bytes) of the address returned.
This call is used with connection-based socket types, currently with SOCK_STREAM.
libsocket
Use the -l socket option to
qcc
to link against this library.
The accept() function:
- Extracts the first connection request on the queue of pending connections.
- Creates a new socket with the same properties of s,
where s is a socket that's been created with
socket(),
bound to an address with
bind(),
and is listening for connections after a
listen().
- Allocates a new file descriptor for the socket.
If no pending connections are present on the queue,
and the socket isn't marked as nonblocking,
accept() blocks the caller until a connection is present.
If the socket is marked as nonblocking and no pending connections are present on the queue,
accept() returns an error as described below.
The accepted socket may not be used to accept more connections.
The original socket s remains open.
If you do a
select()
for read on an unconnected socket (on which a listen() has been done),
the select() indicates when a connect request has occurred.
In this way, an accept() can be made that won't block.
For more information, see
select().
For certain protocols that require an explicit confirmation,
accept() can be thought of as merely dequeuing
the next connection request and not implying confirmation.
Confirmation can be implied by a normal read or write on the new file descriptor,
and rejection can be implied by closing the new socket.
You can obtain user-connection request data without confirming the connection by:
- Issuing a
recvmsg()
call with a msg_iovlen of 0 and a nonzero msg_controllen
Or
- Issuing a
getsockopt()
request.
Similarly, you can provide user-connection rejection information by issuing a
sendmsg()
call with only the control information, or by calling
setsockopt().
A descriptor for the accepted socket, or -1 if an error occurs (errno is set).
- EAGAIN
- Insufficient resources to create the new socket.
- EBADF
- Invalid descriptor s.
- EFAULT
- The addr parameter isn't in a writable part of the user address space.
- EINVAL
- You called accept() on a socket that you hadn't called
listen() on.
- EOPNOTSUPP
- The referenced socket isn't a SOCK_STREAM socket.
- ESRCH
- Can't find the socket manager.
- EWOULDBLOCK
- The socket is marked nonblocking and no connections are present to be accepted.
POSIX 1003.1
Safety: | |
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
bind(),
close(),
connect(),
listen(),
select(),
socket()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/a/accept.html on line 236
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/a/accept.html on line 236