File Coverage

blib/lib/MogileFS/Connection/Mogstored.pm
Criterion Covered Total %
statement 9 18 50.0
branch 0 4 0.0
condition n/a
subroutine 3 6 50.0
pod 0 3 0.0
total 12 31 38.7


line stmt bran cond sub pod time code
1             package MogileFS::Connection::Mogstored;
2 21     21   110 use strict;
  21         33  
  21         471  
3 21     21   84 use IO::Socket::INET;
  21         31  
  21         112  
4 21     21   8811 use Socket qw(SO_KEEPALIVE);
  21         33  
  21         3987  
5              
6             sub new {
7 0     0 0   my ($class, $ip, $port) = @_;
8 0           return bless {
9             sock => undef, # undef if not yet connected, else socket to host
10             ip => $ip,
11             port => $port,
12             }, $class;
13             }
14              
15             # returns (or connects to & returns) raw socket to mogstored.
16             sub sock {
17 0     0 0   my ($self, $timeout) = @_;
18 0 0         return $self->{sock} if $self->{sock};
19             $self->{sock} = IO::Socket::INET->new(PeerAddr => $self->{ip},
20             PeerPort => $self->{port},
21 0 0         Timeout => $timeout) or die "Could not connect to mogstored on ".$self->{ip}.":".$self->{port};
22 0           $self->{sock}->sockopt(SO_KEEPALIVE, 1);
23 0           return $self->{sock};
24             }
25              
26             sub mark_dead {
27 0     0 0   my $self = shift;
28 0           $self->{sock} = undef;
29             }
30              
31             1;