#include <sys/types.h> #include <sys/socket.h> int accept(int socket_descriptor, struct sockaddr *address, int *address_length)Service Program Name: QSOSRV1
#define _XOPEN_SOURCE 520 #include <sys/socket.h> int accept(int socket_descriptor, struct sockaddr *address, socklen_t *address_length)
The accept() function is used to wait for connection requests. accept() takes the first connection request on the queue of pending connection requests and creates a new socket to service the connection request.
accept() is used with connection-oriented socket types, such as SOCK_STREAM.
There are two versions of the API, as shown above. The base i5/OS API uses BSD 4.3 structures and syntax. The other uses syntax and struc(TM)tures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.
The BSD 4.3 structure is:
struct sockaddr { u_short sa_family; char sa_data[14]; };
The BSD 4.4/UNIX 98 compatible structure is:
typedef uchar sa_family_t; struct sockaddr { uint8_t sa_len; sa_family_t sa_family; char sa_data[14]; };
The BSD 4.4 sa_len field is the length of the address. The sa_family field identifies the address family to which the address belongs, and sa_data is the address whose format is dependent on the address family.
Note: See the usage notes about using different address families with sockaddr_storage.
When the socket identified by the socket_descriptor is of type AF_INET and a connection indication request is received over an APPC device, the thread must have adequate authority. The thread must have retrieve, insert, delete, and update authority to the APPC device. When the thread does not have this level of authority, an errno of EACCES is returned.
accept() returns an integer. Possible values are:
When accept() fails, errno can be set to one of the following:
[EACCES] | Permission denied.
A connection indication request was received on the socket referenced by the socket_descriptor parameter, but the process that issued the accept() did not have the appropriate privileges required to handle the request. The connection indication request is reset by the system. |
[EBADF] | Descriptor not valid. |
[ECONNABORTED] | Connection ended abnormally.
An accept() was issued on a socket for which receives have been disallowed (due to a shutdown() call). This also could be encountered if time elapsed since a successful Rbind() is greater than the margin allowed by the associated SOCKS server. An accept() was issued on a socket in blocking mode and one or more connections have been reset and there are no acceptable connections in the queue. This is only valid if socket option SO_ACCEPTECONNABORTED was enabled for the listening socket. |
[EFAULT] | Bad address.
System detected an address which was not valid while attempting to access the address or address_length parameters. |
[EINTR] | Interrupted function call. |
[EINVAL] | Parameter not valid.
This error code indicates one of the following:
|
[EIO] | Input/output error. |
[EMFILE] | Too many descriptions for this
process. |
[ENFILE] | Too many descriptions in system. |
[ENOBUFS] | There is not enough buffer space for
the requested operation. |
[ENOTSOCK] | The specified descriptor does not
reference a socket. |
[EOPNOTSUPP] | Operation not supported.
The socket_descriptor parameter references a socket that does not support the accept(). The accept() is only valid on sockets that are connection-oriented (for example, type of SOCK_STREAM). |
[EUNATCH] | The protocol required to support the
specified address family is not available at this time. |
[EUNKNOWN] | Unknown system state. |
[EWOULDBLOCK] | Operation would have caused the
thread to be suspended. |
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
CPFA081 E | Unable to set return value or error code. |
#define _SS_MAXSIZE 304 #define _SS_ALIGNSIZE (sizeof (char*)) #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(sa_family_t)) #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(sa_family_t)+ _SS_PAD1SIZE + _SS_ALIGNSIZE)) struct sockaddr_storage { sa_family_t ss_family; char _ss_pad1[_SS_PAD1SIZE]; char* _ss_align; char _ss_pad2[_SS_PAD2SIZE]; };The BSD 4.4/UNIX 98 compatible structure is:
#define _SS_MAXSIZE 304 #define _SS_ALIGNSIZE (sizeof (char*)) #define _SS_PAD1SIZE (_SS_ALIGNSIZE - (sizeof(uint8_t) + sizeof(sa_family_t))) #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(uint8_t) + sizeof(sa_family_t)+ _SS_PAD1SIZE + _SS_ALIGNSIZE)) struct sockaddr_storage { uint8_t ss_len; sa_family_t ss_family; char _ss_pad1[_SS_PAD1SIZE]; char* _ss_align; char _ss_pad2[_SS_PAD2SIZE]; };
Top | UNIX-Type APIs | APIs by category |