diff options
author | Eric Wong <e@80x24.org> | 2016-03-03 05:14:31 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-03-03 09:19:16 +0000 |
commit | b38de6f02fa04e36b881d2aad9c7f792beb0b6a1 (patch) | |
tree | f0d6f21a534a7da7ac29a0a082921cf1d0566e14 /lib/PublicInbox/Daemon.pm | |
parent | b8e30717b529d6461190b54efa8c6402197cdd4e (diff) | |
download | public-inbox-b38de6f02fa04e36b881d2aad9c7f792beb0b6a1.tar.gz |
This allows us to share more code between daemons and avoids having to make additional syscalls for preparing REMOTE_HOST and REMOTE_PORT in the PSGI env in -httpd. This will also make supporting HTTP (and NNTP) over Unix sockets easier in a future commit.
Diffstat (limited to 'lib/PublicInbox/Daemon.pm')
-rw-r--r-- | lib/PublicInbox/Daemon.pm | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 77ab2a71..c101ecb7 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -157,20 +157,23 @@ sub reopen_logs { sub sockname ($) { my ($s) = @_; - my $n = getsockname($s) or return; - my ($port, $addr); - if (length($n) >= 28) { + my $addr = getsockname($s) or return; + my ($host, $port) = host_with_port($addr); + "$host:$port"; +} + +sub host_with_port ($) { + my ($addr) = @_; + my ($port, $host); + if (length($addr) >= 28) { require Socket6; - ($port, $addr) = Socket6::unpack_sockaddr_in6($n); - } else { - ($port, $addr) = Socket::sockaddr_in($n); - } - if (length($addr) == 4) { - $n = Socket::inet_ntoa($addr) + ($port, $host) = Socket6::unpack_sockaddr_in6($addr); + $host = '['.Socket6::inet_ntop(Socket6::AF_INET6(), $host).']'; } else { - $n = '['.Socket6::inet_ntop(Socket6::AF_INET6(), $addr).']'; + ($port, $host) = Socket::sockaddr_in($addr); + $host = Socket::inet_ntoa($host); } - $n .= ":$port"; + ($host, $port); } sub inherit () { |