Skip to content

Instantly share code, notes, and snippets.

@ixqbar
Created July 21, 2015 06:17
Show Gist options
  • Save ixqbar/b14ef7d3df691819c0f9 to your computer and use it in GitHub Desktop.
Save ixqbar/b14ef7d3df691819c0f9 to your computer and use it in GitHub Desktop.
socket读取
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