roxma / vim-hug-neovim-rpc

EXPERIMENTAL
MIT License
219 stars 28 forks source link

Support additional systems for UNIX domain sockets #58

Open scfarley opened 4 years ago

scfarley commented 4 years ago

With commit 5a20db1f06a4b1bba5015881ffe218678d7ec085, UNIX domain sockets was introduced, yet it only supports Linux and MacOS (Darwin). Additional systems can easily be added. There are a few options, but I am not sure which is best. Here is what I am currently using:

diff --git a/pythonx/neovim_rpc_server.py b/pythonx/neovim_rpc_server.py
index d669fd0..055bbc0 100644
--- a/pythonx/neovim_rpc_server.py
+++ b/pythonx/neovim_rpc_server.py
@@ -296,7 +296,10 @@ class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
     pass

-if sys.platform in ['linux', 'darwin']:
+# if sys.platform in ['freebsd11', 'linux', 'darwin']:
+# if platform.system() in ['Darwin', 'DragonFly', 'FreeBSD', 'Linux', 'NetBSD',
+#                          'OpenBSD']:
+if os.name == 'posix':
     class ThreadedUnixServer(socketserver.ThreadingMixIn,
                              socketserver.UnixStreamServer):
         pass

The test for posix is the most broad, but I do not know if it would include any systems that cannot handle it. While sys.platform would work, it would grow fairly quickly since the BSD's all have the version of the OS appended to them. There is finally platform.system() which is basically uname -s which would work too and be easier than sys.platform.

Another alternative is to try defining the class and handle the exception. It should work everywhere:

diff --git a/pythonx/neovim_rpc_server.py b/pythonx/neovim_rpc_server.py
index d669fd0..ca278c6 100644
--- a/pythonx/neovim_rpc_server.py
+++ b/pythonx/neovim_rpc_server.py
@@ -296,12 +296,12 @@ class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
     pass

-if sys.platform in ['linux', 'darwin']:
+try:
     class ThreadedUnixServer(socketserver.ThreadingMixIn,
                              socketserver.UnixStreamServer):
         pass
     has_unix = True
-else:
+except:
     has_unix = False
roxma commented 4 years ago

https://stackoverflow.com/questions/32612235/what-is-os-name-on-cygwin

Looks like os.name yields posix on cygwin, I'm not sure it's going to work

scfarley commented 4 years ago

The code can check for posix but exclude cygwin. From what I have read, cygwin does have a form of UNIX domain sockets but cannot pass file descriptors using it.

However, what about trying to instantiate ThreadedUnixServer as the check? Does cygwin have it?