From: Daniel Mack Date: Tue, 21 Oct 2014 18:17:45 +0000 (+0200) Subject: test-sync: implement send_reply() X-Git-Tag: upstream/0.20141102.012929utc~60 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=423000bd36fabbd0dce416363cbead354f00f5ed;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git test-sync: implement send_reply() Implement a new helper function to reply to pending messages. Formerly, the test abused the timeout parameter to respond, knowing that its value will eventually end up in the kdbus message in the same union as the cookie_reply field. In the process of switching to absolute timeouts, however, this bites us, so move this hack out of the way first. Signed-off-by: Daniel Mack --- diff --git a/test/test-sync.c b/test/test-sync.c index ffd445f..ec706d6 100644 --- a/test/test-sync.c +++ b/test/test-sync.c @@ -23,6 +23,53 @@ static unsigned int cookie = 0xdeadbeef; static void nop_handler(int sig) {} +static int send_reply(const struct kdbus_conn *conn, + uint64_t reply_cookie, + uint64_t dst_id) +{ + struct kdbus_msg *msg; + const char ref1[1024 * 128 + 3] = "0123456789_0"; + struct kdbus_item *item; + uint64_t size; + int ret; + + size = sizeof(struct kdbus_msg); + size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec)); + + msg = malloc(size); + if (!msg) { + ret = -errno; + kdbus_printf("unable to malloc()!?\n"); + return ret; + } + + memset(msg, 0, size); + msg->size = size; + msg->src_id = conn->id; + msg->dst_id = dst_id; + msg->cookie_reply = reply_cookie; + msg->payload_type = KDBUS_PAYLOAD_DBUS; + + item = msg->items; + + item->type = KDBUS_ITEM_PAYLOAD_VEC; + item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec); + item->vec.address = (uintptr_t)&ref1; + item->vec.size = sizeof(ref1); + item = KDBUS_ITEM_NEXT(item); + + ret = ioctl(conn->fd, KDBUS_CMD_MSG_SEND, msg); + if (ret < 0) { + ret = -errno; + kdbus_printf("error sending message: %d (%m)\n", ret); + return ret; + } + + free(msg); + + return 0; +} + static int interrupt_sync(struct kdbus_conn *conn_src, struct kdbus_conn *conn_dst, int sa_flags) @@ -88,7 +135,7 @@ static void *run_thread_reply(void *data) ret = kdbus_msg_recv_poll(conn_a, 3000, NULL, NULL); if (ret == 0) { kdbus_printf("Thread received message, sending reply ...\n"); - kdbus_msg_send(conn_a, NULL, 0, 0, cookie, 0, conn_b->id); + send_reply(conn_a, cookie, conn_b->id); } pthread_exit(NULL);