line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Audio::Daemon::MPG123; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1659
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
26928
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
1495
|
use IO::Select; |
|
1
|
|
|
|
|
1825
|
|
|
1
|
|
|
|
|
48
|
|
5
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
585
|
|
6
|
|
|
|
|
|
|
$VERSION='0.9Beta'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
0
|
|
my ($proto, %arg) = @_; |
10
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
11
|
0
|
|
|
|
|
|
my $self = {}; |
12
|
0
|
|
|
|
|
|
foreach my $k (qw/Allow Deny Server Port Log/) { |
13
|
0
|
0
|
|
|
|
|
$self->{$k} = $arg{$k} if (defined $arg{$k}); |
14
|
|
|
|
|
|
|
} |
15
|
0
|
|
|
|
|
|
$self->{sep} = sprintf("%c", 255); |
16
|
0
|
|
|
|
|
|
$self->{subsep} = sprintf("%c", 254); |
17
|
0
|
|
|
|
|
|
bless($self, $class); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
|
sub debug { my $self = shift; return $self->log('debug', @_); } |
|
0
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
0
|
|
sub info { my $self = shift; return $self->log('info', @_); } |
|
0
|
|
|
|
|
|
|
22
|
0
|
|
|
0
|
0
|
|
sub error { my $self = shift; return $self->log('error', @_); } |
|
0
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
0
|
|
sub crit { my $self = shift; return $self->log('crit', @_); } |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
0
|
0
|
|
sub warn { my $self = shift; return $self->log('warn', @_); } |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub log { |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
my @caller = caller(2); |
29
|
|
|
|
|
|
|
# print "caller line is ".$caller[2]."\n"; |
30
|
|
|
|
|
|
|
# ($package, $filename, $line, $subroutine, $hasargs, |
31
|
|
|
|
|
|
|
# $wantarray, $evaltext, $is_require, $hints, $bitmask) |
32
|
0
|
0
|
|
|
|
|
if (defined $self->{Log}) { |
33
|
0
|
|
|
|
|
|
&{$self->{Log}}(@_, @caller); |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return 1; |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
|
return 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub socket { |
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
42
|
0
|
0
|
|
|
|
|
if (ref $self->{socket} eq 'IO::Socket::INET') { |
43
|
0
|
|
|
|
|
|
$self->debug('caller requested existing socket'); |
44
|
0
|
|
|
|
|
|
return $self->{socket} |
45
|
|
|
|
|
|
|
} |
46
|
0
|
0
|
|
|
|
|
if (ref $self eq 'Audio::Daemon::MPG123::Server') { |
|
|
0
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if (! defined $self->{Port}) { |
48
|
0
|
|
|
|
|
|
$self->crit("No Port defined for socket creation"); |
49
|
0
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
$self->{socket} = IO::Socket::INET->new(LocalPort => $self->{Port}, Proto=>'udp'); |
52
|
|
|
|
|
|
|
} elsif (ref $self eq 'Audio::Daemon::MPG123::Client') { |
53
|
0
|
0
|
0
|
|
|
|
if (! defined $self->{Port} || ! defined $self->{Server}) { |
54
|
0
|
|
|
|
|
|
$self->crit("Need both the Port and Server defined for socket creation"); |
55
|
0
|
|
|
|
|
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
$self->{socket} = IO::Socket::INET->new(PeerPort => $self->{Port}, PeerAddr => $self->{Server}, Proto=>'udp'); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
0
|
|
|
|
|
if (! defined $self->{socket}) { |
60
|
0
|
|
|
|
|
|
$self->crit("Failed to initialize Socket: $!"); |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
return $self->{socket}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |