Accepts a Connection Request and Retrieves First Block of Data
Portability: |
SAS/C extension
|
#include <sys/types.h>
#include <socket.h>
int accept_and_recv(int s, int *accept_soc,
void *remote_addr, int *remote_addrlen,
void *local_addr, int *local_addrlen,
void *buf, size_t buflen);
accept_and_recv
extracts the first connection in the queue of connection
requests. It either creates a new socket with the same properties as socket
descriptor s
(if *accept_soc
is -1) or reuses the specified socket (if *accept_soc
is not -1). It then
blocks the caller until the
first block of data arrives. The data is returned in the buffer buf of length
buflen.
Socket s
is a connection-based
socket of type SOCK_STREAM that is bound to an address with a bind call and
listens for connections with a listen call.
accept_soc
is a pointer
to an integer which is used for both input and output. If the integer pointed
to by accept_soc
is -1, accept_and_recv
will store the descriptor of a newly created socket in its
place. If the integer pointed to by accept_soc
is not -1, the value must be a reusable socket descriptor with which the accepted
connection is to be associated. When passing a reusable socket value, the
operating system may return a newly assigned socket descriptor. Reusable socket
descriptors usually are created initially through an accept
or an accept_and_recv
, although
any stream socket that is not bound or connected may be reused.
remote_addr
and remote_addrlen
describe the
buffer into which accept_and_recv
places the address of the connecting socket. remote_addr
can be NULL. If it is not NULL, it should point
to a sockaddr
structure or one of its derivatives,
such as sockaddr_in
. remote_addrlen
points to an integer containing the size of the buffer in
bytes. If the buffer size is not large enough to contain the address of the
connecting socket, the value of the address is not completely copied. No error
occurs in this situation. On return, the integer pointed to by remote_addrlen
is set to the length that was actually
copied.
local_addr
and local_addrlen
describe the buffer into which accept_and_recv
places the address of the local socket. local_addr
can be NULL. If it is not NULL, it should point to a sockaddr
structure or one of its derivatives, such as sockaddr_in
.
local_addrlen
points to an integer containing the size of the buffer in bytes. If the buffer
size is not large enough to contain the address of the local socket, the value
of the address is not completely copied. No error occurs in this situation.
On return, the integer pointed to by local_addrlen
is set to the length that was actually copied.
buf
and buflen
describe the buffer into which the first block of
data
is read. If buflen
is set to zero, then no
receive is done.
accept_and_recv
returns the number of bytes read if it is successful. A returned 0 could occur
if the client closed the socket without sending any data. A returned -1 indicates
failure and errno
is set to indicate the type
of error.
Note:
Non-blocking mode is not supported. The
function fails and sets the errno
, EOPNOTSUPP,
if O_NONBLOCK is set on the socket file descriptor s
.
If accept_and_recv
was
interrupted by a signal in the time between the arrival of the connection
and the arrival of the first block of data then a -1 is returned with the
errno set to EINTRNODATA. However, the connection is established and a usable
socket descriptor is returned in accept_soc
.
accept_and_recv
is implemented only under OS/390 V2R6 and later versions.
If the address buffer size is not large
enough to contain the address of the connecting or local socket, the value
of the address is not completely copied. No error occurs in this situation.
On return, the address buffer's length parameter is set to the length that
was actually copied.
accept
, read
,
recv
Copyright © 2001
by SAS Institute Inc., Cary, NC, USA. All rights reserved.