aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2017-05-28 13:26:06 +0000
committerGitHub <noreply@github.com>2017-05-28 13:26:06 +0000
commit9cc185dc6d9d665fe5ba3702a0a8af09151fe5c4 (patch)
tree0d0ac40790e2fc996ff1f43d5b6c0d327b10b48d /src/nvim/eval.c
parenteb71bbb1da073e4a97212f852a51893698fe95f9 (diff)
parent62d020aba1b4940980903a54839ad1f26f2d1527 (diff)
downloadrneovim-9cc185dc6d9d665fe5ba3702a0a8af09151fe5c4.tar.gz
rneovim-9cc185dc6d9d665fe5ba3702a0a8af09151fe5c4.tar.bz2
rneovim-9cc185dc6d9d665fe5ba3702a0a8af09151fe5c4.zip
Merge pull request #6680 from mhinz/listen/localhost
Use uv_getaddrinfo() for servers
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index ecef470666..7bfd638e86 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -14321,22 +14321,39 @@ static void f_serverstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
+ char *address;
// If the user supplied an address, use it, otherwise use a temp.
if (argvars[0].v_type != VAR_UNKNOWN) {
if (argvars[0].v_type != VAR_STRING) {
EMSG(_(e_invarg));
return;
} else {
- rettv->vval.v_string = (char_u *)xstrdup(tv_get_string(argvars));
+ address = xstrdup(tv_get_string(argvars));
}
} else {
- rettv->vval.v_string = (char_u *)server_address_new();
+ address = server_address_new();
}
- int result = server_start((char *) rettv->vval.v_string);
+ int result = server_start(address);
+ xfree(address);
+
if (result != 0) {
- EMSG2("Failed to start server: %s", uv_strerror(result));
+ EMSG2("Failed to start server: %s",
+ result > 0 ? "Unknonwn system error" : uv_strerror(result));
+ return;
}
+
+ // Since it's possible server_start adjusted the given {address} (e.g.,
+ // "localhost:" will now have a port), return the final value to the user.
+ size_t n;
+ char **addrs = server_address_list(&n);
+ rettv->vval.v_string = (char_u *)addrs[n - 1];
+
+ n--;
+ for (size_t i = 0; i < n; i++) {
+ xfree(addrs[i]);
+ }
+ xfree(addrs);
}
/// "serverstop()" function