receive

此方法用于等待套接字以接收数据。

特征符
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;
}

反馈