summaryrefslogtreecommitdiffstats
path: root/src/channel.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-11-30 20:52:27 +0100
committerBram Moolenaar <Bram@vim.org>2019-11-30 20:52:27 +0100
commitc667da5185ce5dce914d2006d62da2be0cedb384 (patch)
treecd06b08e9fb7d701653850cd33524d3f1f5acaaf /src/channel.c
parent71136db1bfbc67c2e55f8070cdf0a241c643e45b (diff)
patch 8.1.2368: using old C style commentsv8.1.2368
Problem: Using old C style comments. Solution: Use // comments where appropriate.
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c545
1 files changed, 272 insertions, 273 deletions
diff --git a/src/channel.c b/src/channel.c
index 0ac9718762..7edca1a19a 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -14,15 +14,15 @@
#if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
-/* TRUE when netbeans is running with a GUI. */
+// TRUE when netbeans is running with a GUI.
#ifdef FEAT_GUI
# define CH_HAS_GUI (gui.in_use || gui.starting)
#endif
-/* Note: when making changes here also adjust configure.ac. */
+// Note: when making changes here also adjust configure.ac.
#ifdef MSWIN
-/* WinSock API is separated from C API, thus we can't use read(), write(),
- * errno... */
+// WinSock API is separated from C API, thus we can't use read(), write(),
+// errno...
# define SOCK_ERRNO errno = WSAGetLastError()
# undef ECONNREFUSED
# define ECONNREFUSED WSAECONNREFUSED
@@ -61,11 +61,11 @@ static ch_part_T channel_part_send(channel_T *channel);
static ch_part_T channel_part_read(channel_T *channel);
static void free_job_options(jobopt_T *opt);
-/* Whether a redraw is needed for appending a line to a buffer. */
+// Whether a redraw is needed for appending a line to a buffer.
static int channel_need_redraw = FALSE;
-/* Whether we are inside channel_parse_messages() or another situation where it
- * is safe to invoke callbacks. */
+// Whether we are inside channel_parse_messages() or another situation where it
+// is safe to invoke callbacks.
static int safe_to_invoke_callback = 0;
static char *part_names[] = {"sock", "out", "err", "in"};
@@ -129,7 +129,7 @@ fd_close(sock_T fd)
}
#endif
-/* Log file opened with ch_logfile(). */
+// Log file opened with ch_logfile().
static FILE *log_fd = NULL;
#ifdef FEAT_RELTIME
static proftime_T log_start;
@@ -269,7 +269,7 @@ strerror_win32(int eno)
0,
NULL);
if (msgbuf != NULL)
- /* chomp \r or \n */
+ // chomp \r or \n
for (ptr = (char_u *)msgbuf; *ptr; ptr++)
switch (*ptr)
{
@@ -352,20 +352,20 @@ channel_still_useful(channel_T *channel)
int has_out_msg;
int has_err_msg;
- /* If the job was killed the channel is not expected to work anymore. */
+ // If the job was killed the channel is not expected to work anymore.
if (channel->ch_job_killed && channel->ch_job == NULL)
return FALSE;
- /* If there is a close callback it may still need to be invoked. */
+ // If there is a close callback it may still need to be invoked.
if (channel->ch_close_cb.cb_name != NULL)
return TRUE;
- /* If reading from or a buffer it's still useful. */
+ // If reading from or a buffer it's still useful.
if (channel->ch_part[PART_IN].ch_bufref.br_buf != NULL)
return TRUE;
- /* If there is no callback then nobody can get readahead. If the fd is
- * closed and there is no readahead then the callback won't be called. */
+ // If there is no callback then nobody can get readahead. If the fd is
+ // closed and there is no readahead then the callback won't be called.
has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD
|| channel->ch_part[PART_SOCK].ch_head.rq_next != NULL
|| channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL;
@@ -468,16 +468,16 @@ free_unused_channels_contents(int copyID, int mask)
int did_free = FALSE;
channel_T *ch;
- /* This is invoked from the garbage collector, which only runs at a safe
- * point. */
+ // This is invoked from the garbage collector, which only runs at a safe
+ // point.
++safe_to_invoke_callback;
for (ch = first_channel; ch != NULL; ch = ch->ch_next)
if (!channel_still_useful(ch)
&& (ch->ch_copyID & mask) != (copyID & mask))
{
- /* Free the channel and ordinary items it contains, but don't
- * recurse into Lists, Dictionaries etc. */
+ // Free the channel and ordinary items it contains, but don't
+ // recurse into Lists, Dictionaries etc.
channel_free_contents(ch);
did_free = TRUE;
}
@@ -498,7 +498,7 @@ free_unused_channels(int copyID, int mask)
if (!channel_still_useful(ch)
&& (ch->ch_copyID & mask) != (copyID & mask))
{
- /* Free the channel struct itself. */
+ // Free the channel struct itself.
channel_free_channel(ch);
}
}
@@ -566,8 +566,8 @@ messageFromServerGtk3(GIOChannel *unused1 UNUSED,
gpointer clientData)
{
channel_read_fd(GPOINTER_TO_INT(clientData));
- return TRUE; /* Return FALSE instead in case the event source is to
- * be removed after this function returns. */
+ return TRUE; // Return FALSE instead in case the event source is to
+ // be removed after this function returns.
}
# else
static void
@@ -586,13 +586,13 @@ channel_gui_register_one(channel_T *channel, ch_part_T part UNUSED)
if (!CH_HAS_GUI)
return;
- /* gets stuck in handling events for a not connected channel */
+ // gets stuck in handling events for a not connected channel
if (channel->ch_keep_open)
return;
# ifdef FEAT_GUI_X11
- /* Tell notifier we are interested in being called when there is input on
- * the editor connection socket. */
+ // Tell notifier we are interested in being called when there is input on
+ // the editor connection socket.
if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL)
{
ch_log(channel, "Registering part %s with fd %d",
@@ -607,8 +607,8 @@ channel_gui_register_one(channel_T *channel, ch_part_T part UNUSED)
}
# else
# ifdef FEAT_GUI_GTK
- /* Tell gdk we are interested in being called when there is input on the
- * editor connection socket. */
+ // Tell gdk we are interested in being called when there is input on the
+ // editor connection socket.
if (channel->ch_part[part].ch_inputHandler == 0)
{
ch_log(channel, "Registering part %s with fd %d",
@@ -740,8 +740,8 @@ channel_open(
return NULL;
}
- /* Get the server internet address and put into addr structure */
- /* fill in the socket address structure and connect to server */
+ // Get the server internet address and put into addr structure
+ // fill in the socket address structure and connect to server
vim_memset((char *)&server, 0, sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(port);
@@ -755,15 +755,15 @@ channel_open(
{
char *p;
- /* When using host->h_addr_list[0] directly ubsan warns for it to not
- * be aligned. First copy the pointer to avoid that. */
+ // When using host->h_addr_list[0] directly ubsan warns for it to not
+ // be aligned. First copy the pointer to avoid that.
memcpy(&p, &host->h_addr_list[0], sizeof(p));
memcpy((char *)&server.sin_addr, p, host->h_length);
}
- /* On Mac and Solaris a zero timeout almost never works. At least wait
- * one millisecond. Let's do it for all systems, because we don't know why
- * this is needed. */
+ // On Mac and Solaris a zero timeout almost never works. At least wait
+ // one millisecond. Let's do it for all systems, because we don't know why
+ // this is needed.
if (waittime == 0)
waittime = 1;
@@ -789,7 +789,7 @@ channel_open(
if (waittime >= 0)
{
- /* Make connect() non-blocking. */
+ // Make connect() non-blocking.
if (
#ifdef MSWIN
ioctlsocket(sd, FIONBIO, &val) < 0
@@ -807,12 +807,12 @@ channel_open(
}
}
- /* Try connecting to the server. */
+ // Try connecting to the server.
ch_log(channel, "Connecting to %s port %d", hostname, port);
ret = connect(sd, (struct sockaddr *)&server, sizeof(server));
if (ret == 0)
- /* The connection could be established. */
+ // The connection could be established.
break;
SOCK_ERRNO;
@@ -831,12 +831,12 @@ channel_open(
return NULL;
}
- /* Limit the waittime to 50 msec. If it doesn't work within this
- * time we close the socket and try creating it again. */
+ // Limit the waittime to 50 msec. If it doesn't work within this
+ // time we close the socket and try creating it again.
waitnow = waittime > 50 ? 50 : waittime;
- /* If connect() didn't finish then try using select() to wait for the
- * connection to be made. For Win32 always use select() to wait. */
+ // If connect() didn't finish then try using select() to wait for the
+ // connection to be made. For Win32 always use select() to wait.
#ifndef MSWIN
if (errno != ECONNREFUSED)
#endif
@@ -876,8 +876,8 @@ channel_open(
}
#ifdef MSWIN
- /* On Win32: select() is expected to work and wait for up to
- * "waitnow" msec for the socket to be open. */
+ // On Win32: select() is expected to work and wait for up to
+ // "waitnow" msec for the socket to be open.
if (FD_ISSET(sd, &wfds))
break;
elapsed_msec = waitnow;
@@ -887,13 +887,13 @@ channel_open(
continue;
}
#else
- /* On Linux-like systems: See socket(7) for the behavior
- * After putting the socket in non-blocking mode, connect() will
- * return EINPROGRESS, select() will not wait (as if writing is
- * possible), need to use getsockopt() to check if the socket is
- * actually able to connect.
- * We detect a failure to connect when either read and write fds
- * are set. Use getsockopt() to find out what kind of failure. */
+ // On Linux-like systems: See socket(7) for the behavior
+ // After putting the socket in non-blocking mode, connect() will
+ // return EINPROGRESS, select() will not wait (as if writing is
+ // possible), need to use getsockopt() to check if the socket is
+ // actually able to connect.
+ // We detect a failure to connect when either read and write fds
+ // are set. Use getsockopt() to find out what kind of failure.
if (FD_ISSET(sd, &rfds) || FD_ISSET(sd, &wfds))
{
ret = getsockopt(sd,
@@ -917,7 +917,7 @@ channel_open(
}
if (FD_ISSET(sd, &wfds) && so_error == 0)
- /* Did not detect an error, connection is established. */
+ // Did not detect an error, connection is established.
break;
gettimeofday(&end_tv, NULL);
@@ -929,10 +929,10 @@ channel_open(
#ifndef MSWIN
if (waittime > 1 && elapsed_msec < waittime)
{
- /* The port isn't ready but we also didn't get an error.
- * This happens when the server didn't open the socket
- * yet. Select() may return early, wait until the remaining
- * "waitnow" and try again. */
+ // The port isn't ready but we also didn't get an error.
+ // This happens when the server didn't open the socket
+ // yet. Select() may return early, wait until the remaining
+ // "waitnow" and try again.
waitnow -= elapsed_msec;
waittime -= elapsed_msec;
if (waitnow > 0)
@@ -944,15 +944,15 @@ channel_open(
if (!got_int)
{
if (waittime <= 0)
- /* give it one more try */
+ // give it one more try
waittime = 1;
continue;
}
- /* we were interrupted, behave as if timed out */
+ // we were interrupted, behave as if timed out
}
#endif
- /* We timed out. */
+ // We timed out.
ch_error(channel, "Connection timed out");
sock_close(sd);
channel_free(channel);
@@ -1115,7 +1115,7 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
{
buf_T *buf;
- /* writing output to a buffer. Default mode is NL. */
+ // writing output to a buffer. Default mode is NL.
if (!(opt->jo_set & JO_OUT_MODE))
channel->ch_part[PART_OUT].ch_mode = MODE_NL;
if (opt->jo_set & JO_OUT_BUF)
@@ -1160,7 +1160,7 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
{
buf_T *buf;
- /* writing err to a buffer. Default mode is NL. */
+ // writing err to a buffer. Default mode is NL.
if (!(opt->jo_set & JO_ERR_MODE))
channel->ch_part[PART_ERR].ch_mode = MODE_NL;
if (opt->jo_io[PART_ERR] == JIO_OUT)
@@ -1226,7 +1226,7 @@ channel_open_func(typval_T *argvars)
return NULL;
}
- /* parse address */
+ // parse address
p = vim_strchr(address, ':');
if (p == NULL)
{
@@ -1242,7 +1242,7 @@ channel_open_func(typval_T *argvars)
return NULL;
}
- /* parse options */
+ // parse options
clear_job_options(&opt);
opt.jo_mode = MODE_JSON;
opt.jo_timeout = 2000;
@@ -1277,8 +1277,8 @@ ch_close_part(channel_T *channel, ch_part_T part)
sock_close(*fd);
else
{
- /* When using a pty the same FD is set on multiple parts, only
- * close it when the last reference is closed. */
+ // When using a pty the same FD is set on multiple parts, only
+ // close it when the last reference is closed.
if ((part == PART_IN || channel->CH_IN_FD != *fd)
&& (part == PART_OUT || channel->CH_OUT_FD != *fd)
&& (part == PART_ERR || channel->CH_ERR_FD != *fd))
@@ -1292,7 +1292,7 @@ ch_close_part(channel_T *channel, ch_part_T part)
}
*fd = INVALID_FD;
- /* channel is closed, may want to end the job if it was the last */
+ // channel is closed, may want to end the job if it was the last
channel->ch_to_be_closed &= ~(1U << part);
}
}
@@ -1305,8 +1305,8 @@ channel_set_pipes(channel_T *channel, sock_T in, sock_T out, sock_T err)
ch_close_part(channel, PART_IN);
channel->CH_IN_FD = in;
# if defined(UNIX)
- /* Do not end the job when all output channels are closed, wait until
- * the job ended. */
+ // Do not end the job when all output channels are closed, wait until
+ // the job ended.
if (mch_isatty(in))
channel->ch_to_be_closed |= (1U << PART_IN);
# endif
@@ -1359,8 +1359,8 @@ channel_set_job(channel_T *channel, job_T *job, jobopt_T *options)
{
if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT))
{
- /* Special mode: send last-but-one line when appending a line
- * to the buffer. */
+ // Special mode: send last-but-one line when appending a line
+ // to the buffer.
in_part->ch_bufref.br_buf->b_write_to_channel = TRUE;
in_part->ch_buf_append = TRUE;
in_part->ch_buf_top =
@@ -1413,7 +1413,7 @@ write_buf_line(buf_T *buf, linenr_T lnum, channel_T *channel)
char_u *p;
int i;
- /* Need to make a copy to be able to append a NL. */
+ // Need to make a copy to be able to append a NL.
if ((p = alloc(len + 2)) == NULL)
return;
memcpy((char *)p, (char *)line, len);
@@ -1443,15 +1443,15 @@ can_write_buf_line(channel_T *channel)
chanpart_T *in_part = &channel->ch_part[PART_IN];
if (in_part->ch_fd == INVALID_FD)
- return FALSE; /* pipe was closed */
+ return FALSE; // pipe was closed
- /* for testing: block every other attempt to write */
+ // for testing: block every other attempt to write
if (in_part->ch_block_write == 1)
in_part->ch_block_write = -1;
else if (in_part->ch_block_write == -1)
in_part->ch_block_write = 1;
- /* TODO: Win32 implementation, probably using WaitForMultipleObjects() */
+ // TODO: Win32 implementation, probably using WaitForMultipleObjects()
#ifndef MSWIN
{
# if defined(HAVE_SELECT)
@@ -1514,10 +1514,10 @@ channel_write_in(channel_T *channel)
int written = 0;
if (buf == NULL || in_part->ch_buf_append)
- return; /* no buffer or using appending */
+ return; // no buffer or using appending
if (!bufref_valid(&in_part->ch_bufref) || buf->b_ml.ml_mfp == NULL)
{
- /* buffer was wiped out or unloaded */
+ // buffer was wiped out or unloaded
ch_log(channel, "input buffer has been wiped out");
in_part->ch_bufref.br_buf = NULL;
return;
@@ -1541,16 +1541,16 @@ channel_write_in(channel_T *channel)
if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot)
{
#if defined(FEAT_TERMINAL)
- /* Send CTRL-D or "eof_chars" to close stdin on MS-Windows. */
+ // Send CTRL-D or "eof_chars" to close stdin on MS-Windows.
if (channel->ch_job != NULL)
term_send_eof(channel);
#endif
- /* Writing is done, no longer need the buffer. */
+ // Writing is done, no longer need the buffer.
in_part->ch_bufref.br_buf = NULL;
ch_log(channel, "Finished writing all lines to channel");
- /* Close the pipe/socket, so that the other side gets EOF. */
+ // Close the pipe/socket, so that the other side gets EOF.
ch_close_part(channel, PART_IN);
}
else
@@ -1621,8 +1621,8 @@ channel_write_new_lines(buf_T *buf)
channel_T *channel;
int found_one = FALSE;
- /* There could be more than one channel for the buffer, loop over all of
- * them. */
+ // There could be more than one channel for the buffer, loop over all of
+ // them.
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
{
chanpart_T *in_part = &channel->ch_part[PART_IN];
@@ -1632,7 +1632,7 @@ channel_write_new_lines(buf_T *buf)
if (in_part->ch_bufref.br_buf == buf && in_part->ch_buf_append)
{
if (in_part->ch_fd == INVALID_FD)
- continue; /* pipe was closed */
+ continue; // pipe was closed
found_one = TRUE;
for (lnum = in_part->ch_buf_bot; lnum < buf->b_ml.ml_line_count;
++lnum)
@@ -1723,7 +1723,7 @@ channel_get(channel_T *channel, ch_part_T part, int *outlen)
return NULL;
if (outlen != NULL)
*outlen += node->rq_buflen;
- /* dispose of the node but keep the buffer */
+ // dispose of the node but keep the buffer
p = node->rq_buffer;
head->rq_next = node->rq_next;
if (node->rq_next == NULL)
@@ -1853,7 +1853,7 @@ channel_collapse(channel_T *channel, ch_part_T part, int want_nl)
p = newbuf = alloc(len + 1);
if (newbuf == NULL)
- return FAIL; /* out of memory */
+ return FAIL; // out of memory
mch_memmove(p, node->rq_buffer, node->rq_buflen);
p += node->rq_buflen;
vim_free(node->rq_buffer);
@@ -1868,7 +1868,7 @@ channel_collapse(channel_T *channel, ch_part_T part, int want_nl)
*p = NUL;
node->rq_buflen = (long_u)(p - newbuf);
- /* dispose of the collapsed nodes and their buffers */
+ // dispose of the collapsed nodes and their buffers
for (n = node->rq_next; n != last_node; )
{
n = n->rq_next;
@@ -1899,19 +1899,19 @@ channel_save(channel_T *channel, ch_part_T part, char_u *buf, int len,
node = ALLOC_ONE(readq_T);
if (node == NULL)
- return FAIL; /* out of memory */
- /* A NUL is added at the end, because netbeans code expects that.
- * Otherwise a NUL may appear inside the text. */
+ return FAIL; // out of memory
+ // A NUL is added at the end, because netbeans code expects that.
+ // Otherwise a NUL may appear inside the text.
node->rq_buffer = alloc(len + 1);
if (node->rq_buffer == NULL)
{
vim_free(node);
- return FAIL; /* out of memory */
+ return FAIL; // out of memory
}
if (channel->ch_part[part].ch_mode == MODE_NL)
{
- /* Drop any CR before a NL. */
+ // Drop any CR before a NL.
p = node->rq_buffer;
for (i = 0; i < len; ++i)
if (buf[i] != CAR || i + 1 >= len || buf[i + 1] != NL)
@@ -1979,7 +1979,7 @@ channel_fill(js_read_T *reader)
keeplen = reader->js_end - reader->js_buf;
if (keeplen > 0)
{
- /* Prepend unused text. */
+ // Prepend unused text.
addlen = (int)STRLEN(next);
p = alloc(keeplen + addlen + 1);
if (p == NULL)
@@ -2023,18 +2023,18 @@ channel_parse_json(channel_T *channel, ch_part_T part)
reader.js_cookie = channel;
reader.js_cookie_arg = part;
- /* When a message is incomplete we wait for a short while for more to
- * arrive. After the delay drop the input, otherwise a truncated string
- * or list will make us hang.
- * Do not generate error messages, they will be written in a channel log. */
+ // When a message is incomplete we wait for a short while for more to
+ // arrive. After the delay drop the input, otherwise a truncated string
+ // or list will make us hang.
+ // Do not generate error messages, they will be written in a channel log.
++emsg_silent;
status = json_decode(&reader, &listtv,
chanpart->ch_mode == MODE_JS ? JSON_JS : 0);
--emsg_silent;
if (status == OK)
{
- /* Only accept the response when it is a list with at least two
- * items. */
+ // Only accept the response when it is a list with at least two
+ // items.
if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2)
{
if (listtv.v_type != VAR_LIST)
@@ -2081,8 +2081,8 @@ channel_parse_json(channel_T *channel, ch_part_T part)
if (chanpart->ch_wait_len < buflen)
{
- /* First time encountering incomplete message or after receiving
- * more (but still incomplete): set a deadline of 100 msec. */
+ // First time encountering incomplete message or after receiving
+ // more (but still incomplete): set a deadline of 100 msec.
ch_log(channel,
"Incomplete message (%d bytes) - wait 100 msec for more",
(int)buflen);
@@ -2137,7 +2137,7 @@ channel_parse_json(channel_T *channel, ch_part_T part)
}
else if (reader.js_buf[reader.js_used] != NUL)
{
- /* Put the unread part back into the channel. */
+ // Put the unread part back into the channel.
channel_save(channel, part, reader.js_buf + reader.js_used,
(int)(reader.js_end - reader.js_buf) - reader.js_used,
TRUE, NULL);
@@ -2296,10 +2296,10 @@ channel_push_json(channel_T *channel, ch_part_T part, typval_T *rettv)
jsonq_T *newitem;
if (head->jq_prev != NULL && head->jq_prev->jq_no_callback)
- /* last item was pushed back, append to the end */
+ // last item was pushed back, append to the end
item = NULL;
else while (item != NULL && item->jq_no_callback)
- /* append after the last item that was pushed back */
+ // append after the last item that was pushed back
item = item->jq_next;
newitem = ALLOC_ONE(jsonq_T);
@@ -2319,7 +2319,7 @@ channel_push_json(channel_T *channel, ch_part_T part, typval_T *rettv)
*newitem->jq_value = *rettv;
if (item == NULL)
{
- /* append to the end */
+ // append to the end
newitem->jq_prev = head->jq_prev;
head->jq_prev = newitem;
newitem->jq_next = NULL;
@@ -2330,7 +2330,7 @@ channel_push_json(channel_T *channel, ch_part_T part, typval_T *rettv)
}
else
{
- /* append after "item" */
+ // append after "item"
newitem->jq_prev = item;
newitem->jq_next = item->jq_next;
item->jq_next = newitem;
@@ -2390,7 +2390,7 @@ channel_exe_cmd(channel_T *channel, ch_part_T part, typval_T *argv)
vim_memset(&ea, 0, sizeof(ea));
ea.arg = arg;
ea.addr_count = 0;
- ea.forceit = TRUE; /* no mapping */
+ ea.forceit = TRUE; // no mapping
ex_normal(&ea);
}
else if (STRCMP(cmd, "redraw") == 0)
@@ -2430,7 +2430,7 @@ channel_exe_cmd(channel_T *channel, ch_part_T part, typval_T *argv)
typval_T err_tv;
char_u *json = NULL;
- /* Don't pollute the display with errors. */
+ // Don't pollute the display with errors.
++emsg_skip;
if (!is_call)
{
@@ -2452,8 +2452,8 @@ channel_exe_cmd(channel_T *channel, ch_part_T part, typval_T *argv)
json = json_encode_nr_expr(id, tv, options | JSON_NL);
if (tv == NULL || (json != NULL && *json == NUL))
{
- /* If evaluation failed or the result can't be encoded
- * then return the string "ERROR". */
+ // If evaluation failed or the result can't be encoded
+ // then return the string "ERROR".
vim_free(json);
err_tv.v_type = VAR_STRING;
err_tv.vval.v_string = (char_u *)"ERROR";
@@ -2494,8 +2494,8 @@ invoke_one_time_callback(
{
ch_log(channel, "Invoking one-time callback %s",
(char *)item->cq_callback.cb_name);
- /* Remove the item from the list first, if the callback
- * invokes ch_close() the list will be cleared. */
+ // Remove the item from the list first, if the callback
+ // invokes ch_close() the list will be cleared.
remove_cb_node(cbhead, item);
invoke_callback(channel, &item->cq_callback, argv);
free_callback(&item->cq_callback);
@@ -2524,29 +2524,29 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
return;
}
- /* If the buffer is also used as input insert above the last
- * line. Don't write these lines. */
+ // If the buffer is also used as input insert above the last
+ // line. Don't write these lines.
if (save_write_to)
{
--lnum;
buffer->b_write_to_channel = FALSE;
}
- /* Append to the buffer */
+ // Append to the buffer
ch_log(channel, "appending line %d to buffer", (int)lnum + 1 - empty);
buffer->b_p_ma = TRUE;
- /* Save curbuf/curwin/curtab and make "buffer" the current buffer. */
+ // Save curbuf/curwin/curtab and make "buffer" the current buffer.
switch_to_win_for_buf(buffer, &save_curwin, &save_curtab, &save_curbuf);
u_sync(TRUE);
- /* ignore undo failure, undo is not very useful here */
+ // ignore undo failure, undo is not very useful here
vim_ignored = u_save(lnum - empty, lnum + 1);
if (empty)
{
- /* The buffer is empty, replace the first (dummy) line. */
+ // The buffer is empty, replace the first (dummy) line.
ml_replace(lnum, msg, TRUE);
lnum = 0;
}
@@ -2554,7 +2554,7 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
ml_append(lnum, msg, 0, FALSE);
appended_lines_mark(lnum, 1L);
- /* Restore curbuf/curwin/curtab */
+ // Restore curbuf/curwin/curtab
restore_win_for_buf(save_curwin, save_curtab, &save_curbuf);
if (ch_part->ch_nomodifiable)
@@ -2598,8 +2598,8 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
{
channel_T *ch;
- /* Find channels reading from this buffer and adjust their
- * next-to-read line number. */
+ // Find channels reading from this buffer and adjust their
+ // next-to-read line number.
buffer->b_write_to_channel = TRUE;
for (ch = first_channel; ch != NULL; ch = ch->ch_next)
{
@@ -2644,10 +2644,10 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
char_u *p;
if (channel->ch_nb_close_cb != NULL)
- /* this channel is handled elsewhere (netbeans) */
+ // this channel is handled elsewhere (netbeans)
return FALSE;
- /* Use a message-specific callback, part callback or channel callback */
+ // Use a message-specific callback, part callback or channel callback
for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next)
if (cbitem->cq_seq_nr == 0)
break;
@@ -2662,7 +2662,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref)
|| buffer->b_ml.ml_mfp == NULL))
{
- /* buffer was wiped out or unloaded */
+ // buffer was wiped out or unloaded
ch_log(channel, "%s buffer has been wiped out", part_names[part]);
ch_part->ch_bufref.br_buf = NULL;
buffer = NULL;
@@ -2673,10 +2673,10 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
listitem_T *item;
int argc = 0;
- /* Get any json message in the queue. */
+ // Get any json message in the queue.
if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL)
{
- /* Parse readahead, return when there is still no message. */
+ // Parse readahead, return when there is still no message.
channel_parse_json(channel, part);
if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL)
return FALSE;
@@ -2691,7 +2691,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
if (argv[0].v_type == VAR_STRING)
{
- /* ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] */
+ // ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg]
channel_exe_cmd(channel, part, argv);
free_tv(listtv);
return TRUE;
@@ -2708,16 +2708,16 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
}
else if (channel_peek(channel, part) == NULL)
{
- /* nothing to read on RAW or NL channel */
+ // nothing to read on RAW or NL channel
return FALSE;
}
else
{
- /* If there is no callback or buffer drop the message. */
+ // If there is no callback or buffer drop the message.
if (callback == NULL && buffer == NULL)
{
- /* If there is a close callback it may use ch_read() to get the
- * messages. */
+ // If there is a close callback it may use ch_read() to get the
+ // messages.
if (channel->ch_close_cb.cb_name == NULL && !channel->ch_drop_never)
drop_messages(channel, part);
return FALSE;
@@ -2729,8 +2729,8 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
char_u *buf;
readq_T *node;
- /* See if we have a message ending in NL in the first buffer. If
- * not try to concatenate the first and the second buffer. */
+ // See if we have a message ending in NL in the first buffer. If
+ // not try to concatenate the first and the second buffer.
while (TRUE)
{
node = channel_peek(channel, part);
@@ -2741,7 +2741,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
{
if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0)
break;
- return FALSE; /* incomplete message */
+ return FALSE; // incomplete message
}
}
buf = node->rq_buffer;
@@ -2765,22 +2765,22 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
}
else
{
- /* Copy the message into allocated memory (excluding the NL)
- * and remove it from the buffer (including the NL). */
+ // Copy the message into allocated memory (excluding the NL)
+ // and remove it from the buffer (including the NL).
msg = vim_strnsave(buf, (int)(nl - buf));
channel_consume(channel, part, (int)(nl - buf) + 1);
}
}
else
{
- /* For a raw channel we don't know where the message ends, just
- * get everything we have.
- * Convert NUL to NL, the internal representation. */
+ // For a raw channel we don't know where the message ends, just
+ // get everything we have.
+ // Convert NUL to NL, the internal representation.
msg = channel_get_all(channel, part, NULL);
}
if (msg == NULL)
- return FALSE; /* out of memory (and avoids Coverity warning) */
+ return FALSE; // out of memory (and avoids Coverity warning)
argv[1].v_type = VAR_STRING;
argv[1].vval.v_string = msg;
@@ -2790,7 +2790,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
{
int done = FALSE;
- /* JSON or JS mode: invoke the one-time callback with the matching nr */
+ // JSON or JS mode: invoke the one-time callback with the matching nr
for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next)
if (cbitem->cq_seq_nr == seq_nr)
{
@@ -2802,7 +2802,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
{
if (channel->ch_drop_never)
{
- /* message must be read with ch_read() */
+ // message must be read with ch_read()
channel_push_json(channel, part, listtv);
listtv = NULL;
}
@@ -2816,7 +2816,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
if (buffer != NULL)
{
if (msg == NULL)
- /* JSON or JS mode: re-encode the message. */
+ // JSON or JS mode: re-encode the message.
msg = json_encode(listtv, ch_mode);
if (msg != NULL)
{
@@ -2835,7 +2835,7 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
invoke_one_time_callback(channel, cbhead, cbitem, argv);
else
{
- /* invoke the channel callback */
+ // invoke the channel callback
ch_log(channel, "Invoking channel callback %s",
(char *)callback->cb_name);
invoke_callback(channel, callback, argv);
@@ -2947,7 +2947,7 @@ channel_status(channel_T *channel, int req_part)
channel_part_info(channel_T *channel, dict_T *dict, char *name, ch_part_T part)
{
chanpart_T *chanpart = &channel->ch_part[part];
- char namebuf[20]; /* longest is "sock_timeout" */
+ char namebuf[20]; // longest is "sock_timeout"
size_t tail;
char *status;
char *s = "";
@@ -3035,7 +3035,7 @@ channel_close(channel_T *channel, int invoke_close_cb)
{
ch_part_T part;
- /* Invoke callbacks and flush buffers before the close callback. */
+ // Invoke callbacks and flush buffers before the close callback.
if (channel->ch_close_cb.cb_name != NULL)
ch_log(channel,
"Invoking callbacks and flushing buffers before closing");
@@ -3044,8 +3044,8 @@ channel_close(channel_T *channel, int invoke_close_cb)
if (channel->ch_close_cb.cb_name != NULL
|| channel->ch_part[part].ch_bufref.br_buf != NULL)
{
- /* Increment the refcount to avoid the channel being freed
- * halfway. */
+ // Increment the refcount to avoid the channel being freed
+ // halfway.
++channel->ch_refcount;
if (channel->ch_close_cb.cb_name == NULL)
ch_log(channel, "flushing %s buffers before closing",
@@ -3061,8 +3061,8 @@ channel_close(channel_T *channel, int invoke_close_cb)
typval_T argv[1];
typval_T rettv;
- /* Increment the refcount to avoid the channel being freed
- * halfway. */
+ // Increment the refcount to avoid the channel being freed
+ // halfway.
++channel->ch_refcount;
ch_log(channel, "Invoking close callback %s",
(char *)channel->ch_close_cb.cb_name);
@@ -3072,7 +3072,7 @@ channel_close(channel_T *channel, int invoke_close_cb)
clear_tv(&rettv);
channel_need_redraw = TRUE;
- /* the callback is only called once */
+ // the callback is only called once
free_callback(&channel->ch_close_cb);
if (channel_need_redraw)
@@ -3082,7 +3082,7 @@ channel_close(channel_T *channel, int invoke_close_cb)
}
if (!channel->ch_drop_never)
- /* any remaining messages are useless now */
+ // any remaining messages are useless now
for (part = PART_SOCK; part < PART_IN; ++part)
drop_messages(channel, part);
@@ -3183,10 +3183,10 @@ channel_free_all(void)
#endif
-/* Sent when the netbeans channel is found closed when reading. */
+// Sent when the netbeans channel is found closed when reading.
#define DETACH_MSG_RAW "DETACH\n"
-/* Buffer size for reading incoming messages. */
+// Buffer size for reading incoming messages.
#define MAXMSGSIZE 4096
#if defined(HAVE_SELECT)
@@ -3270,7 +3270,7 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
DWORD deadline = GetTickCount() + timeout;
int delay = 1;
- /* reading from a pipe, not a socket */
+ // reading from a pipe, not a socket
while (TRUE)
{
int r = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL);
@@ -3286,14 +3286,14 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
else if (r == 0)
return CW_ERROR;
- /* perhaps write some buffer lines */
+ // perhaps write some buffer lines
channel_write_any_lines();
sleep_time = deadline - GetTickCount();
if (sleep_time <= 0)
break;
- /* Wait for a little while. Very short at first, up to 10 msec
- * after looping a few times. */
+ // Wait for a little while. Very short at first, up to 10 msec
+ // after looping a few times.
if (sleep_time > delay)
sleep_time = delay;
Sleep(sleep_time);
@@ -3319,8 +3319,8 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
FD_ZERO(&rfds);
FD_SET((int)fd, &rfds);
- /* Write lines to a pipe when a pipe can be written to. Need to
- * set this every time, some buffers may be done. */
+ // Write lines to a pipe when a pipe can be written to. Need to
+ // set this every time, some buffers may be done.
maxfd = (int)fd + 1;
FD_ZERO(&wfds);
maxfd = channel_fill_wfds(maxfd, &wfds);
@@ -3370,30 +3370,29 @@ ch_close_part_on_error(
char msg[] = "%s(): Read %s from ch_part[%d], closing";
if (is_err)
- /* Do not call emsg(), most likely the other end just exited. */
+ // Do not call emsg(), most likely the other end just exited.
ch_error(channel, msg, func, "error", part);
else
ch_log(channel, msg, func, "EOF", part);
- /* Queue a "DETACH" netbeans message in the command queue in order to
- * terminate the netbeans session later. Do not end the session here
- * directly as we may be running in the context of a call to
- * netbeans_parse_messages():
- * netbeans_parse_messages
- * -> autocmd triggered while processing the netbeans cmd
- * -> ui_breakcheck
- * -> gui event loop or select loop
- * -> channel_read()
- * Only send "