Jam*_*mie 2 c sockets linux io
这段代码在Linux上运行:
int r, c;
...
assert(0 == (O_NONBLOCK & fcntl(sockfd, F_GETFL, 0)));
errno = 0;
r = read(sockfd, &c, 1);
if (r == 0 && errno == 0) {
printf("What gives?\n");
}
...
Run Code Online (Sandbox Code Playgroud)
从套接字执行读操作,偶尔会返回零(in r)并将errnoset设置为零(0).我遇到什么情况?除非出现错误,否则我真的想要读取块.