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

Add local unix socket support #86

Merged
merged 1 commit into from
Oct 2, 2022
Merged

Conversation

sundermann
Copy link
Contributor

Local unix socket support was added in HyperHDR in awawa-dev/HyperHDR@1100093

Local unix sockets are automatically used when the hostname is set to "/tmp/hyperhdr-domain" which is hardcoded in HyperHDR. On my TV local sockets are around 20-30% faster.

@TBSniller
Copy link
Collaborator

Hey there,

thanks again for contribution!
We have mergend unicapture branch to main. Could you please update your PR to also merge it into main?

Thanks!

src/service.c Outdated Show resolved Hide resolved
@sundermann sundermann force-pushed the local-socket branch 3 times, most recently from 7b86104 to d9ac6ba Compare September 27, 2022 20:49
@sundermann sundermann changed the base branch from unicapture to main September 27, 2022 20:51
Copy link
Member

@tuxuser tuxuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

src/service.c Outdated
Comment on lines 411 to 414
char* address = service->settings->address;
if (service->settings->unix_socket) {
address = "127.0.0.1";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this piece of code / overwrite to main.c, after parse_options was called.

Basically overwriting address in global variable settings by doing settings.address = "127.0.0.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work in case of a reconnect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain in more detail in which case it would break?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unix_socket is just a boolean value so where would the unix socket address be stored if it's already overriden just after parsing options. I can only think of making this work by changing unix_socket to be a char* containing the socket address.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the target address/path for the socket need to be stored?

On a later call to hyperion_client it will receive the flag unix_socket again and know that it has to do the scanning for path /tmp/hyperhdr-domain again - to see if its still available.

The logic stays the same.
The overwrite to address 127.0.0.1 is really just used to enable communication to the JSON RPC, when unix domain socket is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I misunderstood your idea at first thinking you wanted to compare the hostname against a list of known sockets. However in fact you want to scan if a specific local socket is available. I agree the second idea can work but still I don't like the idea of scanning against a hardcoded list because the socket address could change or hyperion.ng decides to implement local sockets as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue is that the -a parameter is still mandatory even though in case of local sockets -a is not mandatory and overwritten making it a bit unintuitive to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, so the flow is:

  • Set /tmp/hyperhdr-domain in the IP address field
  • Set whatever in port or leave it the default by not providing it

Result: unix domain socket is used for flatbuffers, Tcp socket for json rpc.

Sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is how it is supposed to work.

src/service.c Outdated
Comment on lines 468 to 471
char* address = service->settings->address;
if (service->settings->unix_socket) {
address = "127.0.0.1";
}
Copy link
Member

@tuxuser tuxuser Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

{
_origin = origin;
_priority = priority;
_connected = false;
_registered = false;
sockfd = 0;
struct sockaddr_in serv_addr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add checking for /tmp/hyperhdr-domain here. Iterate over constant array of possible filelocations, in case Hyperion.NG implements local unix socket support too.

If such unix socket handle is found, use it as parameter to _connect_unix_socket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we should remove the command line option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the cmdline is fine and useful in this case. Just when it knows that a "local unix domain socket" is desired, it should check and use such, if available.

Case 1: No unix domain socket desired

  • Supplied IP and Port is used as-is

Case 2: Unix domain socket is desired

  • Hardcode ddress to 127.0.0.1 for HTTP RPC JSON communication to the daemon
  • Before connecting the socket for flatbuffer data, check if known unix domain sockets exist and use them - otherwise fall back to 127.0.0.1.

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 convinced this is the best option. This tightly couples hyperion-webos to a list of unix sockets which are provided by external software and might change in future. As you pointed out if hyperion.ng were to add a local socket this means that hyperion-webos needs changes as well.

@sundermann sundermann force-pushed the local-socket branch 3 times, most recently from 047d0be to df27e8b Compare September 28, 2022 23:07
@sundermann
Copy link
Contributor Author

Anything missing on this PR?

@tuxuser
Copy link
Member

tuxuser commented Oct 2, 2022

Testing it currently

@tuxuser
Copy link
Member

tuxuser commented Oct 2, 2022

Yup, works fine. Please cleanly rebase against main and correct the linting, then we should be good to go. cheers

@sundermann sundermann force-pushed the local-socket branch 2 times, most recently from a816306 to f813209 Compare October 2, 2022 22:22
Local unix socket support was added in HyperHDR in awawa-dev/HyperHDR@1100093

Adds the --unix-socket / -l switch in which case a connection over a local unix socket on the specified address is established. On my TV unix sockets are around 20-30% faster.
@TBSniller
Copy link
Collaborator

Thanks!

@TBSniller TBSniller merged commit 19eb7ce into webosbrew:main Oct 2, 2022
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.

None yet

4 participants