summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDjalal Harouni <tixxdz@opendz.org>2014-08-18 17:13:10 +0100
committerDaniel Mack <zonque@gmail.com>2014-08-19 09:16:48 +0200
commite00baea00e68fceddc2cbbd06a486b6b02654cf5 (patch)
tree8978f6e31d3d9d7f5f7d27a080f750d788f99012
parent8b742a708c7fd597fdcf18e67078cf2f2da3b42e (diff)
downloadkdbus-bus-e00baea00e68fceddc2cbbd06a486b6b02654cf5.tar.gz
kdbus-bus-e00baea00e68fceddc2cbbd06a486b6b02654cf5.tar.bz2
kdbus-bus-e00baea00e68fceddc2cbbd06a486b6b02654cf5.zip
test: add conn_recv() that use poll() and msg_recv()
Will be used by tests. Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
-rw-r--r--test/kdbus-util.c34
-rw-r--r--test/kdbus-util.h1
2 files changed, 35 insertions, 0 deletions
diff --git a/test/kdbus-util.c b/test/kdbus-util.c
index e59254d4588..f79d7ecf680 100644
--- a/test/kdbus-util.c
+++ b/test/kdbus-util.c
@@ -575,6 +575,40 @@ int msg_recv(struct conn *conn)
return 0;
}
+/* Returns 0 on success, negative errno on failure */
+int conn_recv(struct conn *conn)
+{
+ int ret;
+ int cnt = 3;
+ struct pollfd fd;
+
+ fd.fd = conn->fd;
+ fd.events = POLLIN | POLLPRI | POLLHUP;
+ fd.revents = 0;
+
+ while (cnt) {
+ cnt--;
+ ret = poll(&fd, 1, 4000);
+ if (ret == 0) {
+ ret = -ETIMEDOUT;
+ break;
+ }
+
+ if (ret > 0) {
+ if (fd.revents & POLLIN)
+ ret = msg_recv(conn);
+
+ if (fd.revents & (POLLHUP | POLLERR))
+ ret = -ECONNRESET;
+ }
+
+ if (ret >= 0 || ret != -EAGAIN)
+ break;
+ }
+
+ return ret;
+}
+
int name_acquire(struct conn *conn, const char *name, uint64_t flags)
{
struct kdbus_cmd_name *cmd_name;
diff --git a/test/kdbus-util.h b/test/kdbus-util.h
index 342ea9bc1a5..0490bd83684 100644
--- a/test/kdbus-util.h
+++ b/test/kdbus-util.h
@@ -59,6 +59,7 @@ int name_list(struct conn *conn, uint64_t flags);
int name_release(struct conn *conn, const char *name);
int name_acquire(struct conn *conn, const char *name, uint64_t flags);
int msg_recv(struct conn *conn);
+int conn_recv(struct conn *conn);
void msg_dump(const struct conn *conn, const struct kdbus_msg *msg);
char *msg_id(uint64_t id, char *buf);
int msg_send(const struct conn *conn, const char *name, uint64_t cookie,