comparison src/channel.c @ 10233:d709622a18c9 v8.0.0015

commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 26 22:36:58 2016 +0200 patch 8.0.0015 Problem: Can't tell which part of a channel has "buffered" status. Solution: Add an optional argument to ch_status(). Let ch_info() also return "buffered" for out_status and err_status.
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Sep 2016 22:45:05 +0200
parents 65afd399ffa7
children 175b1116f96a
comparison
equal deleted inserted replaced
10232:95c9ab5b97fc 10233:d709622a18c9
2588 return channel_peek(channel, part) != NULL; 2588 return channel_peek(channel, part) != NULL;
2589 } 2589 }
2590 2590
2591 /* 2591 /*
2592 * Return a string indicating the status of the channel. 2592 * Return a string indicating the status of the channel.
2593 * If "req_part" is not negative check that part.
2593 */ 2594 */
2594 char * 2595 char *
2595 channel_status(channel_T *channel) 2596 channel_status(channel_T *channel, int req_part)
2596 { 2597 {
2597 int part; 2598 int part;
2598 int has_readahead = FALSE; 2599 int has_readahead = FALSE;
2599 2600
2600 if (channel == NULL) 2601 if (channel == NULL)
2601 return "fail"; 2602 return "fail";
2602 if (channel_is_open(channel)) 2603 if (req_part == PART_OUT)
2603 return "open"; 2604 {
2604 for (part = PART_SOCK; part <= PART_ERR; ++part) 2605 if (channel->CH_OUT_FD != INVALID_FD)
2605 if (channel_has_readahead(channel, part)) 2606 return "open";
2606 { 2607 if (channel_has_readahead(channel, PART_OUT))
2607 has_readahead = TRUE; 2608 has_readahead = TRUE;
2608 break; 2609 }
2609 } 2610 else if (req_part == PART_ERR)
2611 {
2612 if (channel->CH_ERR_FD != INVALID_FD)
2613 return "open";
2614 if (channel_has_readahead(channel, PART_ERR))
2615 has_readahead = TRUE;
2616 }
2617 else
2618 {
2619 if (channel_is_open(channel))
2620 return "open";
2621 for (part = PART_SOCK; part <= PART_ERR; ++part)
2622 if (channel_has_readahead(channel, part))
2623 {
2624 has_readahead = TRUE;
2625 break;
2626 }
2627 }
2610 2628
2611 if (has_readahead) 2629 if (has_readahead)
2612 return "buffered"; 2630 return "buffered";
2613 return "closed"; 2631 return "closed";
2614 } 2632 }
2617 channel_part_info(channel_T *channel, dict_T *dict, char *name, int part) 2635 channel_part_info(channel_T *channel, dict_T *dict, char *name, int part)
2618 { 2636 {
2619 chanpart_T *chanpart = &channel->ch_part[part]; 2637 chanpart_T *chanpart = &channel->ch_part[part];
2620 char namebuf[20]; /* longest is "sock_timeout" */ 2638 char namebuf[20]; /* longest is "sock_timeout" */
2621 size_t tail; 2639 size_t tail;
2640 char *status;
2622 char *s = ""; 2641 char *s = "";
2623 2642
2624 vim_strncpy((char_u *)namebuf, (char_u *)name, 4); 2643 vim_strncpy((char_u *)namebuf, (char_u *)name, 4);
2625 STRCAT(namebuf, "_"); 2644 STRCAT(namebuf, "_");
2626 tail = STRLEN(namebuf); 2645 tail = STRLEN(namebuf);
2627 2646
2628 STRCPY(namebuf + tail, "status"); 2647 STRCPY(namebuf + tail, "status");
2629 dict_add_nr_str(dict, namebuf, 0, 2648 if (chanpart->ch_fd != INVALID_FD)
2630 (char_u *)(chanpart->ch_fd == INVALID_FD ? "closed" : "open")); 2649 status = "open";
2650 else if (channel_has_readahead(channel, part))
2651 status = "buffered";
2652 else
2653 status = "closed";
2654 dict_add_nr_str(dict, namebuf, 0, (char_u *)status);
2631 2655
2632 STRCPY(namebuf + tail, "mode"); 2656 STRCPY(namebuf + tail, "mode");
2633 switch (chanpart->ch_mode) 2657 switch (chanpart->ch_mode)
2634 { 2658 {
2635 case MODE_NL: s = "NL"; break; 2659 case MODE_NL: s = "NL"; break;
2658 2682
2659 void 2683 void
2660 channel_info(channel_T *channel, dict_T *dict) 2684 channel_info(channel_T *channel, dict_T *dict)
2661 { 2685 {
2662 dict_add_nr_str(dict, "id", channel->ch_id, NULL); 2686 dict_add_nr_str(dict, "id", channel->ch_id, NULL);
2663 dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel)); 2687 dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel, -1));
2664 2688
2665 if (channel->ch_hostname != NULL) 2689 if (channel->ch_hostname != NULL)
2666 { 2690 {
2667 dict_add_nr_str(dict, "hostname", 0, (char_u *)channel->ch_hostname); 2691 dict_add_nr_str(dict, "hostname", 0, (char_u *)channel->ch_hostname);
2668 dict_add_nr_str(dict, "port", channel->ch_port, NULL); 2692 dict_add_nr_str(dict, "port", channel->ch_port, NULL);
4242 break; 4266 break;
4243 opt->jo_set |= JO_PART; 4267 opt->jo_set |= JO_PART;
4244 val = get_tv_string(item); 4268 val = get_tv_string(item);
4245 if (STRCMP(val, "err") == 0) 4269 if (STRCMP(val, "err") == 0)
4246 opt->jo_part = PART_ERR; 4270 opt->jo_part = PART_ERR;
4271 else if (STRCMP(val, "out") == 0)
4272 opt->jo_part = PART_OUT;
4247 else 4273 else
4248 { 4274 {
4249 EMSG2(_(e_invarg2), val); 4275 EMSG2(_(e_invarg2), val);
4250 return FAIL; 4276 return FAIL;
4251 } 4277 }