*/
static channel_T *
send_common(
- typval_T *argvars,
- char_u *text,
- int id,
- int eval,
- char *fun,
- int *part_read)
+ typval_T *argvars,
+ char_u *text,
+ int id,
+ int eval,
+ jobopt_T *opt,
+ char *fun,
+ int *part_read)
{
channel_T *channel;
- jobopt_T opt;
int part_send;
channel = get_channel_arg(&argvars[0]);
part_send = channel_part_send(channel);
*part_read = channel_part_read(channel);
- clear_job_options(&opt);
- if (get_job_options(&argvars[2], &opt, JO_CALLBACK) == FAIL)
+ clear_job_options(opt);
+ if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT) == FAIL)
return NULL;
/* Set the callback. An empty callback means no callback and not reading
* the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not
* allowed. */
- if (opt.jo_callback != NULL && *opt.jo_callback != NUL)
+ if (opt->jo_callback != NULL && *opt->jo_callback != NUL)
{
if (eval)
{
EMSG2(_("E917: Cannot use a callback with %s()"), fun);
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
- && opt.jo_callback == NULL)
+ && opt->jo_callback == NULL)
return channel;
return NULL;
}
ch_mode_T ch_mode;
int part_send;
int part_read;
+ jobopt_T opt;
int timeout;
/* return an empty string by default */
if (text == NULL)
return;
- channel = send_common(argvars, text, id, eval,
+ channel = send_common(argvars, text, id, eval, &opt,
eval ? "ch_evalexpr" : "ch_sendexpr", &part_read);
vim_free(text);
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);
if (channel_read_json_block(channel, part_read, timeout, id, &listtv)
== OK)
char_u *text;
channel_T *channel;
int part_read;
+ jobopt_T opt;
int timeout;
/* return an empty string by default */
rettv->vval.v_string = NULL;
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);
if (channel != NULL && eval)
{
- /* TODO: timeout from options */
- timeout = channel_get_timeout(channel, part_read);
+ if (opt.jo_set & JO_TIMEOUT)
+ timeout = opt.jo_timeout;
+ else
+ timeout = channel_get_timeout(channel, part_read);
rettv->vval.v_string = channel_read_block(channel, part_read, timeout);
}
}
call assert_equal('added1', getline(line('$') - 1))
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
call assert_equal('added more', getline('$'))
let msg = ch_readraw(handle)
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'))
finally
call job_stop(job)