-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add some missing const refs to CHostAddress params #3259
Conversation
Yep, I guess my only concern is if everything is a reference, then somewhere (untracked?) there's the original data... which could get freed and thus the references are no longer valid. There must be somewhere the actual value gets stored... |
I think the only concern would be if the receiving function is (relatively) long-lived, and the variable of which the reference is passed could change value in a different thread. For passing an unchanging value to a function that will just use it and return, passing a reference to the original parameter would be fine. I'll do a pass through the modified calls to check there are no dodgy possibilities. |
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.
Not sure how much I can say here, but if it runs correctly, it should be fine? Yes, multithreading could be a possible source of incorrectness?
I'm off on holiday for a week. I'll pick it up again when I get back. |
I've reverted most of the changes, specifically the ones relating to signals and slots. Connections from signals to slots can cross thread boundaries, so the receiver doesn't want to be referring to data belonging to the sender. So these should remain as call-by-value, ensuring the receiver has its own copy of the parameter. My original changes probably worked ok for a client, but would be liable to breakage in a server with multiple connections, particularly with multi-threading. That leaves only a few changes remaining. I still need to double-check |
RecHostAddr doesn't need to be a class member, as it is only used in CSocket::OnDataReceived(), so make it local.
Also removed a couple of unused members from |
I need to update the original PR description above, as it is now rather out of date. |
Yes, |
Overall, there's no problems now, I think. |
Could you squash before the merge, please. I'll see if I can get this onto my Servers and Directories. <edit>DONE</edit> |
I may run it quickly ASAP to check for something obvious too but otherwise it's probably ok then. |
@@ -41,7 +41,7 @@ using namespace recorder; | |||
* Creates a file for the raw PCM data and sets up a QDataStream to which to write received frames. | |||
* The data is stored Little Endian. | |||
*/ | |||
CJamClient::CJamClient ( const qint64 frame, const int _numChannels, const QString name, const CHostAddress address, const QDir recordBaseDir ) : |
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.
Please check for bugs here too.
I tested running the server on macOS and it needed multiple tries to show up as directory. The directory did not show up for a local client if a path for recordings is set. It may not be related and needs more investigation (test with a path that is not writable).
It seems as if on 3.10.0 the directory shows up instantly.
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.
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. Current main also shows this issue. Seems to be unrelated.
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.
OK, if this problem behaviour is repeatable post-3.10.0 but not in 3.10.0, it needs to be raised as a new issue. Maybe need to bisect to find where it was introduced?
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.
Issue opened
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.
Otherwise everything seems ok (testing to connect to server, listening, audio goes both ways)
Short description of changes
Refactoring: pass
CHostAddress
read-only parameters as const references instead of by value, except for signals and slots.CHANGELOG: Refactor some
CHostAddress
parameters to be const references.Context: Fixes an issue?
In the current code base, there are many instances where a
CHostAddress
is already passed asconst CHostAddress&
, but some instances where aCHostAddress
object is passed by value instead. Depending on the platform, passing a reference may be more efficient than passing a whole object by value. This PR catches a few pass-by-value instances that can better be passed as const refs. However, when passing to signal or slot functions, pass-by-value is needed for thread safety, so those occurrences have not been changed.The only functions that need to receive a non-const
CHostAddress&
are the ones for parsing addresses, as they pass the results of the parsing back to the caller via the reference.Does this change need documentation? What needs to be documented and how?
Probably not.
Status of this Pull Request
Compiled fine and under test.
What is missing until this pull request can be merged?
Review, and running for a while on a server.
Checklist