Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
accept() z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference SC27-3660-00 |
|
The accept() call is used by a server to accept a connection request from a client. The call accepts the first connection on its queue of pending connections. The accept() call creates a new socket descriptor with the same properties as s and returns it to the caller. If the queue has no pending connection requests, accept() blocks the caller unless s is in nonblocking mode. If no connection requests are queued and s is in nonblocking mode, accept() returns -1 and sets errno to EWOULDBLOCK. The new socket descriptor cannot be used to accept new connections. The original socket, s, remains available to accept additional connection requests.
The s parameter is a stream socket descriptor created using the socket() call. It is usually bound to an address using the bind() call. The listen() call marks the socket as one that accepts connections and allocates a queue to hold pending connection requests. The listen() call allows the caller to place an upper boundary on the size of the queue. The addr parameter points
to a buffer into which the connection requester address is placed.
The addr parameter is optional and can be
set to NULL. If addr or addrlen is null or 0, addr is not specified. The exact format of addr depends on the addressing domain from which the communication
request originated. For example, if the connection request originated
in the AF_INET domain, addr points to a sockaddr_in structure as defined in the header
file IN.H. The addrlen parameter
is used only when name is not NULL. Before
calling accept(), you must set the integer pointed to by addrlen to the size of the buffer, in bytes, pointed
to by addr. If the buffer is not large enough
to hold the address, only the addrlen number
of bytes of the requester address is copied.
Note: This call is used only with SOCK_STREAM sockets. There is
no way to screen requesters without calling accept(). The application
cannot determine which system from which requesters connections will
be accepted. However, the caller can choose to close a connection
immediately after discovering the identity of the requester.
A socket can be checked for incoming connection requests using the select() call. Return valuesA nonnegative socket descriptor indicates success; the value -1 indicates
an error. Errno identifies the specific error.
ExampleFollowing are
two examples of the accept() call. In the first, the caller wants
to have the requester’s address returned. In the second, the caller
does not want the requester address returned’s.
Related callsbind(), connect(), getpeername(), listen(), socket() |
Copyright IBM Corporation 1990, 2014
|