From afd05739d68fe7708153687e1aa177fee4411c5f Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Mon, 4 Nov 2024 21:47:09 -0800 Subject: svm: mq use poll instead of SO_RCVTIMEO setsockopt does not work on eventfds Type: fix Signed-off-by: Florin Coras Change-Id: I652a2b78160abe1bc15879fd8bc320ba4ef38e63 --- src/svm/message_queue.c | 26 +++++++++++++++----------- 1 file 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 #include #include -#include +#include 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; } } -- cgit 1.2.3-korg