Mercurial > vim
comparison src/channel.c @ 7885:6e6f829af138 v7.4.1239
commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 2 18:43:17 2016 +0100
patch 7.4.1239
Problem: JSON message after the first one is dropped.
Solution: Put remainder of message back in the queue.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 02 Feb 2016 18:45:03 +0100 |
parents | 98a96e0ca73b |
children | 93c61501c2cf |
comparison
equal
deleted
inserted
replaced
7884:1cc576119beb | 7885:6e6f829af138 |
---|---|
565 item->next = head; | 565 item->next = head; |
566 item->prev->next = item; | 566 item->prev->next = item; |
567 } | 567 } |
568 } | 568 } |
569 } | 569 } |
570 | |
571 /* Put the unread part back into the channel. | |
572 * TODO: insert in front */ | |
573 if (reader.js_buf[reader.js_used] != NUL) | |
574 channel_save(ch_idx, reader.js_buf + reader.js_used, | |
575 (int)(reader.js_end - reader.js_buf) - reader.js_used); | |
576 vim_free(reader.js_buf); | |
570 } | 577 } |
571 | 578 |
572 /* | 579 /* |
573 * Remove "node" from the queue that it is in and free it. | 580 * Remove "node" from the queue that it is in and free it. |
574 * Caller should have freed or used node->value. | 581 * Caller should have freed or used node->value. |
695 EMSG2("E905: received unknown command: %s", cmd); | 702 EMSG2("E905: received unknown command: %s", cmd); |
696 } | 703 } |
697 | 704 |
698 /* | 705 /* |
699 * Invoke a callback for channel "idx" if needed. | 706 * Invoke a callback for channel "idx" if needed. |
700 */ | 707 * Return OK when a message was handled, there might be another one. |
701 static void | 708 */ |
709 static int | |
702 may_invoke_callback(int idx) | 710 may_invoke_callback(int idx) |
703 { | 711 { |
704 char_u *msg = NULL; | 712 char_u *msg = NULL; |
705 typval_T *listtv = NULL; | 713 typval_T *listtv = NULL; |
706 list_T *list; | 714 list_T *list; |
708 typval_T argv[3]; | 716 typval_T argv[3]; |
709 int seq_nr = -1; | 717 int seq_nr = -1; |
710 int json_mode = channels[idx].ch_json_mode; | 718 int json_mode = channels[idx].ch_json_mode; |
711 | 719 |
712 if (channel_peek(idx) == NULL) | 720 if (channel_peek(idx) == NULL) |
713 return; | 721 return FALSE; |
714 if (channels[idx].ch_close_cb != NULL) | 722 if (channels[idx].ch_close_cb != NULL) |
715 /* this channel is handled elsewhere (netbeans) */ | 723 /* this channel is handled elsewhere (netbeans) */ |
716 return; | 724 return FALSE; |
717 | 725 |
718 if (json_mode) | 726 if (json_mode) |
719 { | 727 { |
720 /* Get any json message. Return if there isn't one. */ | 728 /* Get any json message. Return if there isn't one. */ |
721 channel_read_json(idx); | 729 channel_read_json(idx); |
722 if (channel_get_json(idx, -1, &listtv) == FAIL) | 730 if (channel_get_json(idx, -1, &listtv) == FAIL) |
723 return; | 731 return FALSE; |
724 if (listtv->v_type != VAR_LIST) | 732 if (listtv->v_type != VAR_LIST) |
725 { | 733 { |
726 /* TODO: give error */ | 734 /* TODO: give error */ |
727 clear_tv(listtv); | 735 clear_tv(listtv); |
728 return; | 736 return FALSE; |
729 } | 737 } |
730 | 738 |
731 list = listtv->vval.v_list; | 739 list = listtv->vval.v_list; |
732 if (list->lv_len < 2) | 740 if (list->lv_len < 2) |
733 { | 741 { |
734 /* TODO: give error */ | 742 /* TODO: give error */ |
735 clear_tv(listtv); | 743 clear_tv(listtv); |
736 return; | 744 return FALSE; |
737 } | 745 } |
738 | 746 |
739 argv[1] = list->lv_first->li_next->li_tv; | 747 argv[1] = list->lv_first->li_next->li_tv; |
740 typetv = &list->lv_first->li_tv; | 748 typetv = &list->lv_first->li_tv; |
741 if (typetv->v_type == VAR_STRING) | 749 if (typetv->v_type == VAR_STRING) |
746 /* ["cmd", arg] */ | 754 /* ["cmd", arg] */ |
747 if (list->lv_len == 3) | 755 if (list->lv_len == 3) |
748 arg3 = &list->lv_last->li_tv; | 756 arg3 = &list->lv_last->li_tv; |
749 channel_exe_cmd(idx, cmd, &argv[1], arg3); | 757 channel_exe_cmd(idx, cmd, &argv[1], arg3); |
750 clear_tv(listtv); | 758 clear_tv(listtv); |
751 return; | 759 return TRUE; |
752 } | 760 } |
753 | 761 |
754 if (typetv->v_type != VAR_NUMBER) | 762 if (typetv->v_type != VAR_NUMBER) |
755 { | 763 { |
756 /* TODO: give error */ | 764 /* TODO: give error */ |
757 clear_tv(listtv); | 765 clear_tv(listtv); |
758 return; | 766 return FALSE; |
759 } | 767 } |
760 seq_nr = typetv->vval.v_number; | 768 seq_nr = typetv->vval.v_number; |
761 } | 769 } |
762 else | 770 else |
763 { | 771 { |
783 /* else: drop the message TODO: give error */ | 791 /* else: drop the message TODO: give error */ |
784 | 792 |
785 if (listtv != NULL) | 793 if (listtv != NULL) |
786 clear_tv(listtv); | 794 clear_tv(listtv); |
787 vim_free(msg); | 795 vim_free(msg); |
796 | |
797 return TRUE; | |
788 } | 798 } |
789 | 799 |
790 /* | 800 /* |
791 * Return TRUE when channel "idx" is open. | 801 * Return TRUE when channel "idx" is open. |
792 * Also returns FALSE or invalid "idx". | 802 * Also returns FALSE or invalid "idx". |
1242 channel_parse_messages(void) | 1252 channel_parse_messages(void) |
1243 { | 1253 { |
1244 int i; | 1254 int i; |
1245 | 1255 |
1246 for (i = 0; i < channel_count; ++i) | 1256 for (i = 0; i < channel_count; ++i) |
1247 may_invoke_callback(i); | 1257 while (may_invoke_callback(i) == OK) |
1258 ; | |
1248 } | 1259 } |
1249 | 1260 |
1250 #endif /* FEAT_CHANNEL */ | 1261 #endif /* FEAT_CHANNEL */ |