diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 3af300d..8b9f885 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -2204,13 +2204,18 @@ cdef class TwoPartyClient: del self.thisptr cpdef _connect(self, host_string): - host, port = host_string.split(':') + if host_string.startswith('unix:'): + path = host_string[5:] + sock = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM) + sock.connect(path) + else: + host, port = host_string.split(':') - sock = _socket.create_connection((host, port)) + sock = _socket.create_connection((host, port)) - # Set TCP_NODELAY on socket to disable Nagle's algorithm. This is not - # neccessary, but it speeds things up. - sock.setsockopt(_socket.IPPROTO_TCP, _socket.TCP_NODELAY, 1) + # Set TCP_NODELAY on socket to disable Nagle's algorithm. This is not + # neccessary, but it speeds things up. + sock.setsockopt(_socket.IPPROTO_TCP, _socket.TCP_NODELAY, 1) return sock cpdef restore(self, objectId) except +reraise_kj_exception: diff --git a/test/test_rpc_calculator.py b/test/test_rpc_calculator.py index 2eccf99..1d7777a 100644 --- a/test/test_rpc_calculator.py +++ b/test/test_rpc_calculator.py @@ -2,9 +2,12 @@ import capnp import os import socket import gc +import subprocess +import time import sys # add examples dir to sys.path -sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'examples')) +examples_dir = os.path.join(os.path.dirname(__file__), '..', 'examples') +sys.path.append(examples_dir) import calculator_client import calculator_server @@ -16,6 +19,31 @@ def test_calculator(): calculator_client.main(read) +def run_subprocesses(address): + server = subprocess.Popen([examples_dir + '/calculator_server.py', address]) + time.sleep(.1) # Give the server some small amount of time to start listening + client = subprocess.Popen([examples_dir + '/calculator_client.py', address]) + + ret = client.wait() + server.kill() + assert ret == 0 + + +def test_calculator_tcp(): + address = '127.0.0.1:36431' + run_subprocesses(address) + + +def test_calculator_unix(): + path = '/tmp/pycapnp-test' + try: + os.unlink(path) + except OSError: + pass + + address = 'unix:' + path + run_subprocesses(address) + def test_calculator_gc(): def new_evaluate_impl(old_evaluate_impl): def call(*args, **kwargs):