Hi,

On Thu, 31 Mar 2016 18:03:18 +0200
Mehturt <meht...@gmail.com> wrote:

> On Wed, Mar 30, 2016 at 9:29 AM, Mehturt <meht...@gmail.com> wrote:
...snip...
> > Thanks, I was able to get the async part working with some minor 
> > modifications.
> > I'm seeing one problem though, when I have my script running, and I
> > quit xmms2 via "xmms2 quit", I get infinite loop of the following
> > messages:
> >
> >  ******
> >  * xmmsc_io_in_handle was called although the xmms2 daemon is not connected
> >  * This is probably an error in the application using libxmmsclient
> >  ******
> >
> > Any idea why?
> > Thanks a lot for your support.

This is the mainloop trying to see if there are new messages on the
connection that no longer exists. This is of course doomed to fail.

You should set up a disconnect callback to clean up when the connection
goes away. In the present program you'll probably want to just quit the
mainloop, since xmms2 is the mainloop's only purpose. (In bigger
programs, you could cleanup only the callbacks associated with the
connection that went away, and show a reconnect dialog or so.)

The attached patch quits the mainloop on disconnect for the previously
patched tut6.pl.

> And this is what I use at the moment for testing..
> https://github.com/mehturt/xmms2_lastfm_scrobbler/blob/master/scrobbler.pl
> Comments welcome.

In xmms2_current_id you're using $result->wait(). This is problematic,
as wait() does not know what to do when a different result than $result
comes in. You should use a callback also there.


Cheers,

Erik / nesciens
>From e820977263f7deccc8afa00b40041da4bb9f91d8 Mon Sep 17 00:00:00 2001
From: Erik Massop <emas...@google.com>
Date: Sat, 2 Apr 2016 12:47:53 +0100
Subject: [PATCH 2/2] Use disconnect callback. Add note on mixing sync and
 async.

---
 perl/tut6.pl | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/perl/tut6.pl b/perl/tut6.pl
index 28afb6c..197cf3e 100644
--- a/perl/tut6.pl
+++ b/perl/tut6.pl
@@ -25,9 +25,20 @@ sub my_current_id {
     # which was passed in as the userdata.
 
     printf "Current id is %d\n", $value;
+
+    # We return 1 to signal that we want to stay subscribed to this broadcast.
     return 1
 }
 
+# We also set up a callback for disconnects from xmms2d. Read the main program
+# first before returning here.
+
+sub my_disconnect_cb {
+    my ($xc) = @_;
+    printf "We lost the connection to xmms2d. Exiting the mainloop.\n";
+    $xc->quit_loop;
+}
+
 # Let's ask for the current id in an async way instead of the sync way as we
 # did in tut2. Instead of using the request method you could also do those
 # things by hand:
@@ -35,7 +46,6 @@ sub my_current_id {
 # my $request = $xmms->playback_current_id;
 # $request->notifier_set( \&my_current_id, $xmms );
 
-#$xmms->request( playback_current_id => \&my_current_id );
 $xmms->request( broadcast_playback_current_id
     => sub { my_current_id (@_, $xmms) } );
 
@@ -45,11 +55,20 @@ $xmms->request( broadcast_playback_current_id
 # will keep your GUI from hanging while waiting for xmms2 to answer your
 # command.
 
+# We also ask xmms2 to call our my_disconnect_cb function when the connection is
+# lost. In that callback function we quit the mainloop, so that it does not
+# keep on running and pointlessly checking if there are new messages on the
+# disconnected connection.
+$xmms->disconnect_callback_set( sub { my_disconnect_cb ($xmms) } );
+
+
 # The big difference between a sync client and an async client is that the
 # async client works with callbacks. When you send such an asynchronous
 # command, the callback set up will receive the result when it arrives.  That
 # means you don't need to wait ($result->wait) for results as in synchronous
-# operations.
+# operations. In fact, you should not use $result->wait at all in an async
+# client, as $result->wait does not know what to do when an async message comes
+# in.
 #
 # In order to make Audio::XMMSClient call your callback functions we need to
 # run a mainloop. The default mainloop uses a standard unix io event listener
-- 
2.1.4

--
_______________________________________________
Xmms2-devel mailing list
Xmms2-devel@lists.xmms2.org
https://lists.xmms2.org/cgi-bin/mailman/listinfo/xmms2-devel

Reply via email to