@@ -249,7 +249,11 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
249249rfbBool
250250WriteToRFBServer (rfbClient * client , const char * buf , unsigned int n )
251251{
252+ #ifdef LIBVNCSERVER_HAVE_POLL
253+ struct pollfd pfd ;
254+ #else
252255 fd_set fds ;
256+ #endif
253257 int i = 0 ;
254258 int j ;
255259 const char * obuf = buf ;
@@ -296,13 +300,26 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n)
296300 errno == ENOENT ||
297301#endif
298302 errno == EAGAIN ) {
303+ #ifdef LIBVNCSERVER_HAVE_POLL
304+ struct pollfd pfd ;
305+ pfd .fd = client -> sock ;
306+ pfd .events = POLLOUT ;
307+
308+ if (poll (& pfd , 1 , -1 ) <= 0 ) {
309+ if ((pfd .revents & POLLERR ) || (pfd .revents & POLLHUP )) {
310+ rfbClientErr ("poll\n" );
311+ return FALSE;
312+ }
313+ }
314+ #else
299315 FD_ZERO (& fds );
300316 FD_SET (client -> sock ,& fds );
301317
302318 if (select (client -> sock + 1 , NULL , & fds , NULL , NULL ) <= 0 ) {
303319 rfbClientErr ("select\n" );
304320 return FALSE;
305321 }
322+ #endif
306323 j = 0 ;
307324 } else {
308325 rfbClientErr ("write\n" );
@@ -847,21 +864,33 @@ PrintInHex(char *buf, int len)
847864
848865int WaitForMessage (rfbClient * client ,unsigned int usecs )
849866{
867+ #ifdef LIBVNCSERVER_HAVE_POLL
868+ struct pollfd pfd ;
869+ #else
850870 fd_set fds ;
851871 struct timeval timeout ;
872+ #endif
852873 int num ;
853874
854875 if (client -> serverPort == -1 )
855876 /* playing back vncrec file */
856877 return 1 ;
857878
879+ #ifdef LIBVNCSERVER_HAVE_POLL
880+ pfd .fd = client -> sock ;
881+ pfd .events = POLLIN | POLLPRI ;
882+ num = poll (& pfd , 1 , usecs /1000 );
883+ if ((pfd .revents & POLLERR ) || (pfd .revents & POLLHUP ))
884+ return -1 ;
885+ #else
858886 timeout .tv_sec = (usecs /1000000 );
859887 timeout .tv_usec = (usecs %1000000 );
860888
861889 FD_ZERO (& fds );
862890 FD_SET (client -> sock ,& fds );
863891
864892 num = select (client -> sock + 1 , & fds , NULL , NULL , & timeout );
893+ #endif
865894 if (num < 0 ) {
866895#ifdef WIN32
867896 errno = WSAGetLastError ();
0 commit comments