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   128 use strict;
  21         50  
  21         11796  
3 21     21   142 use IO::Socket::INET;
  21         51  
  21         260  
4 21     21   51293 use Socket qw(SO_KEEPALIVE);
  21         56  
  21         5863  
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 0 0         $self->{sock} = IO::Socket::INET->new(PeerAddr => $self->{ip},
20             PeerPort => $self->{port},
21             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;