0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2016-03-03 18:09:10 +01:00
parent 9f7820f83b
commit da94fdf258
3 changed files with 28 additions and 19 deletions

View File

@@ -10518,15 +10518,15 @@ f_ch_readraw(typval_T *argvars, typval_T *rettv)
*/ */
static channel_T * static channel_T *
send_common( send_common(
typval_T *argvars, typval_T *argvars,
char_u *text, char_u *text,
int id, int id,
int eval, int eval,
char *fun, jobopt_T *opt,
int *part_read) char *fun,
int *part_read)
{ {
channel_T *channel; channel_T *channel;
jobopt_T opt;
int part_send; int part_send;
channel = get_channel_arg(&argvars[0]); channel = get_channel_arg(&argvars[0]);
@@ -10535,25 +10535,25 @@ send_common(
part_send = channel_part_send(channel); part_send = channel_part_send(channel);
*part_read = channel_part_read(channel); *part_read = channel_part_read(channel);
clear_job_options(&opt); clear_job_options(opt);
if (get_job_options(&argvars[2], &opt, JO_CALLBACK) == FAIL) if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT) == FAIL)
return NULL; return NULL;
/* Set the callback. An empty callback means no callback and not reading /* Set the callback. An empty callback means no callback and not reading
* the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not * the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not
* allowed. */ * allowed. */
if (opt.jo_callback != NULL && *opt.jo_callback != NUL) if (opt->jo_callback != NULL && *opt->jo_callback != NUL)
{ {
if (eval) if (eval)
{ {
EMSG2(_("E917: Cannot use a callback with %s()"), fun); EMSG2(_("E917: Cannot use a callback with %s()"), fun);
return NULL; return NULL;
} }
channel_set_req_callback(channel, part_send, opt.jo_callback, id); channel_set_req_callback(channel, part_send, opt->jo_callback, id);
} }
if (channel_send(channel, part_send, text, fun) == OK if (channel_send(channel, part_send, text, fun) == OK
&& opt.jo_callback == NULL) && opt->jo_callback == NULL)
return channel; return channel;
return NULL; return NULL;
} }
@@ -10571,6 +10571,7 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
ch_mode_T ch_mode; ch_mode_T ch_mode;
int part_send; int part_send;
int part_read; int part_read;
jobopt_T opt;
int timeout; int timeout;
/* return an empty string by default */ /* return an empty string by default */
@@ -10595,12 +10596,15 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
if (text == NULL) if (text == NULL)
return; return;
channel = send_common(argvars, text, id, eval, channel = send_common(argvars, text, id, eval, &opt,
eval ? "ch_evalexpr" : "ch_sendexpr", &part_read); eval ? "ch_evalexpr" : "ch_sendexpr", &part_read);
vim_free(text); vim_free(text);
if (channel != NULL && eval) if (channel != NULL && eval)
{ {
/* TODO: timeout from options */ if (opt.jo_set & JO_TIMEOUT)
timeout = opt.jo_timeout;
else
timeout = channel_get_timeout(channel, part_read);
timeout = channel_get_timeout(channel, part_read); timeout = channel_get_timeout(channel, part_read);
if (channel_read_json_block(channel, part_read, timeout, id, &listtv) if (channel_read_json_block(channel, part_read, timeout, id, &listtv)
== OK) == OK)
@@ -10644,6 +10648,7 @@ ch_raw_common(typval_T *argvars, typval_T *rettv, int eval)
char_u *text; char_u *text;
channel_T *channel; channel_T *channel;
int part_read; int part_read;
jobopt_T opt;
int timeout; int timeout;
/* return an empty string by default */ /* return an empty string by default */
@@ -10651,12 +10656,14 @@ ch_raw_common(typval_T *argvars, typval_T *rettv, int eval)
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
text = get_tv_string_buf(&argvars[1], buf); text = get_tv_string_buf(&argvars[1], buf);
channel = send_common(argvars, text, 0, eval, channel = send_common(argvars, text, 0, eval, &opt,
eval ? "ch_evalraw" : "ch_sendraw", &part_read); eval ? "ch_evalraw" : "ch_sendraw", &part_read);
if (channel != NULL && eval) if (channel != NULL && eval)
{ {
/* TODO: timeout from options */ if (opt.jo_set & JO_TIMEOUT)
timeout = channel_get_timeout(channel, part_read); timeout = opt.jo_timeout;
else
timeout = channel_get_timeout(channel, part_read);
rettv->vval.v_string = channel_read_block(channel, part_read, timeout); rettv->vval.v_string = channel_read_block(channel, part_read, timeout);
} }
} }

View File

@@ -120,7 +120,7 @@ func s:communicate(port)
call assert_equal('added1', getline(line('$') - 1)) call assert_equal('added1', getline(line('$') - 1))
call assert_equal('added2', getline('$')) call assert_equal('added2', getline('$'))
call assert_equal('ok', ch_evalexpr(handle, 'do normal')) call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
sleep 10m sleep 10m
call assert_equal('added more', getline('$')) call assert_equal('added more', getline('$'))
@@ -342,7 +342,7 @@ func Test_raw_pipe()
let msg = ch_readraw(handle) let msg = ch_readraw(handle)
call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g')) call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g'))
let reply = ch_evalraw(handle, "quit\n") let reply = ch_evalraw(handle, "quit\n", {'timeout': 100})
call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
finally finally
call job_stop(job) call job_stop(job)

View File

@@ -743,6 +743,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1482,
/**/ /**/
1481, 1481,
/**/ /**/