Created
July 21, 2015 06:17
-
-
Save ixqbar/b14ef7d3df691819c0f9 to your computer and use it in GitHub Desktop.
socket读取
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while(1){ | |
int ret = read(fd, buf, len); | |
if(ret == -1){ | |
if(errno == EINTR){ | |
continue; | |
}else if(errno == EAGAIN){ | |
// 根据你和调用者的约定, 返回一个数值告诉它再次重试 | |
// 一般是结合 select/epoll 等 IO 多路复用函数 | |
} | |
exit(-1); | |
}else if(ret == 0){ | |
close(fd); | |
} | |
// proc | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment