簽章int RiCOSSocket_receive (RiCOSSocket *const me,
char *buf, int bufLen);
參數me
RiCOSSocket 物件
buf
要儲存資料的字串緩衝區
bufLen
緩衝區的長度
範例int 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;
}