Re: Please help with signals, some seem to get lost

Erik Slagter <[email protected]> Tue, 14 Jan 2025 11:32:36 +0100
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <[email protected]>
Update!

Some experimentation led to this code which seems to work! The main 
culprit seems to be that I called dbus_connection_read_write_dispatch 
and then dbus_connection_pop_message, which apparently works for methods 
but not (always) for signals. Looks like some signal messages where 
overwritten before they could be processed.

Please comment on my current approach (code simplified for optimal 
presentation). Please also note that dbus_connection_pop_message now 
always succeeds at the first occurrence (sometimes) or the second 
occurrence (mostly), The code after the second occurrence 
[while(dbus_connection_dispatch(bus_connection) != 
DBUS_DISPATCH_COMPLETE) etc.] doesn't seem to be necessary, at least up 
until now it has never run. Apparently no "dispatch" is necessary. The 
dbus_connection_flush statement may not be necessary as well.

I now send 16 test signals in one go and all of them are received!

get_message(...)
{
	if((pending_message = dbus_connection_pop_message(connection)))
		goto done;

	dbus_connection_flush(bus_connection);

	if(!dbus_connection_read_write(connection, -1))
		throw("failed");

	if((pending_message = dbus_connection_pop_message(connection)))
		goto done;

	while(dbus_connection_dispatch(connection) != DBUS_DISPATCH_COMPLETE)
	{
		print "call dispatch";

		if((pending_message = dbus_connection_pop_message(connection)))
		{
			print << "pop succeeded @3";
			goto done;
		}

		print "repeating dispatch\n";
	}

	if(!(pending_message = dbus_connection_pop_message(connection)))
	{
		print "pop succeeded @4";
		goto done;
	}

	throw("failed"));
}