-
Notifications
You must be signed in to change notification settings - Fork 39
Allow sharing transports between packagers by adding Clone method (BC) #70
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
base: master
Are you sure you want to change the base?
Conversation
2e242c9 to
f3f9ac6
Compare
f3f9ac6 to
e489071
Compare
|
Friendly ping @frzifus. This would be really helpful using the module downstream and cross-goroutines. The diff looks bigger than it is as I've moved the ...Client routines above the respective ...Handlers for clarity. |
|
Any chance for feedback on this change? |
|
Friendly ping. This PR is needed to make a modbus connection usable from multiple goroutines, one per id. |
|
ping @frzifus did you get a chance to review? |
|
ping @frzifus any chance to take a look? Imho this really is a smallish change, although the diff looks large. |
frzifus
left a comment
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.
Since users may initialized handlers without the new... functions, I would consider it to mark it as breaking change. wdyt?
The repository does not have a changelog or similar. Maybe we should introduce something like this as an CHANGELOG.md file?
But I assume thats up to @tretmar @Carelo @guelfey - Or maybe you can ping the right contact person.
| // Clone creates a new client handler with the same underlying shared transport. | ||
| func (mb *ASCIIOverTCPClientHandler) Clone() *ASCIIOverTCPClientHandler { | ||
| h := &ASCIIOverTCPClientHandler{ | ||
| asciiTCPTransporter: mb.asciiTCPTransporter, |
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.
Since tcpTransporter doesnt only contain native values, do we need to add a Clone() method for that 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.
I'm not sure I understand the question (native values?). The purpose of this PR is to share the transporter. The private asciiTCPTransporter etc transporter fields have been converter to pointers to allow this. I didn't see a case for cloning a transporter.
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.
@frzifus does that answer the question? Or is there anything specific to the tcpTransporter that I'm missing?
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.
In other words: the tcpTransporter is a pointer now that gets copied.
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.
TCP is actually a special case that required adjustments to the packager too, see evcc-io#6
That's a good point. Not doing so will be obvious due to nil pointer panics, but it's definitely breaking. Since this is the case, I'd be happy to add a more fluent way of passing parameters, too if that would help to move this PR along. |
|
If anybody wants to test this, I've created a fork at https://github.com/evcc-io/modbus. Happy to update this PR if interest arises. |
|
While is PR is meanwhile severely bit-rotten and for sake of reference, we've been successfully using this with evcc.io for ~3 months now and are happy to report that we can have concurrent Go routines interacting with Modbus devices now using different slave ids. |
|
First of all, thanks for bringing this up @andig! This PR was long-forgotten on our side, so thank you for your patience and for reviving this! We would be happy to get this repository up to date and to follow up on this change. Technically, it looks sound to me. I agree, we should mark it as a breaking change unless we come up with a solution that preserves the previous construction. For me, the name |
|
Thank you @hnicolaysen for the kind words. Lets please try to get #93 merged, then I can update this PR with the remaining fixes. As @frzifus pointed out- though as minimally invasive as possible- this is still a breaking change. Users of the naked structs will now need to initialise the transporters. Due to this it might make sense to merge this only if you're actually going for a v2 version of the library? |
|
Updated PR. Would be great to see the test result. |
|
Hey @andig, I'll take over from Hendrik now. I guess you can't look into the pipeline results due to missing permission. Hope this helps you and we can move forward with this PR 👍🏻 |
|
Hello and thanks for writing this great library. It seems that https://github.com/evcc-io/modbus is now both ahead as well as behind this repository in terms of commit and the evcc-io fork still refers to itself as grid-x. Therefore, I'd very much like to use the original |
|
Seems we have diverged due to this PR and #97. |
|
@pieterhollander I don't think anything is holding us from merging this besides the failing tests. The module has remained unmaintained for a while due to previous maintainers shifting priorities, but IMO what this PR is proposing feels sound. It seems to me that we could simplify a few things in this module (constructors, access to nested fields) by making struct fields public instead of stacking new methods like this |
Fix #56
This is an alternative approach. It features much smaller api surface but leaves responsibility up to the user to understand the transporter's shared nature.
Note: decide name. Is
Clone()sufficiently clear? MaybeShare()orShareConnection()or maybeWithPackager?