socket polling / handle more error case such as hanged socket
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user