accept_and_recv()
The accept_and_recv( ) API accepts a connection on a socket, receives the
first message from the connected client, and returns the local and peer
addresses.
Syntax
#include <types.h>
#include <sys\socket.h>
#include <netinet\in.h>
#include <sys\time.h>
int accpet_and_recv(s,&sock_accex,&cli_addr,&cli_len,&local,&locallen,outbuff,alloc)
int s;
long sock_accex;
struct sockaddr_in cli_addr;
long cli_len;
struct sockaddr_in local;
long locallen;
char * outbuff;
int alloc;
Parameters
s
Socket descriptor of the listening socket.
sock_accex
Pointer
to an int that specifies the socket on which to accept the connection. This
pointer should be initialized to -1 so that the kernel accepts the socket
and returns this pointer to the application using this parameter.
cli_addr
Pointer to a sockaddr structure where the address
of the connecting socket will be returned.
cli_len
Pointer to a socklen_t that, on output, specifies
the length of the stored address.
local_addr
Pointer to a sockaddr structure where the address
of the connecting socket will be returned.
locallen
Pointer to a socklen_t that, on, output specifies
the length of the stored address.
outbuff
Pointer
to the buffer where the message should be stored.
alloc
Length in bytes of the buffer pointed to by
the buffer argument.
Description
The accept_and_recv( ) call combines the socket functions accept( ) and
recv( ) into a single API transition. The accept_and_recv( ) function accepts
a new connection, receives the first block of data from the client and returns
the local and remote addresses to the application. The thread sleeping on
accept_and_recv( ) wakes-up only after it gets the first data block from
the client.
Return Values
The total number of bytes received in the receive buffer associated with
the accept_and_recv() is returned upon successful completion and a value
of -1 is returned in case of an error.
Error Code
EBADF
Thesockfdorthesock
_ accexisnotavaliddescriptor .
ECONNABORTED
Aconnectionhasbeenended
.
ECONNRESET
Aconnectionwasforciblyclosedbyapeer
.
EFAULT
Thebufferpointedtobysock
_ accex , cli _ addr ,clilen ,local ,locallenorbufferwasnotvalid .
EISCONN
Thesock
_ accexiseitherboundoralreadyconnected .
ENOTSOCK
Thesockfdorthesock
_ accexargumentdoesnotrefertoasocket .
EOPNOTSUPP
ThesockettypeofthespecifiedsocketdoesnotsupportacceptingconnectionsortheO
_ NONBLOCKissetforthissocketandnon - blockingisnotsupportedforthisfunction
,orthe accept _ and _ recv ()functionisnotsupportedbythisversionofTCP
/ IP .
ENOREUSE
Socketreuseisnotsupported
.
EINTR
Theaccept _ and _
recv ()functionwasinterruptedbyasignalthatwascaughtbeforeavalidconnectionarrived
.
EINTRNODATA
Theaccept _
and _ recv ()functionwasinterruptedbyasignalthatwascaughtafteravalidconnectionarrivedbutbeforethefirstblockofdata
.
EINVAL
Thesockfdisnotacceptingconnections
.
EMFILE
{ OPEN _ MAX }descriptorsarecurrentlyopeninthecallingprocess
.
ENFILE
Themaximumnumberofdescriptorsinthesystemarealreadyopen
.
EIO
ENOBUFS
ENOMEM
Therewasinsufficientmemoryavailabletocompletetheoperation
.
EPROTO
ENOSR
ThereareinsufficientSTREAMSresourcesavailablefortheoperationtocomplete
.
Related Calls
[Back: accept()]
[Next: addsockettolist()]