@@ -647,9 +647,8 @@ channel_open(
647647 */
648648 while (TRUE)
649649 {
650- #ifndef WIN32
651- long elapsed_msec = 0 ;
652- #endif
650+ long elapsed_msec = 0 ;
651+ int waitnow ;
653652
654653 if (sd >= 0 )
655654 sock_close (sd );
@@ -707,7 +706,7 @@ channel_open(
707706 }
708707
709708 /* If connect() didn't finish then try using select() to wait for the
710- * connection to be made. */
709+ * connection to be made. For Win32 always use select() to wait. */
711710#ifndef WIN32
712711 if (errno != ECONNREFUSED )
713712#endif
@@ -721,19 +720,22 @@ channel_open(
721720 struct timeval start_tv ;
722721 struct timeval end_tv ;
723722#endif
723+ /* Limit the waittime to 50 msec. If it doesn't work within this
724+ * time we close the socket and try creating it again. */
725+ waitnow = waittime > 50 ? 50 : waittime ;
724726
725727 FD_ZERO (& rfds );
726728 FD_SET (sd , & rfds );
727729 FD_ZERO (& wfds );
728730 FD_SET (sd , & wfds );
729731
730- tv .tv_sec = waittime / 1000 ;
731- tv .tv_usec = (waittime % 1000 ) * 1000 ;
732+ tv .tv_sec = waitnow / 1000 ;
733+ tv .tv_usec = (waitnow % 1000 ) * 1000 ;
732734#ifndef WIN32
733735 gettimeofday (& start_tv , NULL );
734736#endif
735737 ch_logn (channel ,
736- "Waiting for connection (waittime %d msec)..." , waittime );
738+ "Waiting for connection (waiting %d msec)..." , waitnow );
737739 ret = select ((int )sd + 1 , & rfds , & wfds , NULL , & tv );
738740
739741 if (ret < 0 )
@@ -748,10 +750,16 @@ channel_open(
748750 }
749751
750752#ifdef WIN32
751- /* On Win32: select() is expected to work and wait for up to the
752- * waittime for the socket to be open. */
753+ /* On Win32: select() is expected to work and wait for up to
754+ * "waitnow" msec for the socket to be open. */
753755 if (FD_ISSET (sd , & wfds ))
754756 break ;
757+ elapsed_msec = waitnow ;
758+ if (waittime > 1 && elapsed_msec < waittime )
759+ {
760+ waittime -= elapsed_msec ;
761+ continue ;
762+ }
755763#else
756764 /* On Linux-like systems: See socket(7) for the behavior
757765 * After putting the socket in non-blocking mode, connect() will
@@ -797,17 +805,20 @@ channel_open(
797805 {
798806 /* The port isn't ready but we also didn't get an error.
799807 * This happens when the server didn't open the socket
800- * yet. Wait a bit and try again. */
801- mch_delay (waittime < 50 ? (long )waittime : 50L , TRUE);
802- ui_breakcheck ();
808+ * yet. Select() may return early, wait until the remaining
809+ * "waitnow" and try again. */
810+ waitnow -= elapsed_msec ;
811+ waittime -= elapsed_msec ;
812+ if (waitnow > 0 )
813+ {
814+ mch_delay ((long )waitnow , TRUE);
815+ ui_breakcheck ();
816+ waittime -= waitnow ;
817+ }
803818 if (!got_int )
804819 {
805- /* reduce the waittime by the elapsed time and the 50
806- * msec delay (or a bit more) */
807- waittime -= elapsed_msec ;
808- if (waittime > 50 )
809- waittime -= 50 ;
810- else
820+ if (waittime <= 0 )
821+ /* give it one more try */
811822 waittime = 1 ;
812823 continue ;
813824 }
@@ -995,7 +1006,11 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
9951006 /* writing output to a buffer. Default mode is NL. */
9961007 if (!(opt -> jo_set & JO_OUT_MODE ))
9971008 channel -> ch_part [PART_OUT ].ch_mode = MODE_NL ;
998- channel -> ch_part [PART_OUT ].ch_buffer =
1009+ if (opt -> jo_set & JO_OUT_BUF )
1010+ channel -> ch_part [PART_OUT ].ch_buffer =
1011+ buflist_findnr (opt -> jo_io_buf [PART_OUT ]);
1012+ else
1013+ channel -> ch_part [PART_OUT ].ch_buffer =
9991014 find_buffer (opt -> jo_io_name [PART_OUT ], FALSE);
10001015 ch_logs (channel , "writing out to buffer '%s'" ,
10011016 (char * )channel -> ch_part [PART_OUT ].ch_buffer -> b_ffname );
@@ -1011,6 +1026,9 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
10111026 if (opt -> jo_io [PART_ERR ] == JIO_OUT )
10121027 channel -> ch_part [PART_ERR ].ch_buffer =
10131028 channel -> ch_part [PART_OUT ].ch_buffer ;
1029+ else if (opt -> jo_set & JO_ERR_BUF )
1030+ channel -> ch_part [PART_ERR ].ch_buffer =
1031+ buflist_findnr (opt -> jo_io_buf [PART_ERR ]);
10141032 else
10151033 channel -> ch_part [PART_ERR ].ch_buffer =
10161034 find_buffer (opt -> jo_io_name [PART_ERR ], TRUE);
0 commit comments