Mercurial > vim
annotate src/channel.c @ 30208:9f6908aa16a7
Added tag v9.0.0439 for changeset 7147c6059e80c57cc6ace1edc39356ea7c346e5f
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Sep 2022 23:45:03 +0200 |
parents | 87e205ae86d3 |
children | 74e64f3a54ef |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10030
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7743
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 |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
13 #ifdef WIN32 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
14 // Must include winsock2.h before windows.h since it conflicts with winsock.h |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
15 // (included in windows.h). |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
16 # include <winsock2.h> |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
17 # include <ws2tcpip.h> |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
18 #endif |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
19 |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 #include "vim.h" |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
22 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
24 // TRUE when netbeans is running with a GUI. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
25 #ifdef FEAT_GUI |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
26 # 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
|
27 #endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
28 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
29 // Note: when making changes here also adjust configure.ac. |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
30 #ifdef MSWIN |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
31 // WinSock API is separated from C API, thus we can't use read(), write(), |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
32 // errno... |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
33 # define SOCK_ERRNO errno = WSAGetLastError() |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
34 # undef ECONNREFUSED |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
35 # define ECONNREFUSED WSAECONNREFUSED |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
36 # undef EWOULDBLOCK |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
37 # define EWOULDBLOCK WSAEWOULDBLOCK |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
38 # undef EINPROGRESS |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
39 # define EINPROGRESS WSAEINPROGRESS |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
40 # ifdef EINTR |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
41 # undef EINTR |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
42 # endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
43 # define EINTR WSAEINTR |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
44 # 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
|
45 # 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
|
46 # define sock_close(sd) closesocket((SOCKET)sd) |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
47 // Support for Unix-domain sockets was added in Windows SDK 17061. |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
48 # define UNIX_PATH_MAX 108 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
49 typedef struct sockaddr_un { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
50 ADDRESS_FAMILY sun_family; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
51 char sun_path[UNIX_PATH_MAX]; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
52 } SOCKADDR_UN, *PSOCKADDR_UN; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
53 #else |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
54 # include <netdb.h> |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
55 # include <netinet/in.h> |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
56 # include <arpa/inet.h> |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
57 # include <sys/socket.h> |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
58 # include <sys/un.h> |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
59 # ifdef HAVE_LIBGEN_H |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
60 # include <libgen.h> |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
61 # endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
62 # define SOCK_ERRNO |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
63 # 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
|
64 # 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
|
65 # 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
|
66 # 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
|
67 # 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
|
68 # 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
|
69 #endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
70 |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
71 static void channel_read(channel_T *channel, ch_part_T part, char *func); |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
72 static ch_mode_T channel_get_mode(channel_T *channel, ch_part_T part); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
73 static int channel_get_timeout(channel_T *channel, ch_part_T part); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
74 static ch_part_T channel_part_send(channel_T *channel); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
75 static ch_part_T channel_part_read(channel_T *channel); |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
76 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
77 #define FOR_ALL_CHANNELS(ch) \ |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
78 for ((ch) = first_channel; (ch) != NULL; (ch) = (ch)->ch_next) |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
79 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
80 // Whether we are inside channel_parse_messages() or another situation where it |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
81 // is safe to invoke callbacks. |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
82 static int safe_to_invoke_callback = 0; |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
83 |
9089
6bc0a492e8ba
commit https://github.com/vim/vim/commit/de7eb0a47b557eb4656c6b63d421c7e7bae1ef30
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
84 static char *part_names[] = {"sock", "out", "err", "in"}; |
6bc0a492e8ba
commit https://github.com/vim/vim/commit/de7eb0a47b557eb4656c6b63d421c7e7bae1ef30
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
85 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
86 #ifdef MSWIN |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
87 static int |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8074
diff
changeset
|
88 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
|
89 { |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
90 HANDLE h = (HANDLE)fd; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
91 DWORD nread; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
92 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
93 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
|
94 return -1; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
95 return (int)nread; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
96 } |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
97 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
98 static int |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8074
diff
changeset
|
99 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
|
100 { |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
101 size_t todo = len; |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
102 HANDLE h = (HANDLE)fd; |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
103 DWORD nwrite, size, done = 0; |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
104 OVERLAPPED ov; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
105 |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
106 while (todo > 0) |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
107 { |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
108 if (todo > MAX_NAMED_PIPE_SIZE) |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
109 size = MAX_NAMED_PIPE_SIZE; |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
110 else |
15661
b6f11ff3b6d1
patch 8.1.0838: compiler warning for type conversion
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
111 size = (DWORD)todo; |
15764
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
112 // If the pipe overflows while the job does not read the data, |
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
113 // WriteFile() will block forever. This abandons the write. |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
114 memset(&ov, 0, sizeof(ov)); |
15764
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
115 nwrite = 0; |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
116 if (!WriteFile(h, buf + done, size, &nwrite, &ov)) |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
117 { |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
118 DWORD err = GetLastError(); |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
119 |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
120 if (err != ERROR_IO_PENDING) |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
121 return -1; |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
122 if (!GetOverlappedResult(h, &ov, &nwrite, FALSE)) |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
123 return -1; |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
124 FlushFileBuffers(h); |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
125 } |
15764
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
126 else if (nwrite == 0) |
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
127 // WriteFile() returns TRUE but did not write anything. This causes |
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
128 // a hang, so bail out. |
208bf8b36075
patch 8.1.0889: MS-Windows: a channel write may hang
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
129 break; |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
130 todo -= nwrite; |
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
131 done += nwrite; |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
132 } |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15577
diff
changeset
|
133 return (int)done; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
134 } |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
135 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
136 static void |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
137 fd_close(sock_T fd) |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
138 { |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
139 HANDLE h = (HANDLE)fd; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
140 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
141 CloseHandle(h); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
142 } |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
143 #endif |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
145 // Log file opened with ch_logfile(). |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
146 static FILE *log_fd = NULL; |
21992
d9acf1e1c799
patch 8.2.1545: ch_logfile() is unclear about closing when forking
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
147 static char_u *log_name = NULL; |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
148 #ifdef FEAT_RELTIME |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
149 static proftime_T log_start; |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
150 #endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
151 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
152 void |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
153 ch_logfile(char_u *fname, char_u *opt) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
154 { |
29069
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
155 FILE *file = NULL; |
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
156 char *mode = "a"; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
157 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
158 if (log_fd != NULL) |
18191
0f8a34c996eb
patch 8.1.2090: not clear why channel log file ends
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
159 { |
0f8a34c996eb
patch 8.1.2090: not clear why channel log file ends
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
160 if (*fname != NUL) |
20384
42ab4d40e78f
patch 8.2.0747: cannot forcefully close all popups
Bram Moolenaar <Bram@vim.org>
parents:
20307
diff
changeset
|
161 ch_log(NULL, "closing this logfile, opening %s", fname); |
18191
0f8a34c996eb
patch 8.1.2090: not clear why channel log file ends
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
162 else |
21992
d9acf1e1c799
patch 8.2.1545: ch_logfile() is unclear about closing when forking
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
163 ch_log(NULL, "closing logfile %s", log_name); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
164 fclose(log_fd); |
18191
0f8a34c996eb
patch 8.1.2090: not clear why channel log file ends
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
165 } |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
166 |
29069
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
167 // The "a" flag overrules the "w" flag. |
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
168 if (vim_strchr(opt, 'a') == NULL && vim_strchr(opt, 'w') != NULL) |
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
169 mode = "w"; |
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
170 ch_log_output = vim_strchr(opt, 'o') != NULL ? LOG_ALWAYS : FALSE; |
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
171 |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
172 if (*fname != NUL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
173 { |
29069
be6c32395444
patch 8.2.5056: the channel log only contains some of the raw terminal output
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
174 file = fopen((char *)fname, mode); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
175 if (file == NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
176 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
177 semsg(_(e_cant_open_file_str), fname); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
178 return; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
179 } |
21992
d9acf1e1c799
patch 8.2.1545: ch_logfile() is unclear about closing when forking
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
180 vim_free(log_name); |
d9acf1e1c799
patch 8.2.1545: ch_logfile() is unclear about closing when forking
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
181 log_name = vim_strsave(fname); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
182 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
183 log_fd = file; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
184 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
185 if (log_fd != NULL) |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
186 { |
28435
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
28347
diff
changeset
|
187 fprintf(log_fd, "==== start log session %s ====\n", |
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
28347
diff
changeset
|
188 get_ctime(time(NULL), FALSE)); |
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
28347
diff
changeset
|
189 // flush now, if fork/exec follows it could be written twice |
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
28347
diff
changeset
|
190 fflush(log_fd); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
191 #ifdef FEAT_RELTIME |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
192 profile_start(&log_start); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
193 #endif |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
194 } |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
195 } |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
196 |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
197 int |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9246
diff
changeset
|
198 ch_log_active(void) |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
199 { |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
200 return log_fd != NULL; |
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 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
203 static void |
14499
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
204 ch_log_lead(const char *what, channel_T *ch, ch_part_T part) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
205 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
206 if (log_fd != NULL) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
207 { |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
208 #ifdef FEAT_RELTIME |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
209 proftime_T log_now; |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
210 |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
211 profile_start(&log_now); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
212 profile_sub(&log_now, &log_start); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
213 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
|
214 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
215 if (ch != NULL) |
14499
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
216 { |
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
217 if (part < PART_COUNT) |
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
218 fprintf(log_fd, "%son %d(%s): ", |
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
219 what, ch->ch_id, part_names[part]); |
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
220 else |
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
221 fprintf(log_fd, "%son %d: ", what, ch->ch_id); |
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
222 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
223 else |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
224 fprintf(log_fd, "%s: ", what); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
225 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
226 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
227 |
15908
379247470597
patch 8.1.0960: when using ConPTY garbage collection has undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
228 #ifndef PROTO // prototype is in proto.h |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
229 void |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
230 ch_log(channel_T *ch, const char *fmt, ...) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
231 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
232 if (log_fd != NULL) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
233 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
234 va_list ap; |
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
235 |
14499
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
236 ch_log_lead("", ch, PART_COUNT); |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
237 va_start(ap, fmt); |
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
238 vfprintf(log_fd, fmt, ap); |
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
239 va_end(ap); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
240 fputc('\n', log_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
241 fflush(log_fd); |
18160
770987511384
patch 8.1.2075: get many log messages when waiting for a typed character
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
242 did_repeated_msg = 0; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
243 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
244 } |
13608
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
245 #endif |
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
246 |
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
247 static void |
25475
038eb6d9003a
patch 8.2.3274: macro for printf format check can be simplified
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
248 ch_error(channel_T *ch, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
249 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
250 static void |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
251 ch_error(channel_T *ch, const char *fmt, ...) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
252 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
253 if (log_fd != NULL) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
254 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
255 va_list ap; |
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
256 |
14499
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
257 ch_log_lead("ERR ", ch, PART_COUNT); |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
258 va_start(ap, fmt); |
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
259 vfprintf(log_fd, fmt, ap); |
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
260 va_end(ap); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
261 fputc('\n', log_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
262 fflush(log_fd); |
18160
770987511384
patch 8.1.2075: get many log messages when waiting for a typed character
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
263 did_repeated_msg = 0; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
264 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
265 } |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
266 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
267 #ifdef MSWIN |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
268 # undef PERROR |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
269 # define PERROR(msg) (void)semsg("%s: %s", msg, strerror_win32(errno)) |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
270 |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
271 static char * |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
272 strerror_win32(int eno) |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
273 { |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
274 static LPVOID msgbuf = NULL; |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
275 char_u *ptr; |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
276 |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
277 if (msgbuf) |
9355
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
278 { |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
279 LocalFree(msgbuf); |
9355
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
280 msgbuf = NULL; |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
281 } |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
282 FormatMessage( |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
283 FORMAT_MESSAGE_ALLOCATE_BUFFER | |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
284 FORMAT_MESSAGE_FROM_SYSTEM | |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
285 FORMAT_MESSAGE_IGNORE_INSERTS, |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
286 NULL, |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
287 eno, |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
288 MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
289 (LPTSTR) &msgbuf, |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
290 0, |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
291 NULL); |
9355
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
292 if (msgbuf != NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
293 // chomp \r or \n |
9355
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
294 for (ptr = (char_u *)msgbuf; *ptr; ptr++) |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
295 switch (*ptr) |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
296 { |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
297 case '\r': |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
298 STRMOVE(ptr, ptr + 1); |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
299 ptr--; |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
300 break; |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
301 case '\n': |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
302 if (*(ptr + 1) == '\0') |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
303 *ptr = '\0'; |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
304 else |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
305 *ptr = ' '; |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
306 break; |
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
307 } |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
308 return msgbuf; |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
309 } |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
310 #endif |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
311 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
312 /* |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
313 * The list of all allocated channels. |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
314 */ |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
315 static channel_T *first_channel = NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
316 static int next_ch_id = 0; |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
317 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
318 /* |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
319 * 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
|
320 * 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
|
321 * Returns NULL if out of memory. |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
322 */ |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
323 channel_T * |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
324 add_channel(void) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
325 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
326 ch_part_T part; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
327 channel_T *channel = ALLOC_CLEAR_ONE(channel_T); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
328 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
329 if (channel == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
330 return NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
331 |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
332 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
|
333 ch_log(channel, "Created channel"); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
334 |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
335 for (part = PART_SOCK; part < PART_COUNT; ++part) |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
336 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
337 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
|
338 #ifdef FEAT_GUI_X11 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
339 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
|
340 #endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
341 #ifdef FEAT_GUI_GTK |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
342 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
|
343 #endif |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
344 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
|
345 } |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
346 |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
347 if (first_channel != NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
348 { |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
349 first_channel->ch_prev = channel; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
350 channel->ch_next = first_channel; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
351 } |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
352 first_channel = channel; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
353 |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
354 channel->ch_refcount = 1; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
355 return channel; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
356 } |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
357 |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10233
diff
changeset
|
358 int |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10233
diff
changeset
|
359 has_any_channel(void) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10233
diff
changeset
|
360 { |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10233
diff
changeset
|
361 return first_channel != NULL; |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10233
diff
changeset
|
362 } |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10233
diff
changeset
|
363 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
364 /* |
8310
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
365 * 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
|
366 * 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
|
367 * killed. |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
368 */ |
22095
2cc0de1e05a6
patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
22077
diff
changeset
|
369 int |
8259
99a70c3b902f
commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents:
8257
diff
changeset
|
370 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
|
371 { |
8332
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
372 int has_sock_msg; |
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
373 int has_out_msg; |
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
374 int has_err_msg; |
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
375 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
376 // 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
|
377 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
|
378 return FALSE; |
8332
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
379 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
380 // If there is a close callback it may still need to be invoked. |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
381 if (channel->ch_close_cb.cb_name != NULL) |
8332
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
382 return TRUE; |
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
383 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
384 // If reading from or a buffer it's still useful. |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
385 if (channel->ch_part[PART_IN].ch_bufref.br_buf != NULL) |
9081
b2b915c1d311
commit https://github.com/vim/vim/commit/5d96e3ae534ade8ed09a5de9ff8fd7519537ec28
Christian Brabandt <cb@256bit.org>
parents:
9079
diff
changeset
|
386 return TRUE; |
b2b915c1d311
commit https://github.com/vim/vim/commit/5d96e3ae534ade8ed09a5de9ff8fd7519537ec28
Christian Brabandt <cb@256bit.org>
parents:
9079
diff
changeset
|
387 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
388 // If there is no callback then nobody can get readahead. If the fd is |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
389 // closed and there is no readahead then the callback won't be called. |
8332
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
390 has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
391 || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
392 || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL; |
8332
07713b8243ac
commit https://github.com/vim/vim/commit/fdd6ce4a2f922afac7bd719a00228dbd8539b9c4
Christian Brabandt <cb@256bit.org>
parents:
8330
diff
changeset
|
393 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
|
394 || 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
|
395 || 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
|
396 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
|
397 || 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
|
398 || channel->ch_part[PART_ERR].ch_json_head.jq_next != NULL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
399 return (channel->ch_callback.cb_name != NULL && (has_sock_msg |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
400 || has_out_msg || has_err_msg)) |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
401 || ((channel->ch_part[PART_OUT].ch_callback.cb_name != NULL |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
402 || channel->ch_part[PART_OUT].ch_bufref.br_buf != NULL) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
403 && has_out_msg) |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
404 || ((channel->ch_part[PART_ERR].ch_callback.cb_name != NULL |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
405 || channel->ch_part[PART_ERR].ch_bufref.br_buf != NULL) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
406 && has_err_msg); |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
407 } |
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
408 |
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
409 /* |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
410 * Return TRUE if "channel" is closeable (i.e. all readable fds are closed). |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
411 */ |
22095
2cc0de1e05a6
patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
22077
diff
changeset
|
412 int |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
413 channel_can_close(channel_T *channel) |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
414 { |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
415 return channel->ch_to_be_closed == 0; |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
416 } |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
417 |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
418 /* |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
419 * Close a channel and free all its resources. |
19772
472dc753e985
patch 8.2.0442: channel contents might be used after being freed
Bram Moolenaar <Bram@vim.org>
parents:
19758
diff
changeset
|
420 * The "channel" pointer remains valid. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
421 */ |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
422 static void |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
423 channel_free_contents(channel_T *channel) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
424 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
425 channel_close(channel, TRUE); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
426 channel_clear(channel); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
427 ch_log(channel, "Freeing channel"); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
428 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
429 |
19772
472dc753e985
patch 8.2.0442: channel contents might be used after being freed
Bram Moolenaar <Bram@vim.org>
parents:
19758
diff
changeset
|
430 /* |
472dc753e985
patch 8.2.0442: channel contents might be used after being freed
Bram Moolenaar <Bram@vim.org>
parents:
19758
diff
changeset
|
431 * Unlink "channel" from the list of channels and free it. |
472dc753e985
patch 8.2.0442: channel contents might be used after being freed
Bram Moolenaar <Bram@vim.org>
parents:
19758
diff
changeset
|
432 */ |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
433 static void |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
434 channel_free_channel(channel_T *channel) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
435 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
436 if (channel->ch_next != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
437 channel->ch_next->ch_prev = channel->ch_prev; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
438 if (channel->ch_prev == NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
439 first_channel = channel->ch_next; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
440 else |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
441 channel->ch_prev->ch_next = channel->ch_next; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
442 vim_free(channel); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
443 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
444 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
445 static void |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
446 channel_free(channel_T *channel) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
447 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
448 if (!in_free_unref_items) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
449 { |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
450 if (safe_to_invoke_callback == 0) |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
451 channel->ch_to_be_freed = TRUE; |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
452 else |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
453 { |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
454 channel_free_contents(channel); |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
455 channel_free_channel(channel); |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
456 } |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
457 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
458 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
459 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
460 /* |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
461 * 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
|
462 * 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
|
463 * killed. |
8318
190d8084cb3a
commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents:
8310
diff
changeset
|
464 * 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
|
465 */ |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
466 static int |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
467 channel_may_free(channel_T *channel) |
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
468 { |
8259
99a70c3b902f
commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Christian Brabandt <cb@256bit.org>
parents:
8257
diff
changeset
|
469 if (!channel_still_useful(channel)) |
8318
190d8084cb3a
commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents:
8310
diff
changeset
|
470 { |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
471 channel_free(channel); |
8318
190d8084cb3a
commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents:
8310
diff
changeset
|
472 return TRUE; |
190d8084cb3a
commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents:
8310
diff
changeset
|
473 } |
190d8084cb3a
commit https://github.com/vim/vim/commit/707659490d35e8d66e8bbdcfd93b12dc1387d86c
Christian Brabandt <cb@256bit.org>
parents:
8310
diff
changeset
|
474 return FALSE; |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
475 } |
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
476 |
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
477 /* |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
478 * Decrement the reference count on "channel" and maybe free it when it goes |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
479 * down to zero. Don't free it if there is a pending action. |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
480 * Returns TRUE when the channel is no longer referenced. |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
481 */ |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
482 int |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
483 channel_unref(channel_T *channel) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
484 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
485 if (channel != NULL && --channel->ch_refcount <= 0) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
486 return channel_may_free(channel); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
487 return FALSE; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
488 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
489 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
490 int |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
491 free_unused_channels_contents(int copyID, int mask) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
492 { |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
493 int did_free = FALSE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
494 channel_T *ch; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
495 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
496 // This is invoked from the garbage collector, which only runs at a safe |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
497 // point. |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
498 ++safe_to_invoke_callback; |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
499 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
500 FOR_ALL_CHANNELS(ch) |
9011
72a597e9e36d
commit https://github.com/vim/vim/commit/674127e1801fd02ff07dddf0dc3bf0d8cce68997
Christian Brabandt <cb@256bit.org>
parents:
9007
diff
changeset
|
501 if (!channel_still_useful(ch) |
72a597e9e36d
commit https://github.com/vim/vim/commit/674127e1801fd02ff07dddf0dc3bf0d8cce68997
Christian Brabandt <cb@256bit.org>
parents:
9007
diff
changeset
|
502 && (ch->ch_copyID & mask) != (copyID & mask)) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
503 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
504 // Free the channel and ordinary items it contains, but don't |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
505 // recurse into Lists, Dictionaries etc. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
506 channel_free_contents(ch); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
507 did_free = TRUE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
508 } |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
509 |
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
510 --safe_to_invoke_callback; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
511 return did_free; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
512 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
513 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
514 void |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
515 free_unused_channels(int copyID, int mask) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
516 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
517 channel_T *ch; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
518 channel_T *ch_next; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
519 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
520 for (ch = first_channel; ch != NULL; ch = ch_next) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
521 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
522 ch_next = ch->ch_next; |
9011
72a597e9e36d
commit https://github.com/vim/vim/commit/674127e1801fd02ff07dddf0dc3bf0d8cce68997
Christian Brabandt <cb@256bit.org>
parents:
9007
diff
changeset
|
523 if (!channel_still_useful(ch) |
72a597e9e36d
commit https://github.com/vim/vim/commit/674127e1801fd02ff07dddf0dc3bf0d8cce68997
Christian Brabandt <cb@256bit.org>
parents:
9007
diff
changeset
|
524 && (ch->ch_copyID & mask) != (copyID & mask)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
525 // Free the channel struct itself. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
526 channel_free_channel(ch); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8859
diff
changeset
|
527 } |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
528 } |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
529 |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
530 #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
|
531 |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
532 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
533 /* |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
534 * Lookup the channel from the socket. Set "partp" to the fd index. |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
535 * Returns NULL when the socket isn't found. |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
536 */ |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
537 static channel_T * |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
538 channel_fd2channel(sock_T fd, ch_part_T *partp) |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
539 { |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
540 channel_T *channel; |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
541 ch_part_T part; |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
542 |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
543 if (fd != INVALID_FD) |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
544 FOR_ALL_CHANNELS(channel) |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
545 { |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
546 for (part = PART_SOCK; part < PART_IN; ++part) |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
547 if (channel->ch_part[part].ch_fd == fd) |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
548 { |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
549 *partp = part; |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
550 return channel; |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
551 } |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
552 } |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
553 return NULL; |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
554 } |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
555 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
556 static void |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
557 channel_read_fd(int fd) |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
558 { |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
559 channel_T *channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
560 ch_part_T part; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
561 |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
562 channel = channel_fd2channel(fd, &part); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
563 if (channel == NULL) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
564 ch_error(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
|
565 else |
9123
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
566 channel_read(channel, part, "channel_read_fd"); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
567 } |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
568 # endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
569 |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
570 /* |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
571 * Read a command from netbeans. |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
572 */ |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
573 # ifdef FEAT_GUI_X11 |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
574 static void |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
575 messageFromServerX11(XtPointer clientData, |
9123
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
576 int *unused1 UNUSED, |
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
577 XtInputId *unused2 UNUSED) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
578 { |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
579 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
|
580 } |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
581 # endif |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
582 |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
583 # ifdef FEAT_GUI_GTK |
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
584 # if GTK_CHECK_VERSION(3,0,0) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
585 static gboolean |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
586 messageFromServerGtk3(GIOChannel *unused1 UNUSED, |
9123
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
587 GIOCondition unused2 UNUSED, |
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
588 gpointer clientData) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
589 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
590 channel_read_fd(GPOINTER_TO_INT(clientData)); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
591 return TRUE; // Return FALSE instead in case the event source is to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
592 // be removed after this function returns. |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
593 } |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
594 # else |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
595 static void |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
596 messageFromServerGtk2(gpointer clientData, |
9123
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
597 gint unused1 UNUSED, |
b430d4f2aa79
commit https://github.com/vim/vim/commit/f8df45d84f1d17dced23e185d4835fc23406d73d
Christian Brabandt <cb@256bit.org>
parents:
9089
diff
changeset
|
598 GdkInputCondition unused2 UNUSED) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
599 { |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
600 channel_read_fd((int)(long)clientData); |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
601 } |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
602 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
603 # endif |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
604 |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
605 static void |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
606 channel_gui_register_one(channel_T *channel, ch_part_T part UNUSED) |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
607 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
608 if (!CH_HAS_GUI) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
609 return; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
610 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
611 // gets stuck in handling events for a not connected channel |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
612 if (channel->ch_keep_open) |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
613 return; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
614 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
615 # ifdef FEAT_GUI_X11 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
616 // Tell notifier we are interested in being called when there is input on |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
617 // the editor connection socket. |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
618 if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL) |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
619 { |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
620 ch_log(channel, "Registering part %s with fd %d", |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
621 part_names[part], channel->ch_part[part].ch_fd); |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
622 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
623 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
|
624 (XtAppContext)app_context, |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
625 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
|
626 (XtPointer)(XtInputReadMask + XtInputExceptMask), |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
627 messageFromServerX11, |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
628 (XtPointer)(long)channel->ch_part[part].ch_fd); |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
629 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
630 # else |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
631 # ifdef FEAT_GUI_GTK |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
632 // Tell gdk we are interested in being called when there is input on the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
633 // editor connection socket. |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
634 if (channel->ch_part[part].ch_inputHandler == 0) |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
635 { |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
636 ch_log(channel, "Registering part %s with fd %d", |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
637 part_names[part], 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
|
638 # 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
|
639 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
|
640 (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
|
641 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
642 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
|
643 chnnl, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
644 G_IO_IN|G_IO_HUP|G_IO_ERR|G_IO_PRI, |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
645 messageFromServerGtk3, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
646 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
|
647 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
648 g_io_channel_unref(chnnl); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8210
diff
changeset
|
649 # else |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
650 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
|
651 (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
|
652 (GdkInputCondition) |
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
653 ((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION), |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
654 messageFromServerGtk2, |
8155
6ee6fb27dcea
commit https://github.com/vim/vim/commit/fffd5560c6c8840be3233ef1c8da3c9e5dd424ea
Christian Brabandt <cb@256bit.org>
parents:
8151
diff
changeset
|
655 (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
|
656 # endif |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
657 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
658 # endif |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
659 # endif |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
660 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
661 |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
662 static void |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
663 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
|
664 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
665 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
|
666 channel_gui_register_one(channel, PART_SOCK); |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
667 if (channel->CH_OUT_FD != INVALID_FD |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
668 && channel->CH_OUT_FD != channel->CH_SOCK_FD) |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
669 channel_gui_register_one(channel, PART_OUT); |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
670 if (channel->CH_ERR_FD != INVALID_FD |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
671 && channel->CH_ERR_FD != channel->CH_SOCK_FD |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
672 && channel->CH_ERR_FD != channel->CH_OUT_FD) |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
673 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
|
674 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
675 |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
676 /* |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
677 * 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
|
678 * Called when the GUI has started. |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
679 */ |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
680 void |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
681 channel_gui_register_all(void) |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
682 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
683 channel_T *channel; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
684 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
685 FOR_ALL_CHANNELS(channel) |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
686 channel_gui_register(channel); |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
687 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
688 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
689 static void |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
690 channel_gui_unregister_one(channel_T *channel UNUSED, ch_part_T part UNUSED) |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
691 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
692 # ifdef FEAT_GUI_X11 |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
693 if (channel->ch_part[part].ch_inputHandler != (XtInputId)NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
694 { |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
695 ch_log(channel, "Unregistering part %s", part_names[part]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
696 XtRemoveInput(channel->ch_part[part].ch_inputHandler); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
697 channel->ch_part[part].ch_inputHandler = (XtInputId)NULL; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
698 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
699 # else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
700 # ifdef FEAT_GUI_GTK |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
701 if (channel->ch_part[part].ch_inputHandler != 0) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
702 { |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
703 ch_log(channel, "Unregistering part %s", part_names[part]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
704 # if GTK_CHECK_VERSION(3,0,0) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
705 g_source_remove(channel->ch_part[part].ch_inputHandler); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
706 # else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
707 gdk_input_remove(channel->ch_part[part].ch_inputHandler); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
708 # endif |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
709 channel->ch_part[part].ch_inputHandler = 0; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
710 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
711 # endif |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
712 # endif |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
713 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
714 |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
715 static void |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
716 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
|
717 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
718 ch_part_T part; |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
719 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
720 for (part = PART_SOCK; part < PART_IN; ++part) |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
721 channel_gui_unregister_one(channel, part); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
722 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
723 |
17974
9fb236d0f386
patch 8.1.1983: compiler nags for uninitialized variable and unused function
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
724 #endif // FEAT_GUI |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
725 |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
726 /* |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
727 * For Unix we need to call connect() again after connect() failed. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
728 * On Win32 one time is sufficient. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
729 */ |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
730 static int |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
731 channel_connect( |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
732 channel_T *channel, |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
733 const struct sockaddr *server_addr, |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
734 int server_addrlen, |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
735 int *waittime) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
736 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
737 int sd = -1; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
738 #ifdef MSWIN |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
739 u_long val = 1; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
740 #endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
741 |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
742 while (TRUE) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
743 { |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
744 long elapsed_msec = 0; |
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
745 int waitnow; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
746 int ret; |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
747 |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
748 if (sd >= 0) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
749 sock_close(sd); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
750 sd = socket(server_addr->sa_family, SOCK_STREAM, 0); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
751 if (sd == -1) |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
752 { |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
753 ch_error(channel, "in socket() in channel_connect()."); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
754 PERROR(_(e_socket_in_channel_connect)); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
755 return -1; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
756 } |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
757 |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
758 if (*waittime >= 0) |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
759 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
760 // Make connect() non-blocking. |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
761 if ( |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
762 #ifdef MSWIN |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
763 ioctlsocket(sd, FIONBIO, &val) < 0 |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
764 #else |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
765 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
|
766 #endif |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
767 ) |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
768 { |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
769 SOCK_ERRNO; |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
770 ch_error(channel, |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
771 "channel_connect: Connect failed with errno %d", errno); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
772 sock_close(sd); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
773 return -1; |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
774 } |
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 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
777 // Try connecting to the server. |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
778 ch_log(channel, "Connecting..."); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
779 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
780 ret = connect(sd, server_addr, server_addrlen); |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
781 if (ret == 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
782 // The connection could be established. |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
783 break; |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
784 |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
785 SOCK_ERRNO; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
786 if (*waittime < 0 || (errno != EWOULDBLOCK |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
787 && errno != ECONNREFUSED |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
788 #ifdef EINPROGRESS |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
789 && errno != EINPROGRESS |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
790 #endif |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
791 )) |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
792 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
793 ch_error(channel, |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
794 "channel_connect: Connect failed with errno %d", errno); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
795 PERROR(_(e_cannot_connect_to_port)); |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
796 sock_close(sd); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
797 return -1; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
798 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
799 else if (errno == ECONNREFUSED) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
800 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
801 ch_error(channel, "channel_connect: Connection refused"); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
802 sock_close(sd); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
803 return -1; |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
804 } |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
805 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
806 // Limit the waittime to 50 msec. If it doesn't work within this |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
807 // time we close the socket and try creating it again. |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
808 waitnow = *waittime > 50 ? 50 : *waittime; |
8481
8924d7adbc22
commit https://github.com/vim/vim/commit/40e8cb292c36f5057628e570591e8917ac1ca121
Christian Brabandt <cb@256bit.org>
parents:
8477
diff
changeset
|
809 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
810 // If connect() didn't finish then try using select() to wait for the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
811 // connection to be made. For Win32 always use select() to wait. |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
812 { |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
813 struct timeval tv; |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
814 fd_set rfds; |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
815 fd_set wfds; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
816 #ifndef MSWIN |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
817 int so_error = 0; |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
818 socklen_t so_error_len = sizeof(so_error); |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
819 struct timeval start_tv; |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
820 struct timeval end_tv; |
8334
ad4b00bf2984
commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents:
8332
diff
changeset
|
821 #endif |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
822 FD_ZERO(&rfds); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
823 FD_SET(sd, &rfds); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
824 FD_ZERO(&wfds); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
825 FD_SET(sd, &wfds); |
8096
882ba5080c5c
commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
826 |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
827 tv.tv_sec = waitnow / 1000; |
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
828 tv.tv_usec = (waitnow % 1000) * 1000; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
829 #ifndef MSWIN |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
830 gettimeofday(&start_tv, NULL); |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
831 #endif |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
832 ch_log(channel, |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
833 "Waiting for connection (waiting %d msec)...", waitnow); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
834 |
27426
41e0dcf38521
patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
835 ret = select(sd + 1, &rfds, &wfds, NULL, &tv); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
836 if (ret < 0) |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
837 { |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
838 SOCK_ERRNO; |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
839 ch_error(channel, |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
840 "channel_connect: Connect failed with errno %d", errno); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
841 PERROR(_(e_cannot_connect_to_port)); |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
842 sock_close(sd); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
843 return -1; |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
844 } |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
845 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
846 #ifdef MSWIN |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
847 // On Win32: select() is expected to work and wait for up to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
848 // "waitnow" msec for the socket to be open. |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
849 if (FD_ISSET(sd, &wfds)) |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
850 break; |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
851 elapsed_msec = waitnow; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
852 if (*waittime > 1 && elapsed_msec < *waittime) |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
853 { |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
854 *waittime -= elapsed_msec; |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
855 continue; |
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
856 } |
8334
ad4b00bf2984
commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents:
8332
diff
changeset
|
857 #else |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
858 // On Linux-like systems: See socket(7) for the behavior |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
859 // After putting the socket in non-blocking mode, connect() will |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
860 // return EINPROGRESS, select() will not wait (as if writing is |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
861 // possible), need to use getsockopt() to check if the socket is |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
862 // actually able to connect. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
863 // We detect a failure to connect when either read and write fds |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
864 // 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
|
865 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
|
866 { |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
867 ret = getsockopt(sd, |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
868 SOL_SOCKET, SO_ERROR, &so_error, &so_error_len); |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
869 if (ret < 0 || (so_error != 0 |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
870 && so_error != EWOULDBLOCK |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
871 && so_error != ECONNREFUSED |
8334
ad4b00bf2984
commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents:
8332
diff
changeset
|
872 # ifdef EINPROGRESS |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
873 && so_error != EINPROGRESS |
8334
ad4b00bf2984
commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents:
8332
diff
changeset
|
874 # endif |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
875 )) |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
876 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
877 ch_error(channel, |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
878 "channel_connect: Connect failed with errno %d", |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
879 so_error); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
880 PERROR(_(e_cannot_connect_to_port)); |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
881 sock_close(sd); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
882 return -1; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
883 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
884 else if (errno == ECONNREFUSED) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
885 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
886 ch_error(channel, "channel_connect: Connection refused"); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
887 sock_close(sd); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
888 return -1; |
8330
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
889 } |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
890 } |
ec940c11f749
commit https://github.com/vim/vim/commit/d42119fff228434fe57e88d501c744de0a9fb1b1
Christian Brabandt <cb@256bit.org>
parents:
8320
diff
changeset
|
891 |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
892 if (FD_ISSET(sd, &wfds) && so_error == 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
893 // Did not detect an error, connection is established. |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
894 break; |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
895 |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
896 gettimeofday(&end_tv, NULL); |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
897 elapsed_msec = (end_tv.tv_sec - start_tv.tv_sec) * 1000 |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
898 + (end_tv.tv_usec - start_tv.tv_usec) / 1000; |
8334
ad4b00bf2984
commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Christian Brabandt <cb@256bit.org>
parents:
8332
diff
changeset
|
899 #endif |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
900 } |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
901 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
902 #ifndef MSWIN |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
903 if (*waittime > 1 && elapsed_msec < *waittime) |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
904 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
905 // The port isn't ready but we also didn't get an error. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
906 // This happens when the server didn't open the socket |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
907 // yet. Select() may return early, wait until the remaining |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
908 // "waitnow" and try again. |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
909 waitnow -= elapsed_msec; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
910 *waittime -= elapsed_msec; |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
911 if (waitnow > 0) |
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
912 { |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
913 mch_delay((long)waitnow, MCH_DELAY_IGNOREINPUT); |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
914 ui_breakcheck(); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
915 *waittime -= waitnow; |
8473
ade1797aa6f4
commit https://github.com/vim/vim/commit/562ca7142845273bca656aa5aeeda90f001062e0
Christian Brabandt <cb@256bit.org>
parents:
8467
diff
changeset
|
916 } |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
917 if (!got_int) |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
918 { |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
919 if (*waittime <= 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
920 // give it one more try |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
921 *waittime = 1; |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
922 continue; |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
923 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
924 // we were interrupted, behave as if timed out |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
925 } |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
926 #endif |
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
927 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
928 // We timed out. |
8467
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
929 ch_error(channel, "Connection timed out"); |
86a327403fb0
commit https://github.com/vim/vim/commit/045a284a83c2a85113de233d5233eae34724a4b6
Christian Brabandt <cb@256bit.org>
parents:
8463
diff
changeset
|
930 sock_close(sd); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
931 return -1; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
932 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
933 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
934 if (*waittime >= 0) |
7982
5c30ba57aaea
commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
935 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
936 #ifdef MSWIN |
7935
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
937 val = 0; |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
938 ioctlsocket(sd, FIONBIO, &val); |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
939 #else |
7961
a7e58c6e4e9a
commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents:
7945
diff
changeset
|
940 (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
|
941 #endif |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
942 } |
3f2e0b62003d
commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents:
7933
diff
changeset
|
943 |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
944 return sd; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
945 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
946 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
947 /* |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
948 * Open a socket channel to the UNIX socket at "path". |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
949 * Returns the channel for success. |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
950 * Returns NULL for failure. |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
951 */ |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
952 static channel_T * |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
953 channel_open_unix( |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
954 const char *path, |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
955 void (*nb_close_cb)(void)) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
956 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
957 channel_T *channel = NULL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
958 int sd = -1; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
959 size_t path_len = STRLEN(path); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
960 struct sockaddr_un server; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
961 size_t server_len; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
962 int waittime = -1; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
963 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
964 if (*path == NUL || path_len >= sizeof(server.sun_path)) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
965 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
966 semsg(_(e_invalid_argument_str), path); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
967 return NULL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
968 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
969 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
970 channel = add_channel(); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
971 if (channel == NULL) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
972 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
973 ch_error(NULL, "Cannot allocate channel."); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
974 return NULL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
975 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
976 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
977 CLEAR_FIELD(server); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
978 server.sun_family = AF_UNIX; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
979 STRNCPY(server.sun_path, path, sizeof(server.sun_path) - 1); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
980 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
981 ch_log(channel, "Trying to connect to %s", path); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
982 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
983 server_len = offsetof(struct sockaddr_un, sun_path) + path_len + 1; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
984 sd = channel_connect(channel, (struct sockaddr *)&server, (int)server_len, |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
985 &waittime); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
986 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
987 if (sd < 0) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
988 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
989 channel_free(channel); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
990 return NULL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
991 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
992 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
993 ch_log(channel, "Connection made"); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
994 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
995 channel->CH_SOCK_FD = (sock_T)sd; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
996 channel->ch_nb_close_cb = nb_close_cb; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
997 channel->ch_hostname = (char *)vim_strsave((char_u *)path); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
998 channel->ch_port = 0; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
999 channel->ch_to_be_closed |= (1U << PART_SOCK); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1000 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1001 #ifdef FEAT_GUI |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1002 channel_gui_register_one(channel, PART_SOCK); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1003 #endif |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1004 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1005 return channel; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1006 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1007 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1008 /* |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1009 * Open a socket channel to "hostname":"port". |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1010 * "waittime" is the time in msec to wait for the connection. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1011 * When negative wait forever. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1012 * Returns the channel for success. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1013 * Returns NULL for failure. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1014 */ |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1015 channel_T * |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1016 channel_open( |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1017 const char *hostname, |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1018 int port, |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1019 int waittime, |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1020 void (*nb_close_cb)(void)) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1021 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1022 int sd = -1; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1023 channel_T *channel = NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1024 #ifdef FEAT_IPV6 |
20267
456c3b98d4c8
patch 8.2.0689: when using getaddrinfo() the error message is unclear
Bram Moolenaar <Bram@vim.org>
parents:
20077
diff
changeset
|
1025 int err; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1026 struct addrinfo hints; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1027 struct addrinfo *res = NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1028 struct addrinfo *addr = NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1029 #else |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1030 struct sockaddr_in server; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1031 struct hostent *host = NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1032 #endif |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1033 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1034 #ifdef MSWIN |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1035 channel_init_winsock(); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1036 #endif |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1037 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1038 channel = add_channel(); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1039 if (channel == NULL) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1040 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1041 ch_error(NULL, "Cannot allocate channel."); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1042 return NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1043 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1044 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1045 // Get the server internet address and put into addr structure fill in the |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1046 // socket address structure and connect to server. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1047 #ifdef FEAT_IPV6 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20003
diff
changeset
|
1048 CLEAR_FIELD(hints); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1049 hints.ai_family = AF_UNSPEC; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1050 hints.ai_socktype = SOCK_STREAM; |
22224
a5bda73bc640
patch 8.2.1661: cannot connect to 127.0.0.1 for host with only IPv6 addresses
Bram Moolenaar <Bram@vim.org>
parents:
22210
diff
changeset
|
1051 # if defined(AI_ADDRCONFIG) && defined(AI_V4MAPPED) |
a5bda73bc640
patch 8.2.1661: cannot connect to 127.0.0.1 for host with only IPv6 addresses
Bram Moolenaar <Bram@vim.org>
parents:
22210
diff
changeset
|
1052 hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1053 # endif |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1054 // Set port number manually in order to prevent name resolution services |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1055 // from being invoked in the environment where AI_NUMERICSERV is not |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1056 // defined. |
20267
456c3b98d4c8
patch 8.2.0689: when using getaddrinfo() the error message is unclear
Bram Moolenaar <Bram@vim.org>
parents:
20077
diff
changeset
|
1057 if ((err = getaddrinfo(hostname, NULL, &hints, &res)) != 0) |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1058 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1059 ch_error(channel, "in getaddrinfo() in channel_open()"); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1060 semsg(_(e_getaddrinfo_in_channel_open_str), gai_strerror(err)); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1061 channel_free(channel); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1062 return NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1063 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1064 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1065 for (addr = res; addr != NULL; addr = addr->ai_next) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1066 { |
20077
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1067 const char *dst = hostname; |
20567
5e86e00fa712
patch 8.2.0837: compiler warning for value set but not used
Bram Moolenaar <Bram@vim.org>
parents:
20524
diff
changeset
|
1068 # ifdef HAVE_INET_NTOP |
20077
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1069 const void *src = NULL; |
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1070 char buf[NUMBUFLEN]; |
20577
5f0f1f63c8df
patch 8.2.0842: MS-Windows: channel tests fail
Bram Moolenaar <Bram@vim.org>
parents:
20567
diff
changeset
|
1071 # endif |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1072 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1073 if (addr->ai_family == AF_INET6) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1074 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1075 struct sockaddr_in6 *sai = (struct sockaddr_in6 *)addr->ai_addr; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1076 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1077 sai->sin6_port = htons(port); |
20577
5f0f1f63c8df
patch 8.2.0842: MS-Windows: channel tests fail
Bram Moolenaar <Bram@vim.org>
parents:
20567
diff
changeset
|
1078 # ifdef HAVE_INET_NTOP |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1079 src = &sai->sin6_addr; |
20577
5f0f1f63c8df
patch 8.2.0842: MS-Windows: channel tests fail
Bram Moolenaar <Bram@vim.org>
parents:
20567
diff
changeset
|
1080 # endif |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1081 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1082 else if (addr->ai_family == AF_INET) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1083 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1084 struct sockaddr_in *sai = (struct sockaddr_in *)addr->ai_addr; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1085 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1086 sai->sin_port = htons(port); |
20577
5f0f1f63c8df
patch 8.2.0842: MS-Windows: channel tests fail
Bram Moolenaar <Bram@vim.org>
parents:
20567
diff
changeset
|
1087 # ifdef HAVE_INET_NTOP |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1088 src = &sai->sin_addr; |
20577
5f0f1f63c8df
patch 8.2.0842: MS-Windows: channel tests fail
Bram Moolenaar <Bram@vim.org>
parents:
20567
diff
changeset
|
1089 #endif |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1090 } |
20577
5f0f1f63c8df
patch 8.2.0842: MS-Windows: channel tests fail
Bram Moolenaar <Bram@vim.org>
parents:
20567
diff
changeset
|
1091 # ifdef HAVE_INET_NTOP |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1092 if (src != NULL) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1093 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1094 dst = inet_ntop(addr->ai_family, src, buf, sizeof(buf)); |
20077
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1095 if (dst == NULL) |
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1096 dst = hostname; |
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1097 else if (STRCMP(hostname, dst) != 0) |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1098 ch_log(channel, "Resolved %s to %s", hostname, dst); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1099 } |
20077
128963cd954f
patch 8.2.0594: MS-Windows: cannot build with WINVER set to 0x0501
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1100 # endif |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1101 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1102 ch_log(channel, "Trying to connect to %s port %d", dst, port); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1103 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1104 // On Mac and Solaris a zero timeout almost never works. At least wait |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1105 // one millisecond. Let's do it for all systems, because we don't know |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1106 // why this is needed. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1107 if (waittime == 0) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1108 waittime = 1; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1109 |
20307
ad6949eaa1c7
patch 8.2.0709: MS-Windows: compiler warning for int vs size_t
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
1110 sd = channel_connect(channel, addr->ai_addr, (int)addr->ai_addrlen, |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1111 &waittime); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1112 if (sd >= 0) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1113 break; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1114 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1115 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1116 freeaddrinfo(res); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1117 #else |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20003
diff
changeset
|
1118 CLEAR_FIELD(server); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1119 server.sin_family = AF_INET; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1120 server.sin_port = htons(port); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1121 if ((host = gethostbyname(hostname)) == NULL) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1122 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1123 ch_error(channel, "in gethostbyname() in channel_open()"); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
1124 PERROR(_(e_gethostbyname_in_channel_open)); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1125 channel_free(channel); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1126 return NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1127 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1128 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1129 char *p; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1130 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1131 // When using host->h_addr_list[0] directly ubsan warns for it to not |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1132 // be aligned. First copy the pointer to avoid that. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1133 memcpy(&p, &host->h_addr_list[0], sizeof(p)); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1134 memcpy((char *)&server.sin_addr, p, host->h_length); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1135 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1136 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1137 ch_log(channel, "Trying to connect to %s port %d", hostname, port); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1138 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1139 // On Mac and Solaris a zero timeout almost never works. At least wait one |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1140 // millisecond. Let's do it for all systems, because we don't know why |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1141 // this is needed. |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1142 if (waittime == 0) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1143 waittime = 1; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1144 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1145 sd = channel_connect(channel, (struct sockaddr *)&server, sizeof(server), |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1146 &waittime); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1147 #endif |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1148 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1149 if (sd < 0) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1150 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1151 channel_free(channel); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1152 return NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1153 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1154 |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1155 ch_log(channel, "Connection made"); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1156 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1157 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
|
1158 channel->ch_nb_close_cb = nb_close_cb; |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
1159 channel->ch_hostname = (char *)vim_strsave((char_u *)hostname); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1160 channel->ch_port = port; |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1161 channel->ch_to_be_closed |= (1U << PART_SOCK); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
1162 |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
1163 #ifdef FEAT_GUI |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1164 channel_gui_register_one(channel, PART_SOCK); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
1165 #endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
1166 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1167 return channel; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
1168 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
1169 |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1170 static void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1171 free_set_callback(callback_T *cbp, callback_T *callback) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1172 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1173 free_callback(cbp); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1174 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1175 if (callback->cb_name != NULL && *callback->cb_name != NUL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1176 copy_callback(cbp, callback); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1177 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1178 cbp->cb_name = NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1179 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1180 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1181 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1182 * Prepare buffer "buf" for writing channel output to. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1183 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1184 static void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1185 prepare_buffer(buf_T *buf) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1186 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1187 buf_T *save_curbuf = curbuf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1188 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1189 buf_copy_options(buf, BCO_ENTER); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1190 curbuf = buf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1191 #ifdef FEAT_QUICKFIX |
28457
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28435
diff
changeset
|
1192 set_option_value_give_err((char_u *)"bt", |
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28435
diff
changeset
|
1193 0L, (char_u *)"nofile", OPT_LOCAL); |
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28435
diff
changeset
|
1194 set_option_value_give_err((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1195 #endif |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1196 if (curbuf->b_ml.ml_mfp == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1197 ml_open(curbuf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1198 curbuf = save_curbuf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1199 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1200 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1201 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1202 * Find a buffer matching "name" or create a new one. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1203 * Returns NULL if there is something very wrong (error already reported). |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1204 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1205 static buf_T * |
18010
cf8e0c7e0cb9
patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
17974
diff
changeset
|
1206 channel_find_buffer(char_u *name, int err, int msg) |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1207 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1208 buf_T *buf = NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1209 buf_T *save_curbuf = curbuf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1210 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1211 if (name != NULL && *name != NUL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1212 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1213 buf = buflist_findname(name); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1214 if (buf == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1215 buf = buflist_findname_exp(name); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1216 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1217 if (buf == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1218 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1219 buf = buflist_new(name == NULL || *name == NUL ? NULL : name, |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1220 NULL, (linenr_T)0, BLN_LISTED | BLN_NEW); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1221 if (buf == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1222 return NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1223 prepare_buffer(buf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1224 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1225 curbuf = buf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1226 if (msg) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1227 ml_replace(1, (char_u *)(err ? "Reading from channel error..." |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1228 : "Reading from channel output..."), TRUE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1229 changed_bytes(1, 0); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1230 curbuf = save_curbuf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1231 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1232 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1233 return buf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1234 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1235 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1236 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1237 * Set various properties from an "opt" argument. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1238 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1239 static void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1240 channel_set_options(channel_T *channel, jobopt_T *opt) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1241 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1242 ch_part_T part; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1243 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1244 if (opt->jo_set & JO_MODE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1245 for (part = PART_SOCK; part < PART_COUNT; ++part) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1246 channel->ch_part[part].ch_mode = opt->jo_mode; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1247 if (opt->jo_set & JO_IN_MODE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1248 channel->ch_part[PART_IN].ch_mode = opt->jo_in_mode; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1249 if (opt->jo_set & JO_OUT_MODE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1250 channel->ch_part[PART_OUT].ch_mode = opt->jo_out_mode; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1251 if (opt->jo_set & JO_ERR_MODE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1252 channel->ch_part[PART_ERR].ch_mode = opt->jo_err_mode; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1253 channel->ch_nonblock = opt->jo_noblock; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1254 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1255 if (opt->jo_set & JO_TIMEOUT) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1256 for (part = PART_SOCK; part < PART_COUNT; ++part) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1257 channel->ch_part[part].ch_timeout = opt->jo_timeout; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1258 if (opt->jo_set & JO_OUT_TIMEOUT) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1259 channel->ch_part[PART_OUT].ch_timeout = opt->jo_out_timeout; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1260 if (opt->jo_set & JO_ERR_TIMEOUT) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1261 channel->ch_part[PART_ERR].ch_timeout = opt->jo_err_timeout; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1262 if (opt->jo_set & JO_BLOCK_WRITE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1263 channel->ch_part[PART_IN].ch_block_write = 1; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1264 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1265 if (opt->jo_set & JO_CALLBACK) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1266 free_set_callback(&channel->ch_callback, &opt->jo_callback); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1267 if (opt->jo_set & JO_OUT_CALLBACK) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1268 free_set_callback(&channel->ch_part[PART_OUT].ch_callback, |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1269 &opt->jo_out_cb); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1270 if (opt->jo_set & JO_ERR_CALLBACK) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1271 free_set_callback(&channel->ch_part[PART_ERR].ch_callback, |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1272 &opt->jo_err_cb); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1273 if (opt->jo_set & JO_CLOSE_CALLBACK) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1274 free_set_callback(&channel->ch_close_cb, &opt->jo_close_cb); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1275 channel->ch_drop_never = opt->jo_drop_never; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1276 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1277 if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1278 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1279 buf_T *buf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1280 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1281 // writing output to a buffer. Default mode is NL. |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1282 if (!(opt->jo_set & JO_OUT_MODE)) |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
1283 channel->ch_part[PART_OUT].ch_mode = CH_MODE_NL; |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1284 if (opt->jo_set & JO_OUT_BUF) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1285 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1286 buf = buflist_findnr(opt->jo_io_buf[PART_OUT]); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1287 if (buf == NULL) |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26217
diff
changeset
|
1288 semsg(_(e_buffer_nr_does_not_exist), |
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26217
diff
changeset
|
1289 (long)opt->jo_io_buf[PART_OUT]); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1290 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1291 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1292 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1293 int msg = TRUE; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1294 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1295 if (opt->jo_set2 & JO2_OUT_MSG) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1296 msg = opt->jo_message[PART_OUT]; |
18010
cf8e0c7e0cb9
patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
17974
diff
changeset
|
1297 buf = channel_find_buffer(opt->jo_io_name[PART_OUT], FALSE, msg); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1298 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1299 if (buf != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1300 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1301 if (opt->jo_set & JO_OUT_MODIFIABLE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1302 channel->ch_part[PART_OUT].ch_nomodifiable = |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1303 !opt->jo_modifiable[PART_OUT]; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1304 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1305 if (!buf->b_p_ma && !channel->ch_part[PART_OUT].ch_nomodifiable) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1306 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24812
diff
changeset
|
1307 emsg(_(e_cannot_make_changes_modifiable_is_off)); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1308 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1309 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1310 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1311 ch_log(channel, "writing out to buffer '%s'", |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1312 (char *)buf->b_ffname); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1313 set_bufref(&channel->ch_part[PART_OUT].ch_bufref, buf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1314 // if the buffer was deleted or unloaded resurrect it |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1315 if (buf->b_ml.ml_mfp == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1316 prepare_buffer(buf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1317 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1318 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1319 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1320 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1321 if ((opt->jo_set & JO_ERR_IO) && (opt->jo_io[PART_ERR] == JIO_BUFFER |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1322 || (opt->jo_io[PART_ERR] == JIO_OUT && (opt->jo_set & JO_OUT_IO) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1323 && opt->jo_io[PART_OUT] == JIO_BUFFER))) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1324 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1325 buf_T *buf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1326 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1327 // writing err to a buffer. Default mode is NL. |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1328 if (!(opt->jo_set & JO_ERR_MODE)) |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
1329 channel->ch_part[PART_ERR].ch_mode = CH_MODE_NL; |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1330 if (opt->jo_io[PART_ERR] == JIO_OUT) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1331 buf = channel->ch_part[PART_OUT].ch_bufref.br_buf; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1332 else if (opt->jo_set & JO_ERR_BUF) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1333 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1334 buf = buflist_findnr(opt->jo_io_buf[PART_ERR]); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1335 if (buf == NULL) |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26217
diff
changeset
|
1336 semsg(_(e_buffer_nr_does_not_exist), |
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26217
diff
changeset
|
1337 (long)opt->jo_io_buf[PART_ERR]); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1338 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1339 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1340 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1341 int msg = TRUE; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1342 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1343 if (opt->jo_set2 & JO2_ERR_MSG) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1344 msg = opt->jo_message[PART_ERR]; |
18010
cf8e0c7e0cb9
patch 8.1.2001: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
17974
diff
changeset
|
1345 buf = channel_find_buffer(opt->jo_io_name[PART_ERR], TRUE, msg); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1346 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1347 if (buf != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1348 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1349 if (opt->jo_set & JO_ERR_MODIFIABLE) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1350 channel->ch_part[PART_ERR].ch_nomodifiable = |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1351 !opt->jo_modifiable[PART_ERR]; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1352 if (!buf->b_p_ma && !channel->ch_part[PART_ERR].ch_nomodifiable) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1353 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24812
diff
changeset
|
1354 emsg(_(e_cannot_make_changes_modifiable_is_off)); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1355 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1356 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1357 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1358 ch_log(channel, "writing err to buffer '%s'", |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1359 (char *)buf->b_ffname); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1360 set_bufref(&channel->ch_part[PART_ERR].ch_bufref, buf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1361 // if the buffer was deleted or unloaded resurrect it |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1362 if (buf->b_ml.ml_mfp == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1363 prepare_buffer(buf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1364 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1365 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1366 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1367 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1368 channel->ch_part[PART_OUT].ch_io = opt->jo_io[PART_OUT]; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1369 channel->ch_part[PART_ERR].ch_io = opt->jo_io[PART_ERR]; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1370 channel->ch_part[PART_IN].ch_io = opt->jo_io[PART_IN]; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1371 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1372 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1373 /* |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1374 * Implements ch_open(). |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1375 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
1376 static channel_T * |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1377 channel_open_func(typval_T *argvars) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1378 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1379 char_u *address; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1380 char_u *p; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1381 char *rest; |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1382 int port = 0; |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1383 int is_ipv6 = FALSE; |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1384 int is_unix = FALSE; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1385 jobopt_T opt; |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
1386 channel_T *channel = NULL; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1387 |
25198
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25090
diff
changeset
|
1388 if (in_vim9script() |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25090
diff
changeset
|
1389 && (check_for_string_arg(argvars, 0) == FAIL |
25759
ea0820d05257
patch 8.2.3415: Vim9: not all function argument types are properly checked
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
1390 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
25198
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25090
diff
changeset
|
1391 return NULL; |
eafc0e07b188
patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25090
diff
changeset
|
1392 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15160
diff
changeset
|
1393 address = tv_get_string(&argvars[0]); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1394 if (argvars[1].v_type != VAR_UNKNOWN |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1395 && check_for_nonnull_dict_arg(argvars, 1) == FAIL) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1396 return NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1397 |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1398 if (*address == NUL) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1399 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1400 semsg(_(e_invalid_argument_str), address); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1401 return NULL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1402 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1403 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1404 if (!STRNCMP(address, "unix:", 5)) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1405 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1406 is_unix = TRUE; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1407 address += 5; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1408 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1409 else if (*address == '[') |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1410 { |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1411 // ipv6 address |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1412 is_ipv6 = TRUE; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1413 p = vim_strchr(address + 1, ']'); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1414 if (p == NULL || *++p != ':') |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1415 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
1416 semsg(_(e_invalid_argument_str), address); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1417 return NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1418 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1419 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1420 else |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1421 { |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1422 // ipv4 address |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1423 p = vim_strchr(address, ':'); |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1424 if (p == NULL) |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1425 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
1426 semsg(_(e_invalid_argument_str), address); |
20003
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1427 return NULL; |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1428 } |
e373843e2980
patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1429 } |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1430 |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1431 if (!is_unix) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1432 { |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1433 port = strtol((char *)(p + 1), &rest, 10); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1434 if (port <= 0 || port >= 65536 || *rest != NUL) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1435 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1436 semsg(_(e_invalid_argument_str), address); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1437 return NULL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1438 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1439 if (is_ipv6) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1440 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1441 // strip '[' and ']' |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1442 ++address; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1443 *(p - 1) = NUL; |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1444 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1445 else |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1446 *p = NUL; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1447 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1448 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1449 // parse options |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1450 clear_job_options(&opt); |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
1451 opt.jo_mode = CH_MODE_JSON; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1452 opt.jo_timeout = 2000; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1453 if (get_job_options(&argvars[1], &opt, |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1454 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1455 + (is_unix? 0 : JO_WAITTIME), 0) == FAIL) |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
1456 goto theend; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1457 if (opt.jo_timeout < 0) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1458 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
1459 emsg(_(e_invalid_argument)); |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
1460 goto theend; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1461 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1462 |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1463 if (is_unix) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1464 channel = channel_open_unix((char *)address, NULL); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1465 else |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1466 channel = channel_open((char *)address, port, opt.jo_waittime, NULL); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1467 if (channel != NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1468 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1469 opt.jo_set = JO_ALL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1470 channel_set_options(channel, &opt); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1471 } |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
1472 theend: |
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
1473 free_job_options(&opt); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1474 return channel; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1475 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1476 |
22095
2cc0de1e05a6
patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
22077
diff
changeset
|
1477 void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1478 ch_close_part(channel_T *channel, ch_part_T part) |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1479 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1480 sock_T *fd = &channel->ch_part[part].ch_fd; |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1481 |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1482 if (*fd != INVALID_FD) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1483 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1484 if (part == PART_SOCK) |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1485 sock_close(*fd); |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1486 else |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11719
diff
changeset
|
1487 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1488 // When using a pty the same FD is set on multiple parts, only |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1489 // close it when the last reference is closed. |
11933
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
1490 if ((part == PART_IN || channel->CH_IN_FD != *fd) |
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
1491 && (part == PART_OUT || channel->CH_OUT_FD != *fd) |
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
1492 && (part == PART_ERR || channel->CH_ERR_FD != *fd)) |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12313
diff
changeset
|
1493 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
1494 #ifdef MSWIN |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12313
diff
changeset
|
1495 if (channel->ch_named_pipe) |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12313
diff
changeset
|
1496 DisconnectNamedPipe((HANDLE)fd); |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12313
diff
changeset
|
1497 #endif |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11719
diff
changeset
|
1498 fd_close(*fd); |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12313
diff
changeset
|
1499 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11719
diff
changeset
|
1500 } |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1501 *fd = INVALID_FD; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1502 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1503 // channel is closed, may want to end the job if it was the last |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1504 channel->ch_to_be_closed &= ~(1U << part); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1505 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1506 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1507 |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1508 void |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
1509 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
|
1510 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1511 if (in != INVALID_FD) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1512 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1513 ch_close_part(channel, PART_IN); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1514 channel->CH_IN_FD = in; |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1515 # if defined(UNIX) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1516 // Do not end the job when all output channels are closed, wait until |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1517 // the job ended. |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
1518 if (mch_isatty(in)) |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1519 channel->ch_to_be_closed |= (1U << PART_IN); |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1520 # endif |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1521 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1522 if (out != INVALID_FD) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1523 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1524 # if defined(FEAT_GUI) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1525 channel_gui_unregister_one(channel, PART_OUT); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1526 # endif |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1527 ch_close_part(channel, PART_OUT); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1528 channel->CH_OUT_FD = out; |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1529 channel->ch_to_be_closed |= (1U << PART_OUT); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1530 # if defined(FEAT_GUI) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1531 channel_gui_register_one(channel, PART_OUT); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1532 # endif |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1533 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1534 if (err != INVALID_FD) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1535 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1536 # if defined(FEAT_GUI) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1537 channel_gui_unregister_one(channel, PART_ERR); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1538 # endif |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1539 ch_close_part(channel, PART_ERR); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1540 channel->CH_ERR_FD = err; |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
1541 channel->ch_to_be_closed |= (1U << PART_ERR); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1542 # if defined(FEAT_GUI) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1543 channel_gui_register_one(channel, PART_ERR); |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1544 # endif |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8481
diff
changeset
|
1545 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
1546 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
1547 |
8310
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
1548 /* |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1549 * 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
|
1550 * 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
|
1551 */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
1552 void |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1553 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
|
1554 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1555 channel->ch_job = job; |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1556 |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1557 channel_set_options(channel, options); |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1558 |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1559 if (job->jv_in_buf != NULL) |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1560 { |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1561 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
|
1562 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1563 set_bufref(&in_part->ch_bufref, job->jv_in_buf); |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
1564 ch_log(channel, "reading from buffer '%s'", |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1565 (char *)in_part->ch_bufref.br_buf->b_ffname); |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1566 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
|
1567 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1568 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
|
1569 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1570 // Special mode: send last-but-one line when appending a line |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1571 // to the buffer. |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1572 in_part->ch_bufref.br_buf->b_write_to_channel = TRUE; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1573 in_part->ch_buf_append = TRUE; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1574 in_part->ch_buf_top = |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1575 in_part->ch_bufref.br_buf->b_ml.ml_line_count + 1; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1576 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1577 else |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1578 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
|
1579 } |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1580 else |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1581 in_part->ch_buf_top = 1; |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1582 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
|
1583 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
|
1584 else |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1585 in_part->ch_buf_bot = in_part->ch_bufref.br_buf->b_ml.ml_line_count; |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1586 } |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1587 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1588 |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1589 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1590 * 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
|
1591 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
1592 static void |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1593 channel_set_req_callback( |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8508
diff
changeset
|
1594 channel_T *channel, |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1595 ch_part_T part, |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1596 callback_T *callback, |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8508
diff
changeset
|
1597 int id) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
1598 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1599 cbq_T *head = &channel->ch_part[part].ch_cb_head; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1600 cbq_T *item = ALLOC_ONE(cbq_T); |
7933
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
1601 |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
1602 if (item != NULL) |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
1603 { |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1604 copy_callback(&item->cq_callback, callback); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1605 item->cq_seq_nr = id; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1606 item->cq_prev = head->cq_prev; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1607 head->cq_prev = item; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1608 item->cq_next = NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1609 if (item->cq_prev == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1610 head->cq_next = item; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1611 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1612 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
|
1613 } |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1614 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1615 |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1616 static void |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1617 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
|
1618 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1619 char_u *line = ml_get_buf(buf, lnum, FALSE); |
8453
fed4e19bd884
commit https://github.com/vim/vim/commit/367aabdbf76f7df00fd18e39d9378d1360a526ab
Christian Brabandt <cb@256bit.org>
parents:
8428
diff
changeset
|
1620 int len = (int)STRLEN(line); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1621 char_u *p; |
9434
8f904a323b3f
commit https://github.com/vim/vim/commit/bf2cc5f36d5ffd5de445e6970602000c7869b65a
Christian Brabandt <cb@256bit.org>
parents:
9367
diff
changeset
|
1622 int i; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1623 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1624 // Need to make a copy to be able to append a NL. |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1625 if ((p = alloc(len + 2)) == NULL) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1626 return; |
9367
2465b6cda394
commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents:
9355
diff
changeset
|
1627 memcpy((char *)p, (char *)line, len); |
9434
8f904a323b3f
commit https://github.com/vim/vim/commit/bf2cc5f36d5ffd5de445e6970602000c7869b65a
Christian Brabandt <cb@256bit.org>
parents:
9367
diff
changeset
|
1628 |
12311
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1629 if (channel->ch_write_text_mode) |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1630 p[len] = CAR; |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1631 else |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1632 { |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1633 for (i = 0; i < len; ++i) |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1634 if (p[i] == NL) |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1635 p[i] = NUL; |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1636 |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1637 p[len] = NL; |
66fa8eabbd6e
patch 8.0.1035: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12309
diff
changeset
|
1638 } |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1639 p[len + 1] = NUL; |
10363
471b87c3b67d
commit https://github.com/vim/vim/commit/79cbdcb1eeead00bad6fc64ab4a53e5860d5a663
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
1640 channel_send(channel, PART_IN, p, len + 1, "write_buf_line"); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1641 vim_free(p); |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1642 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1643 |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1644 /* |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1645 * Return TRUE if "channel" can be written to. |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1646 * Returns FALSE if the input is closed or the write would block. |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1647 */ |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1648 static int |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1649 can_write_buf_line(channel_T *channel) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1650 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1651 chanpart_T *in_part = &channel->ch_part[PART_IN]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1652 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1653 if (in_part->ch_fd == INVALID_FD) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1654 return FALSE; // pipe was closed |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1655 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1656 // for testing: block every other attempt to write |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1657 if (in_part->ch_block_write == 1) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1658 in_part->ch_block_write = -1; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1659 else if (in_part->ch_block_write == -1) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1660 in_part->ch_block_write = 1; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1661 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1662 // TODO: Win32 implementation, probably using WaitForMultipleObjects() |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
1663 #ifndef MSWIN |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1664 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1665 # if defined(HAVE_SELECT) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1666 struct timeval tval; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1667 fd_set wfds; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1668 int ret; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1669 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1670 FD_ZERO(&wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1671 FD_SET((int)in_part->ch_fd, &wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1672 tval.tv_sec = 0; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1673 tval.tv_usec = 0; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1674 for (;;) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1675 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1676 ret = select((int)in_part->ch_fd + 1, NULL, &wfds, NULL, &tval); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1677 # ifdef EINTR |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1678 SOCK_ERRNO; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1679 if (ret == -1 && errno == EINTR) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1680 continue; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1681 # endif |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1682 if (ret <= 0 || in_part->ch_block_write == 1) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1683 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1684 if (ret > 0) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1685 ch_log(channel, "FAKED Input not ready for writing"); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1686 else |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1687 ch_log(channel, "Input not ready for writing"); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1688 return FALSE; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1689 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1690 break; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1691 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1692 # else |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1693 struct pollfd fds; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1694 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1695 fds.fd = in_part->ch_fd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1696 fds.events = POLLOUT; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1697 if (poll(&fds, 1, 0) <= 0) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1698 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1699 ch_log(channel, "Input not ready for writing"); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1700 return FALSE; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1701 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1702 if (in_part->ch_block_write == 1) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1703 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1704 ch_log(channel, "FAKED Input not ready for writing"); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1705 return FALSE; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1706 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1707 # endif |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1708 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1709 #endif |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1710 return TRUE; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1711 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1712 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1713 /* |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1714 * Write any buffer lines to the input channel. |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1715 */ |
22095
2cc0de1e05a6
patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
22077
diff
changeset
|
1716 void |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1717 channel_write_in(channel_T *channel) |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1718 { |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1719 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
|
1720 linenr_T lnum; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1721 buf_T *buf = in_part->ch_bufref.br_buf; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1722 int written = 0; |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1723 |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1724 if (buf == NULL || in_part->ch_buf_append) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1725 return; // no buffer or using appending |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1726 if (!bufref_valid(&in_part->ch_bufref) || buf->b_ml.ml_mfp == NULL) |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1727 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1728 // buffer was wiped out or unloaded |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
1729 ch_log(channel, "input buffer has been wiped out"); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1730 in_part->ch_bufref.br_buf = NULL; |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1731 return; |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1732 } |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1733 |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1734 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
|
1735 && 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
|
1736 { |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1737 if (!can_write_buf_line(channel)) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1738 break; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1739 write_buf_line(buf, lnum, channel); |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1740 ++written; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1741 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1742 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1743 if (written == 1) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
1744 ch_log(channel, "written line %d to channel", (int)lnum - 1); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1745 else if (written > 1) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
1746 ch_log(channel, "written %d lines to channel", written); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1747 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1748 in_part->ch_buf_top = lnum; |
10052
c1ba49441c90
commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1749 if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1750 { |
12313
44f3c9b7eec4
patch 8.0.1036: ++eof argument for terminal only available on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12311
diff
changeset
|
1751 #if defined(FEAT_TERMINAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1752 // Send CTRL-D or "eof_chars" to close stdin on MS-Windows. |
12309
e1f44e4afe67
patch 8.0.1034: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
1753 if (channel->ch_job != NULL) |
e1f44e4afe67
patch 8.0.1034: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
1754 term_send_eof(channel); |
e1f44e4afe67
patch 8.0.1034: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
1755 #endif |
e1f44e4afe67
patch 8.0.1034: sending buffer lines to terminal doesn't work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12250
diff
changeset
|
1756 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1757 // Writing is done, no longer need the buffer. |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1758 in_part->ch_bufref.br_buf = NULL; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1759 ch_log(channel, "Finished writing all lines to channel"); |
10052
c1ba49441c90
commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1760 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1761 // Close the pipe/socket, so that the other side gets EOF. |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1762 ch_close_part(channel, PART_IN); |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1763 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1764 else |
13608
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
1765 ch_log(channel, "Still %ld more lines to write", |
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
1766 (long)(buf->b_ml.ml_line_count - lnum + 1)); |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1767 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1768 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1769 /* |
9355
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
1770 * Handle buffer "buf" being freed, remove it from any channels. |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1771 */ |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1772 void |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1773 channel_buffer_free(buf_T *buf) |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1774 { |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1775 channel_T *channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1776 ch_part_T part; |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1777 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
1778 FOR_ALL_CHANNELS(channel) |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1779 for (part = PART_SOCK; part < PART_COUNT; ++part) |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1780 { |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1781 chanpart_T *ch_part = &channel->ch_part[part]; |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1782 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1783 if (ch_part->ch_bufref.br_buf == buf) |
9089
6bc0a492e8ba
commit https://github.com/vim/vim/commit/de7eb0a47b557eb4656c6b63d421c7e7bae1ef30
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
1784 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
1785 ch_log(channel, "%s buffer has been wiped out", |
9089
6bc0a492e8ba
commit https://github.com/vim/vim/commit/de7eb0a47b557eb4656c6b63d421c7e7bae1ef30
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
1786 part_names[part]); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1787 ch_part->ch_bufref.br_buf = NULL; |
9089
6bc0a492e8ba
commit https://github.com/vim/vim/commit/de7eb0a47b557eb4656c6b63d421c7e7bae1ef30
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
1788 } |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1789 } |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1790 } |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1791 |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
9085
diff
changeset
|
1792 /* |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1793 * Write any lines waiting to be written to "channel". |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1794 */ |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1795 static void |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1796 channel_write_input(channel_T *channel) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1797 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1798 chanpart_T *in_part = &channel->ch_part[PART_IN]; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1799 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1800 if (in_part->ch_writeque.wq_next != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1801 channel_send(channel, PART_IN, (char_u *)"", 0, "channel_write_input"); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1802 else if (in_part->ch_bufref.br_buf != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1803 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1804 if (in_part->ch_buf_append) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1805 channel_write_new_lines(in_part->ch_bufref.br_buf); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1806 else |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1807 channel_write_in(channel); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1808 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1809 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1810 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1811 /* |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1812 * Write any lines waiting to be written to a channel. |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1813 */ |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1814 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9246
diff
changeset
|
1815 channel_write_any_lines(void) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1816 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1817 channel_T *channel; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1818 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
1819 FOR_ALL_CHANNELS(channel) |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
1820 channel_write_input(channel); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1821 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1822 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1823 /* |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1824 * 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
|
1825 */ |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1826 void |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1827 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
|
1828 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1829 channel_T *channel; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1830 int found_one = FALSE; |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1831 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1832 // There could be more than one channel for the buffer, loop over all of |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1833 // them. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
1834 FOR_ALL_CHANNELS(channel) |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1835 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1836 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
|
1837 linenr_T lnum; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1838 int written = 0; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1839 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
1840 if (in_part->ch_bufref.br_buf == buf && in_part->ch_buf_append) |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1841 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1842 if (in_part->ch_fd == INVALID_FD) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1843 continue; // pipe was closed |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1844 found_one = TRUE; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1845 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
|
1846 ++lnum) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1847 { |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1848 if (!can_write_buf_line(channel)) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1849 break; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1850 write_buf_line(buf, lnum, channel); |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1851 ++written; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1852 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1853 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1854 if (written == 1) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
1855 ch_log(channel, "written line %d to channel", (int)lnum - 1); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1856 else if (written > 1) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
1857 ch_log(channel, "written %d lines to channel", written); |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
1858 if (lnum < buf->b_ml.ml_line_count) |
13608
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
1859 ch_log(channel, "Still %ld more lines to write", |
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
1860 (long)(buf->b_ml.ml_line_count - lnum)); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1861 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1862 in_part->ch_buf_bot = lnum; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1863 } |
8386
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1864 } |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1865 if (!found_one) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
1866 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
|
1867 } |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1868 |
3b9a306724ec
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents:
8382
diff
changeset
|
1869 /* |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1870 * Invoke the "callback" on channel "channel". |
8928
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
1871 * This does not redraw but sets channel_need_redraw; |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1872 */ |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1873 static void |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1874 invoke_callback(channel_T *channel, callback_T *callback, typval_T *argv) |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1875 { |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1876 typval_T rettv; |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
1877 |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
1878 if (safe_to_invoke_callback == 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1879 iemsg("INTERNAL: Invoking callback when it is not safe"); |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
1880 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1881 argv[0].v_type = VAR_CHANNEL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1882 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
|
1883 |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17557
diff
changeset
|
1884 call_callback(callback, -1, &rettv, 2, argv); |
8174
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
1885 clear_tv(&rettv); |
8928
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
1886 channel_need_redraw = TRUE; |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1887 } |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1888 |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
1889 /* |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1890 * Return the first node from "channel"/"part" without removing it. |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1891 * Returns NULL if there is nothing. |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1892 */ |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1893 readq_T * |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
1894 channel_peek(channel_T *channel, ch_part_T part) |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1895 { |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1896 readq_T *head = &channel->ch_part[part].ch_head; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1897 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1898 return head->rq_next; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1899 } |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1900 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1901 /* |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1902 * Return a pointer to the first NL in "node". |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1903 * Skips over NUL characters. |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1904 * Returns NULL if there is no NL. |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1905 */ |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1906 char_u * |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1907 channel_first_nl(readq_T *node) |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1908 { |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1909 char_u *buffer = node->rq_buffer; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1910 long_u i; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1911 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1912 for (i = 0; i < node->rq_buflen; ++i) |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1913 if (buffer[i] == NL) |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1914 return buffer + i; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1915 return NULL; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1916 } |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1917 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1918 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1919 * 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
|
1920 * The caller must free it. |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1921 * Returns NULL if there is nothing. |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1922 */ |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1923 char_u * |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1924 channel_get(channel_T *channel, ch_part_T part, int *outlen) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1925 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1926 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
|
1927 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
|
1928 char_u *p; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1929 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1930 if (node == NULL) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1931 return NULL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1932 if (outlen != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1933 *outlen += node->rq_buflen; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
1934 // 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
|
1935 p = node->rq_buffer; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1936 head->rq_next = node->rq_next; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1937 if (node->rq_next == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1938 head->rq_prev = NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1939 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
1940 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
|
1941 vim_free(node); |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1942 return p; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1943 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1944 |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1945 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
1946 * Returns the whole buffer contents concatenated for "channel"/"part". |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1947 * Replaces NUL bytes with NL. |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1948 */ |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1949 static char_u * |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1950 channel_get_all(channel_T *channel, ch_part_T part, int *outlen) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
1951 { |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1952 readq_T *head = &channel->ch_part[part].ch_head; |
16054
78faa25f9698
patch 8.1.1032: warnings from clang static analyzer
Bram Moolenaar <Bram@vim.org>
parents:
15975
diff
changeset
|
1953 readq_T *node; |
9367
2465b6cda394
commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents:
9355
diff
changeset
|
1954 long_u len = 0; |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1955 char_u *res; |
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1956 char_u *p; |
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1957 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1958 // Concatenate everything into one buffer. |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1959 for (node = head->rq_next; node != NULL; node = node->rq_next) |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
1960 len += node->rq_buflen; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1961 res = alloc(len + 1); |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1962 if (res == NULL) |
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1963 return NULL; |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
1964 p = res; |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1965 for (node = head->rq_next; node != NULL; node = node->rq_next) |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
1966 { |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
1967 mch_memmove(p, node->rq_buffer, node->rq_buflen); |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
1968 p += node->rq_buflen; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
1969 } |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
1970 *p = NUL; |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1971 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1972 // Free all buffers |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1973 do |
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1974 { |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1975 p = channel_get(channel, part, NULL); |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1976 vim_free(p); |
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1977 } while (p != NULL); |
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
1978 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1979 if (outlen != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1980 { |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1981 // Returning the length, keep NUL characters. |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1982 *outlen += len; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1983 return res; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1984 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
1985 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1986 // Turn all NUL into NL, so that the result can be used as a string. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1987 p = res; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1988 while (p < res + len) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1989 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1990 if (*p == NUL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1991 *p = NL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
1992 #ifdef MSWIN |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1993 else if (*p == 0x1b) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1994 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1995 // crush the escape sequence OSC 0/1/2: ESC ]0; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1996 if (p + 3 < res + len |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1997 && p[1] == ']' |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1998 && (p[2] == '0' || p[2] == '1' || p[2] == '2') |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
1999 && p[3] == ';') |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2000 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2001 // '\a' becomes a NL |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28769
diff
changeset
|
2002 while (p < res + (len - 1) && *p != '\a') |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2003 ++p; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2004 // BEL is zero width characters, suppress display mistake |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2005 // ConPTY (after 10.0.18317) requires advance checking |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2006 if (p[-1] == NUL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2007 p[-1] = 0x07; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2008 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2009 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2010 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15711
diff
changeset
|
2011 ++p; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2012 } |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2013 |
8759
cc2ef7367643
commit https://github.com/vim/vim/commit/ee1f7b3cb71684aaa9bf457e2caf9d02187e6b7c
Christian Brabandt <cb@256bit.org>
parents:
8757
diff
changeset
|
2014 return res; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2015 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2016 |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2017 /* |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9246
diff
changeset
|
2018 * Consume "len" bytes from the head of "node". |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2019 * Caller must check these bytes are available. |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2020 */ |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2021 void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2022 channel_consume(channel_T *channel, ch_part_T part, int len) |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2023 { |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2024 readq_T *head = &channel->ch_part[part].ch_head; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2025 readq_T *node = head->rq_next; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2026 char_u *buf = node->rq_buffer; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2027 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2028 mch_memmove(buf, buf + len, node->rq_buflen - len); |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2029 node->rq_buflen -= len; |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
2030 node->rq_buffer[node->rq_buflen] = NUL; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2031 } |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2032 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2033 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2034 * Collapses the first and second buffer for "channel"/"part". |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2035 * Returns FAIL if nothing was done. |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2036 * When "want_nl" is TRUE collapse more buffers until a NL is found. |
28528
6b1da12297e5
patch 8.2.4788: large payload for LSP message not tested
Bram Moolenaar <Bram@vim.org>
parents:
28511
diff
changeset
|
2037 * When the channel part mode is "lsp", collapse all the buffers as the http |
6b1da12297e5
patch 8.2.4788: large payload for LSP message not tested
Bram Moolenaar <Bram@vim.org>
parents:
28511
diff
changeset
|
2038 * header and the JSON content can be present in multiple buffers. |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2039 */ |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2040 int |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2041 channel_collapse(channel_T *channel, ch_part_T part, int want_nl) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2042 { |
28511
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2043 ch_mode_T mode = channel->ch_part[part].ch_mode; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2044 readq_T *head = &channel->ch_part[part].ch_head; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2045 readq_T *node = head->rq_next; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2046 readq_T *last_node; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2047 readq_T *n; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2048 char_u *newbuf; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2049 char_u *p; |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2050 long_u len; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2051 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2052 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
|
2053 return FAIL; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2054 |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2055 last_node = node->rq_next; |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
2056 len = node->rq_buflen + last_node->rq_buflen; |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2057 if (want_nl || mode == CH_MODE_LSP) |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2058 while (last_node->rq_next != NULL |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2059 && (mode == CH_MODE_LSP |
28511
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
2060 || channel_first_nl(last_node) == NULL)) |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2061 { |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2062 last_node = last_node->rq_next; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2063 len += last_node->rq_buflen; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2064 } |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2065 |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
2066 p = newbuf = alloc(len + 1); |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2067 if (newbuf == NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2068 return FAIL; // out of memory |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2069 mch_memmove(p, node->rq_buffer, node->rq_buflen); |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2070 p += node->rq_buflen; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2071 vim_free(node->rq_buffer); |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2072 node->rq_buffer = newbuf; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2073 for (n = node; n != last_node; ) |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2074 { |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2075 n = n->rq_next; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2076 mch_memmove(p, n->rq_buffer, n->rq_buflen); |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2077 p += n->rq_buflen; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2078 vim_free(n->rq_buffer); |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2079 } |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
2080 *p = NUL; |
9238
7d13d180a6ae
commit https://github.com/vim/vim/commit/bbe8d91e695184771d7e45315258fab8eb3e6b07
Christian Brabandt <cb@256bit.org>
parents:
9215
diff
changeset
|
2081 node->rq_buflen = (long_u)(p - newbuf); |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2082 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2083 // dispose of the collapsed nodes and their buffers |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2084 for (n = node->rq_next; n != last_node; ) |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2085 { |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2086 n = n->rq_next; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2087 vim_free(n->rq_prev); |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2088 } |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2089 node->rq_next = last_node->rq_next; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2090 if (last_node->rq_next == NULL) |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2091 head->rq_prev = node; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2092 else |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2093 last_node->rq_next->rq_prev = node; |
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2094 vim_free(last_node); |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2095 return OK; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2096 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2097 |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2098 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2099 * Store "buf[len]" on "channel"/"part". |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2100 * When "prepend" is TRUE put in front, otherwise append at the end. |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2101 * Returns OK or FAIL. |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2102 */ |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2103 static int |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2104 channel_save(channel_T *channel, ch_part_T part, char_u *buf, int len, |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2105 int prepend, char *lead) |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2106 { |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2107 readq_T *node; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2108 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
|
2109 char_u *p; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2110 int i; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2111 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2112 node = ALLOC_ONE(readq_T); |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2113 if (node == NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2114 return FAIL; // out of memory |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2115 // A NUL is added at the end, because netbeans code expects that. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2116 // Otherwise a NUL may appear inside the text. |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2117 node->rq_buffer = alloc(len + 1); |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2118 if (node->rq_buffer == NULL) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2119 { |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2120 vim_free(node); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2121 return FAIL; // out of memory |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2122 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2123 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2124 if (channel->ch_part[part].ch_mode == CH_MODE_NL) |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2125 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2126 // Drop any CR before a NL. |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2127 p = node->rq_buffer; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2128 for (i = 0; i < len; ++i) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2129 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
|
2130 *p++ = buf[i]; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2131 *p = NUL; |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2132 node->rq_buflen = (long_u)(p - node->rq_buffer); |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2133 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2134 else |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2135 { |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2136 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
|
2137 node->rq_buffer[len] = NUL; |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
2138 node->rq_buflen = (long_u)len; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2139 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2140 |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2141 if (prepend) |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2142 { |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16306
diff
changeset
|
2143 // prepend node to the head of the queue |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2144 node->rq_next = head->rq_next; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2145 node->rq_prev = NULL; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2146 if (head->rq_next == NULL) |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2147 head->rq_prev = node; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2148 else |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2149 head->rq_next->rq_prev = node; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2150 head->rq_next = node; |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2151 } |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2152 else |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2153 { |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16306
diff
changeset
|
2154 // append node to the tail of the queue |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2155 node->rq_next = NULL; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2156 node->rq_prev = head->rq_prev; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2157 if (head->rq_prev == NULL) |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2158 head->rq_next = node; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2159 else |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2160 head->rq_prev->rq_next = node; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2161 head->rq_prev = node; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2162 } |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2163 |
12443
579faede5d9c
patch 8.0.1101: channel write fails if writing to log fails
Christian Brabandt <cb@256bit.org>
parents:
12407
diff
changeset
|
2164 if (ch_log_active() && lead != NULL) |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2165 { |
14499
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2166 ch_log_lead(lead, channel, part); |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2167 fprintf(log_fd, "'"); |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14675
diff
changeset
|
2168 vim_ignored = (int)fwrite(buf, len, 1, log_fd); |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2169 fprintf(log_fd, "'\n"); |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2170 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2171 return OK; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2172 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2173 |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2174 /* |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2175 * Try to fill the buffer of "reader". |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2176 * Returns FALSE when nothing was added. |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2177 */ |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2178 static int |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2179 channel_fill(js_read_T *reader) |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2180 { |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2181 channel_T *channel = (channel_T *)reader->js_cookie; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2182 ch_part_T part = reader->js_cookie_arg; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
2183 char_u *next = channel_get(channel, part, NULL); |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2184 int keeplen; |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2185 int addlen; |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2186 char_u *p; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2187 |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2188 if (next == NULL) |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2189 return FALSE; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2190 |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2191 keeplen = reader->js_end - reader->js_buf; |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2192 if (keeplen > 0) |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2193 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2194 // Prepend unused text. |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2195 addlen = (int)STRLEN(next); |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2196 p = alloc(keeplen + addlen + 1); |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2197 if (p == NULL) |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2198 { |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2199 vim_free(next); |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2200 return FALSE; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2201 } |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2202 mch_memmove(p, reader->js_buf, keeplen); |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2203 mch_memmove(p + keeplen, next, addlen + 1); |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2204 vim_free(next); |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2205 next = p; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2206 } |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2207 |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2208 vim_free(reader->js_buf); |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2209 reader->js_buf = next; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2210 return TRUE; |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2211 } |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2212 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2213 /* |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2214 * Process the HTTP header in a Language Server Protocol (LSP) message. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2215 * |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2216 * The message format is described in the LSP specification: |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2217 * https://microsoft.github.io/language-server-protocol/specification |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2218 * |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2219 * It has the following two fields: |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2220 * |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2221 * Content-Length: ... |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2222 * Content-Type: application/vscode-jsonrpc; charset=utf-8 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2223 * |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2224 * Each field ends with "\r\n". The header ends with an additional "\r\n". |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2225 * |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2226 * Returns OK if a valid header is received and FAIL if some fields in the |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2227 * header are not correct. Returns MAYBE if a partial header is received and |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2228 * need to wait for more data to arrive. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2229 */ |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2230 static int |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2231 channel_process_lsp_http_hdr(js_read_T *reader) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2232 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2233 char_u *line_start; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2234 char_u *p; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2235 int_u hdr_len; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2236 int payload_len = -1; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2237 int_u jsbuf_len; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2238 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2239 // We find the end once, to avoid calling strlen() many times. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2240 jsbuf_len = (int_u)STRLEN(reader->js_buf); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2241 reader->js_end = reader->js_buf + jsbuf_len; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2242 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2243 p = reader->js_buf; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2244 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2245 // Process each line in the header till an empty line is read (header |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2246 // separator). |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2247 while (TRUE) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2248 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2249 line_start = p; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2250 while (*p != NUL && *p != '\n') |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2251 p++; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2252 if (*p == NUL) // partial header |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2253 return MAYBE; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2254 p++; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2255 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2256 // process the content length field (if present) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2257 if ((p - line_start > 16) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2258 && STRNICMP(line_start, "Content-Length: ", 16) == 0) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2259 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2260 errno = 0; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2261 payload_len = strtol((char *)line_start + 16, NULL, 10); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2262 if (errno == ERANGE || payload_len < 0) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2263 // invalid length, discard the payload |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2264 return FAIL; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2265 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2266 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2267 if ((p - line_start) == 2 && line_start[0] == '\r' && |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2268 line_start[1] == '\n') |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2269 // reached the empty line |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2270 break; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2271 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2272 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2273 if (payload_len == -1) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2274 // Content-Length field is not present in the header |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2275 return FAIL; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2276 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2277 hdr_len = p - reader->js_buf; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2278 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2279 // if the entire payload is not received, wait for more data to arrive |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2280 if (jsbuf_len < hdr_len + payload_len) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2281 return MAYBE; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2282 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2283 reader->js_used += hdr_len; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2284 // recalculate the end based on the length read from the header. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2285 reader->js_end = reader->js_buf + hdr_len + payload_len; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2286 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2287 return OK; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2288 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2289 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2290 /* |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2291 * Use the read buffer of "channel"/"part" and parse a JSON message that is |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2292 * 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
|
2293 * 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
|
2294 */ |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2295 static int |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2296 channel_parse_json(channel_T *channel, ch_part_T part) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2297 { |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2298 js_read_T reader; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2299 typval_T listtv; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2300 jsonq_T *item; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2301 chanpart_T *chanpart = &channel->ch_part[part]; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2302 jsonq_T *head = &chanpart->ch_json_head; |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2303 int status = OK; |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2304 int ret; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2305 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2306 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
|
2307 return FALSE; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2308 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
2309 reader.js_buf = channel_get(channel, part, NULL); |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2310 reader.js_used = 0; |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2311 reader.js_fill = channel_fill; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2312 reader.js_cookie = channel; |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2313 reader.js_cookie_arg = part; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2314 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2315 if (chanpart->ch_mode == CH_MODE_LSP) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2316 status = channel_process_lsp_http_hdr(&reader); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2317 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2318 // When a message is incomplete we wait for a short while for more to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2319 // arrive. After the delay drop the input, otherwise a truncated string |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2320 // or list will make us hang. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2321 // Do not generate error messages, they will be written in a channel log. |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2322 if (status == OK) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2323 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2324 ++emsg_silent; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2325 status = json_decode(&reader, &listtv, |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2326 chanpart->ch_mode == CH_MODE_JS ? JSON_JS : 0); |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2327 --emsg_silent; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2328 } |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2329 if (status == OK) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2330 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2331 // Only accept the response when it is a list with at least two |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2332 // items. |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2333 if (chanpart->ch_mode == CH_MODE_LSP && listtv.v_type != VAR_DICT) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2334 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2335 ch_error(channel, "Did not receive a LSP dict, discarding"); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2336 clear_tv(&listtv); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2337 } |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2338 else if (chanpart->ch_mode != CH_MODE_LSP |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2339 && (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
|
2340 { |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2341 if (listtv.v_type != VAR_LIST) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2342 ch_error(channel, "Did not receive a list, discarding"); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2343 else |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2344 ch_error(channel, "Expected list with two items, got %d", |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2345 listtv.vval.v_list->lv_len); |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2346 clear_tv(&listtv); |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2347 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2348 else |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2349 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2350 item = ALLOC_ONE(jsonq_T); |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2351 if (item == NULL) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2352 clear_tv(&listtv); |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2353 else |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2354 { |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2355 item->jq_no_callback = FALSE; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2356 item->jq_value = alloc_tv(); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2357 if (item->jq_value == NULL) |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2358 { |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2359 vim_free(item); |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2360 clear_tv(&listtv); |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2361 } |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2362 else |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2363 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2364 *item->jq_value = listtv; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2365 item->jq_prev = head->jq_prev; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2366 head->jq_prev = item; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2367 item->jq_next = NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2368 if (item->jq_prev == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2369 head->jq_next = item; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2370 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2371 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
|
2372 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2373 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2374 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2375 } |
7885
6e6f829af138
commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents:
7883
diff
changeset
|
2376 |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2377 if (status == OK) |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2378 chanpart->ch_wait_len = 0; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2379 else if (status == MAYBE) |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2380 { |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2381 size_t buflen = STRLEN(reader.js_buf); |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2382 |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2383 if (chanpart->ch_wait_len < buflen) |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2384 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2385 // First time encountering incomplete message or after receiving |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2386 // more (but still incomplete): set a deadline of 100 msec. |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2387 ch_log(channel, |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2388 "Incomplete message (%d bytes) - wait 100 msec for more", |
10996
2f041b367cd9
patch 8.0.0387: compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
10845
diff
changeset
|
2389 (int)buflen); |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2390 reader.js_used = 0; |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2391 chanpart->ch_wait_len = buflen; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
2392 #ifdef MSWIN |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2393 chanpart->ch_deadline = GetTickCount() + 100L; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2394 #else |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2395 gettimeofday(&chanpart->ch_deadline, NULL); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2396 chanpart->ch_deadline.tv_usec += 100 * 1000; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2397 if (chanpart->ch_deadline.tv_usec > 1000 * 1000) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2398 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2399 chanpart->ch_deadline.tv_usec -= 1000 * 1000; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2400 ++chanpart->ch_deadline.tv_sec; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2401 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2402 #endif |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2403 } |
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2404 else |
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2405 { |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2406 int timeout; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
2407 #ifdef MSWIN |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2408 timeout = GetTickCount() > chanpart->ch_deadline; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2409 #else |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2410 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2411 struct timeval now_tv; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2412 |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2413 gettimeofday(&now_tv, NULL); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2414 timeout = now_tv.tv_sec > chanpart->ch_deadline.tv_sec |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2415 || (now_tv.tv_sec == chanpart->ch_deadline.tv_sec |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2416 && now_tv.tv_usec > chanpart->ch_deadline.tv_usec); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2417 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2418 #endif |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2419 if (timeout) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2420 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2421 status = FAIL; |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2422 chanpart->ch_wait_len = 0; |
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2423 ch_log(channel, "timed out"); |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2424 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2425 else |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2426 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2427 reader.js_used = 0; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2428 ch_log(channel, "still waiting on incomplete message"); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2429 } |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2430 } |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2431 } |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2432 |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2433 if (status == FAIL) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2434 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2435 ch_error(channel, "Decoding failed - discarding input"); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2436 ret = FALSE; |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
2437 chanpart->ch_wait_len = 0; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2438 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2439 else if (reader.js_buf[reader.js_used] != NUL) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2440 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2441 // Put the unread part back into the channel. |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2442 channel_save(channel, part, reader.js_buf + reader.js_used, |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2443 (int)(reader.js_end - reader.js_buf) - reader.js_used, |
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
2444 TRUE, NULL); |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2445 ret = status == MAYBE ? FALSE: TRUE; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2446 } |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2447 else |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2448 ret = FALSE; |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2449 |
7885
6e6f829af138
commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents:
7883
diff
changeset
|
2450 vim_free(reader.js_buf); |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
2451 return ret; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2452 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2453 |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2454 /* |
8074
dc32c8026899
commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents:
8072
diff
changeset
|
2455 * 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
|
2456 */ |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
2457 static void |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2458 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
|
2459 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2460 if (node->cq_prev == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2461 head->cq_next = node->cq_next; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2462 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2463 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
|
2464 if (node->cq_next == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2465 head->cq_prev = node->cq_prev; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2466 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2467 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
|
2468 } |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
2469 |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
2470 /* |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
2471 * 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
|
2472 * 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
|
2473 */ |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2474 static void |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2475 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
|
2476 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2477 if (node->jq_prev == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2478 head->jq_next = node->jq_next; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2479 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2480 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
|
2481 if (node->jq_next == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2482 head->jq_prev = node->jq_prev; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2483 else |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2484 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
|
2485 vim_free(node); |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2486 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2487 |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2488 /* |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2489 * Add "id" to the list of JSON message IDs we are waiting on. |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2490 */ |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2491 static void |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2492 channel_add_block_id(chanpart_T *chanpart, int id) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2493 { |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2494 garray_T *gap = &chanpart->ch_block_ids; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2495 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2496 if (gap->ga_growsize == 0) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
2497 ga_init2(gap, sizeof(int), 10); |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2498 if (ga_grow(gap, 1) == OK) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2499 { |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2500 ((int *)gap->ga_data)[gap->ga_len] = id; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2501 ++gap->ga_len; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2502 } |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2503 } |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2504 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2505 /* |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2506 * Remove "id" from the list of JSON message IDs we are waiting on. |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2507 */ |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2508 static void |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2509 channel_remove_block_id(chanpart_T *chanpart, int id) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2510 { |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2511 garray_T *gap = &chanpart->ch_block_ids; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2512 int i; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2513 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2514 for (i = 0; i < gap->ga_len; ++i) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2515 if (((int *)gap->ga_data)[i] == id) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2516 { |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2517 --gap->ga_len; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2518 if (i < gap->ga_len) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2519 { |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2520 int *p = ((int *)gap->ga_data) + i; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2521 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2522 mch_memmove(p, p + 1, (gap->ga_len - i) * sizeof(int)); |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2523 } |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2524 return; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2525 } |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2526 siemsg("INTERNAL: channel_remove_block_id: cannot find id %d", id); |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2527 } |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2528 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2529 /* |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2530 * Return TRUE if "id" is in the list of JSON message IDs we are waiting on. |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2531 */ |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2532 static int |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2533 channel_has_block_id(chanpart_T *chanpart, int id) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2534 { |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2535 garray_T *gap = &chanpart->ch_block_ids; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2536 int i; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2537 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2538 for (i = 0; i < gap->ga_len; ++i) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2539 if (((int *)gap->ga_data)[i] == id) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2540 return TRUE; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2541 return FALSE; |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2542 } |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2543 |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2544 /* |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2545 * 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
|
2546 * When "id" is positive it must match the first number in the list. |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2547 * When "id" is zero or negative jut get the first message. But not one |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2548 * in the ch_block_ids list. |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2549 * When "without_callback" is TRUE also get messages that were pushed back. |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2550 * 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
|
2551 * Return FAIL otherwise. |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2552 */ |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2553 static int |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2554 channel_get_json( |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2555 channel_T *channel, |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2556 ch_part_T part, |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2557 int id, |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2558 int without_callback, |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2559 typval_T **rettv) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2560 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2561 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
|
2562 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
|
2563 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2564 while (item != NULL) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2565 { |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2566 list_T *l; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19168
diff
changeset
|
2567 typval_T *tv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19168
diff
changeset
|
2568 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2569 if (channel->ch_part[part].ch_mode != CH_MODE_LSP) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2570 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2571 l = item->jq_value->vval.v_list; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2572 CHECK_LIST_MATERIALIZE(l); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2573 tv = &l->lv_first->li_tv; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2574 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2575 else |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2576 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2577 dict_T *d; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2578 dictitem_T *di; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2579 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2580 // LSP message payload is a JSON-RPC dict. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2581 // For RPC requests and responses, the 'id' item will be present. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2582 // For notifications, it will not be present. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2583 if (id > 0) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2584 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2585 if (item->jq_value->v_type != VAR_DICT) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2586 goto nextitem; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2587 d = item->jq_value->vval.v_dict; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2588 if (d == NULL) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2589 goto nextitem; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2590 di = dict_find(d, (char_u *)"id", -1); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2591 if (di == NULL) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2592 goto nextitem; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2593 tv = &di->di_tv; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2594 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2595 else |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2596 tv = item->jq_value; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2597 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2598 |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2599 if ((without_callback || !item->jq_no_callback) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2600 && ((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
|
2601 || (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
|
2602 || tv->vval.v_number == 0 |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2603 || !channel_has_block_id( |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
2604 &channel->ch_part[part], tv->vval.v_number))))) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2605 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2606 *rettv = item->jq_value; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
2607 if (tv->v_type == VAR_NUMBER) |
13608
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
2608 ch_log(channel, "Getting JSON message %ld", |
2a2b668cf24c
patch 8.0.1676: no compiler warning for wrong printf format
Christian Brabandt <cb@256bit.org>
parents:
13598
diff
changeset
|
2609 (long)tv->vval.v_number); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2610 remove_json_node(head, item); |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2611 return OK; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2612 } |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2613 nextitem: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2614 item = item->jq_next; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2615 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2616 return FAIL; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2617 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2618 |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2619 /* |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2620 * Put back "rettv" into the JSON queue, there was no callback for it. |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2621 * Takes over the values in "rettv". |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2622 */ |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2623 static void |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2624 channel_push_json(channel_T *channel, ch_part_T part, typval_T *rettv) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2625 { |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2626 jsonq_T *head = &channel->ch_part[part].ch_json_head; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2627 jsonq_T *item = head->jq_next; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2628 jsonq_T *newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2629 |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2630 if (head->jq_prev != NULL && head->jq_prev->jq_no_callback) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2631 // last item was pushed back, append to the end |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2632 item = NULL; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2633 else while (item != NULL && item->jq_no_callback) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2634 // append after the last item that was pushed back |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2635 item = item->jq_next; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2636 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2637 newitem = ALLOC_ONE(jsonq_T); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2638 if (newitem == NULL) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2639 clear_tv(rettv); |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2640 else |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2641 { |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2642 newitem->jq_value = alloc_tv(); |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2643 if (newitem->jq_value == NULL) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2644 { |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2645 vim_free(newitem); |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2646 clear_tv(rettv); |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2647 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2648 else |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2649 { |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2650 newitem->jq_no_callback = FALSE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2651 *newitem->jq_value = *rettv; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2652 if (item == NULL) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2653 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2654 // append to the end |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2655 newitem->jq_prev = head->jq_prev; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2656 head->jq_prev = newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2657 newitem->jq_next = NULL; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2658 if (newitem->jq_prev == NULL) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2659 head->jq_next = newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2660 else |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2661 newitem->jq_prev->jq_next = newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2662 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2663 else |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2664 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2665 // append after "item" |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2666 newitem->jq_prev = item; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2667 newitem->jq_next = item->jq_next; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2668 item->jq_next = newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2669 if (newitem->jq_next == NULL) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2670 head->jq_prev = newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2671 else |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2672 newitem->jq_next->jq_prev = newitem; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2673 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2674 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2675 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2676 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
2677 |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2678 #define CH_JSON_MAX_ARGS 4 |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2679 |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2680 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2681 * 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
|
2682 * "argv[0]" is the command string. |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2683 * "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
|
2684 */ |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2685 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2686 channel_exe_cmd(channel_T *channel, ch_part_T part, typval_T *argv) |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2687 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2688 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
|
2689 char_u *arg; |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2690 int options = channel->ch_part[part].ch_mode == CH_MODE_JS |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2691 ? JSON_JS : 0; |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2692 |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2693 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
|
2694 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2695 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
|
2696 if (p_verbose > 2) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
2697 emsg(_(e_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
|
2698 return; |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2699 } |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2700 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
|
2701 if (arg == NULL) |
4b9d4600166f
commit https://github.com/vim/vim/commit/14ad611ca435d97e8fd0d9ab03ddc982843298ac
Christian Brabandt <cb@256bit.org>
parents:
7868
diff
changeset
|
2702 arg = (char_u *)""; |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2703 |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2704 if (STRCMP(cmd, "ex") == 0) |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2705 { |
25090
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2706 int called_emsg_before = called_emsg; |
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2707 char_u *p = arg; |
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2708 int do_emsg_silent; |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18943
diff
changeset
|
2709 |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2710 ch_log(channel, "Executing ex command '%s'", (char *)arg); |
25090
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2711 do_emsg_silent = !checkforcmd(&p, "echoerr", 5); |
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2712 if (do_emsg_silent) |
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2713 ++emsg_silent; |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2714 do_cmdline_cmd(arg); |
25090
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2715 if (do_emsg_silent) |
73503bafb3bf
patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents:
25088
diff
changeset
|
2716 --emsg_silent; |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18943
diff
changeset
|
2717 if (called_emsg > called_emsg_before) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2718 ch_log(channel, "Ex command error: '%s'", |
8746
4c38a4733578
commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents:
8684
diff
changeset
|
2719 (char *)get_vim_var_str(VV_ERRMSG)); |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2720 } |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2721 else if (STRCMP(cmd, "normal") == 0) |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2722 { |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2723 exarg_T ea; |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2724 |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2725 ch_log(channel, "Executing normal command '%s'", (char *)arg); |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20003
diff
changeset
|
2726 CLEAR_FIELD(ea); |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2727 ea.arg = arg; |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2728 ea.addr_count = 0; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2729 ea.forceit = TRUE; // no mapping |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2730 ex_normal(&ea); |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2731 } |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2732 else if (STRCMP(cmd, "redraw") == 0) |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2733 { |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2734 ch_log(channel, "redraw"); |
30025
d269dd3cd31d
patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
2735 redraw_cmd(*arg != NUL); |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2736 showruler(FALSE); |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2737 setcursor(); |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13010
diff
changeset
|
2738 out_flush_cursor(TRUE, FALSE); |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2739 } |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2740 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
|
2741 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2742 int is_call = cmd[0] == 'c'; |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2743 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
|
2744 |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2745 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
|
2746 && 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
|
2747 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2748 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
|
2749 if (p_verbose > 2) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
2750 emsg(_(e_last_argument_for_expr_call_must_be_number)); |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2751 } |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2752 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
|
2753 { |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2754 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
|
2755 if (p_verbose > 2) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
2756 emsg(_(e_third_argument_for_call_must_be_list)); |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2757 } |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2758 else |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2759 { |
10112
90b9898d05a6
commit https://github.com/vim/vim/commit/c8fe338d64cc6183c03d4c12b1e036a7745e2932
Christian Brabandt <cb@256bit.org>
parents:
10054
diff
changeset
|
2760 typval_T *tv = NULL; |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2761 typval_T res_tv; |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2762 typval_T err_tv; |
7965
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2763 char_u *json = NULL; |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2764 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2765 // Don't pollute the display with errors. |
25088
5f6a70167daa
patch 8.2.3081: cannot catch errors in a channel command
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2766 // Do generate the errors so that try/catch works. |
5f6a70167daa
patch 8.2.3081: cannot catch errors in a channel command
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2767 ++emsg_silent; |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2768 if (!is_call) |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2769 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2770 ch_log(channel, "Evaluating expression '%s'", (char *)arg); |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2771 tv = eval_expr(arg, NULL); |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2772 } |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2773 else |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2774 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2775 ch_log(channel, "Calling '%s'", (char *)arg); |
8653
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2776 if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK) |
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2777 tv = &res_tv; |
d80edead9675
commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents:
8607
diff
changeset
|
2778 } |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2779 |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2780 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
|
2781 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2782 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
|
2783 |
7965
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2784 if (tv != NULL) |
9969
176e34b0d678
commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
2785 json = json_encode_nr_expr(id, tv, options | JSON_NL); |
7965
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2786 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
|
2787 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2788 // If evaluation failed or the result can't be encoded |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2789 // then return the string "ERROR". |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
2790 vim_free(json); |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2791 err_tv.v_type = VAR_STRING; |
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2792 err_tv.vval.v_string = (char_u *)"ERROR"; |
10112
90b9898d05a6
commit https://github.com/vim/vim/commit/c8fe338d64cc6183c03d4c12b1e036a7745e2932
Christian Brabandt <cb@256bit.org>
parents:
10054
diff
changeset
|
2793 json = json_encode_nr_expr(id, &err_tv, options | JSON_NL); |
7864
6b0891de44a9
commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
2794 } |
7965
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2795 if (json != NULL) |
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2796 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2797 channel_send(channel, |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2798 part == PART_SOCK ? PART_SOCK : PART_IN, |
9434
8f904a323b3f
commit https://github.com/vim/vim/commit/bf2cc5f36d5ffd5de445e6970602000c7869b65a
Christian Brabandt <cb@256bit.org>
parents:
9367
diff
changeset
|
2799 json, (int)STRLEN(json), (char *)cmd); |
7965
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2800 vim_free(json); |
646d5148fee2
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents:
7961
diff
changeset
|
2801 } |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2802 } |
25088
5f6a70167daa
patch 8.2.3081: cannot catch errors in a channel command
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2803 --emsg_silent; |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2804 if (tv == &res_tv) |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2805 clear_tv(tv); |
10112
90b9898d05a6
commit https://github.com/vim/vim/commit/c8fe338d64cc6183c03d4c12b1e036a7745e2932
Christian Brabandt <cb@256bit.org>
parents:
10054
diff
changeset
|
2806 else |
7906
ea1fd8d750a6
commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents:
7899
diff
changeset
|
2807 free_tv(tv); |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2808 } |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2809 } |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2810 else if (p_verbose > 2) |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2811 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2812 ch_error(channel, "Received unknown command: %s", (char *)cmd); |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
2813 semsg(_(e_received_unknown_command_str), cmd); |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2814 } |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2815 } |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2816 |
8928
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
2817 /* |
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
2818 * Invoke the callback at "cbhead". |
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
2819 * Does not redraw but sets channel_need_redraw. |
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
2820 */ |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2821 static void |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2822 invoke_one_time_callback( |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2823 channel_T *channel, |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2824 cbq_T *cbhead, |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2825 cbq_T *item, |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2826 typval_T *argv) |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2827 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2828 ch_log(channel, "Invoking one-time callback %s", |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2829 (char *)item->cq_callback.cb_name); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2830 // Remove the item from the list first, if the callback |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2831 // invokes ch_close() the list will be cleared. |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2832 remove_cb_node(cbhead, item); |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2833 invoke_callback(channel, &item->cq_callback, argv); |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2834 free_callback(&item->cq_callback); |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2835 vim_free(item); |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2836 } |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
2837 |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2838 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2839 append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part) |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2840 { |
22210
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2841 aco_save_T aco; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2842 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
|
2843 int save_write_to = buffer->b_write_to_channel; |
9147
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2844 chanpart_T *ch_part = &channel->ch_part[part]; |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2845 int save_p_ma = buffer->b_p_ma; |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
2846 int empty = (buffer->b_ml.ml_flags & ML_EMPTY) ? 1 : 0; |
9147
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2847 |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2848 if (!buffer->b_p_ma && !ch_part->ch_nomodifiable) |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2849 { |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2850 if (!ch_part->ch_nomod_error) |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2851 { |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2852 ch_error(channel, "Buffer is not modifiable, cannot append"); |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2853 ch_part->ch_nomod_error = TRUE; |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2854 } |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2855 return; |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2856 } |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2857 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2858 // If the buffer is also used as input insert above the last |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2859 // line. Don't write these lines. |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2860 if (save_write_to) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2861 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2862 --lnum; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2863 buffer->b_write_to_channel = FALSE; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2864 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2865 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2866 // Append to the buffer |
22210
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2867 ch_log(channel, "appending line %d to buffer %s", |
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2868 (int)lnum + 1 - empty, buffer->b_fname); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2869 |
9147
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2870 buffer->b_p_ma = TRUE; |
11959
91a26b7a4119
patch 8.0.0860: side effects when channel appends to a buffer
Christian Brabandt <cb@256bit.org>
parents:
11939
diff
changeset
|
2871 |
22210
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2872 // set curbuf to be our buf, temporarily |
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2873 aucmd_prepbuf(&aco, buffer); |
11959
91a26b7a4119
patch 8.0.0860: side effects when channel appends to a buffer
Christian Brabandt <cb@256bit.org>
parents:
11939
diff
changeset
|
2874 |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2875 u_sync(TRUE); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2876 // ignore undo failure, undo is not very useful here |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14675
diff
changeset
|
2877 vim_ignored = u_save(lnum - empty, lnum + 1); |
10147
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2878 |
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2879 if (empty) |
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2880 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2881 // The buffer is empty, replace the first (dummy) line. |
10147
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2882 ml_replace(lnum, msg, TRUE); |
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2883 lnum = 0; |
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2884 } |
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2885 else |
65afd399ffa7
commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents:
10112
diff
changeset
|
2886 ml_append(lnum, msg, 0, FALSE); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2887 appended_lines_mark(lnum, 1L); |
11959
91a26b7a4119
patch 8.0.0860: side effects when channel appends to a buffer
Christian Brabandt <cb@256bit.org>
parents:
11939
diff
changeset
|
2888 |
22210
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2889 // reset notion of buffer |
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2890 aucmd_restbuf(&aco); |
11959
91a26b7a4119
patch 8.0.0860: side effects when channel appends to a buffer
Christian Brabandt <cb@256bit.org>
parents:
11939
diff
changeset
|
2891 |
9147
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2892 if (ch_part->ch_nomodifiable) |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2893 buffer->b_p_ma = FALSE; |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2894 else |
053bc64433ec
commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents:
9143
diff
changeset
|
2895 buffer->b_p_ma = save_p_ma; |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2896 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2897 if (buffer->b_nwindows > 0) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2898 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2899 win_T *wp; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2900 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2901 FOR_ALL_WINDOWS(wp) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2902 { |
17557
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2903 if (wp->w_buffer == buffer) |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2904 { |
17557
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2905 int move_cursor = save_write_to |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2906 ? wp->w_cursor.lnum == lnum + 1 |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2907 : (wp->w_cursor.lnum == lnum |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2908 && wp->w_cursor.col == 0); |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2909 |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2910 // If the cursor is at or above the new line, move it one line |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2911 // down. If the topline is outdated update it now. |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2912 if (move_cursor || wp->w_topline > buffer->b_ml.ml_line_count) |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2913 { |
22210
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2914 win_T *save_curwin = curwin; |
d6f6f9fed7d7
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22095
diff
changeset
|
2915 |
17557
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2916 if (move_cursor) |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2917 ++wp->w_cursor.lnum; |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2918 curwin = wp; |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2919 curbuf = curwin->w_buffer; |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2920 scroll_cursor_bot(0, FALSE); |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2921 curwin = save_curwin; |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2922 curbuf = curwin->w_buffer; |
4a22102fda8f
patch 8.1.1776: text added with a job isn't displayed
Bram Moolenaar <Bram@vim.org>
parents:
17308
diff
changeset
|
2923 } |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2924 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2925 } |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2926 redraw_buf_and_status_later(buffer, UPD_VALID); |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2927 channel_need_redraw = TRUE; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2928 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2929 |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2930 if (save_write_to) |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2931 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2932 channel_T *ch; |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2933 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2934 // Find channels reading from this buffer and adjust their |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2935 // next-to-read line number. |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2936 buffer->b_write_to_channel = TRUE; |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
2937 FOR_ALL_CHANNELS(ch) |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2938 { |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2939 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
|
2940 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9434
diff
changeset
|
2941 if (in_part->ch_bufref.br_buf == buffer) |
8422
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2942 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
|
2943 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2944 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2945 } |
5d2c84be23b5
commit https://github.com/vim/vim/commit/99ef06296f3c37490511c03786a2c8672e015c56
Christian Brabandt <cb@256bit.org>
parents:
8410
diff
changeset
|
2946 |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2947 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2948 drop_messages(channel_T *channel, ch_part_T part) |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2949 { |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2950 char_u *msg; |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2951 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
2952 while ((msg = channel_get(channel, part, NULL)) != NULL) |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2953 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
2954 ch_log(channel, "Dropping message '%s'", (char *)msg); |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2955 vim_free(msg); |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2956 } |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2957 } |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
2958 |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2959 /* |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2960 * Return TRUE if for "channel" / "part" ch_json_head should be used. |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2961 */ |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2962 static int |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2963 channel_use_json_head(channel_T *channel, ch_part_T part) |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2964 { |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2965 ch_mode_T ch_mode = channel->ch_part[part].ch_mode; |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2966 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2967 return ch_mode == CH_MODE_JSON || ch_mode == CH_MODE_JS |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
2968 || ch_mode == CH_MODE_LSP; |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2969 } |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2970 |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
2971 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
2972 * Invoke a callback for "channel"/"part" if needed. |
8928
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
2973 * This does not redraw but sets channel_need_redraw when redraw is needed. |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2974 * 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
|
2975 */ |
7885
6e6f829af138
commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents:
7883
diff
changeset
|
2976 static int |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
2977 may_invoke_callback(channel_T *channel, ch_part_T part) |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2978 { |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2979 char_u *msg = NULL; |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
2980 typval_T *listtv = NULL; |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
2981 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
|
2982 int seq_nr = -1; |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2983 chanpart_T *ch_part = &channel->ch_part[part]; |
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2984 ch_mode_T ch_mode = ch_part->ch_mode; |
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2985 cbq_T *cbhead = &ch_part->ch_cb_head; |
8404
8894d595b786
commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
2986 cbq_T *cbitem; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2987 callback_T *callback = NULL; |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
2988 buf_T *buffer = NULL; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
2989 char_u *p; |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2990 int called_otc; // one time callbackup |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2991 |
8210
b717dae2f26d
commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents:
8204
diff
changeset
|
2992 if (channel->ch_nb_close_cb != NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2993 // 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
|
2994 return FALSE; |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
2995 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
2996 // Use a message-specific callback, part callback or channel callback |
8404
8894d595b786
commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
2997 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
|
2998 if (cbitem->cq_seq_nr == 0) |
8894d595b786
commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
2999 break; |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3000 if (cbitem != NULL) |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3001 callback = &cbitem->cq_callback; |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3002 else if (ch_part->ch_callback.cb_name != NULL) |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3003 callback = &ch_part->ch_callback; |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3004 else if (channel->ch_callback.cb_name != NULL) |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3005 callback = &channel->ch_callback; |
8291
ac0c43e7af20
commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents:
8267
diff
changeset
|
3006 |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3007 buffer = ch_part->ch_bufref.br_buf; |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
3008 if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref) |
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11416
diff
changeset
|
3009 || buffer->b_ml.ml_mfp == NULL)) |
8291
ac0c43e7af20
commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents:
8267
diff
changeset
|
3010 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3011 // buffer was wiped out or unloaded |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3012 ch_log(channel, "%s buffer has been wiped out", part_names[part]); |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3013 ch_part->ch_bufref.br_buf = NULL; |
8291
ac0c43e7af20
commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents:
8267
diff
changeset
|
3014 buffer = NULL; |
ac0c43e7af20
commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents:
8267
diff
changeset
|
3015 } |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3016 |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3017 if (channel_use_json_head(channel, part)) |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
3018 { |
8159
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
3019 listitem_T *item; |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
3020 int argc = 0; |
d0958e22d9ff
commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents:
8157
diff
changeset
|
3021 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3022 // Get any json message in the queue. |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3023 if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3024 { |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3025 if (ch_mode == CH_MODE_LSP) |
28511
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
3026 // In the "lsp" mode, the http header and the json payload may |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
3027 // be received in multiple messages. So concatenate all the |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
3028 // received messages. |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
3029 (void)channel_collapse(channel, part, FALSE); |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
3030 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3031 // 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
|
3032 channel_parse_json(channel, part); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3033 if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL) |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
3034 return FALSE; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3035 } |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3036 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3037 if (ch_mode == CH_MODE_LSP) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3038 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3039 dict_T *d = listtv->vval.v_dict; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3040 dictitem_T *di; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3041 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3042 seq_nr = 0; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3043 if (d != NULL) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3044 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3045 di = dict_find(d, (char_u *)"id", -1); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3046 if (di != NULL && di->di_tv.v_type == VAR_NUMBER) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3047 seq_nr = di->di_tv.vval.v_number; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3048 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3049 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3050 argv[1] = *listtv; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3051 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3052 else |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3053 { |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3054 for (item = listtv->vval.v_list->lv_first; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3055 item != NULL && argc < CH_JSON_MAX_ARGS; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3056 item = item->li_next) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3057 argv[argc++] = item->li_tv; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3058 while (argc < CH_JSON_MAX_ARGS) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3059 argv[argc++].v_type = VAR_UNKNOWN; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3060 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3061 if (argv[0].v_type == VAR_STRING) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3062 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3063 // ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3064 channel_exe_cmd(channel, part, argv); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3065 free_tv(listtv); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3066 return TRUE; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3067 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3068 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3069 if (argv[0].v_type != VAR_NUMBER) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3070 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3071 ch_error(channel, |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3072 "Dropping message with invalid sequence number type"); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3073 free_tv(listtv); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3074 return FALSE; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3075 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3076 seq_nr = argv[0].vval.v_number; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3077 } |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
3078 } |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3079 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
|
3080 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3081 // 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
|
3082 return FALSE; |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
3083 } |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3084 else |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3085 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3086 // If there is no callback or buffer drop the message. |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3087 if (callback == NULL && buffer == NULL) |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3088 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3089 // If there is a close callback it may use ch_read() to get the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3090 // messages. |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3091 if (channel->ch_close_cb.cb_name == NULL && !channel->ch_drop_never) |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3092 drop_messages(channel, part); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3093 return FALSE; |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3094 } |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3095 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3096 if (ch_mode == CH_MODE_NL) |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3097 { |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3098 char_u *nl = NULL; |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3099 char_u *buf; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3100 readq_T *node; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3101 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3102 // See if we have a message ending in NL in the first buffer. If |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3103 // not try to concatenate the first and the second buffer. |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3104 while (TRUE) |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3105 { |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3106 node = channel_peek(channel, part); |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3107 nl = channel_first_nl(node); |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3108 if (nl != NULL) |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3109 break; |
9215
d2d44592467d
commit https://github.com/vim/vim/commit/9ed96efb3d47d46e9637da04656efff715102407
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
3110 if (channel_collapse(channel, part, TRUE) == FAIL) |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3111 { |
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3112 if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0) |
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3113 break; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3114 return FALSE; // incomplete message |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3115 } |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3116 } |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3117 buf = node->rq_buffer; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3118 |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3119 // Convert NUL to NL, the internal representation. |
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3120 for (p = buf; (nl == NULL || p < nl) |
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3121 && p < buf + node->rq_buflen; ++p) |
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3122 if (*p == NUL) |
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3123 *p = NL; |
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3124 |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3125 if (nl == NULL) |
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3126 { |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3127 // get the whole buffer, drop the NL |
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3128 msg = channel_get(channel, part, NULL); |
10249
920c73a27dda
commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3129 } |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3130 else if (nl + 1 == buf + node->rq_buflen) |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3131 { |
15975
915ed7ca92fa
patch 8.1.0993: ch_read() may return garbage if terminating NL is missing
Bram Moolenaar <Bram@vim.org>
parents:
15908
diff
changeset
|
3132 // get the whole buffer |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3133 msg = channel_get(channel, part, NULL); |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3134 *nl = NUL; |
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3135 } |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3136 else |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3137 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3138 // Copy the message into allocated memory (excluding the NL) |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3139 // and remove it from the buffer (including the NL). |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20577
diff
changeset
|
3140 msg = vim_strnsave(buf, nl - buf); |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3141 channel_consume(channel, part, (int)(nl - buf) + 1); |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3142 } |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3143 } |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3144 else |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3145 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3146 // For a raw channel we don't know where the message ends, just |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3147 // get everything we have. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3148 // Convert NUL to NL, the internal representation. |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3149 msg = channel_get_all(channel, part, NULL); |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3150 } |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3151 |
8358
49d0e094cb93
commit https://github.com/vim/vim/commit/bf73b91c664488ca57e2b4a8eb9b1f36f6625bc7
Christian Brabandt <cb@256bit.org>
parents:
8356
diff
changeset
|
3152 if (msg == NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3153 return FALSE; // out of memory (and avoids Coverity warning) |
8358
49d0e094cb93
commit https://github.com/vim/vim/commit/bf73b91c664488ca57e2b4a8eb9b1f36f6625bc7
Christian Brabandt <cb@256bit.org>
parents:
8356
diff
changeset
|
3154 |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3155 argv[1].v_type = VAR_STRING; |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3156 argv[1].vval.v_string = msg; |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3157 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3158 |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3159 called_otc = FALSE; |
7933
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
3160 if (seq_nr > 0) |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3161 { |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3162 // JSON or JS or LSP mode: invoke the one-time callback with the |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3163 // matching nr |
8404
8894d595b786
commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
3164 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
|
3165 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
|
3166 { |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3167 invoke_one_time_callback(channel, cbhead, cbitem, argv); |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3168 called_otc = TRUE; |
7933
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
3169 break; |
1f0743f4f88f
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents:
7931
diff
changeset
|
3170 } |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3171 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3172 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3173 if (seq_nr > 0 && (ch_mode != CH_MODE_LSP || called_otc)) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3174 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3175 if (!called_otc) |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3176 { |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3177 // If the 'drop' channel attribute is set to 'never' or if |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3178 // ch_evalexpr() is waiting for this response message, then don't |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3179 // drop this message. |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3180 if (channel->ch_drop_never) |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3181 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3182 // message must be read with ch_read() |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3183 channel_push_json(channel, part, listtv); |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3184 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3185 // Change the type to avoid the value being freed. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3186 listtv->v_type = VAR_NUMBER; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
3187 free_tv(listtv); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3188 listtv = NULL; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3189 } |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3190 else |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3191 ch_log(channel, "Dropping message %d without callback", |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3192 seq_nr); |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3193 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3194 } |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3195 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
|
3196 { |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3197 if (buffer != NULL) |
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3198 { |
8346
8fa75a4c39bd
commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents:
8334
diff
changeset
|
3199 if (msg == NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3200 // JSON or JS mode: re-encode the message. |
8346
8fa75a4c39bd
commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents:
8334
diff
changeset
|
3201 msg = json_encode(listtv, ch_mode); |
8fa75a4c39bd
commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents:
8334
diff
changeset
|
3202 if (msg != NULL) |
11670
3b2afa2b77b3
patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
3203 { |
11672
3c6cc2f24645
patch 8.0.0719: build failure without +terminal feature
Christian Brabandt <cb@256bit.org>
parents:
11670
diff
changeset
|
3204 #ifdef FEAT_TERMINAL |
11670
3b2afa2b77b3
patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
3205 if (buffer->b_term != NULL) |
3b2afa2b77b3
patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
3206 write_to_term(buffer, msg, channel); |
3b2afa2b77b3
patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
3207 else |
11672
3c6cc2f24645
patch 8.0.0719: build failure without +terminal feature
Christian Brabandt <cb@256bit.org>
parents:
11670
diff
changeset
|
3208 #endif |
11670
3b2afa2b77b3
patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
3209 append_to_buffer(buffer, msg, channel, part); |
3b2afa2b77b3
patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
3210 } |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3211 } |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3212 |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3213 if (callback != NULL) |
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3214 { |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3215 if (cbitem != NULL) |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3216 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
|
3217 else |
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3218 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3219 // invoke the channel callback |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3220 ch_log(channel, "Invoking channel callback %s", |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3221 (char *)callback->cb_name); |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3222 invoke_callback(channel, callback, argv); |
8382
3dbe93a240d8
commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents:
8358
diff
changeset
|
3223 } |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
3224 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3225 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3226 else |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3227 ch_log(channel, "Dropping message %d", seq_nr); |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3228 |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3229 if (listtv != NULL) |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3230 free_tv(listtv); |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
3231 vim_free(msg); |
7885
6e6f829af138
commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents:
7883
diff
changeset
|
3232 |
6e6f829af138
commit https://github.com/vim/vim/commit/df5b27b20ec023274fb0f5347973d5abcde7ddd6
Christian Brabandt <cb@256bit.org>
parents:
7883
diff
changeset
|
3233 return TRUE; |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3234 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3235 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
3236 #if defined(FEAT_NETBEANS_INTG) || defined(PROTO) |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3237 /* |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3238 * 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
|
3239 * 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
|
3240 */ |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3241 int |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3242 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
|
3243 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3244 return channel != NULL && (channel->CH_SOCK_FD != INVALID_FD |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3245 || channel->CH_IN_FD != INVALID_FD); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3246 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
3247 #endif |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3248 |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3249 /* |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3250 * 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
|
3251 * 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
|
3252 */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3253 int |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3254 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
|
3255 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3256 return channel != NULL && (channel->CH_SOCK_FD != INVALID_FD |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3257 || channel->CH_IN_FD != INVALID_FD |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3258 || channel->CH_OUT_FD != INVALID_FD |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3259 || 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
|
3260 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3261 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3262 /* |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3263 * Return a pointer indicating the readahead. Can only be compared between |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3264 * calls. Returns NULL if there is no readahead. |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3265 */ |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3266 static void * |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3267 channel_readahead_pointer(channel_T *channel, ch_part_T part) |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3268 { |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3269 if (channel_use_json_head(channel, part)) |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3270 { |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3271 jsonq_T *head = &channel->ch_part[part].ch_json_head; |
17212
fd983b381ec0
patch 8.1.1605: Vim may delay processing messages on a json channel
Bram Moolenaar <Bram@vim.org>
parents:
17170
diff
changeset
|
3272 |
fd983b381ec0
patch 8.1.1605: Vim may delay processing messages on a json channel
Bram Moolenaar <Bram@vim.org>
parents:
17170
diff
changeset
|
3273 if (head->jq_next == NULL) |
fd983b381ec0
patch 8.1.1605: Vim may delay processing messages on a json channel
Bram Moolenaar <Bram@vim.org>
parents:
17170
diff
changeset
|
3274 // Parse json from readahead, there might be a complete message to |
fd983b381ec0
patch 8.1.1605: Vim may delay processing messages on a json channel
Bram Moolenaar <Bram@vim.org>
parents:
17170
diff
changeset
|
3275 // process. |
fd983b381ec0
patch 8.1.1605: Vim may delay processing messages on a json channel
Bram Moolenaar <Bram@vim.org>
parents:
17170
diff
changeset
|
3276 channel_parse_json(channel, part); |
fd983b381ec0
patch 8.1.1605: Vim may delay processing messages on a json channel
Bram Moolenaar <Bram@vim.org>
parents:
17170
diff
changeset
|
3277 |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3278 return head->jq_next; |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3279 } |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3280 return channel_peek(channel, part); |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3281 } |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3282 |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3283 /* |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3284 * Return TRUE if "channel" has JSON or other typeahead. |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3285 */ |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3286 static int |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3287 channel_has_readahead(channel_T *channel, ch_part_T part) |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3288 { |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
3289 return channel_readahead_pointer(channel, part) != NULL; |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3290 } |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3291 |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3292 /* |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3293 * Return a string indicating the status of the channel. |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3294 * If "req_part" is not negative check that part. |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3295 */ |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
3296 static char * |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3297 channel_status(channel_T *channel, int req_part) |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3298 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3299 ch_part_T part; |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3300 int has_readahead = FALSE; |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3301 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3302 if (channel == NULL) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3303 return "fail"; |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3304 if (req_part == PART_OUT) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3305 { |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3306 if (channel->CH_OUT_FD != INVALID_FD) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3307 return "open"; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3308 if (channel_has_readahead(channel, PART_OUT)) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3309 has_readahead = TRUE; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3310 } |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3311 else if (req_part == PART_ERR) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3312 { |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3313 if (channel->CH_ERR_FD != INVALID_FD) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3314 return "open"; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3315 if (channel_has_readahead(channel, PART_ERR)) |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3316 has_readahead = TRUE; |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3317 } |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3318 else |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3319 { |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3320 if (channel_is_open(channel)) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3321 return "open"; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3322 for (part = PART_SOCK; part < PART_IN; ++part) |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3323 if (channel_has_readahead(channel, part)) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3324 { |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3325 has_readahead = TRUE; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3326 break; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3327 } |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3328 } |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3329 |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3330 if (has_readahead) |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
3331 return "buffered"; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3332 return "closed"; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3333 } |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3334 |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3335 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3336 channel_part_info(channel_T *channel, dict_T *dict, char *name, ch_part_T part) |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3337 { |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3338 chanpart_T *chanpart = &channel->ch_part[part]; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3339 char namebuf[20]; // longest is "sock_timeout" |
8678
a4e7f4a62193
commit https://github.com/vim/vim/commit/3f3fbd3fdb73bdfbfeab22a9dfc7a25e38bdf5f6
Christian Brabandt <cb@256bit.org>
parents:
8669
diff
changeset
|
3340 size_t tail; |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3341 char *status; |
8684
6e567914f55a
commit https://github.com/vim/vim/commit/573e445664eef399a72b1bfc975260a639605fef
Christian Brabandt <cb@256bit.org>
parents:
8678
diff
changeset
|
3342 char *s = ""; |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3343 |
8783
23b7f05a7f48
commit https://github.com/vim/vim/commit/925ccfde79bf734bc89269c705cebe2d49fe6444
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
3344 vim_strncpy((char_u *)namebuf, (char_u *)name, 4); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3345 STRCAT(namebuf, "_"); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3346 tail = STRLEN(namebuf); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3347 |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3348 STRCPY(namebuf + tail, "status"); |
10233
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3349 if (chanpart->ch_fd != INVALID_FD) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3350 status = "open"; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3351 else if (channel_has_readahead(channel, part)) |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3352 status = "buffered"; |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3353 else |
d709622a18c9
commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents:
10147
diff
changeset
|
3354 status = "closed"; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
3355 dict_add_string(dict, namebuf, (char_u *)status); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3356 |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3357 STRCPY(namebuf + tail, "mode"); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3358 switch (chanpart->ch_mode) |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3359 { |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3360 case CH_MODE_NL: s = "NL"; break; |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3361 case CH_MODE_RAW: s = "RAW"; break; |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3362 case CH_MODE_JSON: s = "JSON"; break; |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3363 case CH_MODE_JS: s = "JS"; break; |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3364 case CH_MODE_LSP: s = "LSP"; break; |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3365 } |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
3366 dict_add_string(dict, namebuf, (char_u *)s); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3367 |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3368 STRCPY(namebuf + tail, "io"); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3369 if (part == PART_SOCK) |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3370 s = "socket"; |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3371 else switch (chanpart->ch_io) |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3372 { |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3373 case JIO_NULL: s = "null"; break; |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3374 case JIO_PIPE: s = "pipe"; break; |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3375 case JIO_FILE: s = "file"; break; |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3376 case JIO_BUFFER: s = "buffer"; break; |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3377 case JIO_OUT: s = "out"; break; |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3378 } |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
3379 dict_add_string(dict, namebuf, (char_u *)s); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3380 |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3381 STRCPY(namebuf + tail, "timeout"); |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
3382 dict_add_number(dict, namebuf, chanpart->ch_timeout); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3383 } |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3384 |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3385 static void |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3386 channel_info(channel_T *channel, dict_T *dict) |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3387 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
3388 dict_add_number(dict, "id", channel->ch_id); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
3389 dict_add_string(dict, "status", (char_u *)channel_status(channel, -1)); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3390 |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3391 if (channel->ch_hostname != NULL) |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3392 { |
28317
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3393 if (channel->ch_port) |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3394 { |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3395 dict_add_string(dict, "hostname", (char_u *)channel->ch_hostname); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3396 dict_add_number(dict, "port", channel->ch_port); |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3397 } |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3398 else |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3399 // Unix-domain socket. |
d32dc906dd2c
patch 8.2.4684: cannot open a channel on a Unix domain socket
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
3400 dict_add_string(dict, "path", (char_u *)channel->ch_hostname); |
8669
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3401 channel_part_info(channel, dict, "sock", PART_SOCK); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3402 } |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3403 else |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3404 { |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3405 channel_part_info(channel, dict, "out", PART_OUT); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3406 channel_part_info(channel, dict, "err", PART_ERR); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3407 channel_part_info(channel, dict, "in", PART_IN); |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3408 } |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3409 } |
06848fe9c816
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents:
8667
diff
changeset
|
3410 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3411 /* |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3412 * Close channel "channel". |
8257
c4ffdda8cdfd
commit https://github.com/vim/vim/commit/c8dcbb12c5d7f3eb0c334daebb4475bb015b91e7
Christian Brabandt <cb@256bit.org>
parents:
8240
diff
changeset
|
3413 * 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
|
3414 * Does not clear the buffers. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3415 */ |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3416 void |
8240
60586ce747c4
commit https://github.com/vim/vim/commit/8b374215ccd35003b95ba1df8f12e03bf8a8adc3
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
3417 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
|
3418 { |
8114
4aea0b0aa714
commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents:
8096
diff
changeset
|
3419 ch_log(channel, "Closing channel"); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3420 |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
3421 #ifdef FEAT_GUI |
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
3422 channel_gui_unregister(channel); |
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
3423 #endif |
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
3424 |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3425 ch_close_part(channel, PART_SOCK); |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3426 ch_close_part(channel, PART_IN); |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3427 ch_close_part(channel, PART_OUT); |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3428 ch_close_part(channel, PART_ERR); |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
3429 |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3430 if (invoke_close_cb) |
8210
b717dae2f26d
commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents:
8204
diff
changeset
|
3431 { |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3432 ch_part_T part; |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3433 |
26217
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
25759
diff
changeset
|
3434 #ifdef FEAT_TERMINAL |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
25759
diff
changeset
|
3435 // let the terminal know it is closing to avoid getting stuck |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
25759
diff
changeset
|
3436 term_channel_closing(channel); |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
25759
diff
changeset
|
3437 #endif |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3438 // Invoke callbacks and flush buffers before the close callback. |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3439 if (channel->ch_close_cb.cb_name != NULL) |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3440 ch_log(channel, |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3441 "Invoking callbacks and flushing buffers before closing"); |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3442 for (part = PART_SOCK; part < PART_IN; ++part) |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3443 { |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3444 if (channel->ch_close_cb.cb_name != NULL |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3445 || channel->ch_part[part].ch_bufref.br_buf != NULL) |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3446 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3447 // Increment the refcount to avoid the channel being freed |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3448 // halfway. |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3449 ++channel->ch_refcount; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3450 if (channel->ch_close_cb.cb_name == NULL) |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3451 ch_log(channel, "flushing %s buffers before closing", |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3452 part_names[part]); |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3453 while (may_invoke_callback(channel, part)) |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3454 ; |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3455 --channel->ch_refcount; |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3456 } |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3457 } |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3458 |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3459 if (channel->ch_close_cb.cb_name != NULL) |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3460 { |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3461 typval_T argv[1]; |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3462 typval_T rettv; |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3463 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3464 // Increment the refcount to avoid the channel being freed |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3465 // halfway. |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3466 ++channel->ch_refcount; |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3467 ch_log(channel, "Invoking close callback %s", |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3468 (char *)channel->ch_close_cb.cb_name); |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3469 argv[0].v_type = VAR_CHANNEL; |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3470 argv[0].vval.v_channel = channel; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17557
diff
changeset
|
3471 call_callback(&channel->ch_close_cb, -1, &rettv, 1, argv); |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3472 clear_tv(&rettv); |
9064
a86103d4b356
commit https://github.com/vim/vim/commit/cefe4f994853c2d4866e2aa4ea3e3f36ab2fea13
Christian Brabandt <cb@256bit.org>
parents:
9058
diff
changeset
|
3473 channel_need_redraw = TRUE; |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3474 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3475 // the callback is only called once |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3476 free_callback(&channel->ch_close_cb); |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3477 |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3478 if (channel_need_redraw) |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3479 { |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3480 channel_need_redraw = FALSE; |
26466
d413104a94c8
patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
3481 redraw_after_callback(TRUE, FALSE); |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3482 } |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3483 |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3484 if (!channel->ch_drop_never) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3485 // any remaining messages are useless now |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3486 for (part = PART_SOCK; part < PART_IN; ++part) |
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3487 drop_messages(channel, part); |
12818
60e1e4cfb21e
patch 8.0.1286: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
12584
diff
changeset
|
3488 |
60e1e4cfb21e
patch 8.0.1286: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
12584
diff
changeset
|
3489 --channel->ch_refcount; |
11977
701aea3bc68b
patch 8.0.0869: job output is sometimes not displayed in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11969
diff
changeset
|
3490 } |
8210
b717dae2f26d
commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents:
8204
diff
changeset
|
3491 } |
b717dae2f26d
commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents:
8204
diff
changeset
|
3492 |
b717dae2f26d
commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents:
8204
diff
changeset
|
3493 channel->ch_nb_close_cb = NULL; |
11834
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3494 |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3495 #ifdef FEAT_TERMINAL |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3496 term_channel_closed(channel); |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3497 #endif |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3498 } |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3499 |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3500 /* |
10054
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3501 * Close the "in" part channel "channel". |
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3502 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3503 static void |
10054
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3504 channel_close_in(channel_T *channel) |
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3505 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3506 ch_close_part(channel, PART_IN); |
10054
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3507 } |
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3508 |
12403
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3509 static void |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3510 remove_from_writeque(writeq_T *wq, writeq_T *entry) |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3511 { |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3512 ga_clear(&entry->wq_ga); |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3513 wq->wq_next = entry->wq_next; |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3514 if (wq->wq_next == NULL) |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3515 wq->wq_prev = NULL; |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3516 else |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3517 wq->wq_next->wq_prev = NULL; |
12407
e9dbdc4d8279
patch 8.0.1083: leaking memory in input part of channel
Christian Brabandt <cb@256bit.org>
parents:
12403
diff
changeset
|
3518 vim_free(entry); |
12403
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3519 } |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3520 |
10054
d4b7232fc63a
commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents:
10052
diff
changeset
|
3521 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3522 * 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
|
3523 */ |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3524 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3525 channel_clear_one(channel_T *channel, ch_part_T part) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3526 { |
12403
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3527 chanpart_T *ch_part = &channel->ch_part[part]; |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3528 jsonq_T *json_head = &ch_part->ch_json_head; |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3529 cbq_T *cb_head = &ch_part->ch_cb_head; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3530 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3531 while (channel_peek(channel, part) != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3532 vim_free(channel_get(channel, part, NULL)); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3533 |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3534 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
|
3535 { |
dc32c8026899
commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents:
8072
diff
changeset
|
3536 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
|
3537 |
dc32c8026899
commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents:
8072
diff
changeset
|
3538 remove_cb_node(cb_head, node); |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3539 free_callback(&node->cq_callback); |
8074
dc32c8026899
commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents:
8072
diff
changeset
|
3540 vim_free(node); |
dc32c8026899
commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents:
8072
diff
changeset
|
3541 } |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3542 |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3543 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
|
3544 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3545 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
|
3546 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
|
3547 } |
8055
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
3548 |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3549 free_callback(&ch_part->ch_callback); |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
3550 ga_clear(&ch_part->ch_block_ids); |
12403
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3551 |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3552 while (ch_part->ch_writeque.wq_next != NULL) |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3553 remove_from_writeque(&ch_part->ch_writeque, |
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
3554 ch_part->ch_writeque.wq_next); |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3555 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3556 |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3557 /* |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3558 * 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
|
3559 */ |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3560 void |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3561 channel_clear(channel_T *channel) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3562 { |
8310
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
3563 ch_log(channel, "Clearing channel"); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
3564 VIM_CLEAR(channel->ch_hostname); |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3565 channel_clear_one(channel, PART_SOCK); |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3566 channel_clear_one(channel, PART_OUT); |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3567 channel_clear_one(channel, PART_ERR); |
12407
e9dbdc4d8279
patch 8.0.1083: leaking memory in input part of channel
Christian Brabandt <cb@256bit.org>
parents:
12403
diff
changeset
|
3568 channel_clear_one(channel, PART_IN); |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3569 free_callback(&channel->ch_callback); |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3570 free_callback(&channel->ch_close_cb); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3571 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3572 |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3573 #if defined(EXITFREE) || defined(PROTO) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3574 void |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3575 channel_free_all(void) |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3576 { |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3577 channel_T *channel; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3578 |
8310
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
3579 ch_log(NULL, "channel_free_all()"); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
3580 FOR_ALL_CHANNELS(channel) |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3581 channel_clear(channel); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3582 } |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3583 #endif |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3584 |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3585 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3586 // Sent when the netbeans 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
|
3587 #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
|
3588 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3589 // Buffer size for reading incoming messages. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3590 #define MAXMSGSIZE 4096 |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3591 |
30116
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3592 /* |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3593 * Check if there are remaining data that should be written for "in_part". |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3594 */ |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3595 static int |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3596 is_channel_write_remaining(chanpart_T *in_part) |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3597 { |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3598 buf_T *buf = in_part->ch_bufref.br_buf; |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3599 |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3600 if (in_part->ch_writeque.wq_next != NULL) |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3601 return TRUE; |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3602 if (buf == NULL) |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3603 return FALSE; |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3604 return in_part->ch_buf_append |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3605 ? (in_part->ch_buf_bot < buf->b_ml.ml_line_count) |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3606 : (in_part->ch_buf_top <= in_part->ch_buf_bot |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3607 && in_part->ch_buf_top <= buf->b_ml.ml_line_count); |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3608 } |
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3609 |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3610 #if defined(HAVE_SELECT) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3611 /* |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3612 * Add write fds where we are waiting for writing to be possible. |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3613 */ |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3614 static int |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3615 channel_fill_wfds(int maxfd_arg, fd_set *wfds) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3616 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3617 int maxfd = maxfd_arg; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3618 channel_T *ch; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3619 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
3620 FOR_ALL_CHANNELS(ch) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3621 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3622 chanpart_T *in_part = &ch->ch_part[PART_IN]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3623 |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
3624 if (in_part->ch_fd != INVALID_FD |
30116
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3625 && is_channel_write_remaining(in_part)) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3626 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3627 FD_SET((int)in_part->ch_fd, wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3628 if ((int)in_part->ch_fd >= maxfd) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3629 maxfd = (int)in_part->ch_fd + 1; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3630 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3631 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3632 return maxfd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3633 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3634 #else |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3635 /* |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3636 * Add write fds where we are waiting for writing to be possible. |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3637 */ |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3638 static int |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3639 channel_fill_poll_write(int nfd_in, struct pollfd *fds) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3640 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3641 int nfd = nfd_in; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3642 channel_T *ch; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3643 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
3644 FOR_ALL_CHANNELS(ch) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3645 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3646 chanpart_T *in_part = &ch->ch_part[PART_IN]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3647 |
12168
51e5a8602624
patch 8.0.0964: channel write buffer does not work with poll()
Christian Brabandt <cb@256bit.org>
parents:
12158
diff
changeset
|
3648 if (in_part->ch_fd != INVALID_FD |
30116
87e205ae86d3
patch 9.0.0394: Cygwin: multibyte characters may be broken in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
3649 && is_channel_write_remaining(in_part)) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3650 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3651 in_part->ch_poll_idx = nfd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3652 fds[nfd].fd = in_part->ch_fd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3653 fds[nfd].events = POLLOUT; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3654 ++nfd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3655 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3656 else |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3657 in_part->ch_poll_idx = -1; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3658 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3659 return nfd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3660 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3661 #endif |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3662 |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3663 typedef enum { |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3664 CW_READY, |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3665 CW_NOT_READY, |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3666 CW_ERROR |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3667 } channel_wait_result; |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3668 |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3669 /* |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3670 * Check for reading from "fd" with "timeout" msec. |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3671 * Return CW_READY when there is something to read. |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3672 * Return CW_NOT_READY when there is nothing to read. |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3673 * Return CW_ERROR when there is an error. |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3674 */ |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3675 static channel_wait_result |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3676 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
|
3677 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3678 if (timeout > 0) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3679 ch_log(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
|
3680 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
3681 # ifdef MSWIN |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3682 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
|
3683 { |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3684 DWORD nread; |
8757
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3685 int sleep_time; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3686 DWORD deadline = GetTickCount() + timeout; |
8757
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3687 int delay = 1; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3688 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3689 // reading from a pipe, not a socket |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3690 while (TRUE) |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3691 { |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3692 int r = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL); |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3693 |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3694 if (r && nread > 0) |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3695 return CW_READY; |
15577
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3696 |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3697 if (channel->ch_named_pipe) |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3698 { |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3699 DisconnectNamedPipe((HANDLE)fd); |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3700 ConnectNamedPipe((HANDLE)fd, NULL); |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3701 } |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3702 else if (r == 0) |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
3703 return CW_ERROR; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3704 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3705 // perhaps write some buffer lines |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3706 channel_write_any_lines(); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3707 |
8757
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3708 sleep_time = deadline - GetTickCount(); |
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3709 if (sleep_time <= 0) |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3710 break; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3711 // Wait for a little while. Very short at first, up to 10 msec |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3712 // after looping a few times. |
8757
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3713 if (sleep_time > delay) |
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3714 sleep_time = delay; |
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3715 Sleep(sleep_time); |
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3716 delay = delay * 2; |
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3717 if (delay > 10) |
4fb37555e814
commit https://github.com/vim/vim/commit/84e1d2b21a424f2687b61daaf84f5fc4f1ab0abe
Christian Brabandt <cb@256bit.org>
parents:
8755
diff
changeset
|
3718 delay = 10; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3719 } |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3720 } |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3721 else |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3722 #endif |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3723 { |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
3724 #if defined(HAVE_SELECT) |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3725 struct timeval tval; |
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3726 fd_set rfds; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3727 fd_set wfds; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3728 int ret; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3729 int maxfd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3730 |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3731 tval.tv_sec = timeout / 1000; |
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3732 tval.tv_usec = (timeout % 1000) * 1000; |
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3733 for (;;) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3734 { |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3735 FD_ZERO(&rfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3736 FD_SET((int)fd, &rfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3737 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3738 // Write lines to a pipe when a pipe can be written to. Need to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3739 // set this every time, some buffers may be done. |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3740 maxfd = (int)fd + 1; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3741 FD_ZERO(&wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3742 maxfd = channel_fill_wfds(maxfd, &wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3743 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3744 ret = select(maxfd, &rfds, &wfds, NULL, &tval); |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
3745 # ifdef EINTR |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3746 SOCK_ERRNO; |
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3747 if (ret == -1 && errno == EINTR) |
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3748 continue; |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
3749 # endif |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3750 if (ret > 0) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3751 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3752 if (FD_ISSET(fd, &rfds)) |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3753 return CW_READY; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3754 channel_write_any_lines(); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3755 continue; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3756 } |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3757 break; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3758 } |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
3759 #else |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3760 for (;;) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3761 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3762 struct pollfd fds[MAX_OPEN_CHANNELS + 1]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3763 int nfd = 1; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3764 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3765 fds[0].fd = fd; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3766 fds[0].events = POLLIN; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3767 nfd = channel_fill_poll_write(nfd, fds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3768 if (poll(fds, nfd, timeout) > 0) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3769 { |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3770 if (fds[0].revents & POLLIN) |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3771 return CW_READY; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3772 channel_write_any_lines(); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3773 continue; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3774 } |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3775 break; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
3776 } |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3777 #endif |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
3778 } |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3779 return CW_NOT_READY; |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3780 } |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3781 |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3782 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3783 ch_close_part_on_error( |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3784 channel_T *channel, ch_part_T part, int is_err, char *func) |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3785 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3786 char msg[] = "%s(): Read %s from ch_part[%d], closing"; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3787 |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3788 if (is_err) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3789 // Do not call emsg(), most likely the other end just exited. |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3790 ch_error(channel, msg, func, "error", part); |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3791 else |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3792 ch_log(channel, msg, func, "EOF", part); |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3793 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3794 // Queue a "DETACH" netbeans message in the command queue in order to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3795 // terminate the netbeans session later. Do not end the session here |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3796 // directly as we may be running in the context of a call to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3797 // netbeans_parse_messages(): |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3798 // netbeans_parse_messages |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3799 // -> autocmd triggered while processing the netbeans cmd |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3800 // -> ui_breakcheck |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3801 // -> gui event loop or select loop |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3802 // -> channel_read() |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3803 // Only send "DETACH" for a netbeans channel. |
9050
31bba6f25d84
commit https://github.com/vim/vim/commit/715d285d79a1d97928dd717278e25e6de45d1496
Christian Brabandt <cb@256bit.org>
parents:
9044
diff
changeset
|
3804 if (channel->ch_nb_close_cb != NULL) |
10253
a92c4abb8c1f
commit https://github.com/vim/vim/commit/8ddef48d1eade1911b946fdda8c73c80856e6273
Christian Brabandt <cb@256bit.org>
parents:
10249
diff
changeset
|
3805 channel_save(channel, PART_SOCK, (char_u *)DETACH_MSG_RAW, |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3806 (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3807 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3808 // When reading is not possible close this part of the channel. Don't |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3809 // close the channel yet, there may be something to read on another part. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3810 // When stdout and stderr use the same FD we get the error only on one of |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3811 // them, also close the other. |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3812 if (part == PART_OUT || part == PART_ERR) |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3813 { |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3814 ch_part_T other = part == PART_OUT ? PART_ERR : PART_OUT; |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3815 |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3816 if (channel->ch_part[part].ch_fd == channel->ch_part[other].ch_fd) |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3817 ch_close_part(channel, other); |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13806
diff
changeset
|
3818 } |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3819 ch_close_part(channel, part); |
9133
dec3b7b977c0
commit https://github.com/vim/vim/commit/bf981eeb6b4ee63ae8543a7f9865ab700159a79c
Christian Brabandt <cb@256bit.org>
parents:
9131
diff
changeset
|
3820 |
dec3b7b977c0
commit https://github.com/vim/vim/commit/bf981eeb6b4ee63ae8543a7f9865ab700159a79c
Christian Brabandt <cb@256bit.org>
parents:
9131
diff
changeset
|
3821 #ifdef FEAT_GUI |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3822 // Stop listening to GUI events right away. |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3823 channel_gui_unregister_one(channel, part); |
9133
dec3b7b977c0
commit https://github.com/vim/vim/commit/bf981eeb6b4ee63ae8543a7f9865ab700159a79c
Christian Brabandt <cb@256bit.org>
parents:
9131
diff
changeset
|
3824 #endif |
9083
69bb7b230094
commit https://github.com/vim/vim/commit/cf7ff70ca73218d618e7c00ab785bcf5f9120a94
Christian Brabandt <cb@256bit.org>
parents:
9081
diff
changeset
|
3825 } |
69bb7b230094
commit https://github.com/vim/vim/commit/cf7ff70ca73218d618e7c00ab785bcf5f9120a94
Christian Brabandt <cb@256bit.org>
parents:
9081
diff
changeset
|
3826 |
69bb7b230094
commit https://github.com/vim/vim/commit/cf7ff70ca73218d618e7c00ab785bcf5f9120a94
Christian Brabandt <cb@256bit.org>
parents:
9081
diff
changeset
|
3827 static void |
69bb7b230094
commit https://github.com/vim/vim/commit/cf7ff70ca73218d618e7c00ab785bcf5f9120a94
Christian Brabandt <cb@256bit.org>
parents:
9081
diff
changeset
|
3828 channel_close_now(channel_T *channel) |
69bb7b230094
commit https://github.com/vim/vim/commit/cf7ff70ca73218d618e7c00ab785bcf5f9120a94
Christian Brabandt <cb@256bit.org>
parents:
9081
diff
changeset
|
3829 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3830 ch_log(channel, "Closing channel because all readable fds are closed"); |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3831 if (channel->ch_nb_close_cb != NULL) |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3832 (*channel->ch_nb_close_cb)(); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
3833 channel_close(channel, TRUE); |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3834 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3835 |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3836 /* |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
3837 * 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
|
3838 * "part" is PART_SOCK, PART_OUT or PART_ERR. |
9143
b9c1a397a8a6
commit https://github.com/vim/vim/commit/655da31a18ef3f888acf10e68b438e2a851f7b14
Christian Brabandt <cb@256bit.org>
parents:
9139
diff
changeset
|
3839 * The data is put in the read queue. No callbacks are invoked here. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3840 */ |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3841 static void |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3842 channel_read(channel_T *channel, ch_part_T part, char *func) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3843 { |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3844 static char_u *buf = NULL; |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3845 int len = 0; |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3846 int readlen = 0; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
3847 sock_T fd; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3848 int use_socket = FALSE; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3849 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3850 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
|
3851 if (fd == INVALID_FD) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3852 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3853 ch_error(channel, "channel_read() called while %s part is closed", |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
3854 part_names[part]); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3855 return; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3856 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3857 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
|
3858 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3859 // Allocate a buffer to read into. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3860 if (buf == NULL) |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3861 { |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3862 buf = alloc(MAXMSGSIZE); |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3863 if (buf == NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3864 return; // out of memory! |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3865 } |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3866 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3867 // Keep on reading for as long as there is something to read. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3868 // Use select() or poll() to avoid blocking on a message that is exactly |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3869 // MAXMSGSIZE long. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3870 for (;;) |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3871 { |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3872 if (channel_wait(channel, fd, 0) != CW_READY) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3873 break; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3874 if (use_socket) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8074
diff
changeset
|
3875 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
|
3876 else |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8074
diff
changeset
|
3877 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
|
3878 if (len <= 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3879 break; // error or nothing more to read |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3880 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3881 // Store the read message in the queue. |
8755
7038ec89d1fd
commit https://github.com/vim/vim/commit/46c00a6565b8f1f4b7b1041d03eaceaf6ffc4aee
Christian Brabandt <cb@256bit.org>
parents:
8753
diff
changeset
|
3882 channel_save(channel, part, buf, len, FALSE, "RECV "); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3883 readlen += len; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3884 } |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3885 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3886 // 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
|
3887 if (readlen <= 0) |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
3888 { |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
3889 if (!channel->ch_keep_open) |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
3890 ch_close_part_on_error(channel, part, (len < 0), func); |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
3891 } |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3892 #if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK) |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
3893 else if (CH_HAS_GUI && gtk_main_level() > 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3894 // 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
|
3895 gtk_main_quit(); |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3896 #endif |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3897 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3898 |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3899 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3900 * 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
|
3901 * read or the timeout expires. |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3902 * When "raw" is TRUE don't block waiting on a NL. |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3903 * Does not trigger timers or handle messages. |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3904 * 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
|
3905 * 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
|
3906 */ |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3907 static char_u * |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3908 channel_read_block( |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3909 channel_T *channel, ch_part_T part, int timeout, int raw, int *outlen) |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3910 { |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3911 char_u *buf; |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3912 char_u *msg; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3913 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
|
3914 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
|
3915 char_u *nl; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3916 readq_T *node; |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3917 |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3918 ch_log(channel, "Blocking %s read, timeout: %d msec", |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3919 mode == CH_MODE_RAW ? "RAW" : "NL", timeout); |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3920 |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3921 while (TRUE) |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3922 { |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3923 node = channel_peek(channel, part); |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3924 if (node != NULL) |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3925 { |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3926 if (mode == CH_MODE_RAW || (mode == CH_MODE_NL |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3927 && channel_first_nl(node) != NULL)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3928 // got a complete message |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3929 break; |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3930 if (channel_collapse(channel, part, mode == CH_MODE_NL) == OK) |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3931 continue; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3932 // If not blocking or nothing more is coming then return what we |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3933 // have. |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3934 if (raw || fd == INVALID_FD) |
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3935 break; |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3936 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
3937 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3938 // Wait for up to the channel timeout. |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
3939 if (fd == INVALID_FD) |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3940 return NULL; |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
3941 if (channel_wait(channel, fd, timeout) != CW_READY) |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
3942 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
3943 ch_log(channel, "Timed out"); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
3944 return NULL; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
3945 } |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
3946 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
|
3947 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3948 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3949 // We have a complete message now. |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
3950 if (mode == CH_MODE_RAW || outlen != NULL) |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3951 { |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3952 msg = channel_get_all(channel, part, outlen); |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3953 } |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3954 else |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3955 { |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3956 char_u *p; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3957 |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3958 buf = node->rq_buffer; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3959 nl = channel_first_nl(node); |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3960 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3961 // Convert NUL to NL, the internal representation. |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3962 for (p = buf; (nl == NULL || p < nl) && p < buf + node->rq_buflen; ++p) |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3963 if (*p == NUL) |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3964 *p = NL; |
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3965 |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3966 if (nl == NULL) |
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3967 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3968 // must be a closed channel with missing NL |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3969 msg = channel_get(channel, part, NULL); |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3970 } |
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
3971 else if (nl + 1 == buf + node->rq_buflen) |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3972 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3973 // get the whole buffer |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
3974 msg = channel_get(channel, part, NULL); |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3975 *nl = NUL; |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3976 } |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3977 else |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3978 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3979 // Copy the message into allocated memory and remove it from the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
3980 // buffer. |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20577
diff
changeset
|
3981 msg = vim_strnsave(buf, nl - buf); |
9246
6ee88fa405b3
commit https://github.com/vim/vim/commit/5f1032d2a55b9417a0a6fa225e35089c98a5a419
Christian Brabandt <cb@256bit.org>
parents:
9238
diff
changeset
|
3982 channel_consume(channel, part, (int)(nl - buf) + 1); |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3983 } |
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3984 } |
12443
579faede5d9c
patch 8.0.1101: channel write fails if writing to log fails
Christian Brabandt <cb@256bit.org>
parents:
12407
diff
changeset
|
3985 if (ch_log_active()) |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
3986 ch_log(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
|
3987 return msg; |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
3988 } |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
3989 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3990 static int channel_blocking_wait = 0; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3991 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3992 /* |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3993 * Return TRUE if in a blocking wait that might trigger callbacks. |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3994 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3995 int |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3996 channel_in_blocking_wait(void) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3997 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3998 return channel_blocking_wait > 0; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
3999 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
4000 |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4001 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4002 * 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
|
4003 * result in "rettv". |
8157
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
4004 * 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
|
4005 * Blocks until the message is received or the timeout is reached. |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4006 * In corner cases this can be called recursively, that is why ch_block_ids is |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4007 * a list. |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4008 */ |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
4009 static int |
8157
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
4010 channel_read_json_block( |
8310
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
4011 channel_T *channel, |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4012 ch_part_T part, |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4013 int timeout_arg, |
8310
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
4014 int id, |
aec8f8ce8e4c
commit https://github.com/vim/vim/commit/d6051b5eb83687f60bb4a2f3d5cd23fe8b290eb4
Christian Brabandt <cb@256bit.org>
parents:
8297
diff
changeset
|
4015 typval_T **rettv) |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4016 { |
7997
c1c9ab17e197
commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents:
7988
diff
changeset
|
4017 int more; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8055
diff
changeset
|
4018 sock_T fd; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4019 int timeout; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4020 chanpart_T *chanpart = &channel->ch_part[part]; |
28511
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
4021 ch_mode_T mode = channel->ch_part[part].ch_mode; |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4022 int retval = FAIL; |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4023 |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4024 ch_log(channel, "Blocking read JSON for id %d", id); |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
4025 ++channel_blocking_wait; |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4026 |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4027 if (id >= 0) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4028 channel_add_block_id(chanpart, id); |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4029 |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4030 for (;;) |
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4031 { |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4032 if (mode == CH_MODE_LSP) |
28511
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
4033 // In the "lsp" mode, the http header and the json payload may be |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
4034 // received in multiple messages. So concatenate all the received |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
4035 // messages. |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
4036 (void)channel_collapse(channel, part, FALSE); |
d7ca583e5772
patch 8.2.4780: parsing an LSP message fails when it is split
Bram Moolenaar <Bram@vim.org>
parents:
28493
diff
changeset
|
4037 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4038 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
|
4039 |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4040 // search for message "id" |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10422
diff
changeset
|
4041 if (channel_get_json(channel, part, id, TRUE, rettv) == OK) |
7997
c1c9ab17e197
commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents:
7988
diff
changeset
|
4042 { |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4043 ch_log(channel, "Received JSON for id %d", id); |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4044 retval = OK; |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4045 break; |
7997
c1c9ab17e197
commit https://github.com/vim/vim/commit/e56bf15c163a921ce9e1c09c0d5b3a03efc63324
Christian Brabandt <cb@256bit.org>
parents:
7988
diff
changeset
|
4046 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4047 |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4048 if (!more) |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4049 { |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4050 void *prev_readahead_ptr = channel_readahead_pointer(channel, part); |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4051 void *readahead_ptr; |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4052 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4053 // Handle any other messages in the queue. If done some more |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4054 // messages may have arrived. |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4055 if (channel_parse_messages()) |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4056 continue; |
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4057 |
28347
d6892ed619e0
patch 8.2.4699: hard to reproduce hang when reading from a channel
Bram Moolenaar <Bram@vim.org>
parents:
28317
diff
changeset
|
4058 // channel_parse_messages() may fill the queue with new data to |
28612
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4059 // process. Only loop when the readahead changed, otherwise we |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4060 // would busy-loop. |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4061 readahead_ptr = channel_readahead_pointer(channel, part); |
352806724e12
patch 8.2.4830: possible endless loop if there is unused typahead
Bram Moolenaar <Bram@vim.org>
parents:
28528
diff
changeset
|
4062 if (readahead_ptr != NULL && readahead_ptr != prev_readahead_ptr) |
28347
d6892ed619e0
patch 8.2.4699: hard to reproduce hang when reading from a channel
Bram Moolenaar <Bram@vim.org>
parents:
28317
diff
changeset
|
4063 continue; |
d6892ed619e0
patch 8.2.4699: hard to reproduce hang when reading from a channel
Bram Moolenaar <Bram@vim.org>
parents:
28317
diff
changeset
|
4064 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4065 // Wait for up to the timeout. If there was an incomplete message |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4066 // use the deadline for that. |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4067 timeout = timeout_arg; |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
4068 if (chanpart->ch_wait_len > 0) |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4069 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
4070 #ifdef MSWIN |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4071 timeout = chanpart->ch_deadline - GetTickCount() + 1; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4072 #else |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4073 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4074 struct timeval now_tv; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4075 |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4076 gettimeofday(&now_tv, NULL); |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4077 timeout = (chanpart->ch_deadline.tv_sec |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4078 - now_tv.tv_sec) * 1000 |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4079 + (chanpart->ch_deadline.tv_usec |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4080 - now_tv.tv_usec) / 1000 |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4081 + 1; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4082 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4083 #endif |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4084 if (timeout < 0) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4085 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4086 // Something went wrong, channel_parse_json() didn't |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4087 // discard message. Cancel waiting. |
10845
c31782d57569
patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents:
10587
diff
changeset
|
4088 chanpart->ch_wait_len = 0; |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4089 timeout = timeout_arg; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4090 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4091 else if (timeout > timeout_arg) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4092 timeout = timeout_arg; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4093 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4094 fd = chanpart->ch_fd; |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4095 if (fd == INVALID_FD |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4096 || channel_wait(channel, fd, timeout) != CW_READY) |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4097 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4098 if (timeout == timeout_arg) |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4099 { |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4100 if (fd != INVALID_FD) |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4101 ch_log(channel, "Timed out on id %d", id); |
8655
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4102 break; |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4103 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4104 } |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4105 else |
1eb302bf2475
commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents:
8653
diff
changeset
|
4106 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
|
4107 } |
7868
17e6ff1a74f1
commit https://github.com/vim/vim/commit/19d2f1589850d7db1ce77efec052929246f156e2
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
4108 } |
17024
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4109 if (id >= 0) |
727f8cc87a45
patch 8.1.1512: ch_evalexpr() hangs when used recursively
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
4110 channel_remove_block_id(chanpart, id); |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18102
diff
changeset
|
4111 --channel_blocking_wait; |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4112 |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4113 return retval; |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
4114 } |
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
4115 |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4116 /* |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4117 * Get the channel from the argument. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4118 * Returns NULL if the handle is invalid. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4119 * When "check_open" is TRUE check that the channel can be used. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4120 * When "reading" is TRUE "check_open" considers typeahead useful. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4121 * "part" is used to check typeahead, when PART_COUNT use the default part. |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4122 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4123 static channel_T * |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4124 get_channel_arg(typval_T *tv, int check_open, int reading, ch_part_T part) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4125 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4126 channel_T *channel = NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4127 int has_readahead = FALSE; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4128 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4129 if (tv->v_type == VAR_JOB) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4130 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4131 if (tv->vval.v_job != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4132 channel = tv->vval.v_job->jv_channel; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4133 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4134 else if (tv->v_type == VAR_CHANNEL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4135 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4136 channel = tv->vval.v_channel; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4137 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4138 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4139 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
4140 semsg(_(e_invalid_argument_str), tv_get_string(tv)); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4141 return NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4142 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4143 if (channel != NULL && reading) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4144 has_readahead = channel_has_readahead(channel, |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4145 part != PART_COUNT ? part : channel_part_read(channel)); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4146 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4147 if (check_open && (channel == NULL || (!channel_is_open(channel) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4148 && !(reading && has_readahead)))) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4149 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
4150 emsg(_(e_not_an_open_channel)); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4151 return NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4152 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4153 return channel; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4154 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4155 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4156 /* |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4157 * Common for ch_read() and ch_readraw(). |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4158 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
4159 static void |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4160 common_channel_read(typval_T *argvars, typval_T *rettv, int raw, int blob) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4161 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4162 channel_T *channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4163 ch_part_T part = PART_COUNT; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4164 jobopt_T opt; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4165 int mode; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4166 int timeout; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4167 int id = -1; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4168 typval_T *listtv = NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4169 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4170 // return an empty string by default |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4171 rettv->v_type = VAR_STRING; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4172 rettv->vval.v_string = NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4173 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
4174 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
4175 && (check_for_chan_or_job_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
4176 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
4177 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
4178 |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4179 clear_job_options(&opt); |
12056
0498547dace0
patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
4180 if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID, 0) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4181 == FAIL) |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4182 goto theend; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4183 |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
4184 if (opt.jo_set & JO_PART) |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
4185 part = opt.jo_part; |
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
4186 channel = get_channel_arg(&argvars[0], TRUE, TRUE, part); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4187 if (channel != NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4188 { |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4189 if (part == PART_COUNT) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4190 part = channel_part_read(channel); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4191 mode = channel_get_mode(channel, part); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4192 timeout = channel_get_timeout(channel, part); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4193 if (opt.jo_set & JO_TIMEOUT) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4194 timeout = opt.jo_timeout; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4195 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4196 if (blob) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4197 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4198 int outlen = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4199 char_u *p = channel_read_block(channel, part, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4200 timeout, TRUE, &outlen); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4201 if (p != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4202 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4203 blob_T *b = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4204 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4205 if (b != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4206 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4207 b->bv_ga.ga_len = outlen; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4208 if (ga_grow(&b->bv_ga, outlen) == FAIL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4209 blob_free(b); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4210 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4211 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4212 memcpy(b->bv_ga.ga_data, p, outlen); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4213 rettv_blob_set(rettv, b); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4214 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4215 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4216 vim_free(p); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4217 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4218 } |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4219 else if (raw || mode == CH_MODE_RAW || mode == CH_MODE_NL) |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
4220 rettv->vval.v_string = channel_read_block(channel, part, |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4221 timeout, raw, NULL); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4222 else |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4223 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4224 if (opt.jo_set & JO_ID) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4225 id = opt.jo_id; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4226 channel_read_json_block(channel, part, timeout, id, &listtv); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4227 if (listtv != NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4228 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4229 *rettv = *listtv; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4230 vim_free(listtv); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4231 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4232 else |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4233 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4234 rettv->v_type = VAR_SPECIAL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4235 rettv->vval.v_number = VVAL_NONE; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4236 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4237 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4238 } |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4239 |
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4240 theend: |
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4241 free_job_options(&opt); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4242 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4243 |
20277
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4244 #if defined(MSWIN) || defined(__HAIKU__) || defined(FEAT_GUI) || defined(PROTO) |
8172
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4245 /* |
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4246 * 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
|
4247 * The data is put in the read queue. |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
4248 * if "only_keep_open" is TRUE only check channels where ch_keep_open is set. |
8172
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4249 */ |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
4250 void |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
4251 channel_handle_events(int only_keep_open) |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
4252 { |
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
4253 channel_T *channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4254 ch_part_T part; |
8172
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4255 sock_T fd; |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
4256 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
4257 FOR_ALL_CHANNELS(channel) |
8122
39532ee7dd43
commit https://github.com/vim/vim/commit/ed5a78e11c80c7b13b233149fd4273b71fc96262
Christian Brabandt <cb@256bit.org>
parents:
8114
diff
changeset
|
4258 { |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
4259 if (only_keep_open && !channel->ch_keep_open) |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
4260 continue; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12178
diff
changeset
|
4261 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4262 // check the socket and pipes |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4263 for (part = PART_SOCK; part < PART_IN; ++part) |
8172
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4264 { |
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4265 fd = channel->ch_part[part].ch_fd; |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4266 if (fd != INVALID_FD) |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4267 { |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4268 int r = channel_wait(channel, fd, 0); |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4269 |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4270 if (r == CW_READY) |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4271 channel_read(channel, part, "channel_handle_events"); |
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4272 else if (r == CW_ERROR) |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4273 ch_close_part_on_error(channel, part, TRUE, |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4274 "channel_handle_events"); |
9003
072556995a8e
commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents:
8928
diff
changeset
|
4275 } |
8172
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8165
diff
changeset
|
4276 } |
20277
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4277 |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4278 # ifdef __HAIKU__ |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4279 // Workaround for Haiku: Since select/poll cannot detect EOF from tty, |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4280 // should close fds when the job has finished if 'channel' connects to |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4281 // the pty. |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4282 if (channel->ch_job != NULL) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4283 { |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4284 job_T *job = channel->ch_job; |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4285 |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4286 if (job->jv_tty_out != NULL && job->jv_status == JOB_FINISHED) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4287 for (part = PART_SOCK; part < PART_COUNT; ++part) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4288 ch_close_part(channel, part); |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4289 } |
7780
e09af43f98f7
commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents:
7774
diff
changeset
|
4290 # endif |
20277
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4291 } |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4292 } |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4293 #endif |
7780
e09af43f98f7
commit https://github.com/vim/vim/commit/85be35f33ea848b50e84d57321a45ebfedfad669
Christian Brabandt <cb@256bit.org>
parents:
7774
diff
changeset
|
4294 |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4295 # if defined(FEAT_GUI) || defined(PROTO) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4296 /* |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4297 * Return TRUE when there is any channel with a keep_open flag. |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4298 */ |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4299 int |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4300 channel_any_keep_open() |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4301 { |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4302 channel_T *channel; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4303 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
4304 FOR_ALL_CHANNELS(channel) |
12250
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4305 if (channel->ch_keep_open) |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4306 return TRUE; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4307 return FALSE; |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4308 } |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4309 # endif |
ac8b2f9c1409
patch 8.0.1005: terminal without job updates slowly in GUI
Christian Brabandt <cb@256bit.org>
parents:
12246
diff
changeset
|
4310 |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4311 /* |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4312 * Set "channel"/"part" to non-blocking. |
12158
b3e39486880a
patch 8.0.0959: build failure on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12154
diff
changeset
|
4313 * Only works for sockets and pipes. |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4314 */ |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4315 void |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4316 channel_set_nonblock(channel_T *channel, ch_part_T part) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4317 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4318 chanpart_T *ch_part = &channel->ch_part[part]; |
14675
71c17b688bc6
patch 8.1.0350: Vim may block on ch_sendraw()
Christian Brabandt <cb@256bit.org>
parents:
14499
diff
changeset
|
4319 int fd = ch_part->ch_fd; |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4320 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4321 if (fd != INVALID_FD) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4322 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
4323 #ifdef MSWIN |
12158
b3e39486880a
patch 8.0.0959: build failure on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12154
diff
changeset
|
4324 u_long val = 1; |
b3e39486880a
patch 8.0.0959: build failure on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12154
diff
changeset
|
4325 |
b3e39486880a
patch 8.0.0959: build failure on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12154
diff
changeset
|
4326 ioctlsocket(fd, FIONBIO, &val); |
b3e39486880a
patch 8.0.0959: build failure on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12154
diff
changeset
|
4327 #else |
12178
a1014f647b61
patch 8.0.0969: Coverity warning for unused return value
Christian Brabandt <cb@256bit.org>
parents:
12168
diff
changeset
|
4328 (void)fcntl(fd, F_SETFL, O_NONBLOCK); |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4329 #endif |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4330 ch_part->ch_nonblocking = TRUE; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4331 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4332 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4333 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4334 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4335 * 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
|
4336 * 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
|
4337 * Return FAIL or OK. |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4338 */ |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
4339 int |
10363
471b87c3b67d
commit https://github.com/vim/vim/commit/79cbdcb1eeead00bad6fc64ab4a53e5860d5a663
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
4340 channel_send( |
471b87c3b67d
commit https://github.com/vim/vim/commit/79cbdcb1eeead00bad6fc64ab4a53e5860d5a663
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
4341 channel_T *channel, |
471b87c3b67d
commit https://github.com/vim/vim/commit/79cbdcb1eeead00bad6fc64ab4a53e5860d5a663
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
4342 ch_part_T part, |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4343 char_u *buf_arg, |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4344 int len_arg, |
10363
471b87c3b67d
commit https://github.com/vim/vim/commit/79cbdcb1eeead00bad6fc64ab4a53e5860d5a663
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
4345 char *fun) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4346 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4347 int res; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4348 sock_T fd; |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4349 chanpart_T *ch_part = &channel->ch_part[part]; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4350 int did_use_queue = FALSE; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4351 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4352 fd = ch_part->ch_fd; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4353 if (fd == INVALID_FD) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4354 { |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4355 if (!channel->ch_error && fun != NULL) |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4356 { |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
4357 ch_error(channel, "%s(): write while not connected", fun); |
26948
51ddf6740ac6
patch 8.2.4003: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4358 semsg(_(e_str_write_while_not_connected), fun); |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4359 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4360 channel->ch_error = TRUE; |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
4361 return FAIL; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4362 } |
7788
192ae655ac91
commit https://github.com/vim/vim/commit/3b5f929b18492fec291d1ec95a91f54e5912c03b
Christian Brabandt <cb@256bit.org>
parents:
7780
diff
changeset
|
4363 |
14675
71c17b688bc6
patch 8.1.0350: Vim may block on ch_sendraw()
Christian Brabandt <cb@256bit.org>
parents:
14499
diff
changeset
|
4364 if (channel->ch_nonblock && !ch_part->ch_nonblocking) |
71c17b688bc6
patch 8.1.0350: Vim may block on ch_sendraw()
Christian Brabandt <cb@256bit.org>
parents:
14499
diff
changeset
|
4365 channel_set_nonblock(channel, part); |
71c17b688bc6
patch 8.1.0350: Vim may block on ch_sendraw()
Christian Brabandt <cb@256bit.org>
parents:
14499
diff
changeset
|
4366 |
12443
579faede5d9c
patch 8.0.1101: channel write fails if writing to log fails
Christian Brabandt <cb@256bit.org>
parents:
12407
diff
changeset
|
4367 if (ch_log_active()) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4368 { |
14499
2661d77e440e
patch 8.1.0263: channel log doesn't show part of channel
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
4369 ch_log_lead("SEND ", channel, part); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4370 fprintf(log_fd, "'"); |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14675
diff
changeset
|
4371 vim_ignored = (int)fwrite(buf_arg, len_arg, 1, log_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4372 fprintf(log_fd, "'\n"); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4373 fflush(log_fd); |
18160
770987511384
patch 8.1.2075: get many log messages when waiting for a typed character
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
4374 did_repeated_msg = 0; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4375 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4376 |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4377 for (;;) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4378 { |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4379 writeq_T *wq = &ch_part->ch_writeque; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4380 char_u *buf; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4381 int len; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4382 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4383 if (wq->wq_next != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4384 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4385 // first write what was queued |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4386 buf = wq->wq_next->wq_ga.ga_data; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4387 len = wq->wq_next->wq_ga.ga_len; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4388 did_use_queue = TRUE; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4389 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4390 else |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4391 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4392 if (len_arg == 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4393 // nothing to write, called from channel_select_check() |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4394 return OK; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4395 buf = buf_arg; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4396 len = len_arg; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4397 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4398 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4399 if (part == PART_SOCK) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4400 res = sock_write(fd, (char *)buf, len); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4401 else |
15577
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4402 { |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4403 res = fd_write(fd, (char *)buf, len); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15764
diff
changeset
|
4404 #ifdef MSWIN |
15577
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4405 if (channel->ch_named_pipe && res < 0) |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4406 { |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4407 DisconnectNamedPipe((HANDLE)fd); |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4408 ConnectNamedPipe((HANDLE)fd, NULL); |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4409 } |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4410 #endif |
f611222a4349
patch 8.1.0796: MS-Windows 7: problem with named pipe on channel
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4411 } |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4412 if (res < 0 && (errno == EWOULDBLOCK |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4413 #ifdef EAGAIN |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4414 || errno == EAGAIN |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4415 #endif |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4416 )) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4417 res = 0; // nothing got written |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4418 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4419 if (res >= 0 && ch_part->ch_nonblocking) |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4420 { |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4421 writeq_T *entry = wq->wq_next; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4422 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4423 if (did_use_queue) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4424 ch_log(channel, "Sent %d bytes now", res); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4425 if (res == len) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4426 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4427 // Wrote all the buf[len] bytes. |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4428 if (entry != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4429 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4430 // Remove the entry from the write queue. |
12403
b44bd42a374e
patch 8.0.1081: memory leak for the channel write queue
Christian Brabandt <cb@256bit.org>
parents:
12393
diff
changeset
|
4431 remove_from_writeque(wq, entry); |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4432 continue; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4433 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4434 if (did_use_queue) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4435 ch_log(channel, "Write queue empty"); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4436 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4437 else |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4438 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4439 // Wrote only buf[res] bytes, can't write more now. |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4440 if (entry != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4441 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4442 if (res > 0) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4443 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4444 // Remove the bytes that were written. |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4445 mch_memmove(entry->wq_ga.ga_data, |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4446 (char *)entry->wq_ga.ga_data + res, |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4447 len - res); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4448 entry->wq_ga.ga_len -= res; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4449 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4450 buf = buf_arg; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4451 len = len_arg; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4452 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4453 else |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4454 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4455 buf += res; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4456 len -= res; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4457 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4458 ch_log(channel, "Adding %d bytes to the write queue", len); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4459 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4460 // Append the not written bytes of the argument to the write |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4461 // buffer. Limit entries to 4000 bytes. |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4462 if (wq->wq_prev != NULL |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4463 && wq->wq_prev->wq_ga.ga_len + len < 4000) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4464 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4465 writeq_T *last = wq->wq_prev; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4466 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4467 // append to the last entry |
17308
d04de6c49f59
patch 8.1.1653: ubsan warns for possibly passing NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
17212
diff
changeset
|
4468 if (len > 0 && ga_grow(&last->wq_ga, len) == OK) |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4469 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4470 mch_memmove((char *)last->wq_ga.ga_data |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4471 + last->wq_ga.ga_len, |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4472 buf, len); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4473 last->wq_ga.ga_len += len; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4474 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4475 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4476 else |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4477 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4478 writeq_T *last = ALLOC_ONE(writeq_T); |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4479 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4480 if (last != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4481 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4482 last->wq_prev = wq->wq_prev; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4483 last->wq_next = NULL; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4484 if (wq->wq_prev == NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4485 wq->wq_next = last; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4486 else |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4487 wq->wq_prev->wq_next = last; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4488 wq->wq_prev = last; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4489 ga_init2(&last->wq_ga, 1, 1000); |
17308
d04de6c49f59
patch 8.1.1653: ubsan warns for possibly passing NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
17212
diff
changeset
|
4490 if (len > 0 && ga_grow(&last->wq_ga, len) == OK) |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4491 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4492 mch_memmove(last->wq_ga.ga_data, buf, len); |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4493 last->wq_ga.ga_len = len; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4494 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4495 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4496 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4497 } |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4498 } |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4499 else if (res != len) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4500 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4501 if (!channel->ch_error && fun != NULL) |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4502 { |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4503 ch_error(channel, "%s(): write failed", fun); |
26948
51ddf6740ac6
patch 8.2.4003: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4504 semsg(_(e_str_write_failed), fun); |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4505 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4506 channel->ch_error = TRUE; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4507 return FAIL; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4508 } |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4509 |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4510 channel->ch_error = FALSE; |
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4511 return OK; |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4512 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4513 } |
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
4514 |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4515 /* |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4516 * Common for "ch_sendexpr()" and "ch_sendraw()". |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4517 * Returns the channel if the caller should read the response. |
9355
40c8a8b012b5
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
4518 * Sets "part_read" to the read fd. |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4519 * Otherwise returns NULL. |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4520 */ |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4521 static channel_T * |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4522 send_common( |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4523 typval_T *argvars, |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4524 char_u *text, |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4525 int len, |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4526 int id, |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4527 int eval, |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4528 jobopt_T *opt, |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4529 char *fun, |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4530 ch_part_T *part_read) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4531 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4532 channel_T *channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4533 ch_part_T part_send; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4534 |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4535 clear_job_options(opt); |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
4536 channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4537 if (channel == NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4538 return NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4539 part_send = channel_part_send(channel); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4540 *part_read = channel_part_read(channel); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4541 |
12056
0498547dace0
patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
4542 if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT, 0) == FAIL) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4543 return NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4544 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4545 // Set the callback. An empty callback means no callback and not reading |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4546 // the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4547 // allowed. |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4548 if (opt->jo_callback.cb_name != NULL && *opt->jo_callback.cb_name != NUL) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4549 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4550 if (eval) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4551 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
4552 semsg(_(e_cannot_use_callback_with_str), fun); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4553 return NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4554 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4555 channel_set_req_callback(channel, *part_read, &opt->jo_callback, id); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4556 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4557 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4558 if (channel_send(channel, part_send, text, len, fun) == OK |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4559 && opt->jo_callback.cb_name == NULL) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4560 return channel; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4561 return NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4562 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4563 |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4564 /* |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4565 * common for "ch_evalexpr()" and "ch_sendexpr()" |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4566 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
4567 static void |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4568 ch_expr_common(typval_T *argvars, typval_T *rettv, int eval) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4569 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4570 char_u *text; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4571 typval_T *listtv; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4572 channel_T *channel; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4573 int id; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4574 ch_mode_T ch_mode; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4575 ch_part_T part_send; |
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4576 ch_part_T part_read; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4577 jobopt_T opt; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4578 int timeout; |
28467
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4579 int callback_present = FALSE; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4580 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4581 // return an empty string by default |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4582 rettv->v_type = VAR_STRING; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4583 rettv->vval.v_string = NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4584 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4585 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4586 && (check_for_chan_or_job_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4587 || check_for_opt_dict_arg(argvars, 2) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4588 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4589 |
9007
d5c6f1c5cd28
commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents:
9003
diff
changeset
|
4590 channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4591 if (channel == NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4592 return; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4593 part_send = channel_part_send(channel); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4594 |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4595 ch_mode = channel_get_mode(channel, part_send); |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4596 if (ch_mode == CH_MODE_RAW || ch_mode == CH_MODE_NL) |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4597 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26948
diff
changeset
|
4598 emsg(_(e_cannot_use_evalexpr_sendexpr_with_raw_or_nl_channel)); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4599 return; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4600 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4601 |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4602 if (ch_mode == CH_MODE_LSP) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4603 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4604 dict_T *d; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4605 dictitem_T *di; |
28467
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4606 |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4607 // return an empty dict by default |
28493
9f8563d05629
patch 8.2.4771: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
28467
diff
changeset
|
4608 if (rettv_dict_alloc(rettv) == FAIL) |
9f8563d05629
patch 8.2.4771: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
28467
diff
changeset
|
4609 return; |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4610 |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4611 if (check_for_dict_arg(argvars, 1) == FAIL) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4612 return; |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4613 |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4614 d = argvars[1].vval.v_dict; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4615 di = dict_find(d, (char_u *)"id", -1); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4616 if (di != NULL && di->di_tv.v_type != VAR_NUMBER) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4617 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4618 // only number type is supported for the 'id' item |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4619 semsg(_(e_invalid_value_for_argument_str), "id"); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4620 return; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4621 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4622 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4623 if (argvars[2].v_type == VAR_DICT) |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
28244
diff
changeset
|
4624 if (dict_has_key(argvars[2].vval.v_dict, "callback")) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4625 callback_present = TRUE; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4626 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4627 if (eval || callback_present) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4628 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4629 // When evaluating an expression or sending an expression with a |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4630 // callback, always assign a generated ID |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4631 id = ++channel->ch_last_msg_id; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4632 if (di == NULL) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4633 dict_add_number(d, "id", id); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4634 else |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4635 di->di_tv.vval.v_number = id; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4636 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4637 else |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4638 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4639 // When sending an expression, if the message has an 'id' item, |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4640 // then use it. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4641 id = 0; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4642 if (di != NULL) |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4643 id = di->di_tv.vval.v_number; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4644 } |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
28244
diff
changeset
|
4645 if (!dict_has_key(d, "jsonrpc")) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4646 dict_add_string(d, "jsonrpc", (char_u *)"2.0"); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4647 text = json_encode_lsp_msg(&argvars[1]); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4648 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4649 else |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4650 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4651 id = ++channel->ch_last_msg_id; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4652 text = json_encode_nr_expr(id, &argvars[1], |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4653 (ch_mode == CH_MODE_JS ? JSON_JS : 0) | JSON_NL); |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4654 } |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4655 if (text == NULL) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4656 return; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4657 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4658 channel = send_common(argvars, text, (int)STRLEN(text), id, eval, &opt, |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4659 eval ? "ch_evalexpr" : "ch_sendexpr", &part_read); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4660 vim_free(text); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4661 if (channel != NULL && eval) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4662 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4663 if (opt.jo_set & JO_TIMEOUT) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4664 timeout = opt.jo_timeout; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4665 else |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4666 timeout = channel_get_timeout(channel, part_read); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4667 if (channel_read_json_block(channel, part_read, timeout, id, &listtv) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4668 == OK) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4669 { |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4670 if (ch_mode == CH_MODE_LSP) |
28244
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4671 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4672 *rettv = *listtv; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4673 // Change the type to avoid the value being freed. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4674 listtv->v_type = VAR_NUMBER; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4675 free_tv(listtv); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4676 } |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4677 else |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4678 { |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4679 list_T *list = listtv->vval.v_list; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4680 |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4681 // Move the item from the list and then change the type to |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4682 // avoid the value being freed. |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4683 *rettv = list->lv_u.mat.lv_last->li_tv; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4684 list->lv_u.mat.lv_last->li_tv.v_type = VAR_NUMBER; |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4685 free_tv(listtv); |
85b07a942518
patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
4686 } |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4687 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4688 } |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4689 free_job_options(&opt); |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
4690 if (ch_mode == CH_MODE_LSP && !eval && callback_present) |
28467
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4691 { |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4692 // if ch_sendexpr() is used to send a LSP message and a callback |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4693 // function is specified, then return the generated identifier for the |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4694 // message. The user can use this to cancel the request (if needed). |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4695 if (rettv->vval.v_dict != NULL) |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4696 dict_add_number(rettv->vval.v_dict, "id", id); |
3beb14b12bbd
patch 8.2.4758: when using an LSP channel want to get the message ID
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
4697 } |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4698 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4699 |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4700 /* |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4701 * common for "ch_evalraw()" and "ch_sendraw()" |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4702 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
4703 static void |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4704 ch_raw_common(typval_T *argvars, typval_T *rettv, int eval) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4705 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4706 char_u buf[NUMBUFLEN]; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4707 char_u *text; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4708 int len; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4709 channel_T *channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4710 ch_part_T part_read; |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4711 jobopt_T opt; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4712 int timeout; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4713 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4714 // return an empty string by default |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4715 rettv->v_type = VAR_STRING; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4716 rettv->vval.v_string = NULL; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4717 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4718 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4719 && (check_for_chan_or_job_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4720 || check_for_string_or_blob_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4721 || check_for_opt_dict_arg(argvars, 2) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4722 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
4723 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4724 if (argvars[1].v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4725 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4726 text = argvars[1].vval.v_blob->bv_ga.ga_data; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4727 len = argvars[1].vval.v_blob->bv_ga.ga_len; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4728 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4729 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4730 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4731 text = tv_get_string_buf(&argvars[1], buf); |
15508
69207f77754a
patch 8.1.0762: compiler warning
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4732 len = (int)STRLEN(text); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4733 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4734 channel = send_common(argvars, text, len, 0, eval, &opt, |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4735 eval ? "ch_evalraw" : "ch_sendraw", &part_read); |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4736 if (channel != NULL && eval) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4737 { |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4738 if (opt.jo_set & JO_TIMEOUT) |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4739 timeout = opt.jo_timeout; |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4740 else |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4741 timeout = channel_get_timeout(channel, part_read); |
13010
c522585ce88d
patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents:
12818
diff
changeset
|
4742 rettv->vval.v_string = channel_read_block(channel, part_read, |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15369
diff
changeset
|
4743 timeout, TRUE, NULL); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4744 } |
8859
03250bc0c63a
commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents:
8798
diff
changeset
|
4745 free_job_options(&opt); |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4746 } |
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
4747 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4748 #define KEEP_OPEN_TIME 20 // msec |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4749 |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4750 #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
|
4751 /* |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4752 * Add open channels to the poll struct. |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4753 * Return the adjusted struct index. |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4754 * 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
|
4755 */ |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4756 int |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4757 channel_poll_setup(int nfd_in, void *fds_in, int *towait) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4758 { |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4759 int nfd = nfd_in; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4760 channel_T *channel; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4761 struct pollfd *fds = fds_in; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4762 ch_part_T part; |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4763 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
4764 FOR_ALL_CHANNELS(channel) |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4765 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4766 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
|
4767 { |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4768 chanpart_T *ch_part = &channel->ch_part[part]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4769 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4770 if (ch_part->ch_fd != INVALID_FD) |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4771 { |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4772 if (channel->ch_keep_open) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4773 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4774 // For unknown reason poll() returns immediately for a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4775 // keep-open channel. Instead of adding it to the fds add |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4776 // a short timeout and check, like polling. |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4777 if (*towait < 0 || *towait > KEEP_OPEN_TIME) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4778 *towait = KEEP_OPEN_TIME; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4779 } |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4780 else |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4781 { |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4782 ch_part->ch_poll_idx = nfd; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4783 fds[nfd].fd = ch_part->ch_fd; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4784 fds[nfd].events = POLLIN; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4785 nfd++; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4786 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4787 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4788 else |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4789 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
|
4790 } |
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4791 } |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4792 |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4793 nfd = channel_fill_poll_write(nfd, fds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4794 |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4795 return nfd; |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4796 } |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4797 |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4798 /* |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4799 * 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
|
4800 */ |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4801 int |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4802 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
|
4803 { |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4804 int ret = ret_in; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4805 channel_T *channel; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4806 struct pollfd *fds = fds_in; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4807 ch_part_T part; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4808 int idx; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4809 chanpart_T *in_part; |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4810 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
4811 FOR_ALL_CHANNELS(channel) |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4812 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4813 for (part = PART_SOCK; part < PART_IN; ++part) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4814 { |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4815 idx = channel->ch_part[part].ch_poll_idx; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4816 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4817 if (ret > 0 && idx != -1 && (fds[idx].revents & POLLIN)) |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4818 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4819 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
|
4820 --ret; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4821 } |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4822 else if (channel->ch_part[part].ch_fd != INVALID_FD |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4823 && channel->ch_keep_open) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4824 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4825 // polling a keep-open channel |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4826 channel_read(channel, part, "channel_poll_check_keep_open"); |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4827 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4828 } |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4829 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4830 in_part = &channel->ch_part[PART_IN]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4831 idx = in_part->ch_poll_idx; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4832 if (ret > 0 && idx != -1 && (fds[idx].revents & POLLOUT)) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4833 { |
12168
51e5a8602624
patch 8.0.0964: channel write buffer does not work with poll()
Christian Brabandt <cb@256bit.org>
parents:
12158
diff
changeset
|
4834 channel_write_input(channel); |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4835 --ret; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4836 } |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4837 } |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4838 |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4839 return ret; |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4840 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4841 #endif // UNIX && !HAVE_SELECT |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4842 |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4843 #if (!defined(MSWIN) && defined(HAVE_SELECT)) || defined(PROTO) |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4844 |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4845 /* |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4846 * The "fd_set" type is hidden to avoid problems with the function proto. |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4847 */ |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4848 int |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4849 channel_select_setup( |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4850 int maxfd_in, |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4851 void *rfds_in, |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4852 void *wfds_in, |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4853 struct timeval *tv, |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4854 struct timeval **tvp) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4855 { |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4856 int maxfd = maxfd_in; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4857 channel_T *channel; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4858 fd_set *rfds = rfds_in; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4859 fd_set *wfds = wfds_in; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4860 ch_part_T part; |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4861 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
4862 FOR_ALL_CHANNELS(channel) |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4863 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4864 for (part = PART_SOCK; part < PART_IN; ++part) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4865 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4866 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
|
4867 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4868 if (fd != INVALID_FD) |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4869 { |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4870 if (channel->ch_keep_open) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4871 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4872 // For unknown reason select() returns immediately for a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4873 // keep-open channel. Instead of adding it to the rfds add |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4874 // a short timeout and check, like polling. |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4875 if (*tvp == NULL || tv->tv_sec > 0 |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4876 || tv->tv_usec > KEEP_OPEN_TIME * 1000) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4877 { |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4878 *tvp = tv; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4879 tv->tv_sec = 0; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4880 tv->tv_usec = KEEP_OPEN_TIME * 1000; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4881 } |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4882 } |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4883 else |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4884 { |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4885 FD_SET((int)fd, rfds); |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4886 if (maxfd < (int)fd) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4887 maxfd = (int)fd; |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4888 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4889 } |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4890 } |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4891 } |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4892 |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4893 maxfd = channel_fill_wfds(maxfd, wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4894 |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4895 return maxfd; |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4896 } |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4897 |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4898 /* |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4899 * The "fd_set" type is hidden to avoid problems with the function proto. |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4900 */ |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4901 int |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4902 channel_select_check(int ret_in, void *rfds_in, void *wfds_in) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4903 { |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4904 int ret = ret_in; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4905 channel_T *channel; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4906 fd_set *rfds = rfds_in; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4907 fd_set *wfds = wfds_in; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4908 ch_part_T part; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4909 chanpart_T *in_part; |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4910 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19820
diff
changeset
|
4911 FOR_ALL_CHANNELS(channel) |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4912 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4913 for (part = PART_SOCK; part < PART_IN; ++part) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4914 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4915 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
|
4916 |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4917 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
|
4918 { |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
4919 channel_read(channel, part, "channel_select_check"); |
12393
128cd982c7b8
patch 8.0.1076: term_start() does not take callbacks
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
4920 FD_CLR(fd, rfds); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4921 --ret; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
4922 } |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4923 else if (fd != INVALID_FD && channel->ch_keep_open) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4924 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4925 // polling a keep-open channel |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4926 channel_read(channel, part, "channel_select_check_keep_open"); |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12443
diff
changeset
|
4927 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8009
diff
changeset
|
4928 } |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4929 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4930 in_part = &channel->ch_part[PART_IN]; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4931 if (ret > 0 && in_part->ch_fd != INVALID_FD |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4932 && FD_ISSET(in_part->ch_fd, wfds)) |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4933 { |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4934 // Clear the flag first, ch_fd may change in channel_write_input(). |
13569
97720d9a01d4
patch 8.0.1657: crash when reading a channel
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
4935 FD_CLR(in_part->ch_fd, wfds); |
12154
71e10b81226d
patch 8.0.0957: a terminal job can deadlock when sending many keys
Christian Brabandt <cb@256bit.org>
parents:
12096
diff
changeset
|
4936 channel_write_input(channel); |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4937 --ret; |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8759
diff
changeset
|
4938 } |
20277
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4939 |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4940 # ifdef __HAIKU__ |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4941 // Workaround for Haiku: Since select/poll cannot detect EOF from tty, |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4942 // should close fds when the job has finished if 'channel' connects to |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4943 // the pty. |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4944 if (channel->ch_job != NULL) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4945 { |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4946 job_T *job = channel->ch_job; |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4947 |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4948 if (job->jv_tty_out != NULL && job->jv_status == JOB_FINISHED) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4949 for (part = PART_SOCK; part < PART_COUNT; ++part) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4950 ch_close_part(channel, part); |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4951 } |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20267
diff
changeset
|
4952 # endif |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
4953 } |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4954 |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4955 return ret; |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4956 } |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4957 #endif // !MSWIN && HAVE_SELECT |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4958 |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4959 /* |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4960 * Execute queued up commands. |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4961 * Invoked from the main loop when it's safe to execute received commands, |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
4962 * and during a blocking wait for ch_evalexpr(). |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4963 * 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
|
4964 */ |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
4965 int |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4966 channel_parse_messages(void) |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4967 { |
8055
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
4968 channel_T *channel = first_channel; |
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
4969 int ret = FALSE; |
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
4970 int r; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
4971 ch_part_T part = PART_SOCK; |
19820
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
4972 static int recursive = 0; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4973 #ifdef ELAPSED_FUNC |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15508
diff
changeset
|
4974 elapsed_T start_tv; |
19791
f46d3a9fe27d
patch 8.2.0452: channel_parse_messages() fails when called recursively
Bram Moolenaar <Bram@vim.org>
parents:
19772
diff
changeset
|
4975 #endif |
f46d3a9fe27d
patch 8.2.0452: channel_parse_messages() fails when called recursively
Bram Moolenaar <Bram@vim.org>
parents:
19772
diff
changeset
|
4976 |
f46d3a9fe27d
patch 8.2.0452: channel_parse_messages() fails when called recursively
Bram Moolenaar <Bram@vim.org>
parents:
19772
diff
changeset
|
4977 // The code below may invoke callbacks, which might call us back. |
19820
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
4978 // In a recursive call channels will not be closed. |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
4979 ++recursive; |
19791
f46d3a9fe27d
patch 8.2.0452: channel_parse_messages() fails when called recursively
Bram Moolenaar <Bram@vim.org>
parents:
19772
diff
changeset
|
4980 ++safe_to_invoke_callback; |
f46d3a9fe27d
patch 8.2.0452: channel_parse_messages() fails when called recursively
Bram Moolenaar <Bram@vim.org>
parents:
19772
diff
changeset
|
4981 |
f46d3a9fe27d
patch 8.2.0452: channel_parse_messages() fails when called recursively
Bram Moolenaar <Bram@vim.org>
parents:
19772
diff
changeset
|
4982 #ifdef ELAPSED_FUNC |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4983 ELAPSED_INIT(start_tv); |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4984 #endif |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4985 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4986 // Only do this message when another message was given, otherwise we get |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
4987 // lots of them. |
18160
770987511384
patch 8.1.2075: get many log messages when waiting for a typed character
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
4988 if ((did_repeated_msg & REPEATED_MSG_LOOKING) == 0) |
8428
4e22d0e7bfb1
commit https://github.com/vim/vim/commit/d0b6502a7ace39d6cd30874110a572371d10beae
Christian Brabandt <cb@256bit.org>
parents:
8422
diff
changeset
|
4989 { |
4e22d0e7bfb1
commit https://github.com/vim/vim/commit/d0b6502a7ace39d6cd30874110a572371d10beae
Christian Brabandt <cb@256bit.org>
parents:
8422
diff
changeset
|
4990 ch_log(NULL, "looking for messages on channels"); |
18160
770987511384
patch 8.1.2075: get many log messages when waiting for a typed character
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
4991 // now we should also give the message for SafeState |
770987511384
patch 8.1.2075: get many log messages when waiting for a typed character
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
4992 did_repeated_msg = REPEATED_MSG_LOOKING; |
8428
4e22d0e7bfb1
commit https://github.com/vim/vim/commit/d0b6502a7ace39d6cd30874110a572371d10beae
Christian Brabandt <cb@256bit.org>
parents:
8422
diff
changeset
|
4993 } |
8055
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
4994 while (channel != NULL) |
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
4995 { |
19820
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
4996 if (recursive == 1) |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
4997 { |
19820
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
4998 if (channel_can_close(channel)) |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
4999 { |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5000 channel->ch_to_be_closed = (1U << PART_COUNT); |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5001 channel_close_now(channel); |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5002 // channel may have been freed, start over |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5003 channel = first_channel; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5004 continue; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5005 } |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5006 if (channel->ch_to_be_freed || channel->ch_killing) |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5007 { |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5008 channel_free_contents(channel); |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5009 if (channel->ch_job != NULL) |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5010 channel->ch_job->jv_channel = NULL; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5011 |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5012 // free the channel and then start over |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5013 channel_free_channel(channel); |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5014 channel = first_channel; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5015 continue; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5016 } |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5017 if (channel->ch_refcount == 0 && !channel_still_useful(channel)) |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5018 { |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5019 // channel is no longer useful, free it |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5020 channel_free(channel); |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5021 channel = first_channel; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5022 part = PART_SOCK; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5023 continue; |
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5024 } |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
5025 } |
19820
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5026 |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
5027 if (channel->ch_part[part].ch_fd != INVALID_FD |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
5028 || channel_has_readahead(channel, part)) |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
5029 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5030 // Increase the refcount, in case the handler causes the channel |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5031 // to be unreferenced or closed. |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5032 ++channel->ch_refcount; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5033 r = may_invoke_callback(channel, part); |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5034 if (r == OK) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5035 ret = TRUE; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5036 if (channel_unref(channel) || (r == OK |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5037 #ifdef ELAPSED_FUNC |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5038 // Limit the time we loop here to 100 msec, otherwise |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5039 // Vim becomes unresponsive when the callback takes |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5040 // more than a bit of time. |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5041 && ELAPSED_FUNC(start_tv) < 100L |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5042 #endif |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5043 )) |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5044 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5045 // channel was freed or something was done, start over |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5046 channel = first_channel; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5047 part = PART_SOCK; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5048 continue; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5049 } |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
5050 } |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5051 if (part < PART_ERR) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5052 ++part; |
8055
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5053 else |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5054 { |
8055
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5055 channel = channel->ch_next; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5056 part = PART_SOCK; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5057 } |
8055
6db4b1c863ec
commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5058 } |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
5059 |
8928
e6916e1683bb
commit https://github.com/vim/vim/commit/7f7c3325d3f1baba32263a3457cfc4d90ecd5ff1
Christian Brabandt <cb@256bit.org>
parents:
8881
diff
changeset
|
5060 if (channel_need_redraw) |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
5061 { |
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
5062 channel_need_redraw = FALSE; |
26466
d413104a94c8
patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
5063 redraw_after_callback(TRUE, FALSE); |
8267
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
5064 } |
108d30ed34ba
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Christian Brabandt <cb@256bit.org>
parents:
8261
diff
changeset
|
5065 |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
5066 --safe_to_invoke_callback; |
19820
49e38e5472e6
patch 8.2.0466: not parsing messages recursively breaks the govim plugin
Bram Moolenaar <Bram@vim.org>
parents:
19797
diff
changeset
|
5067 --recursive; |
9085
d362e6df1deb
commit https://github.com/vim/vim/commit/fb6ffc732e65dbc459c89247ff78134402f1a18b
Christian Brabandt <cb@256bit.org>
parents:
9083
diff
changeset
|
5068 |
7899
93c61501c2cf
commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
7885
diff
changeset
|
5069 return ret; |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
5070 } |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
5071 |
7961
a7e58c6e4e9a
commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents:
7945
diff
changeset
|
5072 /* |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5073 * Return TRUE if any channel has readahead. That means we should not block on |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5074 * waiting for input. |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5075 */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5076 int |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5077 channel_any_readahead(void) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5078 { |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5079 channel_T *channel = first_channel; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5080 ch_part_T part = PART_SOCK; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5081 |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5082 while (channel != NULL) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5083 { |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5084 if (channel_has_readahead(channel, part)) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5085 return TRUE; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5086 if (part < PART_ERR) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5087 ++part; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5088 else |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5089 { |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5090 channel = channel->ch_next; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5091 part = PART_SOCK; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5092 } |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5093 } |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5094 return FALSE; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5095 } |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5096 |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
5097 /* |
7961
a7e58c6e4e9a
commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents:
7945
diff
changeset
|
5098 * 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
|
5099 */ |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5100 int |
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5101 set_ref_in_channel(int copyID) |
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5102 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
5103 int abort = FALSE; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
5104 channel_T *channel; |
9058
87c2e43a4a12
commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents:
9050
diff
changeset
|
5105 typval_T tv; |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5106 |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17024
diff
changeset
|
5107 for (channel = first_channel; !abort && channel != NULL; |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17024
diff
changeset
|
5108 channel = channel->ch_next) |
9058
87c2e43a4a12
commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents:
9050
diff
changeset
|
5109 if (channel_still_useful(channel)) |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5110 { |
9058
87c2e43a4a12
commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents:
9050
diff
changeset
|
5111 tv.v_type = VAR_CHANNEL; |
87c2e43a4a12
commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents:
9050
diff
changeset
|
5112 tv.vval.v_channel = channel; |
87c2e43a4a12
commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents:
9050
diff
changeset
|
5113 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5114 } |
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5115 return abort; |
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7929
diff
changeset
|
5116 } |
7986
8e0d4cd8157a
commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents:
7982
diff
changeset
|
5117 |
8e0d4cd8157a
commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents:
7982
diff
changeset
|
5118 /* |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5119 * 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
|
5120 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5121 static ch_part_T |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5122 channel_part_send(channel_T *channel) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5123 { |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5124 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
|
5125 return PART_IN; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5126 return PART_SOCK; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5127 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5128 |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5129 /* |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5130 * 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
|
5131 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5132 static ch_part_T |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5133 channel_part_read(channel_T *channel) |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5134 { |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5135 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
|
5136 return PART_OUT; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5137 return PART_SOCK; |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5138 } |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5139 |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5140 /* |
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5141 * Return the mode of "channel"/"part" |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
5142 * If "channel" is invalid returns CH_MODE_JSON. |
7986
8e0d4cd8157a
commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents:
7982
diff
changeset
|
5143 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5144 static ch_mode_T |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
5145 channel_get_mode(channel_T *channel, ch_part_T part) |
7986
8e0d4cd8157a
commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents:
7982
diff
changeset
|
5146 { |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8039
diff
changeset
|
5147 if (channel == NULL) |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28612
diff
changeset
|
5148 return CH_MODE_JSON; |
8151
aa845d10c6fb
commit https://github.com/vim/vim/commit/42d38a2db17e70312d073095257555c27a5f9443
Christian Brabandt <cb@256bit.org>
parents:
8134
diff
changeset
|
5149 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
|
5150 } |
8e0d4cd8157a
commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Christian Brabandt <cb@256bit.org>
parents:
7982
diff
changeset
|
5151 |
8157
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
5152 /* |
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
5153 * Return the timeout of "channel"/"part" |
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
5154 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5155 static int |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10253
diff
changeset
|
5156 channel_get_timeout(channel_T *channel, ch_part_T part) |
8157
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
5157 { |
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
5158 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
|
5159 } |
74b44d06d3c7
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents:
8155
diff
changeset
|
5160 |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5161 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5162 * "ch_canread()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5163 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5164 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5165 f_ch_canread(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5166 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5167 channel_T *channel; |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5168 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5169 rettv->vval.v_number = 0; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5170 if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5171 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5172 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5173 channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5174 if (channel != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5175 rettv->vval.v_number = channel_has_readahead(channel, PART_SOCK) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5176 || channel_has_readahead(channel, PART_OUT) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5177 || channel_has_readahead(channel, PART_ERR); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5178 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5179 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5180 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5181 * "ch_close()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5182 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5183 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5184 f_ch_close(typval_T *argvars, typval_T *rettv UNUSED) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5185 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5186 channel_T *channel; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5187 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5188 if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5189 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5190 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5191 channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5192 if (channel != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5193 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5194 channel_close(channel, FALSE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5195 channel_clear(channel); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5196 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5197 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5198 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5199 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5200 * "ch_close()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5201 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5202 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5203 f_ch_close_in(typval_T *argvars, typval_T *rettv UNUSED) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5204 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5205 channel_T *channel; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5206 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5207 if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5208 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5209 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5210 channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5211 if (channel != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5212 channel_close_in(channel); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5213 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5214 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5215 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5216 * "ch_getbufnr()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5217 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5218 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5219 f_ch_getbufnr(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5220 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5221 channel_T *channel; |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5222 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5223 rettv->vval.v_number = -1; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5224 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5225 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5226 && (check_for_chan_or_job_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5227 || check_for_string_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5228 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5229 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5230 channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5231 if (channel != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5232 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5233 char_u *what = tv_get_string(&argvars[1]); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5234 int part; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5235 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5236 if (STRCMP(what, "err") == 0) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5237 part = PART_ERR; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5238 else if (STRCMP(what, "out") == 0) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5239 part = PART_OUT; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5240 else if (STRCMP(what, "in") == 0) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5241 part = PART_IN; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5242 else |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5243 part = PART_SOCK; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5244 if (channel->ch_part[part].ch_bufref.br_buf != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5245 rettv->vval.v_number = |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5246 channel->ch_part[part].ch_bufref.br_buf->b_fnum; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5247 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5248 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5249 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5250 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5251 * "ch_getjob()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5252 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5253 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5254 f_ch_getjob(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5255 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5256 channel_T *channel; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5257 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5258 if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5259 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5260 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5261 channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5262 if (channel != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5263 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5264 rettv->v_type = VAR_JOB; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5265 rettv->vval.v_job = channel->ch_job; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5266 if (channel->ch_job != NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5267 ++channel->ch_job->jv_refcount; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5268 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5269 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5270 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5271 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5272 * "ch_info()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5273 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5274 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5275 f_ch_info(typval_T *argvars, typval_T *rettv UNUSED) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5276 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5277 channel_T *channel; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5278 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5279 if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5280 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5281 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5282 channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
29069
diff
changeset
|
5283 if (channel != NULL && rettv_dict_alloc(rettv) == OK) |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5284 channel_info(channel, rettv->vval.v_dict); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5285 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5286 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5287 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5288 * "ch_log()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5289 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5290 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5291 f_ch_log(typval_T *argvars, typval_T *rettv UNUSED) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5292 { |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5293 char_u *msg; |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5294 channel_T *channel = NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5295 |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5296 if (in_vim9script() |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5297 && (check_for_string_arg(argvars, 0) == FAIL |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5298 || check_for_opt_chan_or_job_arg(argvars, 1) == FAIL)) |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5299 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5300 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5301 msg = tv_get_string(&argvars[0]); |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5302 if (argvars[1].v_type != VAR_UNKNOWN) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5303 channel = get_channel_arg(&argvars[1], FALSE, FALSE, 0); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5304 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5305 ch_log(channel, "%s", msg); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5306 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5307 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5308 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5309 * "ch_logfile()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5310 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5311 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5312 f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5313 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5314 char_u *fname; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5315 char_u *opt = (char_u *)""; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5316 char_u buf[NUMBUFLEN]; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5317 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5318 // Don't open a file in restricted mode. |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5319 if (check_restricted() || check_secure()) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5320 return; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5321 |
24250
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
22224
diff
changeset
|
5322 if (in_vim9script() |
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
22224
diff
changeset
|
5323 && (check_for_string_arg(argvars, 0) == FAIL |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5324 || check_for_opt_string_arg(argvars, 1) == FAIL)) |
24250
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
22224
diff
changeset
|
5325 return; |
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
22224
diff
changeset
|
5326 |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5327 fname = tv_get_string(&argvars[0]); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5328 if (argvars[1].v_type == VAR_STRING) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5329 opt = tv_get_string_buf(&argvars[1], buf); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5330 ch_logfile(fname, opt); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5331 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5332 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5333 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5334 * "ch_open()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5335 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5336 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5337 f_ch_open(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5338 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5339 rettv->v_type = VAR_CHANNEL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5340 if (check_restricted() || check_secure()) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5341 return; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5342 rettv->vval.v_channel = channel_open_func(argvars); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5343 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5344 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5345 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5346 * "ch_read()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5347 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5348 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5349 f_ch_read(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5350 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5351 common_channel_read(argvars, rettv, FALSE, FALSE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5352 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5353 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5354 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5355 * "ch_readblob()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5356 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5357 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5358 f_ch_readblob(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5359 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5360 common_channel_read(argvars, rettv, TRUE, TRUE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5361 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5362 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5363 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5364 * "ch_readraw()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5365 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5366 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5367 f_ch_readraw(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5368 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5369 common_channel_read(argvars, rettv, TRUE, FALSE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5370 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5371 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5372 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5373 * "ch_evalexpr()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5374 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5375 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5376 f_ch_evalexpr(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5377 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5378 ch_expr_common(argvars, rettv, TRUE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5379 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5380 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5381 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5382 * "ch_sendexpr()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5383 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5384 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5385 f_ch_sendexpr(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5386 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5387 ch_expr_common(argvars, rettv, FALSE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5388 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5389 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5390 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5391 * "ch_evalraw()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5392 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5393 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5394 f_ch_evalraw(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5395 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5396 ch_raw_common(argvars, rettv, TRUE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5397 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5398 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5399 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5400 * "ch_sendraw()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5401 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5402 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5403 f_ch_sendraw(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5404 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5405 ch_raw_common(argvars, rettv, FALSE); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5406 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5407 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5408 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5409 * "ch_setoptions()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5410 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5411 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5412 f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5413 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5414 channel_T *channel; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5415 jobopt_T opt; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5416 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5417 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5418 && (check_for_chan_or_job_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5419 || check_for_dict_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5420 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5421 |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5422 channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5423 if (channel == NULL) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5424 return; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5425 clear_job_options(&opt); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5426 if (get_job_options(&argvars[1], &opt, |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5427 JO_CB_ALL + JO_TIMEOUT_ALL + JO_MODE_ALL, 0) == OK) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5428 channel_set_options(channel, &opt); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5429 free_job_options(&opt); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5430 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5431 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5432 /* |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5433 * "ch_status()" function |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5434 */ |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5435 void |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5436 f_ch_status(typval_T *argvars, typval_T *rettv) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5437 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5438 channel_T *channel; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5439 jobopt_T opt; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5440 int part = -1; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5441 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5442 // return an empty string by default |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5443 rettv->v_type = VAR_STRING; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5444 rettv->vval.v_string = NULL; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5445 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5446 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5447 && (check_for_chan_or_job_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5448 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5449 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
5450 |
17170
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5451 channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5452 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5453 if (argvars[1].v_type != VAR_UNKNOWN) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5454 { |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5455 clear_job_options(&opt); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5456 if (get_job_options(&argvars[1], &opt, JO_PART, 0) == OK |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5457 && (opt.jo_set & JO_PART)) |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5458 part = opt.jo_part; |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5459 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5460 |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5461 rettv->vval.v_string = vim_strsave((char_u *)channel_status(channel, part)); |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5462 } |
cee12488e4bc
patch 8.1.1584: the evalfunc.c file is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
5463 |
24812
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5464 /* |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5465 * Get a string with information about the channel in "varp" in "buf". |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5466 * "buf" must be at least NUMBUFLEN long. |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5467 */ |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5468 char_u * |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5469 channel_to_string_buf(typval_T *varp, char_u *buf) |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5470 { |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5471 channel_T *channel = varp->vval.v_channel; |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5472 char *status = channel_status(channel, -1); |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5473 |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5474 if (channel == NULL) |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5475 vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status); |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5476 else |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5477 vim_snprintf((char *)buf, NUMBUFLEN, |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5478 "channel %d %s", channel->ch_id, status); |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5479 return buf; |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5480 } |
8fdf839af1f4
patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
5481 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18191
diff
changeset
|
5482 #endif // FEAT_JOB_CHANNEL |