Skip to content

Commit

Permalink
Merge pull request #23 from openziti/terminator-support
Browse files Browse the repository at this point in the history
add terminator support to connect and bind
  • Loading branch information
ekoby committed Aug 1, 2022
2 parents b69415b + 17c3d7c commit 89f22f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/openziti/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def connect(self, addr):
raise TypeError(f'unsupported address {addr}')
return socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0, fd)

def bind(self, service, sock=None):
def bind(self, service, terminator=None, sock=None):
if sock is None:
sock = zitisock.ZitiSocket(type=socket.SOCK_STREAM)
zitilib.bind(sock.fileno(), self._ctx, service)
zitilib.bind(sock.fileno(), self._ctx, service, terminator)
return sock

@classmethod
Expand Down
23 changes: 17 additions & 6 deletions src/openziti/zitilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ def __repr__(self):
ziti_socket.restype = ctypes.c_int

_ziti_connect = ziti.Ziti_connect
_ziti_connect.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p]
_ziti_connect.argtypes = [ctypes.c_int, # socket fd
ctypes.c_void_p, # zitt context
ctypes.c_char_p, # service
ctypes.c_char_p # terminator
]

_ziti_connect_addr = ziti.Ziti_connect_addr
_ziti_connect_addr.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int]
_ziti_connect_addr.restype = ctypes.c_int

_ziti_bind = ziti.Ziti_bind
_ziti_bind.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p]
_ziti_bind.argtypes = [ctypes.c_int, # socket fd
ctypes.c_void_p, # ziti context
ctypes.c_char_p, # service
ctypes.c_char_p # terminator
]

_ziti_listen = ziti.Ziti_listen
_ziti_listen.argtypes = [ctypes.c_int, ctypes.c_int]
Expand Down Expand Up @@ -125,9 +133,10 @@ def load(path):
return _load_ctx(b_obj)


def connect(fd, ztx, service: str):
def connect(fd, ztx, service: str, terminator: str = None):
srv = bytes(service, encoding='utf-8')
check_error(_ziti_connect(fd, ztx, srv))
terminator = bytes(terminator, encoding='utf-8')
check_error(_ziti_connect(fd, ztx, srv, terminator))


def connect_addr(fd, addr: Tuple[str, int]):
Expand All @@ -136,9 +145,11 @@ def connect_addr(fd, addr: Tuple[str, int]):
check_error(_ziti_connect_addr(fd, host, port))


def bind(fd, ztx, service):
def bind(fd, ztx, service: str, terminator: str = None):
srv = bytes(service, encoding='utf-8')
check_error(_ziti_bind(fd, ztx, srv))
if terminator:
terminator = bytes(terminator, encoding='utf-8')
check_error(_ziti_bind(fd, ztx, srv, terminator))


def listen(fd, backlog):
Expand Down
5 changes: 4 additions & 1 deletion src/openziti/zitisock.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def bind(self, addr) -> None:
raise RuntimeError(f'no ziti binding for {addr}')
ztx = context.get_context(cfg['ztx'])
service = cfg['service']
ztx.bind(service, self)
terminator = None
if isinstance(service, tuple):
service,terminator = service
ztx.bind(service=service, terminator=terminator, sock=self)

def getsockname(self):
# return this for now since frameworks expect something to be returned
Expand Down

0 comments on commit 89f22f8

Please sign in to comment.