이 메소드는 데이터를 수신하도록 소켓을 대기합니다.
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;
}