Skip to content

Commit

Permalink
fix rt#99762 - support for mpd on a Unix socket (smcv)
Browse files Browse the repository at this point in the history
  • Loading branch information
jquelin committed May 20, 2016
1 parent f5ba44f commit 3eb54e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@
Changelog for Audio-MPD

{{$NEXT}}
- fix rt#99762 - support for mpd on a Unix socket (smcv)

2.003 2016-05-20 14:01:00+02:00 Europe/Paris
- fix rt#114136 - allow mpd-dynamic to run without a ratings.db
Expand Down
22 changes: 16 additions & 6 deletions lib/Audio/MPD.pm
Expand Up @@ -56,7 +56,7 @@ has collection => ( ro, lazy_build, isa=>'Audio::MPD::Collection' );
has playlist => ( ro, lazy_build, isa=>'Audio::MPD::Playlist' );
has version => ( rw );

has _socket => ( rw, isa=>'IO::Socket::IP' );
has _socket => ( rw, isa=>'IO::Socket' );


#--
Expand Down Expand Up @@ -119,11 +119,21 @@ sub _connect_to_mpd_server {
my ($self) = @_;

# try to connect to mpd.
my $socket = IO::Socket::IP->new(
PeerAddr => $self->host,
PeerPort => $self->port,
)
or die "Could not create socket: $!\n";
my $socket;

if ($self->host =~ m{^/}) {
eval q{use IO::Socket::UNIX qw(); 1}
or die "Could not load IO::Socket::UNIX: $@\n";
$socket = IO::Socket::UNIX->new($self->host)
or die "Could not create socket: $!\n";
}
else {
$socket = IO::Socket::IP->new(
PeerAddr => $self->host,
PeerPort => $self->port,
)
or die "Could not create socket: $!\n";
}

# parse version information.
my $line = $socket->getline;
Expand Down

0 comments on commit 3eb54e6

Please sign in to comment.