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>--K<br><br><div><span class="gmail_quote">On 1/26/07, <b class="gmail_sendername">Havoc Pennington</b> <<a href="mailto:hp@redhat.com">
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>