此方法會透過 Socket 傳送資料。
int RiCOSSocket_send (RiCOSSocket *const me,
const char *buf, int bufLen);
me
RiCOSSocket 物件
buf
包含要傳送資料的常數字串緩衝區
bufLen
緩衝區的長度
此方法會傳回下列其中一項值:
int RiCOSSocket_send(RiCOSSocket * const me,
const char * buf, int bufLen)
{
int bytes_writ = 0;
int n;
if (me==NULL) return -1;
while (bytes_writ < bufLen) {
n = send(me->theSock, (char *)(buf + bytes_writ),
bufLen - bytes_writ, 0);
if (SOCKET_ERROR == n) {
if (errno == EINTR) {
continue;
}
else {
return -1;
}
}
bytes_writ += n;
}
return bytes_writ;
}