IPX/SPX Programming Manual
Library Routines
HP NonStop IPX/SPX Programming Manual—528022-001
5-11
accept
Errors
If an error occurs, the external variable errno is set to one of the following values:
Usage Guidelines
•
This is a waited call; your program will be blocked until the operation completes.
For nowait I/O, use accept_nw and accept_nw2.
•
For TCP and SPXII server applications, a call to bind and listen must precede
a call to accept.
•
The original socket remains in a listening state.
For information about struct sockaddr_nv and struct sockaddr, see NonStop
IPX/SPX Data Structures on page 4-2.
Example
The following programming example calls the accept function to accept a connection
on an SPXII socket. In the example, fd is the socket number returned by a call to
socket, and from is a structure based on the sockaddr_nv structure. See NonStop
IPX/SPX Data Structures on page 4-2.
#include <socket.h>
#include <nv.h>
...
struct sockaddr_nv from;
int flen;
/* Before accept, program must call socket, bind,
* and listen.
*/
flen = sizeof(from);
if ((s2 = accept(fd, (struct sockaddr *)&from, &flen)) < 0) {
perror (“Server: Accept failed.”);
exit (0);
}
printf("Server: connected on socket %d, SPX port 0x%hx\n",
s2, from.snv_addr.s_port);
ECONNRESET The connection was reset by the peer process before the
accept operation completed.
EINVAL An invalid argument was specified.