From 6dfea32aee7be034d8f16b07bb381e0238635cf1 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Tue, 4 May 2021 09:57:28 +0200 Subject: [PATCH] Improve Events API If the call is interrupted by a signal, this will throw, which we clearly do not want. Simplifying the API to let the user decide what to do on error is probably the best option. --- fairmq/FairMQSocket.h | 2 +- fairmq/shmem/Socket.h | 6 ++---- fairmq/zeromq/Socket.h | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/fairmq/FairMQSocket.h b/fairmq/FairMQSocket.h index 3513523f..9994d52e 100644 --- a/fairmq/FairMQSocket.h +++ b/fairmq/FairMQSocket.h @@ -56,7 +56,7 @@ class FairMQSocket /// If the backend supports it, fills the unsigned integer @a events with the ZMQ_EVENTS value /// DISCLAIMER: this API is experimental and unsupported and might be dropped / refactored in /// the future. - virtual void Events(uint32_t* events) = 0; + virtual int Events(uint32_t* events) = 0; virtual void SetLinger(const int value) = 0; virtual int GetLinger() const = 0; virtual void SetSndBufSize(const int value) = 0; diff --git a/fairmq/shmem/Socket.h b/fairmq/shmem/Socket.h index e2dc6f4c..228836be 100644 --- a/fairmq/shmem/Socket.h +++ b/fairmq/shmem/Socket.h @@ -378,12 +378,10 @@ class Socket final : public fair::mq::Socket } } - void Events(uint32_t* events) override + int Events(uint32_t* events) override { size_t eventsSize = sizeof(uint32_t); - if (zmq_getsockopt(fSocket, ZMQ_EVENTS, events, &eventsSize) < 0) { - throw SocketError(tools::ToString("failed setting ZMQ_EVENTS, reason: ", zmq_strerror(errno))); - } + return zmq_getsockopt(fSocket, ZMQ_EVENTS, events, &eventsSize); } int GetLinger() const override diff --git a/fairmq/zeromq/Socket.h b/fairmq/zeromq/Socket.h index f9ee36ff..10bc30cd 100644 --- a/fairmq/zeromq/Socket.h +++ b/fairmq/zeromq/Socket.h @@ -323,12 +323,10 @@ class Socket final : public fair::mq::Socket } } - void Events(uint32_t* events) override + int Events(uint32_t* events) override { size_t eventsSize = sizeof(uint32_t); - if (zmq_getsockopt(fSocket, ZMQ_EVENTS, events, &eventsSize) < 0) { - throw SocketError(tools::ToString("failed setting ZMQ_EVENTS, reason: ", zmq_strerror(errno))); - } + return zmq_getsockopt(fSocket, ZMQ_EVENTS, events, &eventsSize); } void SetLinger(const int value) override