mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Make unix sockets work from modules
This commit is contained in:
@@ -778,7 +778,7 @@ sub Connect {
|
||||
$self->GetModule->GetManager->Connect(
|
||||
$host,
|
||||
$port,
|
||||
"perl-socket",
|
||||
$self->ConstructSockName("Perl-C"),
|
||||
$arg{timeout}//60,
|
||||
$arg{ssl}//0,
|
||||
$arg{bindhost}//'',
|
||||
@@ -786,11 +786,26 @@ sub Connect {
|
||||
);
|
||||
}
|
||||
|
||||
sub ConnectUnix {
|
||||
my $self = shift;
|
||||
my $path = shift;
|
||||
$self->GetModule->GetManager->ConnectUnix(
|
||||
$self->ConstructSockName("Perl-CU"),
|
||||
$path, $self->{_csock}
|
||||
);
|
||||
}
|
||||
|
||||
sub Listen {
|
||||
my $self = shift;
|
||||
my %arg = @_;
|
||||
my $addrtype = $ZNC::ADDR_ALL;
|
||||
if (defined $arg{addrtype}) {
|
||||
if ($arg{addrtype} =~ /^unix$/i) {
|
||||
return $self->GetModule->GetManager->ListenUnix(
|
||||
$self->ConstructSockName("Perl-LU"),
|
||||
$arg{path}, $self->{_csock},
|
||||
);
|
||||
}
|
||||
if ($arg{addrtype} =~ /^ipv4$/i) { $addrtype = $ZNC::ADDR_IPV4ONLY }
|
||||
elsif ($arg{addrtype} =~ /^ipv6$/i) { $addrtype = $ZNC::ADDR_IPV6ONLY }
|
||||
elsif ($arg{addrtype} =~ /^all$/i) { }
|
||||
@@ -799,7 +814,7 @@ sub Listen {
|
||||
if (defined $arg{port}) {
|
||||
return $arg{port} if $self->GetModule->GetManager->ListenHost(
|
||||
$arg{port},
|
||||
"perl-socket",
|
||||
$self->ConstructSockName("Perl-L"),
|
||||
$arg{bindhost}//'',
|
||||
$arg{ssl}//0,
|
||||
$arg{maxconns}//ZNC::_GetSOMAXCONN,
|
||||
@@ -810,7 +825,7 @@ sub Listen {
|
||||
return 0;
|
||||
}
|
||||
$self->GetModule->GetManager->ListenRand(
|
||||
"perl-socket",
|
||||
$self->ConstructSockName("Perl-L"),
|
||||
$arg{bindhost}//'',
|
||||
$arg{ssl}//0,
|
||||
$arg{maxconns}//ZNC::_GetSOMAXCONN,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user