summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonrad Lipinski <konrad.l@samsung.com>2016-08-25 11:07:26 +0200
committerKonrad Lipinski <konrad.l@samsung.com>2016-08-31 17:03:16 +0200
commitbc10afa760a33082dd89a99ee6b355f70f78980f (patch)
tree72bb3066c9419631add342adb233262340e1612f
parent6e8eb15015243b096d0f3ea7d77e37baf08bb8e7 (diff)
downloaddbus-bc10afa760a33082dd89a99ee6b355f70f78980f.tar.gz
dbus-bc10afa760a33082dd89a99ee6b355f70f78980f.tar.bz2
dbus-bc10afa760a33082dd89a99ee6b355f70f78980f.zip
calculate kdbus timeout based on user timeout
Change-Id: I9fd1720e5c2a1edaa1fcd66b78df0b0238e9ce9f
-rw-r--r--dbus/dbus-connection.c1
-rw-r--r--dbus/dbus-message-internal.h2
-rw-r--r--dbus/dbus-message-private.h1
-rw-r--r--dbus/dbus-message.c8
-rwxr-xr-xdbus/dbus-transport-kdbus.c34
5 files changed, 24 insertions, 22 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 8392e10d..9a5be336 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -3471,6 +3471,7 @@ dbus_connection_send_with_reply (DBusConnection *connection,
return TRUE;
}
+ _dbus_message_set_timeout_ms(message, timeout_milliseconds);
pending = _dbus_pending_call_new_unlocked (connection,
timeout_milliseconds,
reply_handler_timeout);
diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h
index 88586b57..2db5d85a 100644
--- a/dbus/dbus-message-internal.h
+++ b/dbus/dbus-message-internal.h
@@ -50,6 +50,8 @@ typedef struct DBusMessageLoader DBusMessageLoader;
void _dbus_message_get_network_data (DBusMessage *message,
const DBusString **header,
const DBusString **body);
+void _dbus_message_set_timeout_ms(DBusMessage *message, int timeout_ms);
+int _dbus_message_get_timeout_ms(DBusMessage const *message);
DBUS_PRIVATE_EXPORT
void _dbus_message_get_unix_fds (DBusMessage *message,
const int **fds,
diff --git a/dbus/dbus-message-private.h b/dbus/dbus-message-private.h
index 801b1435..13ea36a0 100644
--- a/dbus/dbus-message-private.h
+++ b/dbus/dbus-message-private.h
@@ -113,6 +113,7 @@ struct DBusMessage
DBusList *counters; /**< 0-N DBusCounter used to track message size/unix fds. */
long size_counter_delta; /**< Size we incremented the size counters by. */
+ int timeout_ms;
dbus_uint32_t changed_stamp : CHANGED_STAMP_BITS; /**< Incremented when iterators are invalidated. */
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index e058b7ad..0e3f323b 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -293,6 +293,13 @@ _dbus_message_get_network_data (DBusMessage *message,
*body = &message->body;
}
+void _dbus_message_set_timeout_ms(DBusMessage *message, int timeout_ms) {
+ message->timeout_ms = timeout_ms;
+}
+int _dbus_message_get_timeout_ms(DBusMessage const *message) {
+ return message->timeout_ms;
+}
+
/**
* Gets the unix fds to be sent over the network for this message.
* This function is guaranteed to always return the same data once a
@@ -1359,6 +1366,7 @@ dbus_message_new_empty_header (dbus_bool_t gvariant)
#endif
message->counters = NULL;
message->size_counter_delta = 0;
+ message->timeout_ms = -1;
message->changed_stamp = 0;
#ifdef HAVE_UNIX_FD_PASSING
diff --git a/dbus/dbus-transport-kdbus.c b/dbus/dbus-transport-kdbus.c
index 591df865..39a8842f 100755
--- a/dbus/dbus-transport-kdbus.c
+++ b/dbus/dbus-transport-kdbus.c
@@ -102,7 +102,7 @@ int debug = -1;
((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) && \
((uint8_t *)(iter) >= (uint8_t *)(first)); \
iter = (void*)(((uint8_t *)iter) + ALIGN8((iter)->size)))
-#define KDBUS_DEFAULT_TIMEOUT_NS 50000000000LLU
+#define KDBUS_INFINITE_TIMEOUT_NS 0x3fffffffffffffffLLU
/**
* @defgroup DBusTransportKdbus DBusTransport implementations for kdbus
@@ -770,12 +770,18 @@ kdbus_write_msg_internal (DBusTransportKdbus *transport,
else /* method calls */
{
long tv_sec, tv_usec;
+ int timeout_ms = _dbus_message_get_timeout_ms(message);
_dbus_get_monotonic_time (&tv_sec, &tv_usec);
/* ms us ns */
- timeout_ns_or_cookie_reply = (dbus_uint64_t)tv_sec * 1000ULL * 1000ULL * 1000ULL
- + tv_usec * 1000ULL
- + KDBUS_DEFAULT_TIMEOUT_NS;
+ timeout_ns_or_cookie_reply = 1U | ( /* ensure nonzero */
+ (dbus_uint64_t)tv_sec * 1000ULL * 1000ULL * 1000ULL
+ + tv_usec * 1000ULL + (
+ timeout_ms == -1 ? _DBUS_DEFAULT_TIMEOUT_VALUE * 1000000LLU :
+ timeout_ms == DBUS_TIMEOUT_INFINITE ? KDBUS_INFINITE_TIMEOUT_NS :
+ (uint64_t)timeout_ms * 1000000U
+ )
+ );
flags |= KDBUS_MSG_EXPECT_REPLY;
}
@@ -3111,24 +3117,8 @@ kdbus_decode_kernel_message (const struct kdbus_msg *msg,
{
case KDBUS_ITEM_REPLY_TIMEOUT:
case KDBUS_ITEM_REPLY_DEAD:
- {
- DBusMessage *message = NULL;
- _dbus_verbose (" +%s (%llu bytes) cookie=%llu\n",
- enum_MSG (item->type), item->size, msg->cookie_reply);
-
- message = _dbus_generate_local_error_message (msg->cookie_reply,
- item->type == KDBUS_ITEM_REPLY_TIMEOUT ? DBUS_ERROR_NO_REPLY : DBUS_ERROR_NAME_HAS_NO_OWNER, NULL);
- if (message == NULL)
- {
- ret_size = -1;
- goto out;
- }
-
- dbus_message_set_serial (message, get_next_client_serial (kdbus_transport));
-
- if (!add_message_to_received (message, kdbus_transport->base.connection))
- ret_size = -1;
- }
+ _dbus_verbose (" +%s (%llu bytes) cookie=%llu\n",
+ enum_MSG (item->type), item->size, msg->cookie_reply);
break;
case KDBUS_ITEM_NAME_ADD: