-
Notifications
You must be signed in to change notification settings - Fork 674
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
Use smart pointers for PcapLiveDeviceList's internal memory management. #1440
Merged
tigercosmos
merged 7 commits into
seladb:dev
from
Dimi1010:feature/pcap-live-dev-list-internal-smart-pointers
Jun 8, 2024
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d78f143
Updated 'private deleted' constructors to cpp11 standard.
Dimi1010 f85ef1e
Changed PcapLiveDeviceList to hold its PcapLiveDevices in shared poin…
Dimi1010 f559505
Renamed variables in loops to be more clear.
Dimi1010 5e688f2
Moved view vector to be constructed directly in initialization.
Dimi1010 ad77379
Changed shared_ptr to unique_ptr
Dimi1010 f814c06
Merge remote-tracking branch 'upstream/dev' into feature/pcap-live-de…
Dimi1010 5822cbe
Merge remote-tracking branch 'upstream/dev' into feature/pcap-live-de…
Dimi1010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this a vector of
shared_ptr
and notunique_ptr
? 🤔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.
From the PR description. I plan on having the API return shared pointers.
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 not sure I fully understand point 4, but I'm not sure there's a good reason to unify the APIs of
PcapLiveDeviceList
andPcapRemoteDeviceList
, from multiple reasons:PcapLiveDeviceList
is a singleton because it finds all the interfaces on the machine. HoweverPcapRemoteDeviceList
is not a singleton because it encapsulates remote devices on other machines so a user can have multiple instances of it. The API is quite different so not sure it's a good idea to merge itThere 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.
Well, one of the reasons I started thinking about it is that both
PcapLiveDeviceList
andPcapRemoteDeviceList
share a couple similarities and have some code duplication.vector<DevicePtr>
getPcapLiveDeviceByIp
andgetPcapRemoteDeviceByIP
have practically duplicate implementation.One of the reasons for unifying the API is having an internal base class
template<DeviceType> PcapLiveDeviceListBase
(name subject to change) that implements thegetPcapDeviceByIP
methods that currently have duplicate implementation.The current methods could still be kept and just call the new functions too.
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.
Also, even if the API is not unified, I still have the proposal to get the API to return
shared_ptr
instead of raw pointers so you don't suddenly get invalid pointers. (refresh, or in case ofRemoteDeviceList
just the list going out of scope).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.
to be honest, I wouldn't spend time on it because although there is some code duplication, it's not a lot and we can keep the code simple. If you really insist we can discuss it more...
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.
Hmm, ok then. Gonna shelve point 4 for now.
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.
@seladb Btw, if the class is a singleton, why does it have a
clone
method?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.
Changed to
unique_ptr
. ad77379There 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 agree this API is a bit weird 🙈
The reason is that users wanted to capture traffic from the same interface more than once, here is the GitHub issue: #766
The idea was to allow cloning a live device, or to allow cloning all devices...