socket polling / handle more error case such as hanged socket
This commit is contained in:
parent
a844dbc587
commit
ce9db42c23
@ -54,11 +54,12 @@ namespace ix
|
|||||||
// to ::poll does fix that.
|
// to ::poll does fix that.
|
||||||
//
|
//
|
||||||
// However poll isn't as portable as select and has bugs on Windows, so we
|
// However poll isn't as portable as select and has bugs on Windows, so we
|
||||||
// should write a shim to fallback to select on those platforms. See
|
// have a shim to fallback to select on those platforms. See
|
||||||
// https://github.com/mpv-player/mpv/pull/5203/files for such a select wrapper.
|
// https://github.com/mpv-player/mpv/pull/5203/files for such a select wrapper.
|
||||||
//
|
//
|
||||||
nfds_t nfds = 1;
|
nfds_t nfds = 1;
|
||||||
struct pollfd fds[2];
|
struct pollfd fds[2];
|
||||||
|
memset(fds, 0 , sizeof(fds));
|
||||||
|
|
||||||
fds[0].fd = sockfd;
|
fds[0].fd = sockfd;
|
||||||
fds[0].events = (readyToRead) ? POLLIN : POLLOUT;
|
fds[0].events = (readyToRead) ? POLLIN : POLLOUT;
|
||||||
@ -132,6 +133,10 @@ namespace ix
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else if (sockfd != -1 && (fds[0].revents & POLLERR || fds[0].revents & POLLHUP))
|
||||||
|
{
|
||||||
|
pollResult = PollResultType::Error;
|
||||||
|
}
|
||||||
|
|
||||||
return pollResult;
|
return pollResult;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user