Skip to content

Commit da94fdf

Browse files
committed
patch 7.4.1482
Problem: "timeout" option not supported on ch_send*() and ch_eval*(). Solution: Get and use the timeout option from the argument.
1 parent 9f7820f commit da94fdf

3 files changed

Lines changed: 28 additions & 19 deletions

File tree

src/eval.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10518,15 +10518,15 @@ f_ch_readraw(typval_T *argvars, typval_T *rettv)
1051810518
*/
1051910519
static channel_T *
1052010520
send_common(
10521-
typval_T *argvars,
10522-
char_u *text,
10523-
int id,
10524-
int eval,
10525-
char *fun,
10526-
int *part_read)
10521+
typval_T *argvars,
10522+
char_u *text,
10523+
int id,
10524+
int eval,
10525+
jobopt_T *opt,
10526+
char *fun,
10527+
int *part_read)
1052710528
{
1052810529
channel_T *channel;
10529-
jobopt_T opt;
1053010530
int part_send;
1053110531

1053210532
channel = get_channel_arg(&argvars[0]);
@@ -10535,25 +10535,25 @@ send_common(
1053510535
part_send = channel_part_send(channel);
1053610536
*part_read = channel_part_read(channel);
1053710537

10538-
clear_job_options(&opt);
10539-
if (get_job_options(&argvars[2], &opt, JO_CALLBACK) == FAIL)
10538+
clear_job_options(opt);
10539+
if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT) == FAIL)
1054010540
return NULL;
1054110541

1054210542
/* Set the callback. An empty callback means no callback and not reading
1054310543
* the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not
1054410544
* allowed. */
10545-
if (opt.jo_callback != NULL && *opt.jo_callback != NUL)
10545+
if (opt->jo_callback != NULL && *opt->jo_callback != NUL)
1054610546
{
1054710547
if (eval)
1054810548
{
1054910549
EMSG2(_("E917: Cannot use a callback with %s()"), fun);
1055010550
return NULL;
1055110551
}
10552-
channel_set_req_callback(channel, part_send, opt.jo_callback, id);
10552+
channel_set_req_callback(channel, part_send, opt->jo_callback, id);
1055310553
}
1055410554

1055510555
if (channel_send(channel, part_send, text, fun) == OK
10556-
&& opt.jo_callback == NULL)
10556+
&& opt->jo_callback == NULL)
1055710557
return channel;
1055810558
return NULL;
1055910559
}
@@ -10571,6 +10571,7 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
1057110571
ch_mode_T ch_mode;
1057210572
int part_send;
1057310573
int part_read;
10574+
jobopt_T opt;
1057410575
int timeout;
1057510576

1057610577
/* return an empty string by default */
@@ -10595,12 +10596,15 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
1059510596
if (text == NULL)
1059610597
return;
1059710598

10598-
channel = send_common(argvars, text, id, eval,
10599+
channel = send_common(argvars, text, id, eval, &opt,
1059910600
eval ? "ch_evalexpr" : "ch_sendexpr", &part_read);
1060010601
vim_free(text);
1060110602
if (channel != NULL && eval)
1060210603
{
10603-
/* TODO: timeout from options */
10604+
if (opt.jo_set & JO_TIMEOUT)
10605+
timeout = opt.jo_timeout;
10606+
else
10607+
timeout = channel_get_timeout(channel, part_read);
1060410608
timeout = channel_get_timeout(channel, part_read);
1060510609
if (channel_read_json_block(channel, part_read, timeout, id, &listtv)
1060610610
== OK)
@@ -10644,19 +10648,22 @@ ch_raw_common(typval_T *argvars, typval_T *rettv, int eval)
1064410648
char_u *text;
1064510649
channel_T *channel;
1064610650
int part_read;
10651+
jobopt_T opt;
1064710652
int timeout;
1064810653

1064910654
/* return an empty string by default */
1065010655
rettv->v_type = VAR_STRING;
1065110656
rettv->vval.v_string = NULL;
1065210657

1065310658
text = get_tv_string_buf(&argvars[1], buf);
10654-
channel = send_common(argvars, text, 0, eval,
10659+
channel = send_common(argvars, text, 0, eval, &opt,
1065510660
eval ? "ch_evalraw" : "ch_sendraw", &part_read);
1065610661
if (channel != NULL && eval)
1065710662
{
10658-
/* TODO: timeout from options */
10659-
timeout = channel_get_timeout(channel, part_read);
10663+
if (opt.jo_set & JO_TIMEOUT)
10664+
timeout = opt.jo_timeout;
10665+
else
10666+
timeout = channel_get_timeout(channel, part_read);
1066010667
rettv->vval.v_string = channel_read_block(channel, part_read, timeout);
1066110668
}
1066210669
}

src/testdir/test_channel.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func s:communicate(port)
120120
call assert_equal('added1', getline(line('$') - 1))
121121
call assert_equal('added2', getline('$'))
122122

123-
call assert_equal('ok', ch_evalexpr(handle, 'do normal'))
123+
call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
124124
sleep 10m
125125
call assert_equal('added more', getline('$'))
126126

@@ -342,7 +342,7 @@ func Test_raw_pipe()
342342
let msg = ch_readraw(handle)
343343
call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g'))
344344

345-
let reply = ch_evalraw(handle, "quit\n")
345+
let reply = ch_evalraw(handle, "quit\n", {'timeout': 100})
346346
call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
347347
finally
348348
call job_stop(job)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ static char *(features[]) =
743743

744744
static int included_patches[] =
745745
{ /* Add new patch number below this line */
746+
/**/
747+
1482,
746748
/**/
747749
1481,
748750
/**/

0 commit comments

Comments
 (0)