This method waits on the
socket to receive the data.
Signatureint RiCOSSocket_receive (RiCOSSocket *const me,
char *buf, int bufLen);
Parametersme
The RiCOSSocket object
buf
The string buffer in which data will
be stored
bufLen
The length of the buffer
ReturnsThe
method returns one of the following values:
- 0 - There was an error.
- n - The number of bytes read.
Exampleint RiCOSSocket_receive(RiCOSSocket * const me,
char * buf, int bufLen)
{
int bytes_read = 0;
int n;
if (me==NULL) return -1;
while (bytes_read < bufLen) {
n = recv(me->theSock, buf + bytes_read,
bufLen - bytes_read,0);
if (SOCKET_ERROR == n) {
if (errno == EINTR) {
continue;
}
else {
return -1;
}
}
else {
if (0 == n) { /* Connection closed. */
return -1;
}
}
bytes_read += n;
}
return bytes_read;
}