From 71beccb3715f210a832de82f527c9e9dbcd8160d Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Fri, 18 Jun 2021 16:00:16 -0400 Subject: [PATCH] #### Problem Followups from #6561 Generalize socket-based event loop #### Change overview * mDNS: Convert `platform/Linux/MdnsImpl`; remove Darwin stubs. * Change `mCallbackData` type to `intptr_t` (review feedback). * Comment for `System::WakeEvent` (this is minimal since it's likely to change soon for issue #7725). Fixes #7758 _Convert MDNS to WatchableSocket._ #### Testing Manual sanity check of mDNS using chip-device-ctrl on Linux. Otherwise, no change to functionality is intended. --- .../GenericPlatformManagerImpl_POSIX.cpp | 3 - src/inet/RawEndPoint.cpp | 4 +- src/inet/TCPEndPoint.cpp | 8 +- src/inet/UDPEndPoint.cpp | 4 +- src/platform/Darwin/MdnsImpl.cpp | 4 +- src/platform/Linux/MdnsImpl.cpp | 128 +++++++++--------- src/platform/Linux/MdnsImpl.h | 11 +- src/system/SystemSockets.cpp | 4 +- src/system/SystemSockets.h | 95 +++++++++---- src/system/WatchableSocketLibevent.cpp | 18 ++- src/system/WatchableSocketSelect.cpp | 12 +- 11 files changed, 175 insertions(+), 116 deletions(-) diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp index 6cf7999ce1968b..0fe3dc3d7a953c 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp @@ -30,9 +30,6 @@ // Include the non-inline definitions for the GenericPlatformManagerImpl<> template, // from which the GenericPlatformManagerImpl_POSIX<> template inherits. -#if CHIP_DEVICE_CONFIG_ENABLE_MDNS -#include "lib/mdns/platform/Mdns.h" -#endif #include #include diff --git a/src/inet/RawEndPoint.cpp b/src/inet/RawEndPoint.cpp index d11d24cf09d00b..bb62415af21b2c 100644 --- a/src/inet/RawEndPoint.cpp +++ b/src/inet/RawEndPoint.cpp @@ -424,7 +424,7 @@ INET_ERROR RawEndPoint::Listen(IPEndPointBasis::OnMessageReceivedFunct onMessage #if CHIP_SYSTEM_CONFIG_USE_SOCKETS // Wait for ability to read on this endpoint. - mSocket.SetCallback(HandlePendingIO, this); + mSocket.SetCallback(HandlePendingIO, reinterpret_cast(this)); mSocket.RequestCallbackOnPendingRead(); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -1026,7 +1026,7 @@ INET_ERROR RawEndPoint::GetSocket(IPAddressType aAddressType) // static void RawEndPoint::HandlePendingIO(System::WatchableSocket & socket) { - static_cast(socket.GetCallbackData())->HandlePendingIO(); + reinterpret_cast(socket.GetCallbackData())->HandlePendingIO(); } void RawEndPoint::HandlePendingIO() diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp index 4b48a35ff4a1aa..3004dfe7450eaa 100644 --- a/src/inet/TCPEndPoint.cpp +++ b/src/inet/TCPEndPoint.cpp @@ -303,7 +303,7 @@ INET_ERROR TCPEndPoint::Listen(uint16_t backlog) res = chip::System::MapErrorPOSIX(errno); // Wait for ability to read on this endpoint. - mSocket.SetCallback(HandlePendingIO, this); + mSocket.SetCallback(HandlePendingIO, reinterpret_cast(this)); mSocket.RequestCallbackOnPendingRead(); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -507,7 +507,7 @@ INET_ERROR TCPEndPoint::Connect(const IPAddress & addr, uint16_t port, Interface return res; } - mSocket.SetCallback(HandlePendingIO, this); + mSocket.SetCallback(HandlePendingIO, reinterpret_cast(this)); // Once Connecting or Connected, bump the reference count. The corresponding Release() // [or on LwIP, DeferredRelease()] will happen in DoClose(). @@ -2440,7 +2440,7 @@ INET_ERROR TCPEndPoint::GetSocket(IPAddressType addrType) // static void TCPEndPoint::HandlePendingIO(System::WatchableSocket & socket) { - static_cast(socket.GetCallbackData())->HandlePendingIO(); + reinterpret_cast(socket.GetCallbackData())->HandlePendingIO(); } void TCPEndPoint::HandlePendingIO() @@ -2693,7 +2693,7 @@ void TCPEndPoint::HandleIncomingConnection() conEP->Retain(); // Wait for ability to read on this endpoint. - conEP->mSocket.SetCallback(HandlePendingIO, conEP); + conEP->mSocket.SetCallback(HandlePendingIO, reinterpret_cast(conEP)); conEP->mSocket.RequestCallbackOnPendingRead(); // Call the app's callback function. diff --git a/src/inet/UDPEndPoint.cpp b/src/inet/UDPEndPoint.cpp index e85da7edf4237a..0af80423861c81 100644 --- a/src/inet/UDPEndPoint.cpp +++ b/src/inet/UDPEndPoint.cpp @@ -350,7 +350,7 @@ INET_ERROR UDPEndPoint::Listen(OnMessageReceivedFunct onMessageReceived, OnRecei #if CHIP_SYSTEM_CONFIG_USE_SOCKETS // Wait for ability to read on this endpoint. - mSocket.SetCallback(HandlePendingIO, this); + mSocket.SetCallback(HandlePendingIO, reinterpret_cast(this)); mSocket.RequestCallbackOnPendingRead(); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -909,7 +909,7 @@ INET_ERROR UDPEndPoint::GetSocket(IPAddressType aAddressType) // static void UDPEndPoint::HandlePendingIO(System::WatchableSocket & socket) { - static_cast(socket.GetCallbackData())->HandlePendingIO(); + reinterpret_cast(socket.GetCallbackData())->HandlePendingIO(); } void UDPEndPoint::HandlePendingIO() diff --git a/src/platform/Darwin/MdnsImpl.cpp b/src/platform/Darwin/MdnsImpl.cpp index bf3dcae76c343f..504e3007547efa 100644 --- a/src/platform/Darwin/MdnsImpl.cpp +++ b/src/platform/Darwin/MdnsImpl.cpp @@ -544,9 +544,9 @@ CHIP_ERROR ChipMdnsResolve(MdnsService * service, chip::Inet::InterfaceId interf return Resolve(context, callback, interfaceId, service->mAddressType, regtype.c_str(), service->mName); } -void UpdateMdnsDataset(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet, int & maxFd, timeval & timeout) {} +void GetMdnsTimeout(timeval & timeout) {} -void ProcessMdns(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet) {} +void HandleMdnsTimeout() {} } // namespace Mdns } // namespace chip diff --git a/src/platform/Linux/MdnsImpl.cpp b/src/platform/Linux/MdnsImpl.cpp index 9e22169d0d04dc..9d1a9f71391797 100644 --- a/src/platform/Linux/MdnsImpl.cpp +++ b/src/platform/Linux/MdnsImpl.cpp @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -32,6 +33,7 @@ using chip::Mdns::kMdnsTypeMaxSize; using chip::Mdns::MdnsServiceProtocol; using chip::Mdns::TextEntry; +using chip::System::SocketEvents; using std::chrono::duration_cast; using std::chrono::microseconds; using std::chrono::seconds; @@ -79,6 +81,29 @@ chip::Inet::IPAddressType ToAddressType(AvahiProtocol protocol) return type; } +#if 0 +SocketEvents ToSocketEvents(AvahiWatchEvent events) +{ + return SocketEvents() + .Set(chip::System::SocketEventFlags::kRead, events & AVAHI_WATCH_IN) + .Set(chip::System::SocketEventFlags::kWrite, events & AVAHI_WATCH_OUT) + .Set(chip::System::SocketEventFlags::kError, events & AVAHI_WATCH_ERR); +} +#endif + +AvahiWatchEvent ToAvahiWatchEvent(SocketEvents events) +{ + return static_cast((events.Has(chip::System::SocketEventFlags::kRead) ? AVAHI_WATCH_IN : 0) | + (events.Has(chip::System::SocketEventFlags::kWrite) ? AVAHI_WATCH_OUT : 0) | + (events.Has(chip::System::SocketEventFlags::kError) ? AVAHI_WATCH_ERR : 0)); +} + +void AvahiWatchCallbackTrampoline(chip::System::WatchableSocket & socket) +{ + AvahiWatch * const watch = reinterpret_cast(socket.GetCallbackData()); + watch->mCallback(watch, socket.GetFD(), ToAvahiWatchEvent(socket.GetPendingEvents()), watch->mContext); +} + CHIP_ERROR MakeAvahiStringListFromTextEntries(TextEntry * entries, size_t size, AvahiStringList ** strListOut) { *strListOut = avahi_string_list_new(nullptr, nullptr); @@ -133,6 +158,8 @@ Poller::Poller() mAvahiPoller.timeout_new = TimeoutNew; mAvahiPoller.timeout_update = TimeoutUpdate; mAvahiPoller.timeout_free = TimeoutFree; + + mWatchableEvents = &DeviceLayer::SystemLayer.WatchableEvents(); } AvahiWatch * Poller::WatchNew(const struct AvahiPoll * poller, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, @@ -145,19 +172,43 @@ AvahiWatch * Poller::WatchNew(int fd, AvahiWatchEvent event, AvahiWatchCallback { VerifyOrDie(callback != nullptr && fd >= 0); - mWatches.emplace_back(new AvahiWatch{ fd, event, 0, callback, context, this }); + AvahiWatch * const watch = new AvahiWatch; + watch->mSocket.Init(*mWatchableEvents) + .Attach(fd) + .SetCallback(AvahiWatchCallbackTrampoline, reinterpret_cast(watch)) + .RequestCallbackOnPendingRead(event & AVAHI_WATCH_IN) + .RequestCallbackOnPendingWrite(event & AVAHI_WATCH_OUT); + watch->mCallback = callback; + watch->mContext = context; + watch->mPoller = this; + mWatches.emplace_back(watch); - return mWatches.back().get(); + return watch; } void Poller::WatchUpdate(AvahiWatch * watch, AvahiWatchEvent event) { - watch->mWatchEvents = event; + if (event & AVAHI_WATCH_IN) + { + watch->mSocket.RequestCallbackOnPendingRead(); + } + else + { + watch->mSocket.ClearCallbackOnPendingRead(); + } + if (event & AVAHI_WATCH_OUT) + { + watch->mSocket.RequestCallbackOnPendingWrite(); + } + else + { + watch->mSocket.ClearCallbackOnPendingWrite(); + } } AvahiWatchEvent Poller::WatchGetEvents(AvahiWatch * watch) { - return static_cast(watch->mHappenedEvents); + return ToAvahiWatchEvent(watch->mSocket.GetPendingEvents()); } void Poller::WatchFree(AvahiWatch * watch) @@ -167,6 +218,7 @@ void Poller::WatchFree(AvahiWatch * watch) void Poller::WatchFree(AvahiWatch & watch) { + (void) watch.mSocket.ReleaseFD(); mWatches.erase(std::remove_if(mWatches.begin(), mWatches.end(), [&watch](const std::unique_ptr & aValue) { return aValue.get() == &watch; }), mWatches.end()); @@ -226,38 +278,10 @@ void Poller::TimeoutFree(AvahiTimeout & timer) mTimers.end()); } -void Poller::UpdateFdSet(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet, int & aMaxFd, timeval & timeout) +void Poller::GetTimeout(timeval & timeout) { microseconds timeoutVal = seconds(timeout.tv_sec) + microseconds(timeout.tv_usec); - for (auto && watch : mWatches) - { - int fd = watch->mFd; - AvahiWatchEvent events = watch->mWatchEvents; - - if (AVAHI_WATCH_IN & events) - { - FD_SET(fd, &readFdSet); - } - - if (AVAHI_WATCH_OUT & events) - { - FD_SET(fd, &writeFdSet); - } - - if (AVAHI_WATCH_ERR & events) - { - FD_SET(fd, &errorFdSet); - } - - if (aMaxFd < fd) - { - aMaxFd = fd; - } - - watch->mHappenedEvents = 0; - } - for (auto && timer : mTimers) { steady_clock::time_point absTimeout = timer->mAbsTimeout; @@ -282,38 +306,10 @@ void Poller::UpdateFdSet(fd_set & readFdSet, fd_set & writeFdSet, fd_set & error timeout.tv_usec = static_cast(timeoutVal.count()) % kUsPerSec; } -void Poller::Process(const fd_set & readFdSet, const fd_set & writeFdSet, const fd_set & errorFdSet) +void Poller::HandleTimeout() { steady_clock::time_point now = steady_clock::now(); - for (auto && watch : mWatches) - { - int fd = watch->mFd; - AvahiWatchEvent events = watch->mWatchEvents; - - watch->mHappenedEvents = 0; - - if ((AVAHI_WATCH_IN & events) && FD_ISSET(fd, &readFdSet)) - { - watch->mHappenedEvents |= AVAHI_WATCH_IN; - } - - if ((AVAHI_WATCH_OUT & events) && FD_ISSET(fd, &writeFdSet)) - { - watch->mHappenedEvents |= AVAHI_WATCH_OUT; - } - - if ((AVAHI_WATCH_ERR & events) && FD_ISSET(fd, &errorFdSet)) - { - watch->mHappenedEvents |= AVAHI_WATCH_ERR; - } - - if (watch->mHappenedEvents) - { - watch->mCallback(watch.get(), watch->mFd, static_cast(watch->mHappenedEvents), watch->mContext); - } - } - for (auto && timer : mTimers) { if (!timer->mEnabled) @@ -753,14 +749,14 @@ MdnsAvahi::~MdnsAvahi() } } -void UpdateMdnsDataset(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet, int & maxFd, timeval & timeout) +void GetMdnsTimeout(timeval & timeout) { - MdnsAvahi::GetInstance().GetPoller().UpdateFdSet(readFdSet, writeFdSet, errorFdSet, maxFd, timeout); + MdnsAvahi::GetInstance().GetPoller().GetTimeout(timeout); } -void ProcessMdns(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet) +void HandleMdnsTimeout() { - MdnsAvahi::GetInstance().GetPoller().Process(readFdSet, writeFdSet, errorFdSet); + MdnsAvahi::GetInstance().GetPoller().HandleTimeout(); } CHIP_ERROR ChipMdnsInit(MdnsAsyncReturnCallback initCallback, MdnsAsyncReturnCallback errorCallback, void * context) diff --git a/src/platform/Linux/MdnsImpl.h b/src/platform/Linux/MdnsImpl.h index 9facbb982479d9..3db656019473f9 100644 --- a/src/platform/Linux/MdnsImpl.h +++ b/src/platform/Linux/MdnsImpl.h @@ -34,12 +34,17 @@ #include #include "lib/mdns/platform/Mdns.h" +#include "system/SystemSockets.h" struct AvahiWatch { +#if 1 + chip::System::WatchableSocket mSocket; +#else int mFd; ///< The file descriptor to watch. AvahiWatchEvent mWatchEvents; ///< The interested events. int mHappenedEvents; ///< The events happened. +#endif AvahiWatchCallback mCallback; ///< The function to be called when interested events happened on mFd. void * mContext; ///< A pointer to application-specific context. void * mPoller; ///< The poller created this watch. @@ -62,9 +67,8 @@ class Poller public: Poller(void); - void UpdateFdSet(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet, int & maxFd, timeval & timeout); - - void Process(const fd_set & readFdSet, const fd_set & writeFdSet, const fd_set & errorFdSet); + void GetTimeout(timeval & timeout); + void HandleTimeout(); const AvahiPoll * GetAvahiPoll(void) const { return &mAvahiPoller; } @@ -92,6 +96,7 @@ class Poller std::vector> mWatches; std::vector> mTimers; AvahiPoll mAvahiPoller; + System::WatchableEventManager * mWatchableEvents; }; class MdnsAvahi diff --git a/src/system/SystemSockets.cpp b/src/system/SystemSockets.cpp index a5b3368a0ee7cc..8234157cefc697 100644 --- a/src/system/SystemSockets.cpp +++ b/src/system/SystemSockets.cpp @@ -70,7 +70,7 @@ Error WakeEvent::Open(WatchableEventManager & watchState) mFD.Init(watchState); mFD.Attach(fds[FD_READ]); - mFD.SetCallback(Confirm, this); + mFD.SetCallback(Confirm, reinterpret_cast(this)); mFD.RequestCallbackOnPendingRead(); mWriteFD = fds[FD_WRITE]; @@ -135,7 +135,7 @@ Error WakeEvent::Open(WatchableEventManager & watchState) } mFD.Attach(fd); - mFD.SetCallback(Confirm, this); + mFD.SetCallback(Confirm, reinterpret_cast(this)); mFD.RequestCallbackOnPendingRead(); return CHIP_SYSTEM_NO_ERROR; diff --git a/src/system/SystemSockets.h b/src/system/SystemSockets.h index b8aa4415213231..2c041636aaec3c 100644 --- a/src/system/SystemSockets.h +++ b/src/system/SystemSockets.h @@ -120,14 +120,16 @@ class WatchableSocketBasis * * @param[in] manager Reference to shared socket-event state (which must already have been initialized). */ - void Init(WatchableEventManager & manager) + Impl & Init(WatchableEventManager & manager) { mFD = kInvalidFd; mPendingIO.ClearAll(); - mCallback = nullptr; - mCallbackData = nullptr; - mSharedState = &manager; - static_cast(this)->OnInit(); + mCallback = nullptr; + mCallbackData = 0; + mSharedState = &manager; + Impl * const impl = static_cast(this); + impl->OnInit(); + return *impl; } /** @@ -135,25 +137,34 @@ class WatchableSocketBasis * * @param[in] fd An open file descriptor. */ - void Attach(int fd) + Impl & Attach(int fd) { - mFD = fd; - static_cast(this)->OnAttach(); + mFD = fd; + Impl * const impl = static_cast(this); + impl->OnAttach(); + return *impl; } /** - * Close the associated file descriptor. + * Disassociate this WatchableSocket from its file descriptor. * - * @returns the return value of `close()`. + * @returns the file descriptor. */ - int Close() + int ReleaseFD() { static_cast(this)->OnClose(); - const int r = close(mFD); - mFD = kInvalidFd; - return r; + const int fd = mFD; + mFD = kInvalidFd; + return fd; } + /** + * Close the associated file descriptor. + * + * @returns the return value of `close(2)`. + */ + int Close() { return close(ReleaseFD()); } + /** * Test whether there is an associated open file descriptor. */ @@ -167,22 +178,48 @@ class WatchableSocketBasis /** * Indicate that the socket-event system should invoke the registered callback when the file descriptor is ready to read. */ - void RequestCallbackOnPendingRead() { static_cast(this)->OnRequestCallbackOnPendingRead(); } + Impl & RequestCallbackOnPendingRead(bool request = true) + { + Impl * const impl = static_cast(this); + if (request) + { + impl->OnRequestCallbackOnPendingRead(); + } + return *impl; + } /** * Indicate that the socket-event system should invoke the registered callback when the file descriptor is ready to write. */ - void RequestCallbackOnPendingWrite() { static_cast(this)->OnRequestCallbackOnPendingWrite(); } + Impl & RequestCallbackOnPendingWrite(bool request = true) + { + Impl * const impl = static_cast(this); + if (request) + { + impl->OnRequestCallbackOnPendingWrite(); + } + return *impl; + } /** * Indicate that the socket-event system need not invoke the registered callback when the file descriptor is ready to read. */ - void ClearCallbackOnPendingRead() { static_cast(this)->OnClearCallbackOnPendingRead(); } + Impl & ClearCallbackOnPendingRead() + { + Impl * const impl = static_cast(this); + impl->OnClearCallbackOnPendingRead(); + return *impl; + } /** * Indicate that the socket-event system need not invoke the registered callback when the file descriptor is ready to write. */ - void ClearCallbackOnPendingWrite() { static_cast(this)->OnClearCallbackOnPendingWrite(); } + Impl & ClearCallbackOnPendingWrite() + { + Impl * const impl = static_cast(this); + impl->OnClearCallbackOnPendingWrite(); + return *impl; + } /** * The callback is passed a reference to the WatchableSocket for which the requested event(s) are ready. @@ -195,12 +232,13 @@ class WatchableSocketBasis * The callback will be invoked (with the CHIP stack lock held) when requested event(s) are ready. * * @param[in] callback Function invoked when event(s) are ready. - * @param[in] data Arbitrary pointer accessible within a callback function. + * @param[in] data Arbitrary data accessible within a callback function. */ - void SetCallback(Callback callback, void * data) + Impl & SetCallback(Callback callback, intptr_t data) { mCallback = callback; mCallbackData = data; + return *static_cast(this); } /** @@ -208,7 +246,12 @@ class WatchableSocketBasis * * @returns the pointer supplied to SetCallback(). */ - void * GetCallbackData() const { return mCallbackData; } + intptr_t GetCallbackData() const { return mCallbackData; } + + /** + * Inside a callback function, get the pending SocketEvents. + */ + SocketEvents GetPendingEvents() const { return mPendingIO; } /** * Inside a callback function, test whether the file descriptor is ready to read. @@ -248,7 +291,7 @@ class WatchableSocketBasis int mFD; SocketEvents mPendingIO; Callback mCallback; - void * mCallbackData; + intptr_t mCallbackData; WatchableEventManager * mSharedState; }; @@ -268,6 +311,12 @@ namespace System { using ::chip::System::Error; +/** + * @class WakeEvent + * + * An instance of this type is contained in System::Layer. Its purpose is to allow other threads + * to wake the event loop thread via System::Layer::WakeIOThread(). + */ class WakeEvent { public: @@ -278,7 +327,7 @@ class WakeEvent Error Notify(); /**< Set the event. */ void Confirm(); /**< Clear the event. */ - static void Confirm(WatchableSocket & socket) { static_cast(socket.GetCallbackData())->Confirm(); } + static void Confirm(WatchableSocket & socket) { reinterpret_cast(socket.GetCallbackData())->Confirm(); } private: #if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE diff --git a/src/system/WatchableSocketLibevent.cpp b/src/system/WatchableSocketLibevent.cpp index 8813ff3b736086..c6aeed0d801cfa 100644 --- a/src/system/WatchableSocketLibevent.cpp +++ b/src/system/WatchableSocketLibevent.cpp @@ -20,14 +20,22 @@ * This file implements WatchableEvents using libevent. */ +#include #include #include #include -#if CHIP_DEVICE_CONFIG_ENABLE_MDNS +#if CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ + +namespace chip { +namespace Mdns { // TODO(#5556): Convert MDNS to WatchableSocket. -#error "POSIX platform with MDNS currently must use select()" -#endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS +void GetMdnsTimeout(timeval & timeout); +void HandleMdnsTimeout(); +} // namespace Mdns +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ #ifndef CHIP_CONFIG_LIBEVENT_DEBUG_CHECKS #define CHIP_CONFIG_LIBEVENT_DEBUG_CHECKS 1 // TODO(#5556): default to off @@ -97,6 +105,10 @@ void WatchableEventManager::HandleEvents() { mSystemLayer->HandleTimeout(); +#if CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ + chip::Mdns::HandleMdnsTimeout(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ + while (mActiveSockets != nullptr) { WatchableSocket * const watcher = mActiveSockets; diff --git a/src/system/WatchableSocketSelect.cpp b/src/system/WatchableSocketSelect.cpp index c90878bba8cf4c..6521e5faed8400 100644 --- a/src/system/WatchableSocketSelect.cpp +++ b/src/system/WatchableSocketSelect.cpp @@ -35,8 +35,8 @@ namespace chip { namespace Mdns { // TODO(#5556): Convert MDNS to WatchableSocket. -void UpdateMdnsDataset(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet, int & maxFd, timeval & timeout); -void ProcessMdns(fd_set & readFdSet, fd_set & writeFdSet, fd_set & errorFdSet); +void GetMdnsTimeout(timeval & timeout); +void HandleMdnsTimeout(); } // namespace Mdns } // namespace chip @@ -163,12 +163,12 @@ void WatchableEventManager::PrepareEventsWithTimeout(struct timeval & nextTimeou // TODO(#5556): Integrate timer platform details with WatchableEventManager. mSystemLayer->GetTimeout(nextTimeout); - mSelected = mRequest; - #if CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ // TODO(#5556): Convert MDNS to WatchableSocket. - chip::Mdns::UpdateMdnsDataset(mSelected.mReadSet, mSelected.mWriteSet, mSelected.mErrorSet, mMaxFd, nextTimeout); + chip::Mdns::GetMdnsTimeout(nextTimeout); #endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ + + mSelected = mRequest; } void WatchableEventManager::WaitForEvents() @@ -204,7 +204,7 @@ void WatchableEventManager::HandleEvents() #if CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ // TODO(#5556): Convert MDNS to WatchableSocket. - chip::Mdns::ProcessMdns(mSelected.mReadSet, mSelected.mWriteSet, mSelected.mErrorSet); + chip::Mdns::HandleMdnsTimeout(); #endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS && !__ZEPHYR__ }