annotate src/channel.c @ 8422:5d2c84be23b5 v7.4.1502

commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 6 20:22:25 2016 +0100 patch 7.4.1502 Problem: Writing last-but-one line of buffer to a channel isn't implemented yet. Solution: Implement it. Fix leaving a swap file behind.
author Christian Brabandt <cb@256bit.org>
date Sun, 06 Mar 2016 20:30:04 +0100
parents 05ec48deb353
children 4e22d0e7bfb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 */
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 /*
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 * Implements communication through a socket or any file handle.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 */
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 #include "vim.h"
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 #if defined(FEAT_CHANNEL) || defined(PROTO)
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
17 /* TRUE when netbeans is running with a GUI. */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
18 #ifdef FEAT_GUI
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
19 # define CH_HAS_GUI (gui.in_use || gui.starting)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
20 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
21
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
22 /* Note: when making changes here also adjust configure.in. */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
23 #ifdef WIN32
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
24 /* WinSock API is separated from C API, thus we can't use read(), write(),
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
25 * errno... */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
26 # define SOCK_ERRNO errno = WSAGetLastError()
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
27 # undef ECONNREFUSED
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
28 # define ECONNREFUSED WSAECONNREFUSED
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
29 # undef EWOULDBLOCK
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
30 # define EWOULDBLOCK WSAEWOULDBLOCK
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
31 # undef EINPROGRESS
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
32 # define EINPROGRESS WSAEINPROGRESS
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
33 # ifdef EINTR
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
34 # undef EINTR
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
35 # endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
36 # define EINTR WSAEINTR
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
37 # define sock_write(sd, buf, len) send((SOCKET)sd, buf, len, 0)
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
38 # define sock_read(sd, buf, len) recv((SOCKET)sd, buf, len, 0)
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
39 # define sock_close(sd) closesocket((SOCKET)sd)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
40 #else
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
41 # include <netdb.h>
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
42 # include <netinet/in.h>
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
43
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
44 # include <sys/socket.h>
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
45 # ifdef HAVE_LIBGEN_H
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
46 # include <libgen.h>
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
47 # endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
48 # define SOCK_ERRNO
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
49 # define sock_write(sd, buf, len) write(sd, buf, len)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
50 # define sock_read(sd, buf, len) read(sd, buf, len)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
51 # define sock_close(sd) close(sd)
8072
38887bf423ba commit https://github.com/vim/vim/commit/0943a09db84b036ec550d7f2e5b832f621b400ca
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
52 # define fd_read(fd, buf, len) read(fd, buf, len)
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
53 # define fd_write(sd, buf, len) write(sd, buf, len)
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
54 # define fd_close(sd) close(sd)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
55 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
56
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
57 /* Whether a redraw is needed for appending a line to a buffer. */
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
58 static int channel_need_redraw = FALSE;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
59
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
60
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
61 #ifdef WIN32
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
62 static int
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 8074
diff changeset
63 fd_read(sock_T fd, char *buf, size_t len)
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
64 {
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
65 HANDLE h = (HANDLE)fd;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
66 DWORD nread;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
67
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
68 if (!ReadFile(h, buf, (DWORD)len, &nread, NULL))
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
69 return -1;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
70 return (int)nread;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
71 }
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
72
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
73 static int
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 8074
diff changeset
74 fd_write(sock_T fd, char *buf, size_t len)
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
75 {
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
76 HANDLE h = (HANDLE)fd;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
77 DWORD nwrite;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
78
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
79 if (!WriteFile(h, buf, (DWORD)len, &nwrite, NULL))
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
80 return -1;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
81 return (int)nwrite;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
82 }
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
83
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
84 static void
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
85 fd_close(sock_T fd)
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
86 {
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
87 HANDLE h = (HANDLE)fd;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
88
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
89 CloseHandle(h);
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
90 }
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
91 #endif
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
93 /* Log file opened with ch_logfile(). */
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
94 static FILE *log_fd = NULL;
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
95 #ifdef FEAT_RELTIME
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
96 static proftime_T log_start;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
97 #endif
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
98
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
99 void
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
100 ch_logfile(FILE *file)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
101 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
102 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
103 fclose(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
104 log_fd = file;
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
105 if (log_fd != NULL)
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
106 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
107 fprintf(log_fd, "==== start log session ====\n");
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
108 #ifdef FEAT_RELTIME
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
109 profile_start(&log_start);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
110 #endif
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
111 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
112 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
113
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
114 int
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
115 ch_log_active()
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
116 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
117 return log_fd != NULL;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
118 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
119
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
120 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
121 ch_log_lead(char *what, channel_T *ch)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
122 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
123 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
124 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
125 #ifdef FEAT_RELTIME
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
126 proftime_T log_now;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
127
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
128 profile_start(&log_now);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
129 profile_sub(&log_now, &log_start);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
130 fprintf(log_fd, "%s ", profile_msg(&log_now));
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
131 #endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
132 if (ch != NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
133 fprintf(log_fd, "%son %d: ", what, ch->ch_id);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
134 else
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
135 fprintf(log_fd, "%s: ", what);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
136 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
137 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
138
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
139 void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
140 ch_log(channel_T *ch, char *msg)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
141 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
142 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
143 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
144 ch_log_lead("", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
145 fputs(msg, log_fd);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
146 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
147 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
148 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
149 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
150
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
151 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
152 ch_logn(channel_T *ch, char *msg, int nr)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
153 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
154 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
155 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
156 ch_log_lead("", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
157 fprintf(log_fd, msg, nr);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
158 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
159 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
160 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
161 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
162
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
163 void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
164 ch_logs(channel_T *ch, char *msg, char *name)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
165 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
166 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
167 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
168 ch_log_lead("", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
169 fprintf(log_fd, msg, name);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
170 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
171 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
172 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
173 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
174
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
175 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
176 ch_logsn(channel_T *ch, char *msg, char *name, int nr)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
177 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
178 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
179 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
180 ch_log_lead("", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
181 fprintf(log_fd, msg, name, nr);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
182 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
183 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
184 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
185 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
186
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
187 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
188 ch_error(channel_T *ch, char *msg)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
189 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
190 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
191 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
192 ch_log_lead("ERR ", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
193 fputs(msg, log_fd);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
194 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
195 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
196 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
197 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
198
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
199 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
200 ch_errorn(channel_T *ch, char *msg, int nr)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
201 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
202 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
203 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
204 ch_log_lead("ERR ", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
205 fprintf(log_fd, msg, nr);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
206 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
207 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
208 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
209 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
210
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
211 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
212 ch_errors(channel_T *ch, char *msg, char *arg)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
213 {
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
214 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
215 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
216 ch_log_lead("ERR ", ch);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
217 fprintf(log_fd, msg, arg);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
218 fputc('\n', log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
219 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
220 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
221 }
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
222
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
223 #ifdef _WIN32
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
224 # undef PERROR
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
225 # define PERROR(msg) (void)emsg3((char_u *)"%s: %s", \
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
226 (char_u *)msg, (char_u *)strerror_win32(errno))
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
227
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
228 static char *
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
229 strerror_win32(int eno)
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
230 {
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
231 static LPVOID msgbuf = NULL;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
232 char_u *ptr;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
233
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
234 if (msgbuf)
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
235 LocalFree(msgbuf);
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
236 FormatMessage(
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
237 FORMAT_MESSAGE_ALLOCATE_BUFFER |
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
238 FORMAT_MESSAGE_FROM_SYSTEM |
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
239 FORMAT_MESSAGE_IGNORE_INSERTS,
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
240 NULL,
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
241 eno,
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
242 MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
243 (LPTSTR) &msgbuf,
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
244 0,
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
245 NULL);
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
246 /* chomp \r or \n */
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
247 for (ptr = (char_u *)msgbuf; *ptr; ptr++)
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
248 switch (*ptr)
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
249 {
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
250 case '\r':
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
251 STRMOVE(ptr, ptr + 1);
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
252 ptr--;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
253 break;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
254 case '\n':
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
255 if (*(ptr + 1) == '\0')
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
256 *ptr = '\0';
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
257 else
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
258 *ptr = ' ';
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
259 break;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
260 }
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
261 return msgbuf;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
262 }
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
263 #endif
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
264
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
265 /*
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
266 * The list of all allocated channels.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
267 */
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
268 static channel_T *first_channel = NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
269 static int next_ch_id = 0;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
271 /*
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
272 * Allocate a new channel. The refcount is set to 1.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
273 * The channel isn't actually used until it is opened.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
274 * Returns NULL if out of memory.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
275 */
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
276 channel_T *
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
277 add_channel(void)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
278 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
279 int part;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
280 channel_T *channel = (channel_T *)alloc_clear((int)sizeof(channel_T));
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
281
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
282 if (channel == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
283 return NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
284
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
285 channel->ch_id = next_ch_id++;
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
286 ch_log(channel, "Created channel");
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
287
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
288 #ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
289 for (part = PART_SOCK; part <= PART_IN; ++part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
290 #else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
291 part = PART_SOCK;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
292 #endif
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
293 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
294 channel->ch_part[part].ch_fd = INVALID_FD;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
295 #ifdef FEAT_GUI_X11
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
296 channel->ch_part[part].ch_inputHandler = (XtInputId)NULL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
297 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
298 #ifdef FEAT_GUI_GTK
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
299 channel->ch_part[part].ch_inputHandler = 0;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
300 #endif
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
301 channel->ch_part[part].ch_timeout = 2000;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
302 }
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
303
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
304 if (first_channel != NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
305 {
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
306 first_channel->ch_prev = channel;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
307 channel->ch_next = first_channel;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
308 }
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
309 first_channel = channel;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
310
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
311 channel->ch_refcount = 1;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
312 return channel;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
313 }
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
314
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
315 /*
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
316 * Called when the refcount of a channel is zero.
8259
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
317 * Return TRUE if "channel" has a callback and the associated job wasn't
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
318 * killed.
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
319 */
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
320 static int
8259
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
321 channel_still_useful(channel_T *channel)
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
322 {
8332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
323 int has_sock_msg;
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
324 #ifdef CHANNEL_PIPES
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
325 int has_out_msg;
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
326 int has_err_msg;
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
327 #endif
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
328
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
329 /* If the job was killed the channel is not expected to work anymore. */
8259
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
330 if (channel->ch_job_killed && channel->ch_job == NULL)
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
331 return FALSE;
8332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
333 /* If there is a close callback it may still need to be invoked. */
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
334 if (channel->ch_close_cb != NULL)
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
335 return TRUE;
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
336
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
337 /* If there is no callback then nobody can get readahead. If the fd is
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
338 * closed and there is no readahead then the callback won't be called. */
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
339 has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
340 || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
341 || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL;
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
342 #ifdef CHANNEL_PIPES
8332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
343 has_out_msg = channel->ch_part[PART_OUT].ch_fd != INVALID_FD
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
344 || channel->ch_part[PART_OUT].ch_head.rq_next != NULL
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
345 || channel->ch_part[PART_OUT].ch_json_head.jq_next != NULL;
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
346 has_err_msg = channel->ch_part[PART_ERR].ch_fd != INVALID_FD
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
347 || channel->ch_part[PART_ERR].ch_head.rq_next != NULL
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
348 || channel->ch_part[PART_ERR].ch_json_head.jq_next != NULL;
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
349 #endif
8332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
350 return (channel->ch_callback != NULL && (has_sock_msg
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
351 #ifdef CHANNEL_PIPES
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
352 || has_out_msg || has_err_msg
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
353 #endif
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
354 ))
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
355 #ifdef CHANNEL_PIPES
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
356 || (channel->ch_part[PART_OUT].ch_callback != NULL && has_out_msg)
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
357 || (channel->ch_part[PART_ERR].ch_callback != NULL && has_err_msg)
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
358 #endif
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
359 ;
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
360 }
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
361
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
362 /*
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
363 * Close a channel and free all its resources if there is no further action
8259
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
364 * possible, there is no callback to be invoked or the associated job was
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
365 * killed.
8318
190d8084cb3a commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents: 8310
diff changeset
366 * Return TRUE if the channel was freed.
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
367 */
8318
190d8084cb3a commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents: 8310
diff changeset
368 int
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
369 channel_may_free(channel_T *channel)
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
370 {
8259
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
371 if (!channel_still_useful(channel))
8318
190d8084cb3a commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents: 8310
diff changeset
372 {
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
373 channel_free(channel);
8318
190d8084cb3a commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents: 8310
diff changeset
374 return TRUE;
190d8084cb3a commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents: 8310
diff changeset
375 }
190d8084cb3a commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents: 8310
diff changeset
376 return FALSE;
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
377 }
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
378
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
379 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
380 * Close a channel and free all its resources.
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
381 */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
382 void
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
383 channel_free(channel_T *channel)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
384 {
8240
60586ce747c4 commit https://github.com/vim/vim/commit/8b374215ccd35003b95ba1df8f12e03bf8a8adc3
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
385 channel_close(channel, TRUE);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
386 channel_clear(channel);
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
387 ch_log(channel, "Freeing channel");
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
388 if (channel->ch_next != NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
389 channel->ch_next->ch_prev = channel->ch_prev;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
390 if (channel->ch_prev == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
391 first_channel = channel->ch_next;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
392 else
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
393 channel->ch_prev->ch_next = channel->ch_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
394 vim_free(channel);
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 }
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
397 #if defined(FEAT_GUI) || defined(PROTO)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
398
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
399 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
400 static void
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
401 channel_read_fd(int fd)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
402 {
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
403 channel_T *channel;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
404 int part;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
405
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
406 channel = channel_fd2channel(fd, &part);
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
407 if (channel == NULL)
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
408 ch_errorn(NULL, "Channel for fd %d not found", fd);
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
409 else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
410 channel_read(channel, part, "messageFromNetbeans");
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
411 }
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
412 #endif
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
413
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414 /*
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
415 * Read a command from netbeans.
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
416 * TODO: instead of channel ID use the FD.
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417 */
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
418 #ifdef FEAT_GUI_X11
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
419 static void
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
420 messageFromNetbeans(XtPointer clientData,
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
421 int *unused1 UNUSED,
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
422 XtInputId *unused2 UNUSED)
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 {
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
424 channel_read_fd((int)(long)clientData);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
425 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
426 #endif
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
427
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
428 #ifdef FEAT_GUI_GTK
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
429 # if GTK_CHECK_VERSION(3,0,0)
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
430 static gboolean
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
431 messageFromNetbeans(GIOChannel *unused1 UNUSED,
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
432 GIOCondition unused2 UNUSED,
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
433 gpointer clientData)
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
434 {
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
435 channel_read_fd(GPOINTER_TO_INT(clientData));
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
436 return TRUE; /* Return FALSE instead in case the event source is to
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
437 * be removed after this function returns. */
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
438 }
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
439 # else
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
440 static void
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
441 messageFromNetbeans(gpointer clientData,
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
442 gint unused1 UNUSED,
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
443 GdkInputCondition unused2 UNUSED)
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 {
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
445 channel_read_fd((int)(long)clientData);
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 }
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
447 # endif
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 #endif
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 static void
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
451 channel_gui_register_one(channel_T *channel, int part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
452 {
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
453 # ifdef FEAT_GUI_X11
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
454 /* Tell notifier we are interested in being called
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
455 * when there is input on the editor connection socket. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
456 if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
457 channel->ch_part[part].ch_inputHandler = XtAppAddInput(
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
458 (XtAppContext)app_context,
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
459 channel->ch_part[part].ch_fd,
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
460 (XtPointer)(XtInputReadMask + XtInputExceptMask),
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
461 messageFromNetbeans,
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
462 (XtPointer)(long)channel->ch_part[part].ch_fd);
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
463 # else
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
464 # ifdef FEAT_GUI_GTK
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
465 /* Tell gdk we are interested in being called when there
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
466 * is input on the editor connection socket. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
467 if (channel->ch_part[part].ch_inputHandler == 0)
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
468 # if GTK_CHECK_VERSION(3,0,0)
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
469 {
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
470 GIOChannel *chnnl = g_io_channel_unix_new(
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
471 (gint)channel->ch_part[part].ch_fd);
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
472
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
473 channel->ch_part[part].ch_inputHandler = g_io_add_watch(
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
474 chnnl,
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
475 G_IO_IN|G_IO_HUP|G_IO_ERR|G_IO_PRI,
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
476 messageFromNetbeans,
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
477 GINT_TO_POINTER(channel->ch_part[part].ch_fd));
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
478
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
479 g_io_channel_unref(chnnl);
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
480 }
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
481 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
482 channel->ch_part[part].ch_inputHandler = gdk_input_add(
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
483 (gint)channel->ch_part[part].ch_fd,
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
484 (GdkInputCondition)
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
485 ((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
486 messageFromNetbeans,
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
487 (gpointer)(long)channel->ch_part[part].ch_fd);
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
488 # endif
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
489 # endif
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
490 # endif
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
491 }
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
492
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
493 void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
494 channel_gui_register(channel_T *channel)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
495 {
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
496 if (!CH_HAS_GUI)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
497 return;
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
498
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
499 if (channel->CH_SOCK_FD != INVALID_FD)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
500 channel_gui_register_one(channel, PART_SOCK);
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
501 # ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
502 if (channel->CH_OUT_FD != INVALID_FD)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
503 channel_gui_register_one(channel, PART_OUT);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
504 if (channel->CH_ERR_FD != INVALID_FD)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
505 channel_gui_register_one(channel, PART_ERR);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
506 # endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
507 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
508
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
509 /*
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
510 * Register any of our file descriptors with the GUI event handling system.
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
511 * Called when the GUI has started.
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
512 */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
513 void
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
514 channel_gui_register_all(void)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
515 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
516 channel_T *channel;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
517
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
518 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
519 channel_gui_register(channel);
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
520 }
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
521
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
522 static void
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
523 channel_gui_unregister(channel_T *channel)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
524 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
525 int part;
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
526
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
527 #ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
528 for (part = PART_SOCK; part < PART_IN; ++part)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
529 #else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
530 part = PART_SOCK;
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
531 #endif
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
532 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
533 # ifdef FEAT_GUI_X11
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
534 if (channel->ch_part[part].ch_inputHandler != (XtInputId)NULL)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
535 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
536 XtRemoveInput(channel->ch_part[part].ch_inputHandler);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
537 channel->ch_part[part].ch_inputHandler = (XtInputId)NULL;
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
538 }
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
539 # else
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
540 # ifdef FEAT_GUI_GTK
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
541 if (channel->ch_part[part].ch_inputHandler != 0)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
542 {
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
543 # if GTK_CHECK_VERSION(3,0,0)
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
544 g_source_remove(channel->ch_part[part].ch_inputHandler);
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
545 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
546 gdk_input_remove(channel->ch_part[part].ch_inputHandler);
8218
3456e2ebebd4 commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
547 # endif
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
548 channel->ch_part[part].ch_inputHandler = 0;
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
549 }
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
550 # endif
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
551 # endif
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
552 }
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
553 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
554
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
555 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
556
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
557 static char *e_cannot_connect = N_("E902: Cannot connect to port");
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
558
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
559 /*
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
560 * Open a socket channel to "hostname":"port".
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
561 * "waittime" is the time in msec to wait for the connection.
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
562 * When negative wait forever.
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
563 * Returns the channel for success.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
564 * Returns NULL for failure.
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
565 */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
566 channel_T *
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
567 channel_open(
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
568 char *hostname,
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
569 int port_in,
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
570 int waittime,
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
571 void (*nb_close_cb)(void))
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
573 int sd = -1;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
574 struct sockaddr_in server;
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
575 struct hostent *host;
7797
0d46cea25641 commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents: 7795
diff changeset
576 #ifdef WIN32
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
577 u_short port = port_in;
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
578 u_long val = 1;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
579 #else
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
580 int port = port_in;
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
581 struct timeval start_tv;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
582 #endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
583 channel_T *channel;
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
584 int ret;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
585
7797
0d46cea25641 commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents: 7795
diff changeset
586 #ifdef WIN32
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
587 channel_init_winsock();
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
588 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
589
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
590 channel = add_channel();
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
591 if (channel == NULL)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
592 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
593 ch_error(NULL, "Cannot allocate channel.");
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
594 return NULL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
595 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
596
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
597 /* Get the server internet address and put into addr structure */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
598 /* fill in the socket address structure and connect to server */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
599 vim_memset((char *)&server, 0, sizeof(server));
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
600 server.sin_family = AF_INET;
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
601 server.sin_port = htons(port);
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
602 if ((host = gethostbyname(hostname)) == NULL)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
603 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
604 ch_error(channel, "in gethostbyname() in channel_open()");
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
605 PERROR("E901: gethostbyname() in channel_open()");
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
606 channel_free(channel);
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
607 return NULL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
608 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
609 memcpy((char *)&server.sin_addr, host->h_addr, host->h_length);
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
610
8134
8abef552ece7 commit https://github.com/vim/vim/commit/254e00d71429aa4e71b93d3e8c6bb93bfebe4f26
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
611 /* On Mac and Solaris a zero timeout almost never works. At least wait
8abef552ece7 commit https://github.com/vim/vim/commit/254e00d71429aa4e71b93d3e8c6bb93bfebe4f26
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
612 * one millisecond. Let's do it for all systems, because we don't know why
8abef552ece7 commit https://github.com/vim/vim/commit/254e00d71429aa4e71b93d3e8c6bb93bfebe4f26
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
613 * this is needed. */
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
614 if (waittime == 0)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
615 waittime = 1;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
616
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
617 /*
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
618 * For Unix we need to call connect() again after connect() failed.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
619 * On Win32 one time is sufficient.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
620 */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
621 while (TRUE)
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
623 if (sd >= 0)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
624 sock_close(sd);
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
625 sd = socket(AF_INET, SOCK_STREAM, 0);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
626 if (sd == -1)
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
627 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
628 ch_error(channel, "in socket() in channel_open().");
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
629 PERROR("E898: socket() in channel_open()");
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
630 channel_free(channel);
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
631 return NULL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
632 }
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
633
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
634 if (waittime >= 0)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
635 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
636 /* Make connect() non-blocking. */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
637 if (
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
638 #ifdef _WIN32
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
639 ioctlsocket(sd, FIONBIO, &val) < 0
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
640 #else
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
641 fcntl(sd, F_SETFL, O_NONBLOCK) < 0
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
642 #endif
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
643 )
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
644 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
645 SOCK_ERRNO;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
646 ch_errorn(channel,
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
647 "channel_open: Connect failed with errno %d", errno);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
648 sock_close(sd);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
649 channel_free(channel);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
650 return NULL;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
651 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
652 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
653
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
654 /* Try connecting to the server. */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
655 ch_logsn(channel, "Connecting to %s port %d", hostname, port);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
656 ret = connect(sd, (struct sockaddr *)&server, sizeof(server));
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
657
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
658 SOCK_ERRNO;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
659 if (ret < 0)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
660 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
661 if (errno != EWOULDBLOCK
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
662 && errno != ECONNREFUSED
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
663 #ifdef EINPROGRESS
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
664 && errno != EINPROGRESS
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
665 #endif
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
666 )
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
667 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
668 ch_errorn(channel,
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
669 "channel_open: Connect failed with errno %d", errno);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
670 PERROR(_(e_cannot_connect));
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
671 sock_close(sd);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
672 channel_free(channel);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
673 return NULL;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
674 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
675 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
676
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
677 /* If we don't block and connect() failed then try using select() to
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
678 * wait for the connection to be made. */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
679 if (waittime >= 0 && ret < 0)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
680 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
681 struct timeval tv;
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
682 fd_set rfds;
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
683 fd_set wfds;
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
684 #ifndef WIN32
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
685 int so_error = 0;
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
686 socklen_t so_error_len = sizeof(so_error);
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
687 #endif
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
688
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
689 FD_ZERO(&rfds);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
690 FD_SET(sd, &rfds);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
691 FD_ZERO(&wfds);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
692 FD_SET(sd, &wfds);
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
693
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
694 tv.tv_sec = waittime / 1000;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
695 tv.tv_usec = (waittime % 1000) * 1000;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
696 #ifndef WIN32
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
697 gettimeofday(&start_tv, NULL);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
698 #endif
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
699 ch_logn(channel,
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
700 "Waiting for connection (waittime %d msec)...", waittime);
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
701 ret = select((int)sd + 1, &rfds, &wfds, NULL, &tv);
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
702
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
703 if (ret < 0)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
704 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
705 SOCK_ERRNO;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
706 ch_errorn(channel,
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
707 "channel_open: Connect failed with errno %d", errno);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
708 PERROR(_(e_cannot_connect));
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
709 sock_close(sd);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
710 channel_free(channel);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
711 return NULL;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
712 }
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
713
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
714 #ifdef WIN32
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
715 /* On Win32: select() is expected to work and wait for up to the
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
716 * waittime for the socket to be open. */
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
717 if (!FD_ISSET(sd, &wfds) || ret == 0)
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
718 #else
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
719 /* On Linux-like systems: See socket(7) for the behavior
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
720 * After putting the socket in non-blocking mode, connect() will
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
721 * return EINPROGRESS, select() will not wait (as if writing is
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
722 * possible), need to use getsockopt() to check if the socket is
8354
b151c3f9be72 commit https://github.com/vim/vim/commit/42bc6dde46f1b52476cc84ee89277f981b4116c4
Christian Brabandt <cb@256bit.org>
parents: 8348
diff changeset
723 * actually able to connect.
b151c3f9be72 commit https://github.com/vim/vim/commit/42bc6dde46f1b52476cc84ee89277f981b4116c4
Christian Brabandt <cb@256bit.org>
parents: 8348
diff changeset
724 * We detect an failure to connect when either read and write fds
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
725 * are set. Use getsockopt() to find out what kind of failure. */
8354
b151c3f9be72 commit https://github.com/vim/vim/commit/42bc6dde46f1b52476cc84ee89277f981b4116c4
Christian Brabandt <cb@256bit.org>
parents: 8348
diff changeset
726 if (FD_ISSET(sd, &rfds) || FD_ISSET(sd, &wfds))
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
727 {
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
728 ret = getsockopt(sd,
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
729 SOL_SOCKET, SO_ERROR, &so_error, &so_error_len);
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
730 if (ret < 0 || (so_error != 0
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
731 && so_error != EWOULDBLOCK
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
732 && so_error != ECONNREFUSED
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
733 # ifdef EINPROGRESS
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
734 && so_error != EINPROGRESS
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
735 # endif
8330
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
736 ))
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
737 {
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
738 ch_errorn(channel,
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
739 "channel_open: Connect failed with errno %d",
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
740 so_error);
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
741 PERROR(_(e_cannot_connect));
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
742 sock_close(sd);
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
743 channel_free(channel);
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
744 return NULL;
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
745 }
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
746 }
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
747
ec940c11f749 commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents: 8320
diff changeset
748 if (!FD_ISSET(sd, &wfds) || so_error != 0)
8334
ad4b00bf2984 commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents: 8332
diff changeset
749 #endif
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
750 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
751 #ifndef WIN32
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
752 struct timeval end_tv;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
753 long elapsed_msec;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
754
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
755 gettimeofday(&end_tv, NULL);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
756 elapsed_msec = (end_tv.tv_sec - start_tv.tv_sec) * 1000
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
757 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
758 if (waittime > 1 && elapsed_msec < waittime)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
759 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
760 /* The port isn't ready but we also didn't get an error.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
761 * This happens when the server didn't open the socket
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
762 * yet. Wait a bit and try again. */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
763 mch_delay(waittime < 50 ? (long)waittime : 50L, TRUE);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
764 ui_breakcheck();
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
765 if (!got_int)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
766 {
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
767 /* reduce the waittime by the elapsed time and the 50
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
768 * msec delay (or a bit more) */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
769 waittime -= elapsed_msec;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
770 if (waittime > 50)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
771 waittime -= 50;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
772 else
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
773 waittime = 1;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
774 continue;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
775 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
776 /* we were interrupted, behave as if timed out */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
777 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
778 #endif
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
779 /* We timed out. */
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
780 ch_error(channel, "Connection timed out");
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
781 sock_close(sd);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
782 channel_free(channel);
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
783 return NULL;
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
784 }
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
785
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
786 ch_log(channel, "Connection made");
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
787 break;
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
788 }
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
789 }
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
790
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
791 if (waittime >= 0)
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
792 {
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
793 #ifdef _WIN32
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
794 val = 0;
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
795 ioctlsocket(sd, FIONBIO, &val);
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
796 #else
7961
a7e58c6e4e9a commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents: 7945
diff changeset
797 (void)fcntl(sd, F_SETFL, 0);
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
798 #endif
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
799 }
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
800
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
801 channel->CH_SOCK_FD = (sock_T)sd;
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
802 channel->ch_nb_close_cb = nb_close_cb;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
803
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
804 #ifdef FEAT_GUI
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
805 channel_gui_register(channel);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
806 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
807
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
808 return channel;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
809 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
810
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
811 #if defined(CHANNEL_PIPES) || defined(PROTO)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
812 void
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
813 channel_set_pipes(channel_T *channel, sock_T in, sock_T out, sock_T err)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
814 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
815 channel->CH_IN_FD = in;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
816 channel->CH_OUT_FD = out;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
817 channel->CH_ERR_FD = err;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
818 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
819 #endif
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
820
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
821 /*
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
822 * Sets the job the channel is associated with and associated options.
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
823 * This does not keep a refcount, when the job is freed ch_job is cleared.
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
824 */
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
825 void
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
826 channel_set_job(channel_T *channel, job_T *job, jobopt_T *options)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
827 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
828 channel->ch_job = job;
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
829
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
830 channel_set_options(channel, options);
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
831
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
832 if (job->jv_in_buf != NULL)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
833 {
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
834 chanpart_T *in_part = &channel->ch_part[PART_IN];
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
835
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
836 in_part->ch_buffer = job->jv_in_buf;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
837 ch_logs(channel, "reading from buffer '%s'",
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
838 (char *)in_part->ch_buffer->b_ffname);
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
839 if (options->jo_set & JO_IN_TOP)
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
840 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
841 if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT))
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
842 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
843 /* Special mode: send last-but-one line when appending a line
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
844 * to the buffer. */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
845 in_part->ch_buffer->b_write_to_channel = TRUE;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
846 in_part->ch_buf_top =
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
847 in_part->ch_buffer->b_ml.ml_line_count + 1;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
848 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
849 else
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
850 in_part->ch_buf_top = options->jo_in_top;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
851 }
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
852 else
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
853 in_part->ch_buf_top = 1;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
854 if (options->jo_set & JO_IN_BOT)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
855 in_part->ch_buf_bot = options->jo_in_bot;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
856 else
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
857 in_part->ch_buf_bot = in_part->ch_buffer->b_ml.ml_line_count;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
858 }
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
859 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
860
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
861 /*
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
862 * Find a buffer matching "name" or create a new one.
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
863 */
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
864 static buf_T *
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
865 find_buffer(char_u *name)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
866 {
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
867 buf_T *buf = NULL;
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
868 buf_T *save_curbuf = curbuf;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
869
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
870 if (name != NULL && *name != NUL)
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
871 buf = buflist_findname(name);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
872 if (buf == NULL)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
873 {
8297
4929eca308b7 commit https://github.com/vim/vim/commit/e26643e6bcd6c6c42f5eae78cee2e7950cd3f629
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
874 buf = buflist_new(name == NULL || *name == NUL ? NULL : name,
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
875 NULL, (linenr_T)0, BLN_LISTED);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
876 buf_copy_options(buf, BCO_ENTER);
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
877 #ifdef FEAT_QUICKFIX
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
878 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
879 set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
880 #endif
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
881 curbuf = buf;
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
882 if (curbuf->b_ml.ml_mfp == NULL)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
883 ml_open(curbuf);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
884 ml_replace(1, (char_u *)"Reading from channel output...", TRUE);
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
885 changed_bytes(1, 0);
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
886 curbuf = save_curbuf;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
887 }
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
888
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
889 return buf;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
890 }
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
891
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
892 /*
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
893 * Set various properties from an "opt" argument.
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
894 */
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
895 void
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
896 channel_set_options(channel_T *channel, jobopt_T *opt)
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
897 {
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
898 int part;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
899 char_u **cbp;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
900
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
901 if (opt->jo_set & JO_MODE)
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
902 for (part = PART_SOCK; part <= PART_IN; ++part)
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
903 channel->ch_part[part].ch_mode = opt->jo_mode;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
904 if (opt->jo_set & JO_IN_MODE)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
905 channel->ch_part[PART_IN].ch_mode = opt->jo_in_mode;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
906 if (opt->jo_set & JO_OUT_MODE)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
907 channel->ch_part[PART_OUT].ch_mode = opt->jo_out_mode;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
908 if (opt->jo_set & JO_ERR_MODE)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
909 channel->ch_part[PART_ERR].ch_mode = opt->jo_err_mode;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
910
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
911 if (opt->jo_set & JO_TIMEOUT)
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
912 for (part = PART_SOCK; part <= PART_IN; ++part)
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
913 channel->ch_part[part].ch_timeout = opt->jo_timeout;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
914 if (opt->jo_set & JO_OUT_TIMEOUT)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
915 channel->ch_part[PART_OUT].ch_timeout = opt->jo_out_timeout;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
916 if (opt->jo_set & JO_ERR_TIMEOUT)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
917 channel->ch_part[PART_ERR].ch_timeout = opt->jo_err_timeout;
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
918
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
919 if (opt->jo_set & JO_CALLBACK)
8132
f96536c291d8 commit https://github.com/vim/vim/commit/0ba75a9714884895b2ac09733158c47544a8dfb9
Christian Brabandt <cb@256bit.org>
parents: 8124
diff changeset
920 {
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
921 cbp = &channel->ch_callback;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
922 vim_free(*cbp);
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
923 if (opt->jo_callback != NULL && *opt->jo_callback != NUL)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
924 *cbp = vim_strsave(opt->jo_callback);
8132
f96536c291d8 commit https://github.com/vim/vim/commit/0ba75a9714884895b2ac09733158c47544a8dfb9
Christian Brabandt <cb@256bit.org>
parents: 8124
diff changeset
925 else
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
926 *cbp = NULL;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
927 }
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
928 if (opt->jo_set & JO_OUT_CALLBACK)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
929 {
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
930 cbp = &channel->ch_part[PART_OUT].ch_callback;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
931 vim_free(*cbp);
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
932 if (opt->jo_out_cb != NULL && *opt->jo_out_cb != NUL)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
933 *cbp = vim_strsave(opt->jo_out_cb);
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
934 else
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
935 *cbp = NULL;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
936 }
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
937 if (opt->jo_set & JO_ERR_CALLBACK)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
938 {
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
939 cbp = &channel->ch_part[PART_ERR].ch_callback;
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
940 vim_free(*cbp);
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
941 if (opt->jo_err_cb != NULL && *opt->jo_err_cb != NUL)
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
942 *cbp = vim_strsave(opt->jo_err_cb);
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
943 else
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
944 *cbp = NULL;
8132
f96536c291d8 commit https://github.com/vim/vim/commit/0ba75a9714884895b2ac09733158c47544a8dfb9
Christian Brabandt <cb@256bit.org>
parents: 8124
diff changeset
945 }
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
946 if (opt->jo_set & JO_CLOSE_CALLBACK)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
947 {
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
948 cbp = &channel->ch_close_cb;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
949 vim_free(*cbp);
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
950 if (opt->jo_close_cb != NULL && *opt->jo_close_cb != NUL)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
951 *cbp = vim_strsave(opt->jo_close_cb);
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
952 else
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
953 *cbp = NULL;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
954 }
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
955
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
956 if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
957 {
8346
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
958 /* writing output to a buffer. Default mode is NL. */
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
959 if (!(opt->jo_set & JO_OUT_MODE))
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
960 channel->ch_part[PART_OUT].ch_mode = MODE_NL;
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
961 channel->ch_part[PART_OUT].ch_buffer =
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
962 find_buffer(opt->jo_io_name[PART_OUT]);
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
963 ch_logs(channel, "writing to buffer '%s'",
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
964 (char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname);
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
965 }
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
966 }
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
967
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
968 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
969 * Set the callback for "channel"/"part" for the response with "id".
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
970 */
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
971 void
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
972 channel_set_req_callback(
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
973 channel_T *channel,
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
974 int part,
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
975 char_u *callback,
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
976 int id)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
977 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
978 cbq_T *head = &channel->ch_part[part].ch_cb_head;
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
979 cbq_T *item = (cbq_T *)alloc((int)sizeof(cbq_T));
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
980
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
981 if (item != NULL)
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
982 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
983 item->cq_callback = vim_strsave(callback);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
984 item->cq_seq_nr = id;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
985 item->cq_prev = head->cq_prev;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
986 head->cq_prev = item;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
987 item->cq_next = NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
988 if (item->cq_prev == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
989 head->cq_next = item;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
990 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
991 item->cq_prev->cq_next = item;
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
992 }
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
993 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
994
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
995 static void
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
996 write_buf_line(buf_T *buf, linenr_T lnum, channel_T *channel)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
997 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
998 char_u *line = ml_get_buf(buf, lnum, FALSE);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
999 int len = STRLEN(line);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1000 char_u *p;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1001
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1002 /* TODO: check if channel can be written to, do not block on write */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1003 if ((p = alloc(len + 2)) == NULL)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1004 return;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1005 STRCPY(p, line);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1006 p[len] = NL;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1007 p[len + 1] = NUL;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1008 channel_send(channel, PART_IN, p, "write_buf_line()");
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1009 vim_free(p);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1010 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1011
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1012 /*
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1013 * Write any lines to the input channel.
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1014 */
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1015 void
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1016 channel_write_in(channel_T *channel)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1017 {
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1018 chanpart_T *in_part = &channel->ch_part[PART_IN];
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1019 linenr_T lnum;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1020 buf_T *buf = in_part->ch_buffer;
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1021 int written = 0;
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1022
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1023 if (buf == NULL)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1024 return;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1025 if (!buf_valid(buf) || buf->b_ml.ml_mfp == NULL)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1026 {
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1027 /* buffer was wiped out or unloaded */
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1028 in_part->ch_buffer = NULL;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1029 return;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1030 }
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1031 if (in_part->ch_fd == INVALID_FD)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1032 /* pipe was closed */
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1033 return;
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1034
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1035 for (lnum = in_part->ch_buf_top; lnum <= in_part->ch_buf_bot
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1036 && lnum <= buf->b_ml.ml_line_count; ++lnum)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1037 {
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1038 write_buf_line(buf, lnum, channel);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1039 ++written;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1040 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1041
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1042 if (written == 1)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1043 ch_logn(channel, "written line %d to channel", (int)lnum - 1);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1044 else if (written > 1)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1045 ch_logn(channel, "written %d lines to channel", written);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1046
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1047 in_part->ch_buf_top = lnum;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1048 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1049
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1050 /*
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1051 * Write appended lines above the last one in "buf" to the channel.
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1052 */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1053 void
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1054 channel_write_new_lines(buf_T *buf)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1055 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1056 channel_T *channel;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1057 int found_one = FALSE;
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1058
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1059 /* There could be more than one channel for the buffer, loop over all of
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1060 * them. */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1061 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1062 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1063 chanpart_T *in_part = &channel->ch_part[PART_IN];
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1064 linenr_T lnum;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1065 int written = 0;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1066
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1067 if (in_part->ch_buffer == buf)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1068 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1069 if (in_part->ch_fd == INVALID_FD)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1070 /* pipe was closed */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1071 continue;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1072 found_one = TRUE;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1073 for (lnum = in_part->ch_buf_bot; lnum < buf->b_ml.ml_line_count;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1074 ++lnum)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1075 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1076 write_buf_line(buf, lnum, channel);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1077 ++written;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1078 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1079
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1080 if (written == 1)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1081 ch_logn(channel, "written line %d to channel", (int)lnum - 1);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1082 else if (written > 1)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1083 ch_logn(channel, "written %d lines to channel", written);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1084
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1085 in_part->ch_buf_bot = lnum;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1086 }
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1087 }
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1088 if (!found_one)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1089 buf->b_write_to_channel = FALSE;
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1090 }
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1091
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
1092 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1093 * Invoke the "callback" on channel "channel".
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1094 */
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1095 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1096 invoke_callback(channel_T *channel, char_u *callback, typval_T *argv)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1097 {
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1098 typval_T rettv;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1099 int dummy;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1100
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1101 argv[0].v_type = VAR_CHANNEL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1102 argv[0].vval.v_channel = channel;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1103
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1104 call_func(callback, (int)STRLEN(callback),
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1105 &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL);
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8172
diff changeset
1106 clear_tv(&rettv);
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8172
diff changeset
1107
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1108 /* If an echo command was used the cursor needs to be put back where
8320
e2021d6feeda commit https://github.com/vim/vim/commit/18b5d6df10a5f08ffebbec85a1cf2828871e3736
Christian Brabandt <cb@256bit.org>
parents: 8318
diff changeset
1109 * it belongs. If highlighting was changed a redraw is needed. */
e2021d6feeda commit https://github.com/vim/vim/commit/18b5d6df10a5f08ffebbec85a1cf2828871e3736
Christian Brabandt <cb@256bit.org>
parents: 8318
diff changeset
1110 update_screen(0);
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1111 setcursor();
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1112 cursor_on();
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1113 out_flush();
8320
e2021d6feeda commit https://github.com/vim/vim/commit/18b5d6df10a5f08ffebbec85a1cf2828871e3736
Christian Brabandt <cb@256bit.org>
parents: 8318
diff changeset
1114 #ifdef FEAT_GUI
8410
05ec48deb353 commit https://github.com/vim/vim/commit/a96909cfaf21dbbf033e904ccdcda9905799f0fc
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
1115 if (gui.in_use)
05ec48deb353 commit https://github.com/vim/vim/commit/a96909cfaf21dbbf033e904ccdcda9905799f0fc
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
1116 {
05ec48deb353 commit https://github.com/vim/vim/commit/a96909cfaf21dbbf033e904ccdcda9905799f0fc
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
1117 gui_update_cursor(TRUE, FALSE);
05ec48deb353 commit https://github.com/vim/vim/commit/a96909cfaf21dbbf033e904ccdcda9905799f0fc
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
1118 gui_mch_flush();
05ec48deb353 commit https://github.com/vim/vim/commit/a96909cfaf21dbbf033e904ccdcda9905799f0fc
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
1119 }
8320
e2021d6feeda commit https://github.com/vim/vim/commit/18b5d6df10a5f08ffebbec85a1cf2828871e3736
Christian Brabandt <cb@256bit.org>
parents: 8318
diff changeset
1120 #endif
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1121 }
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1122
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1123 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1124 * Return the first buffer from channel "channel"/"part" and remove it.
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1125 * The caller must free it.
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1126 * Returns NULL if there is nothing.
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1127 */
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1128 char_u *
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1129 channel_get(channel_T *channel, int part)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1130 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1131 readq_T *head = &channel->ch_part[part].ch_head;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1132 readq_T *node = head->rq_next;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1133 char_u *p;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1134
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1135 if (node == NULL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1136 return NULL;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1137 /* dispose of the node but keep the buffer */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1138 p = node->rq_buffer;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1139 head->rq_next = node->rq_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1140 if (node->rq_next == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1141 head->rq_prev = NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1142 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1143 node->rq_next->rq_prev = NULL;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1144 vim_free(node);
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1145 return p;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1146 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1147
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1148 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1149 * Returns the whole buffer contents concatenated for "channel"/"part".
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1150 */
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1151 static char_u *
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1152 channel_get_all(channel_T *channel, int part)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1153 {
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1154 /* Concatenate everything into one buffer.
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1155 * TODO: avoid multiple allocations. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1156 while (channel_collapse(channel, part) == OK)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1157 ;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1158 return channel_get(channel, part);
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1159 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1160
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1161 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1162 * Collapses the first and second buffer for "channel"/"part".
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1163 * Returns FAIL if that is not possible.
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1164 */
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1165 int
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1166 channel_collapse(channel_T *channel, int part)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1167 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1168 readq_T *head = &channel->ch_part[part].ch_head;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1169 readq_T *node = head->rq_next;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1170 char_u *p;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1171
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1172 if (node == NULL || node->rq_next == NULL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1173 return FAIL;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1174
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1175 p = alloc((unsigned)(STRLEN(node->rq_buffer)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1176 + STRLEN(node->rq_next->rq_buffer) + 1));
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1177 if (p == NULL)
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1178 return FAIL; /* out of memory */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1179 STRCPY(p, node->rq_buffer);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1180 STRCAT(p, node->rq_next->rq_buffer);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1181 vim_free(node->rq_next->rq_buffer);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1182 node->rq_next->rq_buffer = p;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1183
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1184 /* dispose of the node and its buffer */
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1185 head->rq_next = node->rq_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1186 head->rq_next->rq_prev = NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1187 vim_free(node->rq_buffer);
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1188 vim_free(node);
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1189 return OK;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1190 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1191
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1192 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1193 * Store "buf[len]" on "channel"/"part".
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1194 * Returns OK or FAIL.
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1195 */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1196 static int
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1197 channel_save(channel_T *channel, int part, char_u *buf, int len)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1198 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1199 readq_T *node;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1200 readq_T *head = &channel->ch_part[part].ch_head;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1201 char_u *p;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1202 int i;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1203
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1204 node = (readq_T *)alloc(sizeof(readq_T));
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1205 if (node == NULL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1206 return FAIL; /* out of memory */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1207 node->rq_buffer = alloc(len + 1);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1208 if (node->rq_buffer == NULL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1209 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1210 vim_free(node);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1211 return FAIL; /* out of memory */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1212 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1213
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1214 if (channel->ch_part[part].ch_mode == MODE_NL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1215 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1216 /* Drop any CR before a NL. */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1217 p = node->rq_buffer;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1218 for (i = 0; i < len; ++i)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1219 if (buf[i] != CAR || i + 1 >= len || buf[i + 1] != NL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1220 *p++ = buf[i];
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1221 *p = NUL;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1222 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1223 else
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1224 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1225 mch_memmove(node->rq_buffer, buf, len);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1226 node->rq_buffer[len] = NUL;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1227 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1228
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1229 /* append node to the tail of the queue */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1230 node->rq_next = NULL;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1231 node->rq_prev = head->rq_prev;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1232 if (head->rq_prev == NULL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1233 head->rq_next = node;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1234 else
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1235 head->rq_prev->rq_next = node;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1236 head->rq_prev = node;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1237
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1238 if (log_fd != NULL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1239 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1240 ch_log_lead("RECV ", channel);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1241 fprintf(log_fd, "'");
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1242 if (fwrite(buf, len, 1, log_fd) != 1)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1243 return FAIL;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1244 fprintf(log_fd, "'\n");
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1245 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1246 return OK;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1247 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1248
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1249 /*
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1250 * Use the read buffer of "channel"/"part" and parse a JSON messages that is
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1251 * complete. The messages are added to the queue.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1252 * Return TRUE if there is more to read.
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1253 */
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1254 static int
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1255 channel_parse_json(channel_T *channel, int part)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1256 {
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1257 js_read_T reader;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1258 typval_T listtv;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1259 jsonq_T *item;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1260 jsonq_T *head = &channel->ch_part[part].ch_json_head;
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1261 int ret;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1262
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1263 if (channel_peek(channel, part) == NULL)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1264 return FALSE;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1265
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1266 /* TODO: make reader work properly */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1267 /* reader.js_buf = channel_peek(channel, part); */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1268 reader.js_buf = channel_get_all(channel, part);
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1269 reader.js_used = 0;
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents: 7872
diff changeset
1270 reader.js_fill = NULL;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1271 /* reader.js_fill = channel_fill; */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1272 reader.js_cookie = channel;
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
1273 ret = json_decode(&reader, &listtv,
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1274 channel->ch_part[part].ch_mode == MODE_JS ? JSON_JS : 0);
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1275 if (ret == OK)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1276 {
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
1277 /* Only accept the response when it is a list with at least two
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
1278 * items. */
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
1279 if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1280 {
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1281 /* TODO: give error */
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1282 clear_tv(&listtv);
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1283 }
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1284 else
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1285 {
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1286 item = (jsonq_T *)alloc((unsigned)sizeof(jsonq_T));
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1287 if (item == NULL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1288 clear_tv(&listtv);
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1289 else
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1290 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1291 item->jq_value = alloc_tv();
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1292 if (item->jq_value == NULL)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1293 {
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1294 vim_free(item);
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1295 clear_tv(&listtv);
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1296 }
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1297 else
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1298 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1299 *item->jq_value = listtv;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1300 item->jq_prev = head->jq_prev;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1301 head->jq_prev = item;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1302 item->jq_next = NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1303 if (item->jq_prev == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1304 head->jq_next = item;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1305 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1306 item->jq_prev->jq_next = item;
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1307 }
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1308 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1309 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1310 }
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1311
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1312 /* Put the unread part back into the channel.
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1313 * TODO: insert in front */
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1314 if (reader.js_buf[reader.js_used] != NUL)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1315 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1316 channel_save(channel, part, reader.js_buf + reader.js_used,
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1317 (int)(reader.js_end - reader.js_buf) - reader.js_used);
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1318 ret = TRUE;
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1319 }
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1320 else
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1321 ret = FALSE;
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1322
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1323 vim_free(reader.js_buf);
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1324 return ret;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1325 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1326
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1327 /*
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1328 * Remove "node" from the queue that it is in. Does not free it.
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1329 */
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1330 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1331 remove_cb_node(cbq_T *head, cbq_T *node)
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1332 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1333 if (node->cq_prev == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1334 head->cq_next = node->cq_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1335 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1336 node->cq_prev->cq_next = node->cq_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1337 if (node->cq_next == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1338 head->cq_prev = node->cq_prev;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1339 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1340 node->cq_next->cq_prev = node->cq_prev;
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1341 }
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1342
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1343 /*
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1344 * Remove "node" from the queue that it is in and free it.
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1345 * Caller should have freed or used node->jq_value.
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1346 */
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1347 static void
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1348 remove_json_node(jsonq_T *head, jsonq_T *node)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1349 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1350 if (node->jq_prev == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1351 head->jq_next = node->jq_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1352 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1353 node->jq_prev->jq_next = node->jq_next;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1354 if (node->jq_next == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1355 head->jq_prev = node->jq_prev;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1356 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1357 node->jq_next->jq_prev = node->jq_prev;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1358 vim_free(node);
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1359 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1360
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1361 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1362 * Get a message from the JSON queue for channel "channel".
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1363 * When "id" is positive it must match the first number in the list.
7997
c1c9ab17e197 commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
1364 * When "id" is zero or negative jut get the first message. But not the one
c1c9ab17e197 commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
1365 * with id ch_block_id.
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1366 * Return OK when found and return the value in "rettv".
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1367 * Return FAIL otherwise.
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1368 */
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1369 static int
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1370 channel_get_json(channel_T *channel, int part, int id, typval_T **rettv)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1371 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1372 jsonq_T *head = &channel->ch_part[part].ch_json_head;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1373 jsonq_T *item = head->jq_next;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1374
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1375 while (item != NULL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1376 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1377 list_T *l = item->jq_value->vval.v_list;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1378 typval_T *tv = &l->lv_first->li_tv;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1379
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1380 if ((id > 0 && tv->v_type == VAR_NUMBER && tv->vval.v_number == id)
7997
c1c9ab17e197 commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
1381 || (id <= 0 && (tv->v_type != VAR_NUMBER
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1382 || tv->vval.v_number == 0
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1383 || tv->vval.v_number != channel->ch_part[part].ch_block_id)))
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1384 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1385 *rettv = item->jq_value;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1386 remove_json_node(head, item);
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1387 return OK;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1388 }
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1389 item = item->jq_next;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1390 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1391 return FAIL;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1392 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1393
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1394 #define CH_JSON_MAX_ARGS 4
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1395
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1396 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1397 * Execute a command received over "channel"/"part"
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1398 * "argv[0]" is the command string.
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1399 * "argv[1]" etc. have further arguments, type is VAR_UNKNOWN if missing.
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1400 */
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1401 static void
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1402 channel_exe_cmd(channel_T *channel, int part, typval_T *argv)
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1403 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1404 char_u *cmd = argv[0].vval.v_string;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1405 char_u *arg;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1406 int options = channel->ch_part[part].ch_mode == MODE_JS ? JSON_JS : 0;
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1407
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1408 if (argv[1].v_type != VAR_STRING)
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1409 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1410 ch_error(channel, "received command with non-string argument");
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1411 if (p_verbose > 2)
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1412 EMSG("E903: received command with non-string argument");
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1413 return;
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1414 }
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1415 arg = argv[1].vval.v_string;
7872
4b9d4600166f commit https://github.com/vim/vim/commit/14ad611ca435d97e8fd0d9ab03ddc982843298ac
Christian Brabandt <cb@256bit.org>
parents: 7868
diff changeset
1416 if (arg == NULL)
4b9d4600166f commit https://github.com/vim/vim/commit/14ad611ca435d97e8fd0d9ab03ddc982843298ac
Christian Brabandt <cb@256bit.org>
parents: 7868
diff changeset
1417 arg = (char_u *)"";
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1418
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1419 if (STRCMP(cmd, "ex") == 0)
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1420 {
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1421 do_cmdline_cmd(arg);
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1422 }
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1423 else if (STRCMP(cmd, "normal") == 0)
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1424 {
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1425 exarg_T ea;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1426
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1427 ea.arg = arg;
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1428 ea.addr_count = 0;
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1429 ea.forceit = TRUE; /* no mapping */
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1430 ex_normal(&ea);
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1431 }
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1432 else if (STRCMP(cmd, "redraw") == 0)
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1433 {
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1434 exarg_T ea;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1435
7872
4b9d4600166f commit https://github.com/vim/vim/commit/14ad611ca435d97e8fd0d9ab03ddc982843298ac
Christian Brabandt <cb@256bit.org>
parents: 7868
diff changeset
1436 ea.forceit = *arg != NUL;
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1437 ex_redraw(&ea);
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1438 showruler(FALSE);
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1439 setcursor();
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1440 out_flush();
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1441 #ifdef FEAT_GUI
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1442 if (gui.in_use)
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1443 {
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1444 gui_update_cursor(FALSE, FALSE);
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1445 gui_mch_flush();
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1446 }
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1447 #endif
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1448 }
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1449 else if (STRCMP(cmd, "expr") == 0 || STRCMP(cmd, "call") == 0)
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1450 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1451 int is_call = cmd[0] == 'c';
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1452 int id_idx = is_call ? 3 : 2;
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1453
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1454 if (argv[id_idx].v_type != VAR_UNKNOWN
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1455 && argv[id_idx].v_type != VAR_NUMBER)
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1456 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1457 ch_error(channel, "last argument for expr/call must be a number");
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1458 if (p_verbose > 2)
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1459 EMSG("E904: last argument for expr/call must be a number");
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1460 }
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1461 else if (is_call && argv[2].v_type != VAR_LIST)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1462 {
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1463 ch_error(channel, "third argument for call must be a list");
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1464 if (p_verbose > 2)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1465 EMSG("E904: third argument for call must be a list");
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1466 }
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1467 else
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1468 {
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
1469 typval_T *tv;
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1470 typval_T res_tv;
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1471 typval_T err_tv;
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1472 char_u *json = NULL;
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1473
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
1474 /* Don't pollute the display with errors. */
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
1475 ++emsg_skip;
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1476 if (!is_call)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1477 tv = eval_expr(arg, NULL);
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1478 else if (func_call(arg, &argv[2], NULL, &res_tv) == OK)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1479 tv = &res_tv;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1480 else
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1481 tv = NULL;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1482
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1483 if (argv[id_idx].v_type == VAR_NUMBER)
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1484 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1485 int id = argv[id_idx].vval.v_number;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1486
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1487 if (tv != NULL)
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1488 json = json_encode_nr_expr(id, tv, options);
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1489 if (tv == NULL || (json != NULL && *json == NUL))
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1490 {
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1491 /* If evaluation failed or the result can't be encoded
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1492 * then return the string "ERROR". */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1493 vim_free(json);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1494 free_tv(tv);
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1495 err_tv.v_type = VAR_STRING;
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1496 err_tv.vval.v_string = (char_u *)"ERROR";
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1497 tv = &err_tv;
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1498 json = json_encode_nr_expr(id, tv, options);
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1499 }
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1500 if (json != NULL)
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1501 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1502 channel_send(channel,
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1503 part == PART_SOCK ? PART_SOCK : PART_IN,
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1504 json, (char *)cmd);
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1505 vim_free(json);
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1506 }
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1507 }
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7961
diff changeset
1508 --emsg_skip;
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1509 if (tv == &res_tv)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1510 clear_tv(tv);
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1511 else if (tv != &err_tv)
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
1512 free_tv(tv);
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1513 }
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1514 }
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1515 else if (p_verbose > 2)
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1516 {
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1517 ch_errors(channel, "Receved unknown command: %s", (char *)cmd);
7864
6b0891de44a9 commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents: 7840
diff changeset
1518 EMSG2("E905: received unknown command: %s", cmd);
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1519 }
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1520 }
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1521
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1522 static void
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1523 invoke_one_time_callback(
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1524 channel_T *channel,
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1525 cbq_T *cbhead,
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1526 cbq_T *item,
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1527 typval_T *argv)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1528 {
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1529 ch_logs(channel, "Invoking one-time callback %s",
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1530 (char *)item->cq_callback);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1531 /* Remove the item from the list first, if the callback
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1532 * invokes ch_close() the list will be cleared. */
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1533 remove_cb_node(cbhead, item);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1534 invoke_callback(channel, item->cq_callback, argv);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1535 vim_free(item->cq_callback);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1536 vim_free(item);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1537 }
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1538
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1539 static void
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1540 append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1541 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1542 buf_T *save_curbuf = curbuf;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1543 linenr_T lnum = buffer->b_ml.ml_line_count;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1544 int save_write_to = buffer->b_write_to_channel;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1545
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1546 /* If the buffer is also used as input insert above the last
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1547 * line. Don't write these lines. */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1548 if (save_write_to)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1549 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1550 --lnum;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1551 buffer->b_write_to_channel = FALSE;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1552 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1553
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1554 /* Append to the buffer */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1555 ch_logn(channel, "appending line %d to buffer", (int)lnum + 1);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1556
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1557 curbuf = buffer;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1558 u_sync(TRUE);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1559 /* ignore undo failure, undo is not very useful here */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1560 ignored = u_save(lnum, lnum + 1);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1561
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1562 ml_append(lnum, msg, 0, FALSE);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1563 appended_lines_mark(lnum, 1L);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1564 curbuf = save_curbuf;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1565
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1566 if (buffer->b_nwindows > 0)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1567 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1568 win_T *wp;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1569 win_T *save_curwin;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1570
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1571 FOR_ALL_WINDOWS(wp)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1572 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1573 if (wp->w_buffer == buffer
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1574 && (save_write_to
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1575 ? wp->w_cursor.lnum == lnum + 1
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1576 : (wp->w_cursor.lnum == lnum
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1577 && wp->w_cursor.col == 0)))
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1578 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1579 ++wp->w_cursor.lnum;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1580 save_curwin = curwin;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1581 curwin = wp;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1582 curbuf = curwin->w_buffer;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1583 scroll_cursor_bot(0, FALSE);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1584 curwin = save_curwin;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1585 curbuf = curwin->w_buffer;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1586 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1587 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1588 redraw_buf_later(buffer, VALID);
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1589 channel_need_redraw = TRUE;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1590 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1591
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1592 if (save_write_to)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1593 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1594 channel_T *ch;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1595
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1596 /* Find channels reading from this buffer and adjust their
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1597 * next-to-read line number. */
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1598 buffer->b_write_to_channel = TRUE;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1599 for (ch = first_channel; ch != NULL; ch = ch->ch_next)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1600 {
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1601 chanpart_T *in_part = &ch->ch_part[PART_IN];
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1602
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1603 if (in_part->ch_buffer == buffer)
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1604 in_part->ch_buf_bot = buffer->b_ml.ml_line_count;
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1605 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1606 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1607 }
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1608
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1609 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1610 * Invoke a callback for "channel"/"part" if needed.
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1611 * Return TRUE when a message was handled, there might be another one.
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1612 */
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1613 static int
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1614 may_invoke_callback(channel_T *channel, int part)
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1615 {
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1616 char_u *msg = NULL;
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1617 typval_T *listtv = NULL;
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1618 typval_T argv[CH_JSON_MAX_ARGS];
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1619 int seq_nr = -1;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1620 ch_mode_T ch_mode = channel->ch_part[part].ch_mode;
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1621 cbq_T *cbhead = &channel->ch_part[part].ch_cb_head;
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
1622 cbq_T *cbitem;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1623 char_u *callback = NULL;
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1624 buf_T *buffer = NULL;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1625
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1626 if (channel->ch_nb_close_cb != NULL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1627 /* this channel is handled elsewhere (netbeans) */
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1628 return FALSE;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1629
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
1630 /* Use a message-specific callback, part callback or channel callback */
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
1631 for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
1632 if (cbitem->cq_seq_nr == 0)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
1633 break;
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1634 if (cbitem != NULL)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1635 callback = cbitem->cq_callback;
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1636 else if (channel->ch_part[part].ch_callback != NULL)
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1637 callback = channel->ch_part[part].ch_callback;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1638 else
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1639 callback = channel->ch_callback;
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1640
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1641 buffer = channel->ch_part[part].ch_buffer;
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1642 if (buffer != NULL && !buf_valid(buffer))
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1643 {
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1644 /* buffer was wiped out */
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1645 channel->ch_part[part].ch_buffer = NULL;
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1646 buffer = NULL;
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8267
diff changeset
1647 }
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1648
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1649 if (ch_mode == MODE_JSON || ch_mode == MODE_JS)
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1650 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1651 listitem_T *item;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1652 int argc = 0;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1653
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1654 /* Get any json message in the queue. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1655 if (channel_get_json(channel, part, -1, &listtv) == FAIL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1656 {
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1657 /* Parse readahead, return when there is still no message. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1658 channel_parse_json(channel, part);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1659 if (channel_get_json(channel, part, -1, &listtv) == FAIL)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1660 return FALSE;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1661 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1662
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1663 for (item = listtv->vval.v_list->lv_first;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1664 item != NULL && argc < CH_JSON_MAX_ARGS;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1665 item = item->li_next)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1666 argv[argc++] = item->li_tv;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1667 while (argc < CH_JSON_MAX_ARGS)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1668 argv[argc++].v_type = VAR_UNKNOWN;
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1669
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1670 if (argv[0].v_type == VAR_STRING)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1671 {
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1672 char_u *cmd = argv[0].vval.v_string;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1673
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1674 /* ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1675 ch_logs(channel, "Executing %s command", (char *)cmd);
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1676 channel_exe_cmd(channel, part, argv);
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1677 free_tv(listtv);
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1678 return TRUE;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1679 }
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1680
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1681 if (argv[0].v_type != VAR_NUMBER)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1682 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1683 ch_error(channel,
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1684 "Dropping message with invalid sequence number type");
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1685 free_tv(listtv);
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1686 return FALSE;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1687 }
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1688 seq_nr = argv[0].vval.v_number;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1689 }
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1690 else if (channel_peek(channel, part) == NULL)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1691 {
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1692 /* nothing to read on RAW or NL channel */
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1693 return FALSE;
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
1694 }
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1695 else
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1696 {
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1697 /* If there is no callback or buffer drop the message. */
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1698 if (callback == NULL && buffer == NULL)
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1699 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1700 while ((msg = channel_get(channel, part)) != NULL)
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1701 {
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1702 ch_logs(channel, "Dropping message '%s'", (char *)msg);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1703 vim_free(msg);
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1704 }
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1705 return FALSE;
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1706 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1707
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1708 if (ch_mode == MODE_NL)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1709 {
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1710 char_u *nl;
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1711 char_u *buf;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1712
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1713 /* See if we have a message ending in NL in the first buffer. If
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1714 * not try to concatenate the first and the second buffer. */
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1715 while (TRUE)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1716 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1717 buf = channel_peek(channel, part);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1718 nl = vim_strchr(buf, NL);
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1719 if (nl != NULL)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1720 break;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1721 if (channel_collapse(channel, part) == FAIL)
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1722 return FALSE; /* incomplete message */
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1723 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1724 if (nl[1] == NUL)
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1725 {
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1726 /* get the whole buffer, drop the NL */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1727 msg = channel_get(channel, part);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1728 *nl = NUL;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1729 }
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1730 else
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1731 {
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1732 /* Copy the message into allocated memory and remove it from
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1733 * the buffer. */
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1734 msg = vim_strnsave(buf, (int)(nl - buf));
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1735 mch_memmove(buf, nl + 1, STRLEN(nl + 1) + 1);
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1736 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1737 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1738 else
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1739 /* For a raw channel we don't know where the message ends, just
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1740 * get everything we have. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1741 msg = channel_get_all(channel, part);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
1742
8358
49d0e094cb93 commit https://github.com/vim/vim/commit/bf73b91c664488ca57e2b4a8eb9b1f36f6625bc7
Christian Brabandt <cb@256bit.org>
parents: 8356
diff changeset
1743 if (msg == NULL)
49d0e094cb93 commit https://github.com/vim/vim/commit/bf73b91c664488ca57e2b4a8eb9b1f36f6625bc7
Christian Brabandt <cb@256bit.org>
parents: 8356
diff changeset
1744 return FALSE; /* out of memory (and avoids Coverity warning) */
49d0e094cb93 commit https://github.com/vim/vim/commit/bf73b91c664488ca57e2b4a8eb9b1f36f6625bc7
Christian Brabandt <cb@256bit.org>
parents: 8356
diff changeset
1745
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1746 argv[1].v_type = VAR_STRING;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1747 argv[1].vval.v_string = msg;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1748 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1749
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1750 if (seq_nr > 0)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1751 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1752 int done = FALSE;
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1753
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1754 /* invoke the one-time callback with the matching nr */
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
1755 for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next)
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1756 if (cbitem->cq_seq_nr == seq_nr)
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1757 {
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1758 invoke_one_time_callback(channel, cbhead, cbitem, argv);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1759 done = TRUE;
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1760 break;
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7931
diff changeset
1761 }
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1762 if (!done)
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1763 ch_logn(channel, "Dropping message %d without callback", seq_nr);
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1764 }
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1765 else if (callback != NULL || buffer != NULL)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1766 {
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1767 if (buffer != NULL)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1768 {
8346
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
1769 if (msg == NULL)
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
1770 /* JSON or JS mode: re-encode the message. */
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
1771 msg = json_encode(listtv, ch_mode);
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8334
diff changeset
1772 if (msg != NULL)
8422
5d2c84be23b5 commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents: 8410
diff changeset
1773 append_to_buffer(buffer, msg, channel);
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1774 }
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1775
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1776 if (callback != NULL)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1777 {
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1778 if (cbitem != NULL)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1779 invoke_one_time_callback(channel, cbhead, cbitem, argv);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1780 else
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1781 {
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1782 /* invoke the channel callback */
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1783 ch_logs(channel, "Invoking channel callback %s",
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1784 (char *)callback);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1785 invoke_callback(channel, callback, argv);
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8358
diff changeset
1786 }
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1787 }
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1788 }
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1789 else
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1790 ch_log(channel, "Dropping message");
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1791
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
1792 if (listtv != NULL)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1793 free_tv(listtv);
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
1794 vim_free(msg);
7885
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1795
6e6f829af138 commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
1796 return TRUE;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1797 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1798
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1799 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1800 * Return TRUE when channel "channel" is open for writing to.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1801 * Also returns FALSE or invalid "channel".
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1802 */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1803 int
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1804 channel_can_write_to(channel_T *channel)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1805 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1806 return channel != NULL && (channel->CH_SOCK_FD != INVALID_FD
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1807 #ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1808 || channel->CH_IN_FD != INVALID_FD
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1809 #endif
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1810 );
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1811 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1812
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1813 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1814 * Return TRUE when channel "channel" is open for reading or writing.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1815 * Also returns FALSE for invalid "channel".
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1816 */
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1817 int
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1818 channel_is_open(channel_T *channel)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1819 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1820 return channel != NULL && (channel->CH_SOCK_FD != INVALID_FD
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1821 #ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1822 || channel->CH_IN_FD != INVALID_FD
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1823 || channel->CH_OUT_FD != INVALID_FD
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1824 || channel->CH_ERR_FD != INVALID_FD
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1825 #endif
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1826 );
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1827 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1828
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1829 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1830 * Return a string indicating the status of the channel.
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1831 */
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1832 char *
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1833 channel_status(channel_T *channel)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1834 {
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1835 if (channel == NULL)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1836 return "fail";
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1837 if (channel_is_open(channel))
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1838 return "open";
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1839 return "closed";
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1840 }
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1841
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1842 /*
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1843 * Close channel "channel".
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
1844 * Trigger the close callback if "invoke_close_cb" is TRUE.
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
1845 * Does not clear the buffers.
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1846 */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1847 void
8240
60586ce747c4 commit https://github.com/vim/vim/commit/8b374215ccd35003b95ba1df8f12e03bf8a8adc3
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
1848 channel_close(channel_T *channel, int invoke_close_cb)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1849 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1850 ch_log(channel, "Closing channel");
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1851
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
1852 #ifdef FEAT_GUI
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
1853 channel_gui_unregister(channel);
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
1854 #endif
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
1855
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1856 if (channel->CH_SOCK_FD != INVALID_FD)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1857 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1858 sock_close(channel->CH_SOCK_FD);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1859 channel->CH_SOCK_FD = INVALID_FD;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 }
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1861 #if defined(CHANNEL_PIPES)
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1862 if (channel->CH_IN_FD != INVALID_FD)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1863 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1864 fd_close(channel->CH_IN_FD);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1865 channel->CH_IN_FD = INVALID_FD;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1866 }
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1867 if (channel->CH_OUT_FD != INVALID_FD)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1868 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1869 fd_close(channel->CH_OUT_FD);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1870 channel->CH_OUT_FD = INVALID_FD;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1871 }
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1872 if (channel->CH_ERR_FD != INVALID_FD)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1873 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1874 fd_close(channel->CH_ERR_FD);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1875 channel->CH_ERR_FD = INVALID_FD;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1876 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1877 #endif
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
1878
8240
60586ce747c4 commit https://github.com/vim/vim/commit/8b374215ccd35003b95ba1df8f12e03bf8a8adc3
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
1879 if (invoke_close_cb && channel->ch_close_cb != NULL)
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1880 {
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1881 typval_T argv[1];
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1882 typval_T rettv;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1883 int dummy;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1884
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1885 /* invoke the close callback; increment the refcount to avoid it
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1886 * being freed halfway */
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1887 ch_logs(channel, "Invoking close callback %s",
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1888 (char *)channel->ch_close_cb);
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1889 argv[0].v_type = VAR_CHANNEL;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1890 argv[0].vval.v_channel = channel;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1891 ++channel->ch_refcount;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1892 call_func(channel->ch_close_cb, (int)STRLEN(channel->ch_close_cb),
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1893 &rettv, 1, argv, 0L, 0L, &dummy, TRUE, NULL);
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1894 clear_tv(&rettv);
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1895 --channel->ch_refcount;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1896
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1897 /* the callback is only called once */
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1898 vim_free(channel->ch_close_cb);
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1899 channel->ch_close_cb = NULL;
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1900 }
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1901
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1902 channel->ch_nb_close_cb = NULL;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1903 }
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1904
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1905 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1906 * Return the first buffer from "channel"/"part" without removing it.
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1907 * Returns NULL if there is nothing.
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1908 */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1909 char_u *
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1910 channel_peek(channel_T *channel, int part)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1911 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1912 readq_T *head = &channel->ch_part[part].ch_head;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1913
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1914 if (head->rq_next == NULL)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1915 return NULL;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1916 return head->rq_next->rq_buffer;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1917 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1918
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1919 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1920 * Clear the read buffer on "channel"/"part".
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1921 */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1922 static void
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1923 channel_clear_one(channel_T *channel, int part)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1924 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1925 jsonq_T *json_head = &channel->ch_part[part].ch_json_head;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1926 cbq_T *cb_head = &channel->ch_part[part].ch_cb_head;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1927
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1928 while (channel_peek(channel, part) != NULL)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1929 vim_free(channel_get(channel, part));
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1930
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1931 while (cb_head->cq_next != NULL)
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1932 {
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1933 cbq_T *node = cb_head->cq_next;
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1934
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1935 remove_cb_node(cb_head, node);
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1936 vim_free(node->cq_callback);
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1937 vim_free(node);
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8072
diff changeset
1938 }
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1939
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1940 while (json_head->jq_next != NULL)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1941 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1942 free_tv(json_head->jq_next->jq_value);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1943 remove_json_node(json_head, json_head->jq_next);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1944 }
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
1945
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1946 vim_free(channel->ch_part[part].ch_callback);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1947 channel->ch_part[part].ch_callback = NULL;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1948 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1949
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1950 /*
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1951 * Clear all the read buffers on "channel".
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1952 */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1953 void
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1954 channel_clear(channel_T *channel)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1955 {
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1956 ch_log(channel, "Clearing channel");
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1957 channel_clear_one(channel, PART_SOCK);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1958 #ifdef CHANNEL_PIPES
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1959 channel_clear_one(channel, PART_OUT);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1960 channel_clear_one(channel, PART_ERR);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1961 #endif
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
1962 vim_free(channel->ch_callback);
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
1963 channel->ch_callback = NULL;
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1964 vim_free(channel->ch_close_cb);
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
1965 channel->ch_close_cb = NULL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1966 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1967
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1968 #if defined(EXITFREE) || defined(PROTO)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1969 void
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1970 channel_free_all(void)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1971 {
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1972 channel_T *channel;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1973
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
1974 ch_log(NULL, "channel_free_all()");
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1975 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1976 channel_clear(channel);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1977 }
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1978 #endif
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1979
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
1980
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1981 /* Sent when the channel is found closed when reading. */
8204
08d251a1c178 commit https://github.com/vim/vim/commit/eed284a16977ab81fa6da8c9562990ba498acd8c
Christian Brabandt <cb@256bit.org>
parents: 8200
diff changeset
1982 #define DETACH_MSG_RAW "DETACH\n"
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1983
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1984 /* Buffer size for reading incoming messages. */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1985 #define MAXMSGSIZE 4096
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1986
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
1987 /*
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1988 * Check for reading from "fd" with "timeout" msec.
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1989 * Return FAIL when there is nothing to read.
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1990 */
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1991 static int
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
1992 channel_wait(channel_T *channel, sock_T fd, int timeout)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
1993 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
1994 if (timeout > 0)
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1995 ch_logn(channel, "Waiting for up to %d msec", timeout);
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
1996
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
1997 # ifdef WIN32
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
1998 if (fd != channel->CH_SOCK_FD)
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
1999 {
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2000 DWORD nread;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2001 int diff;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2002 DWORD deadline = GetTickCount() + timeout;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2003
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2004 /* reading from a pipe, not a socket */
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2005 while (TRUE)
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2006 {
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
2007 if (PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL)
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
2008 && nread > 0)
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2009 return OK;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2010 diff = deadline - GetTickCount();
8172
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2011 if (diff <= 0)
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2012 break;
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2013 /* Wait for 5 msec.
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2014 * TODO: increase the sleep time when looping more often */
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2015 Sleep(5);
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2016 }
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2017 }
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2018 else
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2019 #endif
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2020 {
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
2021 #if defined(HAVE_SELECT)
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2022 struct timeval tval;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2023 fd_set rfds;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2024 int ret;
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2025
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2026 FD_ZERO(&rfds);
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2027 FD_SET((int)fd, &rfds);
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2028 tval.tv_sec = timeout / 1000;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2029 tval.tv_usec = (timeout % 1000) * 1000;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2030 for (;;)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2031 {
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2032 ret = select((int)fd + 1, &rfds, NULL, NULL, &tval);
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
2033 # ifdef EINTR
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2034 SOCK_ERRNO;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2035 if (ret == -1 && errno == EINTR)
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2036 continue;
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
2037 # endif
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2038 if (ret > 0)
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2039 return OK;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2040 break;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2041 }
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
2042 #else
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2043 struct pollfd fds;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2044
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2045 fds.fd = fd;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2046 fds.events = POLLIN;
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2047 if (poll(&fds, 1, timeout) > 0)
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2048 return OK;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2049 #endif
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2050 }
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2051 return FAIL;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2052 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2053
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2054 /*
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2055 * Return a unique ID to be used in a message.
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2056 */
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2057 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7797
diff changeset
2058 channel_get_id(void)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2059 {
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2060 static int next_id = 1;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2061
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2062 return next_id++;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2063 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2064
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2065 /*
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2066 * Read from channel "channel" for as long as there is something to read.
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2067 * "part" is PART_SOCK, PART_OUT or PART_ERR.
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2068 * The data is put in the read queue.
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2069 */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2070 void
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2071 channel_read(channel_T *channel, int part, char *func)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2072 {
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2073 static char_u *buf = NULL;
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2074 int len = 0;
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2075 int readlen = 0;
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2076 sock_T fd;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2077 int use_socket = FALSE;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2078
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2079 fd = channel->ch_part[part].ch_fd;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2080 if (fd == INVALID_FD)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2081 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2082 ch_error(channel, "channel_read() called while socket is closed");
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2083 return;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2084 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2085 use_socket = fd == channel->CH_SOCK_FD;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2086
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2087 /* Allocate a buffer to read into. */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2088 if (buf == NULL)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2089 {
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2090 buf = alloc(MAXMSGSIZE);
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2091 if (buf == NULL)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2092 return; /* out of memory! */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2093 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2094
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2095 /* Keep on reading for as long as there is something to read.
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2096 * Use select() or poll() to avoid blocking on a message that is exactly
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2097 * MAXMSGSIZE long. */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2098 for (;;)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2099 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2100 if (channel_wait(channel, fd, 0) == FAIL)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2101 break;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2102 if (use_socket)
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 8074
diff changeset
2103 len = sock_read(fd, (char *)buf, MAXMSGSIZE);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2104 else
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 8074
diff changeset
2105 len = fd_read(fd, (char *)buf, MAXMSGSIZE);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2106 if (len <= 0)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2107 break; /* error or nothing more to read */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2108
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2109 /* Store the read message in the queue. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2110 channel_save(channel, part, buf, len);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2111 readlen += len;
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2112 if (len < MAXMSGSIZE)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2113 break; /* did read everything that's available */
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2114 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2115
8261
a412b466bedc commit https://github.com/vim/vim/commit/4cafa6dc7f0728b018979aff0ca039908ecf2ae1
Christian Brabandt <cb@256bit.org>
parents: 8259
diff changeset
2116 /* Reading a disconnection (readlen == 0), or an error. */
8200
ee84450e604e commit https://github.com/vim/vim/commit/bd73ae1bc63a3b0187ffe7fc8f0caee5a4eb66fa
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
2117 if (readlen <= 0)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2118 {
8261
a412b466bedc commit https://github.com/vim/vim/commit/4cafa6dc7f0728b018979aff0ca039908ecf2ae1
Christian Brabandt <cb@256bit.org>
parents: 8259
diff changeset
2119 /* Do not give an error message, most likely the other end just
a412b466bedc commit https://github.com/vim/vim/commit/4cafa6dc7f0728b018979aff0ca039908ecf2ae1
Christian Brabandt <cb@256bit.org>
parents: 8259
diff changeset
2120 * exited. */
a412b466bedc commit https://github.com/vim/vim/commit/4cafa6dc7f0728b018979aff0ca039908ecf2ae1
Christian Brabandt <cb@256bit.org>
parents: 8259
diff changeset
2121 ch_errors(channel, "%s(): Cannot read from channel", func);
a412b466bedc commit https://github.com/vim/vim/commit/4cafa6dc7f0728b018979aff0ca039908ecf2ae1
Christian Brabandt <cb@256bit.org>
parents: 8259
diff changeset
2122
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2123 /* Queue a "DETACH" netbeans message in the command queue in order to
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2124 * terminate the netbeans session later. Do not end the session here
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2125 * directly as we may be running in the context of a call to
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2126 * netbeans_parse_messages():
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2127 * netbeans_parse_messages
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2128 * -> autocmd triggered while processing the netbeans cmd
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2129 * -> ui_breakcheck
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2130 * -> gui event loop or select loop
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2131 * -> channel_read()
8332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
2132 * Don't send "DETACH" for a JS or JSON channel.
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2133 */
8332
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
2134 if (channel->ch_part[part].ch_mode == MODE_RAW
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
2135 || channel->ch_part[part].ch_mode == MODE_NL)
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
2136 channel_save(channel, part, (char_u *)DETACH_MSG_RAW,
07713b8243ac commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents: 8330
diff changeset
2137 (int)STRLEN(DETACH_MSG_RAW));
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2138
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2139 /* TODO: When reading from stdout is not possible, should we try to
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2140 * keep stdin and stderr open? Probably not, assume the other side
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2141 * has died. */
8240
60586ce747c4 commit https://github.com/vim/vim/commit/8b374215ccd35003b95ba1df8f12e03bf8a8adc3
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
2142 channel_close(channel, TRUE);
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
2143 if (channel->ch_nb_close_cb != NULL)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8204
diff changeset
2144 (*channel->ch_nb_close_cb)();
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2145 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2146
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2147 #if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2148 /* signal the main loop that there is something to read */
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2149 if (CH_HAS_GUI && gtk_main_level() > 0)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2150 gtk_main_quit();
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2151 #endif
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2152 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2153
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2154 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2155 * Read from RAW or NL "channel"/"part". Blocks until there is something to
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2156 * read or the timeout expires.
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2157 * Returns what was read in allocated memory.
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2158 * Returns NULL in case of error or timeout.
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2159 */
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2160 char_u *
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2161 channel_read_block(channel_T *channel, int part, int timeout)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2162 {
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2163 char_u *buf;
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2164 char_u *msg;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2165 ch_mode_T mode = channel->ch_part[part].ch_mode;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2166 sock_T fd = channel->ch_part[part].ch_fd;
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2167 char_u *nl;
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2168
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
2169 ch_logsn(channel, "Blocking %s read, timeout: %d msec",
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2170 mode == MODE_RAW ? "RAW" : "NL", timeout);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2171
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2172 while (TRUE)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2173 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2174 buf = channel_peek(channel, part);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2175 if (buf != NULL && (mode == MODE_RAW
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2176 || (mode == MODE_NL && vim_strchr(buf, NL) != NULL)))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2177 break;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2178 if (buf != NULL && channel_collapse(channel, part) == OK)
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2179 continue;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2180
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
2181 /* Wait for up to the channel timeout. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2182 if (fd == INVALID_FD
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2183 || channel_wait(channel, fd, timeout) == FAIL)
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2184 return NULL;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2185 channel_read(channel, part, "channel_read_block");
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2186 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2187
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2188 if (mode == MODE_RAW)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2189 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2190 msg = channel_get_all(channel, part);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2191 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2192 else
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2193 {
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2194 nl = vim_strchr(buf, NL);
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2195 if (nl[1] == NUL)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2196 {
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2197 /* get the whole buffer */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2198 msg = channel_get(channel, part);
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2199 *nl = NUL;
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2200 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2201 else
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2202 {
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2203 /* Copy the message into allocated memory and remove it from the
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2204 * buffer. */
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2205 msg = vim_strnsave(buf, (int)(nl - buf));
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2206 mch_memmove(buf, nl + 1, STRLEN(nl + 1) + 1);
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2207 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2208 }
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2209 if (log_fd != NULL)
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
2210 ch_logn(channel, "Returning %d bytes", (int)STRLEN(msg));
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
2211 return msg;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2212 }
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2213
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2214 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2215 * Read one JSON message with ID "id" from "channel"/"part" and store the
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2216 * result in "rettv".
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2217 * When "id" is -1 accept any message;
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
2218 * Blocks until the message is received or the timeout is reached.
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2219 */
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2220 int
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2221 channel_read_json_block(
8310
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
2222 channel_T *channel,
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
2223 int part,
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
2224 int timeout,
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
2225 int id,
aec8f8ce8e4c commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents: 8297
diff changeset
2226 typval_T **rettv)
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2227 {
7997
c1c9ab17e197 commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
2228 int more;
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2229 sock_T fd;
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2230
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
2231 ch_log(channel, "Reading JSON");
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2232 if (id != -1)
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2233 channel->ch_part[part].ch_block_id = id;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2234 for (;;)
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2235 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2236 more = channel_parse_json(channel, part);
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2237
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2238 /* search for messsage "id" */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2239 if (channel_get_json(channel, part, id, rettv) == OK)
7997
c1c9ab17e197 commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
2240 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2241 channel->ch_part[part].ch_block_id = 0;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2242 return OK;
7997
c1c9ab17e197 commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
2243 }
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2244
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2245 if (!more)
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2246 {
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2247 /* Handle any other messages in the queue. If done some more
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2248 * messages may have arrived. */
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2249 if (channel_parse_messages())
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2250 continue;
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2251
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2252 /* Wait for up to the timeout. */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2253 fd = channel->ch_part[part].ch_fd;
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2254 if (fd == INVALID_FD || channel_wait(channel, fd, timeout) == FAIL)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2255 break;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2256 channel_read(channel, part, "channel_read_json_block");
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2257 }
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2258 }
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2259 channel->ch_part[part].ch_block_id = 0;
7868
17e6ff1a74f1 commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
2260 return FAIL;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2261 }
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2262
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
2263 # if defined(WIN32) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) \
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
2264 || defined(PROTO)
7780
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2265 /*
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
2266 * Lookup the channel from the socket. Set "partp" to the fd index.
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2267 * Returns NULL when the socket isn't found.
7780
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2268 */
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2269 channel_T *
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
2270 channel_fd2channel(sock_T fd, int *partp)
7780
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2271 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2272 channel_T *channel;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2273 int part;
7780
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2274
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2275 if (fd != INVALID_FD)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2276 for (channel = first_channel; channel != NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2277 channel = channel->ch_next)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2278 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2279 # ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2280 for (part = PART_SOCK; part < PART_IN; ++part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2281 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2282 part = PART_SOCK;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2283 # endif
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2284 if (channel->ch_part[part].ch_fd == fd)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2285 {
8155
6ee6fb27dcea commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents: 8151
diff changeset
2286 *partp = part;
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2287 return channel;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2288 }
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2289 }
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2290 return NULL;
7780
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2291 }
8172
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2292 # endif
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2293
8172
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2294 # if defined(WIN32) || defined(PROTO)
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2295 /*
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2296 * Check the channels for anything that is ready to be read.
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2297 * The data is put in the read queue.
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2298 */
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2299 void
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2300 channel_handle_events(void)
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2301 {
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2302 channel_T *channel;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2303 int part;
8172
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2304 sock_T fd;
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2305
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2306 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2307 {
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
2308 # ifdef CHANNEL_PIPES
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2309 /* check the socket and pipes */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2310 for (part = PART_SOCK; part <= PART_ERR; ++part)
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8218
diff changeset
2311 # else
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2312 /* only check the socket */
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2313 part = PART_SOCK;
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2314 # endif
8172
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2315 {
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2316 fd = channel->ch_part[part].ch_fd;
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2317 if (fd != INVALID_FD && channel_wait(channel, fd, 0) == OK)
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2318 channel_read(channel, part, "channel_handle_events");
db5c79d93eee commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
2319 }
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2320 }
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2321 }
7780
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2322 # endif
e09af43f98f7 commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents: 7774
diff changeset
2323
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2324 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2325 * Write "buf" (NUL terminated string) to "channel"/"part".
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2326 * When "fun" is not NULL an error message might be given.
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2327 * Return FAIL or OK.
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2328 */
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2329 int
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2330 channel_send(channel_T *channel, int part, char_u *buf, char *fun)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2331 {
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2332 int len = (int)STRLEN(buf);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2333 int res;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2334 sock_T fd;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2335
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2336 fd = channel->ch_part[part].ch_fd;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2337 if (fd == INVALID_FD)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2338 {
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2339 if (!channel->ch_error && fun != NULL)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2340 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
2341 ch_errors(channel, "%s(): write while not connected", fun);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2342 EMSG2("E630: %s(): write while not connected", fun);
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2343 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2344 channel->ch_error = TRUE;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2345 return FAIL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2346 }
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2347
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2348 if (log_fd != NULL)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2349 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2350 ch_log_lead("SEND ", channel);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2351 fprintf(log_fd, "'");
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2352 ignored = (int)fwrite(buf, len, 1, log_fd);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2353 fprintf(log_fd, "'\n");
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2354 fflush(log_fd);
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2355 }
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2356
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2357 if (part == PART_SOCK)
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 8074
diff changeset
2358 res = sock_write(fd, (char *)buf, len);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2359 else
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 8074
diff changeset
2360 res = fd_write(fd, (char *)buf, len);
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2361 if (res != len)
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2362 {
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2363 if (!channel->ch_error && fun != NULL)
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2364 {
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
2365 ch_errors(channel, "%s(): write failed", fun);
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2366 EMSG2("E631: %s(): write failed", fun);
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2367 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2368 channel->ch_error = TRUE;
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2369 return FAIL;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2370 }
7788
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2371
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2372 channel->ch_error = FALSE;
192ae655ac91 commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents: 7780
diff changeset
2373 return OK;
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2374 }
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2375
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2376 # if (defined(UNIX) && !defined(HAVE_SELECT)) || defined(PROTO)
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2377 /*
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2378 * Add open channels to the poll struct.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2379 * Return the adjusted struct index.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2380 * The type of "fds" is hidden to avoid problems with the function proto.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2381 */
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2382 int
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2383 channel_poll_setup(int nfd_in, void *fds_in)
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2384 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2385 int nfd = nfd_in;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2386 channel_T *channel;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2387 struct pollfd *fds = fds_in;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2388 int part;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2389
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2390 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2391 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2392 # ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2393 for (part = PART_SOCK; part < PART_IN; ++part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2394 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2395 part = PART_SOCK;
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2396 # endif
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2397 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2398 if (channel->ch_part[part].ch_fd != INVALID_FD)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2399 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2400 channel->ch_part[part].ch_poll_idx = nfd;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2401 fds[nfd].fd = channel->ch_part[part].ch_fd;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2402 fds[nfd].events = POLLIN;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2403 nfd++;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2404 }
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2405 else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2406 channel->ch_part[part].ch_poll_idx = -1;
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2407 }
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2408 }
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 return nfd;
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 }
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2412
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2413 /*
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2414 * The type of "fds" is hidden to avoid problems with the function proto.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2415 */
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2416 int
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2417 channel_poll_check(int ret_in, void *fds_in)
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2418 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2419 int ret = ret_in;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2420 channel_T *channel;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2421 struct pollfd *fds = fds_in;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2422 int part;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2423
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2424 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2425 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2426 # ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2427 for (part = PART_SOCK; part < PART_IN; ++part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2428 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2429 part = PART_SOCK;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2430 # endif
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2431 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2432 int idx = channel->ch_part[part].ch_poll_idx;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2433
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2434 if (ret > 0 && idx != -1 && fds[idx].revents & POLLIN)
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2435 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2436 channel_read(channel, part, "channel_poll_check");
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2437 --ret;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2438 }
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2439 }
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2440 }
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2441
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2442 return ret;
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2443 }
7770
42c1a4e63d12 commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents: 7743
diff changeset
2444 # endif /* UNIX && !HAVE_SELECT */
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2445
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2446 # if (!defined(WIN32) && defined(HAVE_SELECT)) || defined(PROTO)
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 /*
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 * The type of "rfds" is hidden to avoid problems with the function proto.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449 */
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 int
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451 channel_select_setup(int maxfd_in, void *rfds_in)
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2453 int maxfd = maxfd_in;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2454 channel_T *channel;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2455 fd_set *rfds = rfds_in;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2456 int part;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2458 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2459 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2460 # ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2461 for (part = PART_SOCK; part < PART_IN; ++part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2462 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2463 part = PART_SOCK;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2464 # endif
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2465 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2466 sock_T fd = channel->ch_part[part].ch_fd;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2467
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2468 if (fd != INVALID_FD)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2469 {
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2470 FD_SET((int)fd, rfds);
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2471 if (maxfd < (int)fd)
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
2472 maxfd = (int)fd;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2473 }
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2474 }
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2475 }
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2476
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2477 return maxfd;
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2478 }
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2479
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2480 /*
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2481 * The type of "rfds" is hidden to avoid problems with the function proto.
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2482 */
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2483 int
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2484 channel_select_check(int ret_in, void *rfds_in)
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485 {
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2486 int ret = ret_in;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2487 channel_T *channel;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2488 fd_set *rfds = rfds_in;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2489 int part;
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2490
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2491 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2492 {
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2493 # ifdef CHANNEL_PIPES
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2494 for (part = PART_SOCK; part < PART_IN; ++part)
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2495 # else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2496 part = PART_SOCK;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2497 # endif
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2498 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2499 sock_T fd = channel->ch_part[part].ch_fd;
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2500
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2501 if (ret > 0 && fd != INVALID_FD && FD_ISSET(fd, rfds))
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2502 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2503 channel_read(channel, part, "channel_select_check");
8047
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2504 --ret;
7c74cafac0a1 commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
2505 }
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
2506 }
8049
15253130abd8 commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents: 8047
diff changeset
2507 }
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2508
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2509 return ret;
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2510 }
8122
39532ee7dd43 commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
2511 # endif /* !WIN32 && HAVE_SELECT */
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2512
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2513 /*
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2514 * Return TRUE if "channel" has JSON or other typeahead.
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2515 */
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2516 static int
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2517 channel_has_readahead(channel_T *channel, int part)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2518 {
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2519 ch_mode_T ch_mode = channel->ch_part[part].ch_mode;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2520
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2521 if (ch_mode == MODE_JSON || ch_mode == MODE_JS)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2522 {
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2523 jsonq_T *head = &channel->ch_part[part].ch_json_head;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2524 jsonq_T *item = head->jq_next;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2525
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2526 return item != NULL;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2527 }
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2528 return channel_peek(channel, part) != NULL;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2529 }
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2530
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2531 /*
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2532 * Execute queued up commands.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2533 * Invoked from the main loop when it's safe to execute received commands.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2534 * Return TRUE when something was done.
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2535 */
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2536 int
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2537 channel_parse_messages(void)
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2538 {
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2539 channel_T *channel = first_channel;
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2540 int ret = FALSE;
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2541 int r;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2542 int part = PART_SOCK;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2543
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2544 ch_log(NULL, "looking for messages on channels");
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2545 while (channel != NULL)
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2546 {
8259
99a70c3b902f commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents: 8257
diff changeset
2547 if (channel->ch_refcount == 0 && !channel_still_useful(channel))
8257
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2548 {
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2549 /* channel is no longer useful, free it */
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2550 channel_free(channel);
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2551 channel = first_channel;
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2552 part = PART_SOCK;
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2553 continue;
c4ffdda8cdfd commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents: 8240
diff changeset
2554 }
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2555 if (channel->ch_part[part].ch_fd != INVALID_FD
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2556 || channel_has_readahead(channel, part))
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2557 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2558 /* Increase the refcount, in case the handler causes the channel
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2559 * to be unreferenced or closed. */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2560 ++channel->ch_refcount;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2561 r = may_invoke_callback(channel, part);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2562 if (r == OK)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2563 ret = TRUE;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2564 if (channel_unref(channel) || r == OK)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2565 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2566 /* channel was freed or something was done, start over */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2567 channel = first_channel;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2568 part = PART_SOCK;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2569 continue;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2570 }
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2571 }
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2572 #ifdef CHANNEL_PIPES
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2573 if (part < PART_ERR)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2574 ++part;
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2575 else
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2576 #endif
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2577 {
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2578 channel = channel->ch_next;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2579 part = PART_SOCK;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2580 }
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8049
diff changeset
2581 }
8267
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2582
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2583 if (channel_need_redraw && must_redraw)
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2584 {
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2585 channel_need_redraw = FALSE;
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2586 update_screen(0);
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2587 setcursor();
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2588 cursor_on();
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2589 out_flush();
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2590 }
108d30ed34ba commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents: 8261
diff changeset
2591
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents: 7885
diff changeset
2592 return ret;
7840
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2593 }
28f569c7dab9 commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents: 7817
diff changeset
2594
7961
a7e58c6e4e9a commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents: 7945
diff changeset
2595 /*
a7e58c6e4e9a commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents: 7945
diff changeset
2596 * Mark references to lists used in channels.
a7e58c6e4e9a commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents: 7945
diff changeset
2597 */
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2598 int
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2599 set_ref_in_channel(int copyID)
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2600 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2601 int abort = FALSE;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2602 channel_T *channel;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2603 int part;
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2604
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2605 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2606 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2607 #ifdef CHANNEL_PIPES
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2608 for (part = PART_SOCK; part < PART_IN; ++part)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2609 #else
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2610 part = PART_SOCK;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2611 #endif
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2612 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2613 jsonq_T *head = &channel->ch_part[part].ch_json_head;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2614 jsonq_T *item = head->jq_next;
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2615
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2616 while (item != NULL)
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2617 {
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2618 list_T *l = item->jq_value->vval.v_list;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2619
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2620 if (l->lv_copyID != copyID)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2621 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2622 l->lv_copyID = copyID;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2623 abort = abort || set_ref_in_list(l, copyID, NULL);
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2624 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2625 item = item->jq_next;
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2626 }
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2627 }
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2628 }
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2629 return abort;
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
2630 }
7986
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2631
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2632 /*
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2633 * Return the "part" to write to for "channel".
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2634 */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2635 int
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2636 channel_part_send(channel_T *channel)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2637 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2638 #ifdef CHANNEL_PIPES
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2639 if (channel->CH_SOCK_FD == INVALID_FD)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2640 return PART_IN;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2641 #endif
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2642 return PART_SOCK;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2643 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2644
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2645 /*
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2646 * Return the default "part" to read from for "channel".
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2647 */
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2648 int
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2649 channel_part_read(channel_T *channel)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2650 {
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2651 #ifdef CHANNEL_PIPES
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2652 if (channel->CH_SOCK_FD == INVALID_FD)
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2653 return PART_OUT;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2654 #endif
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2655 return PART_SOCK;
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2656 }
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2657
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2658 /*
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2659 * Return the mode of "channel"/"part"
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2660 * If "channel" is invalid returns MODE_JSON.
7986
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2661 */
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2662 ch_mode_T
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2663 channel_get_mode(channel_T *channel, int part)
7986
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2664 {
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8039
diff changeset
2665 if (channel == NULL)
7986
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2666 return MODE_JSON;
8151
aa845d10c6fb commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents: 8134
diff changeset
2667 return channel->ch_part[part].ch_mode;
7986
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2668 }
8e0d4cd8157a commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
2669
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2670 /*
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2671 * Return the timeout of "channel"/"part"
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2672 */
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2673 int
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2674 channel_get_timeout(channel_T *channel, int part)
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2675 {
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2676 return channel->ch_part[part].ch_timeout;
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2677 }
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8155
diff changeset
2678
7743
6069f43cea4e commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2679 #endif /* FEAT_CHANNEL */