Async DBusMessage reads using the C API

Matthew Johnson dbus at matthew.ath.cx
Mon Nov 7 03:13:22 PST 2005


On Fri, 4 Nov 2005, Havoc Pennington wrote:

> On Fri, 2005-11-04 at 10:25 +0000, Matthew Johnson wrote:
>
> I think the right patch is probably:
> - make the body of read_write_dispatch() into a private function
>   that takes a "dbus_bool_t dispatch" argument
> - wrap it in two public functions, one that calls it with TRUE
>   and another that calls with with FALSE
>
> i.e. this is exactly like read_write_dispatch except it never
> dispatches.
>
OK, I have attached a patch which should do that, and a test case which
uses it.

Matt

-- 
Matthew Johnson
http://www.matthew.ath.cx/
-------------- next part --------------
2839,2843c2839,2843
<  *
<  * If there are messages to dispatch and the dispatch flag is set, this
<  * function will dbus_connection_dispatch() once, and return. If there are no
<  * messages to dispatch, this function will block until it can read or write,
<  * then read or write, then return.
---
>  * 
>  * If there are messages to dispatch, this function will
>  * dbus_connection_dispatch() once, and return. If there are no
>  * messages to dispatch, this function will block until it can read or
>  * write, then read or write, then return.
2855d2854
<  * @param dispatch dispatch new messages or leave them on the incoming queue
2859,2861c2858,2859
< _dbus_connection_read_write_dispatch (DBusConnection *connection,
<                                      int             timeout_milliseconds, 
<                                      dbus_boot_t     dispatch)
---
> dbus_connection_read_write_dispatch (DBusConnection *connection,
>                                      int             timeout_milliseconds)
2870c2868
<   if (dispatch && dstatus == DBUS_DISPATCH_DATA_REMAINS)
---
>   if (dstatus == DBUS_DISPATCH_DATA_REMAINS)
2903,2964d2900
< 
< /**
<  * This function is intended for use with applications that don't want
<  * to write a main loop and deal with #DBusWatch and #DBusTimeout. An
<  * example usage would be:
<  * 
<  * @code
<  *   while (dbus_connection_read_write_dispatch (connection, -1))
<  *     ; // empty loop body
<  * @endcode
<  * 
<  * In this usage you would normally have set up a filter function to look
<  * at each message as it is dispatched. The loop terminates when the last
<  * message from the connection (the disconnected signal) is processed.
<  * 
<  * If there are messages to dispatch, this function will
<  * dbus_connection_dispatch() once, and return. If there are no
<  * messages to dispatch, this function will block until it can read or
<  * write, then read or write, then return.
<  *
<  * The way to think of this function is that it either makes some sort
<  * of progress, or it blocks.
<  *
<  * The return value indicates whether the disconnect message has been
<  * processed, NOT whether the connection is connected. This is
<  * important because even after disconnecting, you want to process any
<  * messages you received prior to the disconnect.
<  *
<  * @param connection the connection
<  * @param timeout_milliseconds max time to block or -1 for infinite
<  * @returns #TRUE if the disconnect message has not been processed
<  */
< dbus_bool_t
< dbus_connection_read_write_dispatch (DBusConnection *connection,
<                                      int             timeout_milliseconds)
< {
<    return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, TRUE);
< }
< 
< /** 
<  * This function is intended for use with applications that don't want to
<  * write a main loop and deal with #DBusWatch and #DBusTimeout.
<  * 
<  * If there are no messages to dispatch, this function will block until it can
<  * read or write, then read or write, then return.
<  *
<  * The return value indicates whether the disconnect message has been
<  * processed, NOT whether the connection is connected. This is important
<  * because even after disconnecting, you want to process any messages you
<  * received prior to the disconnect.
<  *
<  * @param connection the connection 
<  * @param timeout_milliseconds max time to block or -1 for infinite 
<  * @returns #TRUE if the disconnect message has not been processed
<  */
< dbus_bool_t 
< dbus_connection_read_write (DBusConnection *connection, 
<                             int             timeout_milliseconds) 
< { 
<    return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, FALSE);
< }
< 
105,106d104
< dbus_bool_t        dbus_connection_read_write                   (DBusConnection             *connection,
<                                                                  int                         timeout_milliseconds);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-example.c
Type: text/x-csrc
Size: 11893 bytes
Desc: 
Url : http://lists.freedesktop.org/archives/dbus/attachments/20051107/1d9cba97/dbus-example.c


More information about the dbus mailing list