mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
server: init v:servername if $NVIM_LISTEN_ADDRESS is invalid
Before this change, if $NVIM_LISTEN_ADDRESS was invalid, v:servername was left empty.
This commit is contained in:
parent
507bda1c95
commit
704ba4151e
@ -32,28 +32,27 @@ static garray_T watchers = GA_EMPTY_INIT_VALUE;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Initializes the module
|
/// Initializes the module
|
||||||
bool server_init(const char *listen_address)
|
bool server_init(const char *listen_addr)
|
||||||
{
|
{
|
||||||
ga_init(&watchers, sizeof(SocketWatcher *), 1);
|
ga_init(&watchers, sizeof(SocketWatcher *), 1);
|
||||||
|
|
||||||
bool must_free = false;
|
// $NVIM_LISTEN_ADDRESS
|
||||||
if (listen_address == NULL) {
|
const char *env_addr = os_getenv(LISTEN_ADDRESS_ENV_VAR);
|
||||||
// Deprecated: $NVIM_LISTEN_ADDRESS
|
int rv = listen_addr == NULL ? 1 : server_start(listen_addr);
|
||||||
listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR);
|
|
||||||
if (listen_address == NULL) {
|
if (0 != rv) {
|
||||||
must_free = true;
|
rv = env_addr == NULL ? 1 : server_start(env_addr);
|
||||||
listen_address = server_address_new();
|
if (0 != rv) {
|
||||||
if (listen_address == NULL) {
|
listen_addr = server_address_new();
|
||||||
|
if (listen_addr == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
rv = server_start(listen_addr);
|
||||||
|
xfree((char *)listen_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = (server_start(listen_address) == 0);
|
return rv == 0;
|
||||||
if (must_free) {
|
|
||||||
xfree((char *)listen_address);
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Teardown a single server
|
/// Teardown a single server
|
||||||
@ -122,8 +121,8 @@ bool server_owns_pipe_address(const char *path)
|
|||||||
/// @param endpoint Address of the server. Either a 'ip:[port]' string or an
|
/// @param endpoint Address of the server. Either a 'ip:[port]' string or an
|
||||||
/// arbitrary identifier (trimmed to 256 bytes) for the Unix
|
/// arbitrary identifier (trimmed to 256 bytes) for the Unix
|
||||||
/// socket or named pipe.
|
/// socket or named pipe.
|
||||||
/// @returns 0 on success, 1 on a regular error, and negative errno
|
/// @returns 0: success, 1: validation error, 2: already listening,
|
||||||
/// on failure to bind or listen.
|
/// -errno: failed to bind or listen.
|
||||||
int server_start(const char *endpoint)
|
int server_start(const char *endpoint)
|
||||||
{
|
{
|
||||||
if (endpoint == NULL || endpoint[0] == '\0') {
|
if (endpoint == NULL || endpoint[0] == '\0') {
|
||||||
@ -147,7 +146,7 @@ int server_start(const char *endpoint)
|
|||||||
uv_freeaddrinfo(watcher->uv.tcp.addrinfo);
|
uv_freeaddrinfo(watcher->uv.tcp.addrinfo);
|
||||||
}
|
}
|
||||||
socket_watcher_close(watcher, free_server);
|
socket_watcher_close(watcher, free_server);
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,9 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval
|
local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
|
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
|
||||||
|
local iswin = helpers.iswin
|
||||||
local ok = helpers.ok
|
local ok = helpers.ok
|
||||||
local os_name = helpers.os_name
|
local matches = helpers.matches
|
||||||
|
|
||||||
local function clear_serverlist()
|
local function clear_serverlist()
|
||||||
for _, server in pairs(funcs.serverlist()) do
|
for _, server in pairs(funcs.serverlist()) do
|
||||||
@ -25,7 +26,15 @@ describe('server', function()
|
|||||||
eq('', eval('$NVIM_LISTEN_ADDRESS'))
|
eq('', eval('$NVIM_LISTEN_ADDRESS'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('serverstart() sets v:servername at startup or if all servers were stopped',
|
it('sets new v:servername if $NVIM_LISTEN_ADDRESS is invalid', function()
|
||||||
|
clear({env={NVIM_LISTEN_ADDRESS='.'}})
|
||||||
|
eq('.', eval('$NVIM_LISTEN_ADDRESS'))
|
||||||
|
local servers = funcs.serverlist()
|
||||||
|
eq(1, #servers)
|
||||||
|
ok(string.len(servers[1]) > 4) -- Like /tmp/nvim…/… or \\.\pipe\…
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('sets v:servername at startup or if all servers were stopped',
|
||||||
function()
|
function()
|
||||||
local initial_server = meths.get_vvar('servername')
|
local initial_server = meths.get_vvar('servername')
|
||||||
assert(initial_server ~= nil and initial_server:len() > 0,
|
assert(initial_server ~= nil and initial_server:len() > 0,
|
||||||
@ -46,9 +55,8 @@ describe('server', function()
|
|||||||
eq('', meths.get_vvar('servername'))
|
eq('', meths.get_vvar('servername'))
|
||||||
|
|
||||||
-- v:servername will take the next available server.
|
-- v:servername will take the next available server.
|
||||||
local servername = (os_name() == 'windows'
|
local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]]
|
||||||
and [[\\.\pipe\Xtest-functional-server-pipe]]
|
or 'Xtest-functional-server-socket')
|
||||||
or 'Xtest-functional-server-socket')
|
|
||||||
funcs.serverstart(servername)
|
funcs.serverstart(servername)
|
||||||
eq(servername, meths.get_vvar('servername'))
|
eq(servername, meths.get_vvar('servername'))
|
||||||
end)
|
end)
|
||||||
@ -102,7 +110,7 @@ describe('server', function()
|
|||||||
local n = eval('len(serverlist())')
|
local n = eval('len(serverlist())')
|
||||||
|
|
||||||
-- Add some servers.
|
-- Add some servers.
|
||||||
local servs = (os_name() == 'windows'
|
local servs = (iswin()
|
||||||
and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] }
|
and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] }
|
||||||
or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] })
|
or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] })
|
||||||
for _, s in ipairs(servs) do
|
for _, s in ipairs(servs) do
|
||||||
@ -129,18 +137,18 @@ describe('startup --listen', function()
|
|||||||
|
|
||||||
local cmd = { unpack(helpers.nvim_argv) }
|
local cmd = { unpack(helpers.nvim_argv) }
|
||||||
table.insert(cmd, '--listen')
|
table.insert(cmd, '--listen')
|
||||||
eq('nvim: Argument missing after: "--listen"',
|
matches('nvim.*: Argument missing after: "%-%-listen"', funcs.system(cmd))
|
||||||
string.match(funcs.system(cmd), '.-n"'))
|
|
||||||
|
|
||||||
cmd = { unpack(helpers.nvim_argv) }
|
cmd = { unpack(helpers.nvim_argv) }
|
||||||
table.insert(cmd, '--listen2')
|
table.insert(cmd, '--listen2')
|
||||||
eq('nvim: Garbage after option argument: "--listen2"',
|
matches('nvim.*: Garbage after option argument: "%-%-listen2"', funcs.system(cmd))
|
||||||
string.match(funcs.system(cmd), '.-2"'))
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function()
|
it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function()
|
||||||
|
local addr = (iswin() and [[\\.\pipe\Xtest-listen-pipe]]
|
||||||
|
or 'Xtest-listen-pipe')
|
||||||
clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' },
|
clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' },
|
||||||
args={ '--listen', 'Xtest-listen-pipe' } })
|
args={ '--listen', addr } })
|
||||||
eq('Xtest-listen-pipe', meths.get_vvar('servername'))
|
eq(addr, meths.get_vvar('servername'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user