Commit 7c4b3458 authored by Kimmo Hämäläinen's avatar Kimmo Hämäläinen Committed by John Palmieri

fix expiration of pending replies

* bus/expirelist.c
  (do_expiration_with_current_time): calculate correct min wait time
  and next interval
  (bus_expire_list_add, bus_expire_list_add_link): if the timeout is
  disabled when we add an item to the expire list, enable the timeout
  (do_expiration_with_current_time): only set timeout if there are
  items to expire
parent 960fef84
2008-04-03 John (J5) Palmieri <johnp@redhat.com>
Patch from Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>
* bus/expirelist.c
(do_expiration_with_current_time): calculate correct min wait time
and next interval
(bus_expire_list_add, bus_expire_list_add_link): if the timeout is
disabled when we add an item to the expire list, enable the timeout
(do_expiration_with_current_time): only set timeout if there are
items to expire
2008-04-01 Timo Hoenig <thoenig@suse.de> 2008-04-01 Timo Hoenig <thoenig@suse.de>
Patch from Frederic Crozat <fcrozat@mandriva.com> Patch from Frederic Crozat <fcrozat@mandriva.com>
......
...@@ -138,9 +138,11 @@ do_expiration_with_current_time (BusExpireList *list, ...@@ -138,9 +138,11 @@ do_expiration_with_current_time (BusExpireList *list,
long tv_usec) long tv_usec)
{ {
DBusList *link; DBusList *link;
int next_interval; int next_interval, min_wait_time, items_to_expire;
next_interval = -1; next_interval = -1;
min_wait_time = 3600 * 1000; /* this is reset anyway if used */
items_to_expire = 0;
link = _dbus_list_get_first_link (&list->items); link = _dbus_list_get_first_link (&list->items);
while (link != NULL) while (link != NULL)
...@@ -173,17 +175,20 @@ do_expiration_with_current_time (BusExpireList *list, ...@@ -173,17 +175,20 @@ do_expiration_with_current_time (BusExpireList *list,
} }
else else
{ {
/* We can end the loop, since the connections are in oldest-first order */ double to_wait;
next_interval = ((double)list->expire_after) - elapsed;
_dbus_verbose ("Item %p expires in %d milliseconds\n",
item, next_interval);
break; items_to_expire = 1;
to_wait = (double) list->expire_after - elapsed;
if (min_wait_time > to_wait)
min_wait_time = to_wait;
} }
link = next; link = next;
} }
if (next_interval < 0 && items_to_expire)
next_interval = min_wait_time;
return next_interval; return next_interval;
} }
...@@ -223,16 +228,14 @@ void ...@@ -223,16 +228,14 @@ void
bus_expire_list_remove_link (BusExpireList *list, bus_expire_list_remove_link (BusExpireList *list,
DBusList *link) DBusList *link)
{ {
_dbus_list_remove_link (&list->items, _dbus_list_remove_link (&list->items, link);
link);
} }
dbus_bool_t dbus_bool_t
bus_expire_list_remove (BusExpireList *list, bus_expire_list_remove (BusExpireList *list,
BusExpireItem *item) BusExpireItem *item)
{ {
return _dbus_list_remove (&list->items, return _dbus_list_remove (&list->items, item);
item);
} }
void void
...@@ -246,8 +249,13 @@ dbus_bool_t ...@@ -246,8 +249,13 @@ dbus_bool_t
bus_expire_list_add (BusExpireList *list, bus_expire_list_add (BusExpireList *list,
BusExpireItem *item) BusExpireItem *item)
{ {
return _dbus_list_prepend (&list->items, dbus_bool_t ret;
item);
ret = _dbus_list_prepend (&list->items, item);
if (ret && !dbus_timeout_get_enabled (list->timeout))
bus_expire_timeout_set_interval (list->timeout, 0);
return ret;
} }
void void
...@@ -256,8 +264,10 @@ bus_expire_list_add_link (BusExpireList *list, ...@@ -256,8 +264,10 @@ bus_expire_list_add_link (BusExpireList *list,
{ {
_dbus_assert (link->data != NULL); _dbus_assert (link->data != NULL);
_dbus_list_prepend_link (&list->items, _dbus_list_prepend_link (&list->items, link);
link);
if (!dbus_timeout_get_enabled (list->timeout))
bus_expire_timeout_set_interval (list->timeout, 0);
} }
DBusList* DBusList*
...@@ -270,8 +280,7 @@ DBusList* ...@@ -270,8 +280,7 @@ DBusList*
bus_expire_list_get_next_link (BusExpireList *list, bus_expire_list_get_next_link (BusExpireList *list,
DBusList *link) DBusList *link)
{ {
return _dbus_list_get_next_link (&list->items, return _dbus_list_get_next_link (&list->items, link);
link);
} }
dbus_bool_t dbus_bool_t
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment