-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Followups from #6561 Generalize socket-based event loop #7799
Conversation
src/platform/Linux/MdnsImpl.cpp
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is delete
called for these objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of std::vector<std::unique_ptr<AvahiWatch>> mWatches;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto watch = std::make_unique<AvahiWatch>()
?
src/system/WatchableSocketSelect.cpp
Outdated
@@ -35,8 +35,8 @@ | |||
namespace chip { | |||
namespace Mdns { | |||
// TODO(#5556): Convert MDNS to WatchableSocket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these TODOs still relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, they're not; the remaining part is timer-related and pending #7725
src/platform/Linux/MdnsImpl.cpp
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto watch = std::make_unique<AvahiWatch>()
?
@@ -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<intptr_t>(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires a more casts and stronger casts, I wonder if it is worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a request in the previous review, so you and Boris can fight it out :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a suggestion; Boris said he was OK either way. Above was just a question. Ultimately I think it is up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, given what this diff looks like and that we have no non-pointer use cases for this closure, we should probably leave it as void*
for now. If we ever end up with non-pointer use cases, we can think about how to be best address those then...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to my TODO list.
src/platform/Linux/MdnsImpl.h
Outdated
|
||
struct AvahiWatch | ||
{ | ||
#if 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up dead else?
Followups from project-chip#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 project-chip#7725). Fixes project-chip#7758 _Convert MDNS to WatchableSocket._ #### Testing Manual sanity check of mDNS using chip-device-ctrl on Linux. Otherwise, no change to functionality is intended.
@@ -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<intptr_t>(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a suggestion; Boris said he was OK either way. Above was just a question. Ultimately I think it is up to you.
@@ -167,6 +208,7 @@ void Poller::WatchFree(AvahiWatch * watch) | |||
|
|||
void Poller::WatchFree(AvahiWatch & watch) | |||
{ | |||
(void) watch.mSocket.ReleaseFD(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a confused by this. WatchableSocket is normally expected to own the fd but not in the case of avahi?
If WatchableSocket is owning, why doesn't it close in its destructor?
If WatchableSocket is non-owning, why does it close the file descriptor in Close()?
If WatchableSocket non-owning but Close() is just a helper for release-and-close, should "release" call WatchableSocket::OnClose which does the actual detach-from-WatchableEventManager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a confused by this. WatchableSocket is normally expected to own the fd but not in the case of avahi?
Right. In the other cases (Inet and System::WakeEvent) the WatchableSocket effectively owns the fd, and replaces the fd from the point of view of the holder. In the Avahi case, Avahi itself owns the fd and lends it via AvahiPoll.watch_new
and watch_free
.
If WatchableSocket is owning, why doesn't it close in its destructor?
For the normal (Inet) case, it's contained inside an IPEndPointBasis which is not constructible or destructible. It's contained in order to avoid requiring separate allocation. It may be worth revisiting that if/when the System/Inet virtualization and pool allocation improvements happen.
If WatchableSocket is non-owning, why does it close the file descriptor in Close()?
Convenience for the common case.
If WatchableSocket non-owning but Close() is just a helper for release-and-close, should "release" call WatchableSocket::OnClose which does the actual detach-from-WatchableEventManager?
Yes, OnClose()
should be renamed OnRelease()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a confused by this. WatchableSocket is normally expected to own the fd but not in the case of avahi?
Right. In the other cases (Inet and System::WakeEvent) the WatchableSocket effectively owns the fd, and replaces the fd from the point of view of the holder. In the Avahi case, Avahi itself owns the fd and lends it via
AvahiPoll.watch_new
andwatch_free
.
Having a non-owning watcher separate from fd-owner makes the most sense to me and would fit well with avahi but understood there are other constraints here.
If WatchableSocket is owning, why doesn't it close in its destructor?
For the normal (Inet) case, it's contained inside an IPEndPointBasis which is not constructible or destructible. It's contained in order to avoid requiring separate allocation. It may be worth revisiting that if/when the System/Inet virtualization and pool allocation improvements happen.
Ahh, the pool should really run destructors on slots released back to it :(
If WatchableSocket is non-owning, why does it close the file descriptor in Close()?
Convenience for the common case.
If WatchableSocket non-owning but Close() is just a helper for release-and-close, should "release" call WatchableSocket::OnClose which does the actual detach-from-WatchableEventManager?
Yes,
OnClose()
should be renamedOnRelease()
.
Ah, I see that it does I was just confused by the name. Rename sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a non-owning watcher separate from fd-owner makes the most sense to me and would fit well with avahi but understood there are other constraints here.
I'll take a look at this when I do the remaining test and timer TODOs, which likely will be together with #7725. I don't know that it will make much difference; since we don't have weak fds, a watcher must be informed before a file is closed.
Yes,
OnClose()
should be renamedOnRelease()
.Ah, I see that it does I was just confused by the name. Rename sounds good.
Ack, added to my TODO list.
@@ -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<intptr_t>(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, given what this diff looks like and that we have no non-pointer use cases for this closure, we should probably leave it as void*
for now. If we ever end up with non-pointer use cases, we can think about how to be best address those then...
…roject-chip#7799) * #### Problem Followups from project-chip#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 project-chip#7725). Fixes project-chip#7758 _Convert MDNS to WatchableSocket._ #### Testing Manual sanity check of mDNS using chip-device-ctrl on Linux. Otherwise, no change to functionality is intended. * review * review
Problem
Followups from #6561 Generalize socket-based event loop
Change overview
platform/Linux/MdnsImpl
; remove Darwin stubs.mCallbackData
type tointptr_t
(review feedback).System::WakeEvent
(this is minimal since it'slikely to change soon for issue Re-factor of how threading and event dispatch is handled in the SDK #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.