From 03526601ee0137ef9d6aef2badba6bce1847b312 Mon Sep 17 00:00:00 2001 From: Libor Michalek Date: Thu, 30 Jun 2005 18:27:14 +0000 Subject: [PATCH] r2761: Add a convenience function for getting an event within a certain time limit. Signed-off-by: Libor Michalek --- include/infiniband/cm.h | 12 ++++++++++++ src/cm.c | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/include/infiniband/cm.h b/include/infiniband/cm.h index d0566b8..f9c6163 100644 --- a/include/infiniband/cm.h +++ b/include/infiniband/cm.h @@ -245,6 +245,18 @@ struct ib_cm_event { */ int ib_cm_event_get(struct ib_cm_event **event); +/** + * ib_cm_event_get_timed - Retrieves the next pending communications event, + * if no event is pending wait up to a certain timeout for an event. + * @timeout_ms: Maximum time in milliseconds to wait for an event. + * @event: Allocated information about the next communication event. + * Event should be freed using ib_cm_event_put() + * + * If timeout expires without an event, the error -ETIMEDOUT will be + * returned + */ +int ib_cm_event_get_timed(int timeout_ms, struct ib_cm_event **event); + /** * ib_cm_event_put - Free a communications event. * @event: Event to be released. diff --git a/src/cm.c b/src/cm.c index e278192..9053a90 100644 --- a/src/cm.c +++ b/src/cm.c @@ -929,6 +929,9 @@ int ib_cm_event_get_timed(int timeout_ms, struct ib_cm_event **event) struct pollfd ufds; int result; + if (!event) + return -EINVAL; + ufds.fd = ib_cm_get_fd(); ufds.events = POLLIN; ufds.revents = 0; @@ -939,5 +942,8 @@ int ib_cm_event_get_timed(int timeout_ms, struct ib_cm_event **event) if (!result) return -ETIMEDOUT; + if (result < 0) + return result; + return ib_cm_event_get(event); } -- 2.41.0