patch 9.1.1651: Cannot use clientserver over socket

Problem:  Cannot use clientserver over Unix domain socket
Solution: Implement socketserver functionality (Foxe Chen).

fixes: #3509
closes: #17839

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Foxe Chen
2025-08-18 21:40:40 +02:00
committed by Christian Brabandt
parent 31170af24a
commit 96b2154b73
34 changed files with 2562 additions and 68 deletions

View File

@ -13046,6 +13046,7 @@ scrollbind Compiled with 'scrollbind' support. (always true)
showcmd Compiled with 'showcmd' support.
signs Compiled with |:sign| support.
smartindent Compiled with 'smartindent' support. (always true)
socketserver Compiled with socket server functionality. (Unix only)
sodium Compiled with libsodium for better crypt support
sound Compiled with sound support, e.g. `sound_playevent()`
spell Compiled with spell checking support |spell|.

View File

@ -1,4 +1,4 @@
*remote.txt* For Vim version 9.1. Last change: 2022 Feb 17
*remote.txt* For Vim version 9.1. Last change: 2025 Aug 18
VIM REFERENCE MANUAL by Bram Moolenaar
@ -61,7 +61,10 @@ The following command line arguments are available:
--servername {name} Become the server {name}. When used together
with one of the --remote commands: connect to
server {name} instead of the default (see
below). The name used will be uppercase.
below). The name used will be uppercase. If
using the socketserver, you can specify a
path, see |socketserver-name| for more
details.
*--remote-send*
--remote-send {keys} Send {keys} to server and exit. The {keys}
are not mapped. Special key names are
@ -72,6 +75,12 @@ The following command line arguments are available:
on stdout.
*--serverlist*
--serverlist Output a list of server names.
*--clientserver*
--clientserver {method} Use the specified method {method} as the
backend for clientserver functionality. Can
either be "socket" or "x11".
{only available when Vim is compiled with both
|+X11| and |+socketserver| features}
Examples ~
@ -105,7 +114,8 @@ specified name is not available, a postfix is applied until a free name is
encountered, i.e. "gvim1" for the second invocation of gvim on a particular
X-server. The resulting name is available in the servername builtin variable
|v:servername|. The case of the server name is ignored, thus "gvim" and
"GVIM" are considered equal.
"GVIM" are considered equal. Note if a socket server is being used, there are
some differences, see |socketserver-differences|.
When Vim is invoked with --remote, --remote-wait or --remote-send it will try
to locate the server name determined by the invocation name and --servername
@ -119,7 +129,8 @@ itself. This way it is not necessary to know whether gvim is already started
when sending command to it.
The --serverlist argument will cause Vim to print a list of registered command
servers on the standard output (stdout) and exit.
servers on the standard output (stdout) and exit. If a socket server is being
used, there are caveats, see |socketserver-differences|.
*{server}*
The {server} argument is used by several functions. When this is an empty
string then on Unix the default server name is used, which is "GVIM". On
@ -206,4 +217,64 @@ When using gvim, the --remote-wait only works properly this way: >
start /w gvim --remote-wait file.txt
<
==============================================================================
3. Socket server specific items *socketserver-clientserver*
*E1563* *E1564* *E1565* *E1566* *E1567*
The communication between client and server is done using Unix domain sockets.
These sockets are either placed in these directories in the following order of
availability:
1. "$XDG_RUTIME_DIR/vim" if $XDG_RUNTIME_DIR is set in the environment.
2. "$TMPDIR/vim-[uid]", where "[uid]" is the uid of the user. This
directory will have the access permissions set to 700 so only the user
can read or write from/to it. If $TMPDIR is not set, "/tmp" is used.
*socketserver-name*
When specifying the server id/name, it can be taken as a generic name or an
absolute or relative path. If the server id starts with either a "/"
(absolute) or "./" | "../" (relative), then it is taken as path to the socket.
Otherwise the server id will be the filename of the socket which will be
placed in the above common directories. Note that a server id/name can only
contain slashes "/" if it is taken as a path, so names such as "abc/dir" will
be invalid.
Socket server functionality is available in both GTK GUI and terminal versions of
Vim. Unless Vim is compiled with |+autoservername| feature, the socket server
will have to started explicitly, just like X11, even in the GUI.
If Vim crashes or does not exit cleanly, the socket server will not remove the
socket file and it will be left around. This is generally not a problem,
because if a socket name is taken, Vim checks if the socket in its place is
dead (not attached to any process), and can replace it instead of finding a
new name.
To send commands to a Vim socket server from another application, read the
source file src/os_unix.c, there is detailed description of the protocol used.
*socketserver-differences*
Most of the functionality is the same as X11, however unlike X11, where the
client does not need to be a server in order to communicate with another
server, the socket server requires the server to be running even as a client.
The exception is |serverlist()| or the |--serverlist| argument, which does not
require the server to be running.
Additionally, the server id or client id will not be a number like X11 or
MS-Windows (shown in hex representation), instead it is the absolute path to
the socket. This can be seen via the |v:servername| variable.
The |--serverlist| argument will act just like X11, however it only checks the
given common directories above. If a custom path is used for a socket, it
will not be detected, such as a path either not in $XDG_RUNTIME_DIR or
<$TMPDIR or /tmp>/vim of the |--serverlist| Vim process.
If you have both |+socketserver| and |+X11| compiled, you will need to add
|--clientserver| set to "socket" in combination with |--serverlist| to list
the available servers. You cannot list both types of backends in one command.
*socketserver-x11*
If Vim is compiled with both |+X11| and |+socketserver|, then deciding which
backend to use is done at startup time, via the |--clientserver| argument. By
default if it is not specified, then X11 will be used. A Vim instance using a
socket server cannot communicate with one using X11.
vim:tw=78:sw=4:ts=8:noet:ft=help:norl:

View File

@ -1497,6 +1497,7 @@ $quote eval.txt /*$quote*
+scrollbind various.txt /*+scrollbind*
+signs various.txt /*+signs*
+smartindent various.txt /*+smartindent*
+socketserver various.txt /*+socketserver*
+sodium various.txt /*+sodium*
+sound various.txt /*+sound*
+spell various.txt /*+spell*
@ -1557,6 +1558,7 @@ $quote eval.txt /*$quote*
-- starting.txt /*--*
--- starting.txt /*---*
--clean starting.txt /*--clean*
--clientserver remote.txt /*--clientserver*
--cmd starting.txt /*--cmd*
--echo-wid starting.txt /*--echo-wid*
--gui-dialog-file starting.txt /*--gui-dialog-file*
@ -4697,6 +4699,11 @@ E156 sign.txt /*E156*
E1560 vim9.txt /*E1560*
E1561 vim9.txt /*E1561*
E1562 options.txt /*E1562*
E1563 remote.txt /*E1563*
E1564 remote.txt /*E1564*
E1565 remote.txt /*E1565*
E1566 remote.txt /*E1566*
E1567 remote.txt /*E1567*
E157 sign.txt /*E157*
E158 sign.txt /*E158*
E159 sign.txt /*E159*
@ -10225,6 +10232,10 @@ slow-fast-terminal term.txt /*slow-fast-terminal*
slow-start starting.txt /*slow-start*
slow-terminal term.txt /*slow-terminal*
socket-interface channel.txt /*socket-interface*
socketserver-clientserver remote.txt /*socketserver-clientserver*
socketserver-differences remote.txt /*socketserver-differences*
socketserver-name remote.txt /*socketserver-name*
socketserver-x11 remote.txt /*socketserver-x11*
sort() builtin.txt /*sort()*
sorting change.txt /*sorting*
sound-functions usr_41.txt /*sound-functions*

View File

@ -1,4 +1,4 @@
*various.txt* For Vim version 9.1. Last change: 2025 Aug 06
*various.txt* For Vim version 9.1. Last change: 2025 Aug 18
VIM REFERENCE MANUAL by Bram Moolenaar
@ -487,6 +487,8 @@ m *+ruby/dyn* Ruby interface |ruby-dynamic| |/dyn|
T *+scrollbind* 'scrollbind'
N *+signs* |:sign|
T *+smartindent* 'smartindent'
N *+socketserver* Unix only: socket server backend for clientserver
functionality
H *+sodium* compiled with libsodium for better encryption support
H *+sound* |sound_playevent()|, |sound_playfile()| functions, etc.
N *+spell* spell checking support, see |spell|

View File

@ -41745,6 +41745,10 @@ Others: ~
Unicode 16.
- Two additional digraphs have been added: LEFT ANGLE BRACKET "<[" and RIGHT
ANGLE BRACKET "]>".
- Support for Unix domain sockets have been added for the clientserver
feature, see |socketserver-clientserver|.
Platform specific ~
- MS-Winodws: Paths like "\Windows" and "/Windows" are now considered to be
absolute paths (to the current drive) and no longer relative.
@ -41849,6 +41853,7 @@ Options: ~
Vim Arguments: ~
|-Y| Do not connect to the Wayland compositor.
|--clientserver| Specify backend for clientserver functionality.
==============================================================================

View File

@ -499,7 +499,14 @@ List the names of all Vim servers that can be found.
.TP
\-\-servername {name}
Use {name} as the server name. Used for the current Vim, unless used with a
\-\-remote argument, then it's the name of the server to connect to.
\-\-remote argument, then it's the name of the server to connect to. If the
socketserver backend is being used, if the name starts with "/", "./", or "../",
it is taken as either an absolute, relative or relative path to the socket.
.TP
\-\-clientserver {backend}
Use {backend} as the backend for clientserver functionality, either "socket" or
"x11" respectively. Only available when compiled with both socketserver and X11
features present
.TP
\-\-socketid {id}
GTK GUI only: Use the GtkPlug mechanism to run gVim in another window.

View File

@ -378,7 +378,16 @@ OPTIONS
--servername {name}
Use {name} as the server name. Used for the current Vim,
unless used with a --remote argument, then it's the name of
the server to connect to.
the server to connect to. If the socketserver backend is
being used, if the name starts with "/", "./", or "../", it
is taken as either an absolute, relative or relative path
to the socket.
--clientserver {backend}
Use {backend} as the backend for clientserver functional
ity, either "socket" or "x11" respectively. Only available
when compiled with both socketserver and X11 features
present
--socketid {id}
GTK GUI only: Use the GtkPlug mechanism to run gVim in an