@@ -572,61 +572,55 @@ ServerWait(dpy, w, endCond, endData, localLoop, seconds)
572572{
573573 time_t start ;
574574 time_t now ;
575- time_t lastChk = 0 ;
576575 XEvent event ;
577- XPropertyEvent * e = (XPropertyEvent * )& event ;
578- # define SEND_MSEC_POLL 50
576+
577+ #define UI_MSEC_DELAY 50
578+ #define SEND_MSEC_POLL 500
579+ #ifndef HAVE_SELECT
580+ struct pollfd fds ;
581+
582+ fds .fd = ConnectionNumber (dpy );
583+ fds .events = POLLIN ;
584+ #else
585+ fd_set fds ;
586+ struct timeval tv ;
587+
588+ tv .tv_sec = 0 ;
589+ tv .tv_usec = SEND_MSEC_POLL * 1000 ;
590+ FD_ZERO (& fds );
591+ FD_SET (ConnectionNumber (dpy ), & fds );
592+ #endif
579593
580594 time (& start );
581- while (endCond ( endData ) == 0 )
595+ while (TRUE )
582596 {
597+ while (XCheckWindowEvent (dpy , commWindow , PropertyChangeMask , & event ))
598+ serverEventProc (dpy , & event );
599+
600+ if (endCond (endData ) != 0 )
601+ break ;
602+ if (!WindowValid (dpy , w ))
603+ break ;
583604 time (& now );
584605 if (seconds >= 0 && (now - start ) >= seconds )
585606 break ;
586- if (now != lastChk )
587- {
588- lastChk = now ;
589- if (!WindowValid (dpy , w ))
590- break ;
591- /*
592- * Sometimes the PropertyChange event doesn't come.
593- * This can be seen in eg: vim -c 'echo remote_expr("gvim", "3+2")'
594- */
595- serverEventProc (dpy , NULL );
596- }
607+
608+ /* Just look out for the answer without calling back into Vim */
597609 if (localLoop )
598610 {
599- /* Just look out for the answer without calling back into Vim */
600611#ifndef HAVE_SELECT
601- struct pollfd fds ;
602-
603- fds .fd = ConnectionNumber (dpy );
604- fds .events = POLLIN ;
605612 if (poll (& fds , 1 , SEND_MSEC_POLL ) < 0 )
606613 break ;
607614#else
608- fd_set fds ;
609- struct timeval tv ;
610-
611- tv .tv_sec = 0 ;
612- tv .tv_usec = SEND_MSEC_POLL * 1000 ;
613- FD_ZERO (& fds );
614- FD_SET (ConnectionNumber (dpy ), & fds );
615- if (select (ConnectionNumber (dpy ) + 1 , & fds , NULL , NULL , & tv ) < 0 )
615+ if (select (FD_SETSIZE , & fds , NULL , NULL , & tv ) < 0 )
616616 break ;
617617#endif
618- while (XEventsQueued (dpy , QueuedAfterReading ) > 0 )
619- {
620- XNextEvent (dpy , & event );
621- if (event .type == PropertyNotify && e -> window == commWindow )
622- serverEventProc (dpy , & event );
623- }
624618 }
625619 else
626620 {
627621 if (got_int )
628622 break ;
629- ui_delay ((long )SEND_MSEC_POLL , TRUE);
623+ ui_delay ((long )UI_MSEC_DELAY , TRUE);
630624 ui_breakcheck ();
631625 }
632626 }
0 commit comments