Fixed problem with is_socket_alive

This commit is contained in:
yhirose 2021-12-14 17:29:50 -05:00
parent 4a9da530d3
commit fb6c4cdfb4

View file

@ -2338,9 +2338,11 @@ inline bool wait_until_socket_is_ready(socket_t sock, time_t sec, time_t usec) {
}
inline bool is_socket_alive(socket_t sock) {
if (detail::select_read(sock, 0, 0) == 0) {
return true;
}
char buf[1];
return detail::select_read(sock, 0, 0) &&
recv(sock, &buf[0], sizeof(buf), MSG_PEEK) != 0;
return recv(sock, &buf[0], sizeof(buf), MSG_PEEK) > 0;
}
class SocketStream : public Stream {