simonvetter / modbus

Go modbus stack (client and server)
MIT License
280 stars 89 forks source link

Allow starting server on existing listener #19

Open andig opened 1 year ago

andig commented 1 year ago

It would be nice- especially for testing- if an existing listener could be used instead of the server creating it's own listener. Doing so would also externalise the entire TLS checking/handling.

andig commented 1 year ago

I have- for sake of speed and being opinionated in terms of which changes were needed- created a fork at https://github.com/andig/mbserver. The main changes are:

My changes (which are really to large part removal) are in https://github.com/andig/mbserver. If this should be of any interest please let me know if PRs would be of interest. If possible I'd like not having to maintain a fork.

simonvetter commented 1 year ago

Thanks for the heads up andig. I'll dig into your fork and see if there's anything there for me to backport.

simonvetter commented 1 year ago

Out of interest, what custom TLS handling is your application doing?

andig commented 1 year ago

Really no TLS handling. I've sort of come from the "I want to determine the listener" side. Once I do that I can't have the TLS handling in the library. If that breaks things it may not be the way to go but is good enough for my purposes.

andig commented 1 year ago

I've opened https://github.com/simonvetter/modbus/pull/21 if you want to take a look. I've not rewritten the server tests yet as I'd need to migrate them to the grid-x client (or use simonvetter/modbus ;). The whole exercise allows to use the server component for building a modbus proxy in https://github.com/evcc-io/evcc/pull/4981. Having the proxy allows for sharing the modbus connection for devices that otherwise allow a single client only.

andig commented 1 year ago

@simonvetter I'd be happy to open a PR for gofmt and maybe golangcilint- that would already make the diff much smaller.