基于Socket的网络通讯方式,其I/O方式,由下面几种:
•blocking I/O
•
nonblocking
I/O
•
I/O multiplexing (select and poll)
非阻塞模式情况下,等待的资源未就位,呼叫函数就直接返回,查看系统errno,应该是WOULDBLOCK_ERR
|
|
{
if ((now = send(_peer, (char *)pos, size, 0)) == SOCKET_ERROR)
{
int err = sock_error();
#if 1
if (err == WOULDBLOCK_ERR) {;
usleep(1); // sleep, waiting; Try again, after OS sent packet in the send queue
continue;
}
#else
if (err == WOULDBLOCK_ERR) {;
break; // Don’t wait, break; So the send data is truncated
}
#endif
if (err == SHUTDOWN_ERR) {
throw DisconnectedException();
}
if (err == INTERRUPTED_ERR) {
continue;
}
THROW_ERR(ERROR_CODE_SEND_FAILED, "%s (%d)", sock_err_message(err), err);
}
size -= now;
pos += now;
}
| |