Skip to content
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

Allow sharing transports between packagers by adding Clone method (BC) #70

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

andig
Copy link
Contributor

@andig andig commented Apr 10, 2023

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? Maybe Share() or ShareConnection() or maybe WithPackager?

@andig andig marked this pull request as draft April 10, 2023 20:41
@andig andig marked this pull request as ready for review April 10, 2023 20:49
@andig andig changed the title Add clienthandler.Clone() for sharing underlying transport between packagers Allow sharing transports between packagers by adding Clone method Apr 26, 2023
@andig andig force-pushed the feature/split-packager-transporter-v2 branch from 2e242c9 to f3f9ac6 Compare May 2, 2023 10:07
@andig andig force-pushed the feature/split-packager-transporter-v2 branch from f3f9ac6 to e489071 Compare May 2, 2023 10:11
@andig
Copy link
Contributor Author

andig commented May 9, 2023

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.

@andig
Copy link
Contributor Author

andig commented May 19, 2023

Any chance for feedback on this change?

@andig
Copy link
Contributor Author

andig commented Jun 16, 2023

Friendly ping. This PR is needed to make a modbus connection usable from multiple goroutines, one per id.

@andig
Copy link
Contributor Author

andig commented Jul 5, 2023

ping @frzifus did you get a chance to review?

@andig andig mentioned this pull request Feb 1, 2024
@andig
Copy link
Contributor Author

andig commented Mar 24, 2024

ping @frzifus any chance to take a look? Imho this really is a smallish change, although the diff looks large.

Copy link
Contributor

@frzifus frzifus left a 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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@andig
Copy link
Contributor Author

andig commented Mar 24, 2024

Since users may initialized handlers without the new... functions, I would consider it to mark it as breaking change. wdyt?

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.

@andig andig changed the title Allow sharing transports between packagers by adding Clone method Allow sharing transports between packagers by adding Clone method (BC) Mar 24, 2024
@andig
Copy link
Contributor Author

andig commented Jul 6, 2024

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.

@andig
Copy link
Contributor Author

andig commented Sep 11, 2024

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.

@hnicolaysen
Copy link
Contributor

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 Clone() is fine as the description tells the user well what is does.

@andig
Copy link
Contributor Author

andig commented Oct 4, 2024

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?

@hnicolaysen
Copy link
Contributor

Hi @andig,

since #93 is now closed, what does it mean for this PR? I'm happy to merge it once the PR match the other underlying changes you made.

I would also make a new release as version 2 to make the breaking change more visible 👍

@andig
Copy link
Contributor Author

andig commented Oct 28, 2024

Updated PR. Would be great to see the test result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: improve api by exposing packager and transporter
3 participants