diff options
author | Florin Coras <fcoras@cisco.com> | 2024-11-04 21:47:09 -0800 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-11-05 05:31:36 +0000 |
commit | afd05739d68fe7708153687e1aa177fee4411c5f (patch) | |
tree | ccccd7dd5c4ce99dce703c0f581a208a42d91f1e | |
parent | 5a612a4699c6347296d7a6e5d4704a2108cc6a65 (diff) |
svm: mq use poll instead of SO_RCVTIMEO
setsockopt does not work on eventfds
Type: fix
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I652a2b78160abe1bc15879fd8bc320ba4ef38e63
-rw-r--r-- | src/svm/message_queue.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c index ab0d230b1f0..f2856532454 100644 --- a/src/svm/message_queue.c +++ b/src/svm/message_queue.c @@ -18,7 +18,7 @@ #include <vppinfra/format.h> #include <vppinfra/time.h> #include <sys/eventfd.h> -#include <sys/socket.h> +#include <poll.h> static inline svm_msg_q_ring_t * svm_msg_q_ring_inline (svm_msg_q_t * mq, u32 ring_index) @@ -629,25 +629,29 @@ svm_msg_q_timedwait (svm_msg_q_t *mq, double timeout) } else { - struct timeval tv; + struct pollfd fds = { .fd = mq->q.evtfd, .events = POLLIN }; u64 buf; int rv; - tv.tv_sec = (u64) timeout; - tv.tv_usec = ((u64) timeout - (u64) timeout) * 1e9; - rv = setsockopt (mq->q.evtfd, SOL_SOCKET, SO_RCVTIMEO, - (const char *) &tv, sizeof tv); + rv = poll (&fds, 1, timeout * 1e3 /* ms */); if (rv < 0) { - clib_unix_warning ("setsockopt"); + clib_unix_warning ("poll"); return -1; } + else if (rv == 0) + { + /* timeout occured */ + return 0; + } rv = read (mq->q.evtfd, &buf, sizeof (buf)); - if (rv < 0) - clib_warning ("read %u", errno); - - return rv < 0 ? errno : 0; + if (rv < 0 && errno != EAGAIN) + { + clib_warning ("read %u", errno); + return -2; + } + return 0; } } |