view src/testdir/test_channel_unix.py @ 36544:a27d4c0319ac draft default tip

runtime(idris2): include filetype,indent+syntax plugins for (L)Idris2 + ipkg Commit: https://github.com/vim/vim/commit/5ca8f223f03dbd85f5e06c8e1d500c65f311eaf1 Author: Serhii Khoma <srghma@gmail.com> Date: Tue Nov 12 21:49:42 2024 +0100 runtime(idris2): include filetype,indent+syntax plugins for (L)Idris2 + ipkg closes: https://github.com/vim/vim/issues/15993 Co-authored-by: Christian Clason <ch.clason+github@icloud.com> Signed-off-by: Serhii Khoma <srghma@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 12 Nov 2024 22:00:06 +0100
parents cdd13ed3e5cb
children
line wrap: on
line source

#!/usr/bin/env python
#
# Server that will accept connections from a Vim channel.
# Used by test_channel.vim.
#
# This requires Python 2.6 or later.

from __future__ import print_function
from test_channel import ThreadedTCPServer, TestingRequestHandler, \
    writePortInFile
import socket
import threading
import os

try:
    FileNotFoundError
except NameError:
    # Python 2
    FileNotFoundError = (IOError, OSError)

if not hasattr(socket, "AF_UNIX"):
    raise NotImplementedError("Unix sockets are not supported on this platform")

class ThreadedUnixServer(ThreadedTCPServer):
    address_family = socket.AF_UNIX

class ThreadedUnixRequestHandler(TestingRequestHandler):
    pass

def main(path):
    server = ThreadedUnixServer(path, ThreadedUnixRequestHandler)

    # Start a thread with the server.  That thread will then start a new thread
    # for each connection.
    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.start()

    # Signal the test harness we're ready, the port value has no meaning.
    writePortInFile(1234)

    print("Listening on {0}".format(server.server_address))

    # Main thread terminates, but the server continues running
    # until server.shutdown() is called.
    try:
        while server_thread.is_alive():
            server_thread.join(1)
    except (KeyboardInterrupt, SystemExit):
        server.shutdown()

if __name__ == "__main__":
    try:
        os.remove("Xtestsocket")
    except FileNotFoundError:
        pass
    main("Xtestsocket")