Skip to content

connection is not reconnecting on idle #7

Description

@carnager
#!/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:

  1. $mpd->close(); does not work without a try block and bails out.
  2. $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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions