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 timeout_recv(int fd,void * buf,size_t n,int timeout)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret = 0;
|
||||||
int poll_ret;
|
int poll_ret;
|
||||||
struct pollfd fd_single;
|
struct pollfd fd_single;
|
||||||
fd_single.fd = fd;
|
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));
|
poll_ret = (poll(&fd_single,1,timeout * 1000));
|
||||||
if (poll_ret < 0) return -1;
|
if (poll_ret < 0) return -1;
|
||||||
else if(poll_ret == 0) return -2;
|
else if(poll_ret == 0) return -2;
|
||||||
switch (fd_single.revents){
|
if (fd_single.revents & POLLHUP) //We'll treat hangups state like timeouts state.
|
||||||
case POLLHUP: //We'll treat hangups state like timeouts state.
|
|
||||||
return -2;
|
return -2;
|
||||||
case POLLERR:
|
if ((fd_single.revents & POLLERR) || (fd_single.revents & POLLNVAL))
|
||||||
case POLLNVAL:
|
|
||||||
return -1;
|
return -1;
|
||||||
case POLL_IN:
|
if (fd_single.revents & POLL_IN)
|
||||||
ret = recv(fd,buf,n,0);
|
ret = recv(fd,buf,n,0);
|
||||||
assert(ret != 0);
|
assert(ret != 0);
|
||||||
return ret;
|
return ret;
|
||||||
default:
|
|
||||||
assert(0 && "unreachable");
|
|
||||||
}
|
|
||||||
assert(0 && "unreachable");
|
assert(0 && "unreachable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user