#!/usr/bin/env perl
#
use Net::MPD;
my $mpd = Net::MPD->connect($ENV{MPD_HOST} // $mpd_host // 'localhost');
sleep 121;
$mpd->add('flac/Twisted Roots/1993 Turn to Stone/06-Trax.flac')
result:
perl foo.pl
Error reading line from socket at foo.pl line 9.
Documentation says:
close
close the connection. This is pretty worthless as the library will just reconnect for the next command.
So I tried to add a $mpd->close(); line before the sleep, which gives a reading socket error on the close command, which ends the script instantly without ever going to the sleep.
Then I put the close command into a try block. Which resulted in the same behavior as the original script above.
Finally I closed the socket itself after the close command. The final script looks like this now:
#!/usr/bin/env perl
#
use Net::MPD;
use Try::Tiny;
my $mpd = Net::MPD->connect($ENV{MPD_HOST} // $mpd_host // 'localhost');
try { $mpd->close(); };
$mpd->{socket}->close;
sleep 121;
$mpd->add('flac/Twisted Roots/1993 Turn to Stone/06-Trax.flac');
Which finally had the desired result.
So actually there are 2 bugs here:
- $mpd->close(); does not work without a try block and bails out.
- $mpd->close(); does not close the actual socket.
Also I think that both above issues should be done automatically without the user having to close down the socket manually before idle times.
result:
Documentation says:
So I tried to add a
$mpd->close();line before the sleep, which gives a reading socket error on the close command, which ends the script instantly without ever going to the sleep.Then I put the close command into a try block. Which resulted in the same behavior as the original script above.
Finally I closed the socket itself after the close command. The final script looks like this now:
Which finally had the desired result.
So actually there are 2 bugs here:
Also I think that both above issues should be done automatically without the user having to close down the socket manually before idle times.