fix poll
This commit is contained in:
parent
226a0fbdc6
commit
aaeba28fb8
@ -24,7 +24,7 @@ int getBufferSizeFrom(int sock){
|
||||
|
||||
ssize_t timeout_recv(int fd,void * buf,size_t n,int timeout)
|
||||
{
|
||||
ssize_t ret;
|
||||
ssize_t ret = 0;
|
||||
int poll_ret;
|
||||
struct pollfd fd_single;
|
||||
fd_single.fd = fd;
|
||||
@ -32,19 +32,15 @@ ssize_t timeout_recv(int fd,void * buf,size_t n,int timeout)
|
||||
poll_ret = (poll(&fd_single,1,timeout * 1000));
|
||||
if (poll_ret < 0) return -1;
|
||||
else if(poll_ret == 0) return -2;
|
||||
switch (fd_single.revents){
|
||||
case POLLHUP: //We'll treat hangups state like timeouts state.
|
||||
if (fd_single.revents & POLLHUP) //We'll treat hangups state like timeouts state.
|
||||
return -2;
|
||||
case POLLERR:
|
||||
case POLLNVAL:
|
||||
if ((fd_single.revents & POLLERR) || (fd_single.revents & POLLNVAL))
|
||||
return -1;
|
||||
case POLL_IN:
|
||||
if (fd_single.revents & POLL_IN)
|
||||
ret = recv(fd,buf,n,0);
|
||||
assert(ret != 0);
|
||||
return ret;
|
||||
default:
|
||||
assert(0 && "unreachable");
|
||||
}
|
||||
|
||||
assert(0 && "unreachable");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user