From ce9db42c23b3619ce92007a4b08800403fa1830b Mon Sep 17 00:00:00 2001
From: Benjamin Sergeant <bsergean@gmail.com>
Date: Thu, 9 Jan 2020 12:26:57 -0800
Subject: [PATCH] socket polling / handle more error case such as hanged socket

---
 ixwebsocket/IXSocket.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp
index e7be5e9e..cd6a2016 100644
--- a/ixwebsocket/IXSocket.cpp
+++ b/ixwebsocket/IXSocket.cpp
@@ -54,11 +54,12 @@ namespace ix
         // to ::poll does fix that.
         //
         // 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.
         //
         nfds_t nfds = 1;
         struct pollfd fds[2];
+        memset(fds, 0 , sizeof(fds));
 
         fds[0].fd = sockfd;
         fds[0].events = (readyToRead) ? POLLIN : POLLOUT;
@@ -132,6 +133,10 @@ namespace ix
             }
 #endif
         }
+        else if (sockfd != -1 && (fds[0].revents & POLLERR || fds[0].revents & POLLHUP))
+        {
+            pollResult = PollResultType::Error;
+        }
 
         return pollResult;
     }