diff options
author | Kevin Svetlitski <kevin_svetlitski@berkeley.edu> | 2021-01-26 14:43:17 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 20:43:17 +0000 |
commit | cab4280d02f0297ae10ab0611778389c7a5766ae (patch) | |
tree | ab017d04390b3c0079f8413ab673044d0d6c0964 /test/dumb_named_pipe_server.py | |
parent | 3a1728297a915b6e41c6339d571e85bc3756e5ff (diff) | |
download | ale-cab4280d02f0297ae10ab0611778389c7a5766ae.zip |
Feature: Add support for named-pipe sockets for LSPs (#3509)
* Add support for using named pipes for lsp 'socket' servers; documentation updated accordingly
* Add tests for connecting to named pipe sockets
Diffstat (limited to 'test/dumb_named_pipe_server.py')
-rw-r--r-- | test/dumb_named_pipe_server.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/dumb_named_pipe_server.py b/test/dumb_named_pipe_server.py new file mode 100644 index 00000000..a77e538c --- /dev/null +++ b/test/dumb_named_pipe_server.py @@ -0,0 +1,42 @@ +""" +This Python script creates a named pipe server that does nothing but send its input +back to the client that connects to it. Only one argument must be given, the path +of a named pipe to bind to. +""" +import os +import socket +import sys + + +def main(): + if len(sys.argv) < 2: + sys.exit('You must specify a filepath') + + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + if os.path.exists(sys.argv[1]): + os.remove(sys.argv[1]) + sock.bind(sys.argv[1]) + sock.listen(0) + + pid = os.fork() + + if pid: + print(pid) + sys.exit() + + while True: + connection = sock.accept()[0] + connection.settimeout(5) + + while True: + try: + connection.send(connection.recv(1024)) + except socket.timeout: + break + + connection.close() + + +if __name__ == "__main__": + main() |