@@ -119,6 +119,8 @@ typedef struct {
119119
120120 void (* ch_close_cb )(void ); /* callback for when channel is closed */
121121
122+ int ch_block_id ; /* ID that channel_read_json_block() is
123+ waiting for */
122124 char_u * ch_callback ; /* function to call when a msg is not handled */
123125 cbq_T ch_cb_head ; /* dummy node for pre-request callbacks */
124126
@@ -790,23 +792,26 @@ remove_json_node(jsonq_T *node)
790792/*
791793 * Get a message from the JSON queue for channel "ch_idx".
792794 * When "id" is positive it must match the first number in the list.
793- * When "id" is zero or negative jut get the first message.
795+ * When "id" is zero or negative jut get the first message. But not the one
796+ * with id ch_block_id.
794797 * Return OK when found and return the value in "rettv".
795798 * Return FAIL otherwise.
796799 */
797800 static int
798801channel_get_json (int ch_idx , int id , typval_T * * rettv )
799802{
800- jsonq_T * head = & channels [ch_idx ].ch_json_head ;
801- jsonq_T * item = head -> next ;
803+ channel_T * channel = & channels [ch_idx ];
804+ jsonq_T * head = & channel -> ch_json_head ;
805+ jsonq_T * item = head -> next ;
802806
803807 while (item != head )
804808 {
805809 list_T * l = item -> value -> vval .v_list ;
806810 typval_T * tv = & l -> lv_first -> li_tv ;
807811
808812 if ((id > 0 && tv -> v_type == VAR_NUMBER && tv -> vval .v_number == id )
809- || id <= 0 )
813+ || (id <= 0 && (tv -> v_type != VAR_NUMBER
814+ || tv -> vval .v_number != channel -> ch_block_id )))
810815 {
811816 * rettv = item -> value ;
812817 remove_json_node (item );
@@ -1316,15 +1321,20 @@ channel_read_block(int idx)
13161321 int
13171322channel_read_json_block (int ch_idx , int id , typval_T * * rettv )
13181323{
1319- int more ;
1324+ int more ;
1325+ channel_T * channel = & channels [ch_idx ];
13201326
1327+ channel -> ch_block_id = id ;
13211328 for (;;)
13221329 {
13231330 more = channel_parse_json (ch_idx );
13241331
13251332 /* search for messsage "id" */
13261333 if (channel_get_json (ch_idx , id , rettv ) == OK )
1334+ {
1335+ channel -> ch_block_id = 0 ;
13271336 return OK ;
1337+ }
13281338
13291339 if (!more )
13301340 {
@@ -1334,13 +1344,13 @@ channel_read_json_block(int ch_idx, int id, typval_T **rettv)
13341344 continue ;
13351345
13361346 /* Wait for up to the channel timeout. */
1337- if (channels [ch_idx ].ch_fd < 0
1338- || channel_wait (channels [ch_idx ].ch_fd ,
1339- channels [ch_idx ].ch_timeout ) == FAIL )
1347+ if (channel -> ch_fd < 0 || channel_wait (channel -> ch_fd ,
1348+ channel -> ch_timeout ) == FAIL )
13401349 break ;
13411350 channel_read (ch_idx );
13421351 }
13431352 }
1353+ channel -> ch_block_id = 0 ;
13441354 return FAIL ;
13451355}
13461356
0 commit comments