Mercurial > vim
comparison src/eval.c @ 8380:892d7dcf17ec v7.4.1482
commit https://github.com/vim/vim/commit/da94fdf2588b3910d38e477a755748ce2c6d2e66
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 3 18:09:10 2016 +0100
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 03 Mar 2016 18:15:05 +0100 |
parents | db2a07b710ed |
children | 3b9a306724ec |
comparison
equal
deleted
inserted
replaced
8379:c63196126179 | 8380:892d7dcf17ec |
---|---|
10516 * Sets "part_read" to the the read fd. | 10516 * Sets "part_read" to the the read fd. |
10517 * Otherwise returns NULL. | 10517 * Otherwise returns NULL. |
10518 */ | 10518 */ |
10519 static channel_T * | 10519 static channel_T * |
10520 send_common( | 10520 send_common( |
10521 typval_T *argvars, | 10521 typval_T *argvars, |
10522 char_u *text, | 10522 char_u *text, |
10523 int id, | 10523 int id, |
10524 int eval, | 10524 int eval, |
10525 char *fun, | 10525 jobopt_T *opt, |
10526 int *part_read) | 10526 char *fun, |
10527 int *part_read) | |
10527 { | 10528 { |
10528 channel_T *channel; | 10529 channel_T *channel; |
10529 jobopt_T opt; | |
10530 int part_send; | 10530 int part_send; |
10531 | 10531 |
10532 channel = get_channel_arg(&argvars[0]); | 10532 channel = get_channel_arg(&argvars[0]); |
10533 if (channel == NULL) | 10533 if (channel == NULL) |
10534 return NULL; | 10534 return NULL; |
10535 part_send = channel_part_send(channel); | 10535 part_send = channel_part_send(channel); |
10536 *part_read = channel_part_read(channel); | 10536 *part_read = channel_part_read(channel); |
10537 | 10537 |
10538 clear_job_options(&opt); | 10538 clear_job_options(opt); |
10539 if (get_job_options(&argvars[2], &opt, JO_CALLBACK) == FAIL) | 10539 if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT) == FAIL) |
10540 return NULL; | 10540 return NULL; |
10541 | 10541 |
10542 /* Set the callback. An empty callback means no callback and not reading | 10542 /* Set the callback. An empty callback means no callback and not reading |
10543 * the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not | 10543 * the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not |
10544 * allowed. */ | 10544 * allowed. */ |
10545 if (opt.jo_callback != NULL && *opt.jo_callback != NUL) | 10545 if (opt->jo_callback != NULL && *opt->jo_callback != NUL) |
10546 { | 10546 { |
10547 if (eval) | 10547 if (eval) |
10548 { | 10548 { |
10549 EMSG2(_("E917: Cannot use a callback with %s()"), fun); | 10549 EMSG2(_("E917: Cannot use a callback with %s()"), fun); |
10550 return NULL; | 10550 return NULL; |
10551 } | 10551 } |
10552 channel_set_req_callback(channel, part_send, opt.jo_callback, id); | 10552 channel_set_req_callback(channel, part_send, opt->jo_callback, id); |
10553 } | 10553 } |
10554 | 10554 |
10555 if (channel_send(channel, part_send, text, fun) == OK | 10555 if (channel_send(channel, part_send, text, fun) == OK |
10556 && opt.jo_callback == NULL) | 10556 && opt->jo_callback == NULL) |
10557 return channel; | 10557 return channel; |
10558 return NULL; | 10558 return NULL; |
10559 } | 10559 } |
10560 | 10560 |
10561 /* | 10561 /* |
10569 channel_T *channel; | 10569 channel_T *channel; |
10570 int id; | 10570 int id; |
10571 ch_mode_T ch_mode; | 10571 ch_mode_T ch_mode; |
10572 int part_send; | 10572 int part_send; |
10573 int part_read; | 10573 int part_read; |
10574 jobopt_T opt; | |
10574 int timeout; | 10575 int timeout; |
10575 | 10576 |
10576 /* return an empty string by default */ | 10577 /* return an empty string by default */ |
10577 rettv->v_type = VAR_STRING; | 10578 rettv->v_type = VAR_STRING; |
10578 rettv->vval.v_string = NULL; | 10579 rettv->vval.v_string = NULL; |
10593 text = json_encode_nr_expr(id, &argvars[1], | 10594 text = json_encode_nr_expr(id, &argvars[1], |
10594 ch_mode == MODE_JS ? JSON_JS : 0); | 10595 ch_mode == MODE_JS ? JSON_JS : 0); |
10595 if (text == NULL) | 10596 if (text == NULL) |
10596 return; | 10597 return; |
10597 | 10598 |
10598 channel = send_common(argvars, text, id, eval, | 10599 channel = send_common(argvars, text, id, eval, &opt, |
10599 eval ? "ch_evalexpr" : "ch_sendexpr", &part_read); | 10600 eval ? "ch_evalexpr" : "ch_sendexpr", &part_read); |
10600 vim_free(text); | 10601 vim_free(text); |
10601 if (channel != NULL && eval) | 10602 if (channel != NULL && eval) |
10602 { | 10603 { |
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); | |
10604 timeout = channel_get_timeout(channel, part_read); | 10608 timeout = channel_get_timeout(channel, part_read); |
10605 if (channel_read_json_block(channel, part_read, timeout, id, &listtv) | 10609 if (channel_read_json_block(channel, part_read, timeout, id, &listtv) |
10606 == OK) | 10610 == OK) |
10607 { | 10611 { |
10608 list_T *list = listtv->vval.v_list; | 10612 list_T *list = listtv->vval.v_list; |
10642 { | 10646 { |
10643 char_u buf[NUMBUFLEN]; | 10647 char_u buf[NUMBUFLEN]; |
10644 char_u *text; | 10648 char_u *text; |
10645 channel_T *channel; | 10649 channel_T *channel; |
10646 int part_read; | 10650 int part_read; |
10651 jobopt_T opt; | |
10647 int timeout; | 10652 int timeout; |
10648 | 10653 |
10649 /* return an empty string by default */ | 10654 /* return an empty string by default */ |
10650 rettv->v_type = VAR_STRING; | 10655 rettv->v_type = VAR_STRING; |
10651 rettv->vval.v_string = NULL; | 10656 rettv->vval.v_string = NULL; |
10652 | 10657 |
10653 text = get_tv_string_buf(&argvars[1], buf); | 10658 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, |
10655 eval ? "ch_evalraw" : "ch_sendraw", &part_read); | 10660 eval ? "ch_evalraw" : "ch_sendraw", &part_read); |
10656 if (channel != NULL && eval) | 10661 if (channel != NULL && eval) |
10657 { | 10662 { |
10658 /* TODO: timeout from options */ | 10663 if (opt.jo_set & JO_TIMEOUT) |
10659 timeout = channel_get_timeout(channel, part_read); | 10664 timeout = opt.jo_timeout; |
10665 else | |
10666 timeout = channel_get_timeout(channel, part_read); | |
10660 rettv->vval.v_string = channel_read_block(channel, part_read, timeout); | 10667 rettv->vval.v_string = channel_read_block(channel, part_read, timeout); |
10661 } | 10668 } |
10662 } | 10669 } |
10663 | 10670 |
10664 /* | 10671 /* |