comparison src/channel.c @ 18104:e59ff7b5d7a7 v8.1.2047

patch 8.1.2047: cannot check the current state Commit: https://github.com/vim/vim/commit/0e57dd859ecb1e8a3b91509d2f4343e839340eb8 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 16 22:56:03 2019 +0200 patch 8.1.2047: cannot check the current state Problem: Cannot check the current state. Solution: Add the state() function.
author Bram Moolenaar <Bram@vim.org>
date Mon, 16 Sep 2019 23:00:04 +0200
parents 0d9ec3a2821f
children 59bc3cd42cf5
comparison
equal deleted inserted replaced
18103:71bc51a0d8d8 18104:e59ff7b5d7a7
3481 3481
3482 /* 3482 /*
3483 * Read from RAW or NL "channel"/"part". Blocks until there is something to 3483 * Read from RAW or NL "channel"/"part". Blocks until there is something to
3484 * read or the timeout expires. 3484 * read or the timeout expires.
3485 * When "raw" is TRUE don't block waiting on a NL. 3485 * When "raw" is TRUE don't block waiting on a NL.
3486 * Does not trigger timers or handle messages.
3486 * Returns what was read in allocated memory. 3487 * Returns what was read in allocated memory.
3487 * Returns NULL in case of error or timeout. 3488 * Returns NULL in case of error or timeout.
3488 */ 3489 */
3489 static char_u * 3490 static char_u *
3490 channel_read_block( 3491 channel_read_block(
3567 if (ch_log_active()) 3568 if (ch_log_active())
3568 ch_log(channel, "Returning %d bytes", (int)STRLEN(msg)); 3569 ch_log(channel, "Returning %d bytes", (int)STRLEN(msg));
3569 return msg; 3570 return msg;
3570 } 3571 }
3571 3572
3573 static int channel_blocking_wait = 0;
3574
3575 /*
3576 * Return TRUE if in a blocking wait that might trigger callbacks.
3577 */
3578 int
3579 channel_in_blocking_wait(void)
3580 {
3581 return channel_blocking_wait > 0;
3582 }
3583
3572 /* 3584 /*
3573 * Read one JSON message with ID "id" from "channel"/"part" and store the 3585 * Read one JSON message with ID "id" from "channel"/"part" and store the
3574 * result in "rettv". 3586 * result in "rettv".
3575 * When "id" is -1 accept any message; 3587 * When "id" is -1 accept any message;
3576 * Blocks until the message is received or the timeout is reached. 3588 * Blocks until the message is received or the timeout is reached.
3590 int timeout; 3602 int timeout;
3591 chanpart_T *chanpart = &channel->ch_part[part]; 3603 chanpart_T *chanpart = &channel->ch_part[part];
3592 int retval = FAIL; 3604 int retval = FAIL;
3593 3605
3594 ch_log(channel, "Blocking read JSON for id %d", id); 3606 ch_log(channel, "Blocking read JSON for id %d", id);
3607 ++channel_blocking_wait;
3595 3608
3596 if (id >= 0) 3609 if (id >= 0)
3597 channel_add_block_id(chanpart, id); 3610 channel_add_block_id(chanpart, id);
3598 3611
3599 for (;;) 3612 for (;;)
3659 channel_read(channel, part, "channel_read_json_block"); 3672 channel_read(channel, part, "channel_read_json_block");
3660 } 3673 }
3661 } 3674 }
3662 if (id >= 0) 3675 if (id >= 0)
3663 channel_remove_block_id(chanpart, id); 3676 channel_remove_block_id(chanpart, id);
3677 --channel_blocking_wait;
3664 3678
3665 return retval; 3679 return retval;
3666 } 3680 }
3667 3681
3668 /* 3682 /*