69,374
社区成员
发帖
与我相关
我的任务
分享
int MyTcpRcv(int sockfd, char *buffer, int length)
{
int len=0;
int totalcnt;
totalcnt = 0;
while(totalcnt < length) {
len = read(sockfd, buffer + totalcnt, length - totalcnt);
if (len < 0) {
if ((errno == EINTR)||(errno == [EAGAIN)) {
len = 0;
break;
}
else
{
return(-1);
}
}
else if (len == 0)
{
break;
}
totalcnt = totalcnt + len;
}
return(totalcnt);
}