Sockets Programming Interfaces
3-27
Sockets and Stream IO API
Receive Data and Sender’s Name from Socket without Buffer Copy
recvncfrom
Syntax
int recvncfrom( int s, void **ppbuf, int flags, HANDLE *phBuffer, PSA pName,
int *plen );
Parameter(s)
s
Socket
ppbuf
Pointer to receive data buffer pointer
flags
Option flags
phBuffer
Pointer to receive buffer handle
pName
Pointer to place name (address) of sender
plen
Pointer to size of pName
Return Value
If it succeeds, the function returns the number of bytes received. Otherwise,
a value of –1 is returned and the function fdError() can be called to determine
the error:
EBADF
The file descriptor (socket) is invalid.
ENOTSOCK
The file descriptor does not reference a socket.
ENOTCONN
The socket is connection oriented and not con-
nected.
Description
The recvfrom() function attempts to receive a data buffer from a socket. It is
normally called with unconnected, non-connection oriented sockets. A pointer
to the data buffer is returned in ppbuf. A system handle used to free the buffer
is returned in phBuffer. Both of these pointers must be valid. The options in
flags can be used to change the default behavior of the operation. The name
(address) of the sender is written to pName.
The argument pName is a result parameter that is filled in with the address of
the sending entity as known to the communications layer. The domain in which
the communication is occurring determines the exact format of the pName pa-
rameter. The plen is a value-result parameter; it should initially contain at least
sizeof( struct sockaddr ), the amount of space pointed to by pName; on return
it will contain the actual length (in bytes) of the address returned.
The functions returns the length of the message on successful completion.
The receive operation always returns one packet buffer. The caller has no con-
trol over the size of the data returned in this buffer.
If no messages are available at the socket, this call waits for a message to ar-
rive, unless the socket is non-blocking. The function returns the data buffer
available.
When the caller no longer needs the data buffer, it is returned to the system
by calling recvncfree(). Repeated failure to free buffers will eventually cause
the stack to stop receiving data.