-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[WIP/RFC] Implement server_address() #1909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bd82441
to
ed59b98
Compare
Ups clearly I should have moved that somewhere in os/. Any suggestion where. |
Windows requires an include for inttypes.h for PRIu64. |
So does every other system, iirc. |
For some reason it was not building in windows without it. Maybe inttypes is included in os_unix.h/os_unix_defs
Should not interfere. For Unix it does not change the current behaviour. For windows the pipes are named nvim- so that each running process gets a unique address. With two running instances I get
|
Likely. This is an ongoing problem :).
Yea, I forgot that the environment variable would only be set for the terminal from which nvim was run. |
ed59b98
to
96bbda3
Compare
Seems like this has overlap with #1758. Can we add a |
I can, but the random properties of one and the other are not the same:
i.e. there can be no two instances of Neovim running at the same time where os_serveraddress() is the same, but it would be possible for two instances that run sequentially to have the same serveraddress - with what probability I cannot say. The goal of #1758 was different, it was looking for something along the lines of an UUID - completely unique over time. Also plugins can already get the value as returned by os_serveraddress, by requesting $NVIM_LISTEN_ADDRESS (e.g. eval via the api). |
Ok, good points. |
One more comment: |
96bbda3
to
7b313bd
Compare
7b313bd
to
fe64ad7
Compare
/// | ||
const char* os_serveraddress(void) | ||
{ | ||
static char servername[ADDRESS_MAX_SIZE] = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if serverstop()
is called on this address?
Need a "tickle test" for unix and windows to verify that the correct format is returned. Also need a test to assert behavior after |
@equalsraf is this still an issue after @splinterofchaos implemented |
@tarruda yes it is.
|
@equalsraf ok, can rebase these changes on latest master? |
Still have questions in my comments above. |
@justinmk not forgotten (:D at least not completely) need to fix it anyway for serverstart and it should address it too. |
f995327
to
433a89e
Compare
Rewrote most of it, renamed as server_name() - it no longer returns a unique address, just mimics vim_tempname(). In UNIX just calls vim_tempname(). For Windows it returns \.\pipe\nvim-PID-COUNTER where COUNTER is a static counter in As before the PID ensures there are no collisions with other Neovim instaces, the counter increments with each call - I have not checked for a wrap around, but neither does vim_tempname(), in both cases it should be harmless and result in a failed call to server_start. Changed @justinmk for windows |
#ifdef WIN32 | ||
static uint32_t count = 0; | ||
char template[ADDRESS_MAX_SIZE] = ""; | ||
if (template[0] == '\0') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use an if
? The condition is always true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover, template
used to be a static buffer with the value being initialized only once. Removing the if and the initializer.
433a89e
to
07fb5c0
Compare
Since windows will not be supported by 0.1, postponing it |
/// For other systems it is a path returned by vim_tempname(). | ||
/// | ||
/// This function is NOT thread safe | ||
char *server_address(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server_address_create
or server_address_generate
would be a less ambiguous name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would server_address_new()
be better?
@equalsraf Could you address (minor) comments and rebase this? It is needed for XDG. |
f5da242
to
3dc8b0f
Compare
When creating a local socket/pipe (server_start()) Neovim used vim_tempname() to generate a unique socket path. For Windows UNIX filepaths cannot be used as pipe names (they must start with \\.\pipe\). This commit replaces the use of vim_tempname() for server addresses with server_address_new(). server_address_new() generates unique names for local sockets/pipes - for UNIX it uses vim_tempname(), for Windows generates names in the form \\.\pipe\nvim-PID-COUNTER where PID is the current process id, and COUNTER is a static uint32_t counter incremented with every call. This function is now used for server_start() and server_init() when no address is available.
Return 1 if the endpoint argument is NULL, server_start() can get a NULL value when using server_address_new() or vim_tempname(). Removed the function attribute.
3dc8b0f
to
3e84a91
Compare
I've rebased this yesterday and again today, but Travis seems to be stuck. |
@equalsraf Thanks. I emailed travis today, waiting for reply. |
on when no address is supplied.
get a path in the Neovim temp folder.
followed by a name, the pipe name is set as nvim-PID.
Following d52fb89. I think I've addressed all the comments, I just need to go back to Windows and test if I have not broken anything. ping @aktau @justinmk