Database-Async-Engine-PostgreSQL
view release on metacpan or search on metacpan
lib/Database/Async/Engine/PostgreSQL.pm view on Meta::CPAN
my $connected = $self->connected;
die 'We think we are already connected, and that is bad' if $connected->as_numeric;
# Initial connection is made directly through the URI
# parameters. Eventually we also want to support UNIX
# socket and other types.
$self->{uri} ||= $self->uri_for_service($self->service) if $self->service;
my $uri = $self->uri;
die 'bad URI' unless ref $uri;
$log->tracef('URI for connection is %s', "$uri");
my $endpoint = join ':', $uri->host, $uri->port;
$log->tracef('Will connect to %s', $endpoint);
$self->{ssl} = do {
my $mode = $uri->query_param('sslmode') // 'prefer';
$Protocol::Database::PostgreSQL::Constants::SSL_NAME_MAP{$mode} // die 'unknown SSL mode ' . $mode;
};
# We're assuming TCP (either v4 or v6) here, but there's not really any reason we couldn't have
# UNIX sockets or other transport layers here other than lack of demand so far.
my @connect_params;
if ($uri->host and not $uri->host =~ m!^[/@]!) {
@connect_params = (
lib/Database/Async/Engine/PostgreSQL.pm view on Meta::CPAN
socktype => 'stream',
path => $uri->host.'/.s.PGSQL.'.$uri->port,
}
);
}
my $sock = await $loop->connect(@connect_params);
if ($sock->sockdomain == Socket::PF_INET or $sock->sockdomain == Socket::PF_INET6) {
my $local = join ':', $sock->sockhost_service(1);
my $remote = join ':', $sock->peerhost_service(1);
$log->tracef('Connected to %s as %s from %s', $endpoint, $remote, $local);
} elsif ($sock->sockdomain == Socket::PF_UNIX) {
$log->tracef('Connected to %s as %s', $endpoint, $sock->peerpath);
}
# We start with a null handler for read, because our behaviour varies depending on
# whether we want to go through the SSL dance or not.
$self->add_child(
my $stream = IO::Async::Stream->new(
handle => $sock,
on_read => sub { 0 }
)
);
( run in 0.359 second using v1.01-cache-2.11-cpan-b61123c0432 )