receive

此方法在 Socket 上等待接收資料。

簽章
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;
}

意見回饋