Mercurial > vim
diff src/channel.c @ 8669:06848fe9c816 v7.4.1624
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 20 20:57:45 2016 +0100
patch 7.4.1624
Problem: Can't get info about a channel.
Solution: Add ch_info().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Mar 2016 21:00:05 +0100 |
parents | 8c80c21a1885 |
children | a4e7f4a62193 |
line wrap: on
line diff
--- a/src/channel.c +++ b/src/channel.c @@ -838,6 +838,8 @@ channel_open( channel->CH_SOCK_FD = (sock_T)sd; channel->ch_nb_close_cb = nb_close_cb; + channel->ch_hostname = (char *)vim_strsave((char_u *)hostname); + channel->ch_port = port_in; #ifdef FEAT_GUI channel_gui_register_one(channel, PART_SOCK); @@ -1138,6 +1140,10 @@ channel_set_options(channel_T *channel, ch_logs(channel, "writing err to buffer '%s'", (char *)channel->ch_part[PART_ERR].ch_buffer->b_ffname); } + + channel->ch_part[PART_OUT].ch_io = opt->jo_io[PART_OUT]; + channel->ch_part[PART_ERR].ch_io = opt->jo_io[PART_ERR]; + channel->ch_part[PART_IN].ch_io = opt->jo_io[PART_IN]; } /* @@ -2088,6 +2094,69 @@ channel_status(channel_T *channel) return "closed"; } + static void +channel_part_info(channel_T *channel, dict_T *dict, char *name, int part) +{ + chanpart_T *chanpart = &channel->ch_part[part]; + char namebuf[20]; + int tail; + char *s; + + STRCPY(namebuf, name); + STRCAT(namebuf, "_"); + tail = STRLEN(namebuf); + + STRCPY(namebuf + tail, "status"); + dict_add_nr_str(dict, namebuf, 0, + (char_u *)(chanpart->ch_fd == INVALID_FD ? "closed" : "open")); + + STRCPY(namebuf + tail, "mode"); + switch (chanpart->ch_mode) + { + case MODE_NL: s = "NL"; break; + case MODE_RAW: s = "RAW"; break; + case MODE_JSON: s = "JSON"; break; + case MODE_JS: s = "JS"; break; + } + dict_add_nr_str(dict, namebuf, 0, (char_u *)s); + + STRCPY(namebuf + tail, "io"); + if (part == PART_SOCK) + s = "socket"; + else switch (chanpart->ch_io) + { + case JIO_NULL: s = "null"; break; + case JIO_PIPE: s = "pipe"; break; + case JIO_FILE: s = "file"; break; + case JIO_BUFFER: s = "buffer"; break; + case JIO_OUT: s = "out"; break; + } + dict_add_nr_str(dict, namebuf, 0, (char_u *)s); + + STRCPY(namebuf + tail, "timeout"); + dict_add_nr_str(dict, namebuf, chanpart->ch_timeout, NULL); +} + + void +channel_info(channel_T *channel, dict_T *dict) +{ + dict_add_nr_str(dict, "id", channel->ch_id, NULL); + dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel)); + + if (channel->ch_hostname != NULL) + { + dict_add_nr_str(dict, "hostname", 0, (char_u *)channel->ch_hostname); + dict_add_nr_str(dict, "port", channel->ch_port, NULL); + channel_part_info(channel, dict, "sock", PART_SOCK); + } + else + { + channel_part_info(channel, dict, "out", PART_OUT); + channel_part_info(channel, dict, "err", PART_ERR); + channel_part_info(channel, dict, "in", PART_IN); + } +} + /* * Close channel "channel". * Trigger the close callback if "invoke_close_cb" is TRUE. @@ -2195,6 +2264,8 @@ channel_clear_one(channel_T *channel, in channel_clear(channel_T *channel) { ch_log(channel, "Clearing channel"); + vim_free(channel->ch_hostname); + channel->ch_hostname = NULL; channel_clear_one(channel, PART_SOCK); channel_clear_one(channel, PART_OUT); channel_clear_one(channel, PART_ERR);