diff --git a/iceoryx2-ffi/cxx/include/iox2/listener.hpp b/iceoryx2-ffi/cxx/include/iox2/listener.hpp index 10d5c128c..30d6af1ab 100644 --- a/iceoryx2-ffi/cxx/include/iox2/listener.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/listener.hpp @@ -18,6 +18,7 @@ #include "iox/function.hpp" #include "iox/optional.hpp" #include "iox2/event_id.hpp" +#include "iox2/file_descriptor.hpp" #include "iox2/internal/iceoryx2.hpp" #include "iox2/listener_error.hpp" #include "iox2/service_type.hpp" @@ -80,6 +81,33 @@ class Listener { /// in detail. auto blocking_wait_one() -> iox::expected, ListenerWaitError>; + private: + class Unsafe { + public: + Unsafe(const Unsafe&) noexcept = delete; + Unsafe(Unsafe&&) noexcept = delete; + Unsafe& operator=(const Unsafe&) noexcept = delete; + Unsafe& operator=(Unsafe&&) noexcept = delete; + + ~Unsafe() noexcept = default; + + /// Returns a file descriptor to the underlying Listener. The file descriptor must not be closed and only be + /// used for event multiplexing! + auto file_descriptor() && -> iox::optional; + + private: + friend class Listener; + Unsafe(Listener& listener); + + private: + const Listener& m_self; + }; + + public: + /// This function gives access to unsafe operations on the Listener. The returned object must never be stored but + /// just used to access the unsafe functions. + auto unsafe() -> Unsafe; + private: template friend class PortFactoryListener; diff --git a/iceoryx2-ffi/cxx/src/listener.cpp b/iceoryx2-ffi/cxx/src/listener.cpp index c80b8f340..c182b21e1 100644 --- a/iceoryx2-ffi/cxx/src/listener.cpp +++ b/iceoryx2-ffi/cxx/src/listener.cpp @@ -159,6 +159,22 @@ auto Listener::blocking_wait_one() -> iox::expected, L return iox::err(iox::into(result)); } +template +auto Listener::unsafe() -> Unsafe { + return Unsafe(*this); +} + +template +Listener::Unsafe::Unsafe(Listener& listener) + : m_self { listener } { +} + +template +auto Listener::Unsafe::file_descriptor() && -> iox::optional { + auto fd = iox2_listener_get_file_descriptor(&m_self.m_handle); + return FileDescriptor::create_non_owning(fd->value); +} + template class Listener; template class Listener; } // namespace iox2