Metrologic Optimus S Programming Manual page 161

"c" programming guide
Table of Contents

Advertisement

recv
Purpose
To receive data from a connected or bound socket.
Syntax
int recv (SOCKET s, char *buf, int len, int flags);
s
buf
len
flags
Example
SOCKET s;
char buf[1024];
int len;
...................
if (socket_hasdata (s)) {
}
Description
This routine reads incoming data from a specified buffer (buf) on a connected
socket.
The select() routine may be used to determine when more data arrives. (?)
Note that this is a blocking function. This routine will not return unless for the
following reason:
The application can avoid this blocking behavior by using socket_hasdata() to
make sure there is data available before calling recv().
Return
If successful, it returns a non-negative integer (>=0) indicating the number of
bytes received and stored into buffer.
On error, it returns -1.
The global variable errno is set to indicate the error condition encountered.
Chapter 3 Terminal Specific Function Library
Descriptor identifying a connected socket
Pointer to the buffer in which data is received
Maximum number of bytes to be received
MSG_OOB: process out-of-band data
MSG_PEEK: peek at incoming data
len = recv (s, buf, sizeof (buf), 0);
if (len < 0) {
printf ("recv fails on socket: %d", s);
...................
}
The flags argument allows one of the following values:
MSG_OOB
returns urgent data (out-of-bound data)
MSG_PEEK
returns data but do not remove it from buffer,
allowing it to be read again on subsequent calls
an error happens
data is received
the receive action times out
155

Advertisement

Table of Contents
loading

This manual is also suitable for:

Optimus r

Table of Contents