Hmm looks like this may not be it. It works great except that the filter func is never called to rcv the *first* message sent. <br><br>Subsequent sends are rcvd fine. I see that the select gets unblocked when the first time data comes in and read_write_dispatch gets called. But in turn never calls the filterfunc! Why? Doing verbose output i see for the first time i send message, it does a iteration_unlocked and never calls connection_dispatch. All subsequent sends call connectio_dispatch which in turn calls the filter func.
<br><br>dbus_read_write_dispatch() code snippet...<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if (dispatch && dstatus == DBUS_DISPATCH_DATA_REMAINS)</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> dbus_connection_dispatch (connection);
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">... else
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ... _dbus_connection_do_iteration_unlocked (connection,
</span><br style="font-family: courier new,monospace;"><br>So why is the dstatus != DATA_REMAINS the first time and works all other times is the question i couldnt answer myself.<br><br>Thanks,<br>-K<br><br><div><span class="gmail_quote">
On 1/26/07, <b class="gmail_sendername">Krishna R</b> <<a href="mailto:sith.list@gmail.com">sith.list@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks that makes sense. The select method blocking on the readset of the sockets for rcving thread works fine. The documentation says DO NOT use get_socket and use DBUSWatch, but i guess i am ok since this is a simple app and only this thread is recving data and there is no main loop etc?
<br><br>This what i had to do...if there are other newbies trying the same thing...<br><br><font size="2"><span style="font-family: courier new,monospace;"> // Get the socket descriptor of dbus connection of this process
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if (!dbus_connection_get_socket(pConnection,&socketfd))</span><span style="font-family: courier new,monospace;">
{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return NULL;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> } </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> FD_ZERO(&readSet);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
FD_SET(socketfd, &readSet);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
while(1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
retVal = select(socketfd+1, &readSet, NULL, NULL, NULL); // block</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if (-1 == retVal) // The socket might no loger be available</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if (!dbus_connection_read_write_dispatch (pConnection, 0))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // If this returns FALSE, the connection is disconnected
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // and we dont want to spin in this loop forever</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return NULL; // exit from thread </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> else if (FD_ISSET(socketfd, &readSet))
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> { </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
dbus_connection_read_write_dispatch (pConnection, 0);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> } </span></font><br><br>Thanks for your help again.<br><span class="sg">--K</span><div><span class="e" id="q_110609e593f5ed60_2"><br><br><div><span class="gmail_quote">
On 1/26/07, <b class="gmail_sendername">Havoc Pennington</b> <<a href="mailto:hp@redhat.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
hp@redhat.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Krishna R wrote:<br>> Do i still need the main loop you are talking about in the above simple
<br>> scenario?<br>><br><br>The problem is that there's a lock on the socket. When<br>read_write_dispatch() blocks, it will hold this lock. That means<br>dbus_connection_flush() can't acquire it in order to flush.
<br><br>You can imagine various libdbus fixes to make it smarter about this<br>situation, but if you don't want to hack on libdbus you probably have to<br> only call read_write_dispatch() when you know it won't block, which is
<br>normally done with a main loop as Thiago suggests. As a hack you could<br>also just call dbus_connection_get_socket() and poll()/select() on it<br>manually in a simple loop.<br><br>An even worse hack would be to try and wake up the poll by creating an
<br>EINTR (raise some bogus signal), but I don't know if that will work and<br>it probably isn't that portable across unix flavors if it does.<br><br>Another bad hack would be to put a short timeout on the<br>read_write_dispatch so it never blocks too long.
<br><br>Havoc<br><br><br></blockquote></div><br>
</span></div></blockquote></div><br>