AnyMongo
view release on metacpan or search on metacpan
lib/AnyMongo/Connection.pm view on Meta::CPAN
}
}
sub connect {
my ($self,%args) = @_;
return if $self->connected || $self->{_trying_connect};
# warn "connect...\n";
$self->{_trying_connect} = 1;
#setup connection timeout watcher
my $timer; $timer = AnyEvent->timer( after => 5 ,cb => sub {
undef $timer;
unless ( $self->connected ) {
$self->{_trying_connect} = 0;
$self->cv->croak('Failed to connect to any mongodb servers,timeout');
}
});
$self->cv->begin( sub {
undef $timer;
if ($self->connected) {
$self->_connection_error(0);
shift->send;
}
else {
shift->croak("Failed to connect to any mongodb servers");
}
});
my $servers = $self->{mongo_servers};
lib/AnyMongo/Connection.pm view on Meta::CPAN
if (($flags & REPLY_CURSOR_NOT_FOUND) != 0) {
croak("cursor not found");
}
}
sub receive_data {
my ($self,$size,$hd) = @_;
$hd ||= $self->master_handle;
croak 'connection lost' unless $hd or $self->_check_connection;
my $cv = AE::cv;
my $timer; $timer = AnyEvent->timer( after => $self->query_timeout ,cb => sub {
undef $timer;
$cv->croak('receive_data timeout');
});
$hd->push_read(chunk => $size, sub {
my ($hdl, $bytes) = @_;
$cv->send($_[1]);
});
$hd->{cv} = $cv;
my $data = $cv->recv;
delete $hd->{cv};
$data;
( run in 1.265 second using v1.01-cache-2.11-cpan-49f99fa48dc )