Make unix sockets work from modules

This commit is contained in:
Alexey Sokolov
2025-04-20 02:02:59 +01:00
parent 0af3e0705f
commit d3a7f125cf
6 changed files with 192 additions and 32 deletions

View File

@@ -47,7 +47,12 @@ class Socket:
return AsPyModule(self._csock.GetModule()).GetNewPyObj()
def Listen(self, addrtype='all', port=None, bindhost='', ssl=False,
maxconns=GetSOMAXCONN(), timeout=0):
maxconns=GetSOMAXCONN(), timeout=0, path=''):
if addrtype == 'unix':
return self.GetModule().GetManager().ListenUnix(
self.ConstructSockName("Py-LU"),
path, self._csock)
try:
addr = self.ADDR_MAP[addrtype.lower()]
except KeyError:
@@ -55,7 +60,7 @@ class Socket:
"Specified addrtype [{0}] isn't supported".format(addrtype))
args = (
"python socket for {0}".format(self.GetModule()),
self.ConstructSockName("Py-L"),
bindhost,
ssl,
maxconns,
@@ -76,13 +81,19 @@ class Socket:
return self.GetModule().GetManager().Connect(
host,
port,
'python conn socket for {0}'.format(self.GetModule()),
self.ConstructSockName("Py-C"),
timeout,
ssl,
bindhost,
self._csock
)
def ConnectUnix(self, path):
return self.GetModule().GetManager().ConnectUnix(
self.ConstructSockName("Py-CU"),
path, self._csock
)
def Write(self, data):
if (isinstance(data, str)):
return self._csock.Write(data)