我阅读了这些man
页面,我的理解是,如果write()
失败并将 to 设置errno
为EAGAIN
or EINTR
,我可能会write()
再次执行,所以我想出了以下代码:
ret = 0;
while(ret != count) {
write_count = write(connFD, (char *)buf + ret, count);
while (write_count < 0) {
switch(errno) {
case EINTR:
case EAGAIN:
write_count = write(connFD, (char *)buf + ret, count -ret);
break;
default:
printf("\n The value of ret is : %d\n", ret);
printf("\n The error number is : %d\n", errno);
ASSERT(0);
}
}
ret += write_count;
}
我正在执行read()
和write()
处理套接字并处理与read()
上述类似的事情。我正在使用带有gcc
编译器的 Linux。