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 printing to a server connection #544

Closed
davehayes opened this issue Apr 23, 2018 · 4 comments
Closed

Allow printing to a server connection #544

davehayes opened this issue Apr 23, 2018 · 4 comments

Comments

@davehayes
Copy link

I was unable to find any print command that prints arbitrary text to a unix domain socket server connection. Thus I am unable to use the on_end callback to print a message to the server when the song is about to change. This forces my other software to poll the server repeatedly rather than wait for an IO event.

Is it possible to add a command that will print text to a server connection?

@toots
Copy link
Member

toots commented Jun 26, 2018

Hi,

Would you mind describing the functionality a bit more? Are you talking about an existing server connection or a connection you would also open and close?

@davehayes
Copy link
Author

So here's the basicis of the script I'm using:

set("log.file.path","liquidstream.log")
set("log.stdout", true)
set("server.socket", true)
set("server.socket.path", "/tmp/liquidserver")
set("server.socket.permissions",0o660);

defaultsource = blank(duration=15.0)
serverqueue = request.queue(id="mainreq")
serverqueue= amplify(1., override="REPLAYGAIN_TRACK_GAIN", serverqueue)
content = fallback([ serverqueue, defaultsource ])
crossplay = smart_crossfade(content)
output.icecast(
  %vorbis(channels=2, quality=0.3),
  ...
)

So I have an external program that opens the unix domain socket that this script created. Right now, in this external program, I push commands to it and read responses using a simplistic model (no select multiplexing yet, etc.). At the moment, due to this simple model, I poll liquidsoap through this socket to see how big the song queue is and how long the current song has left to play.

What I'd like to accomplish is to move to an event driven model. To do that, I have to somehow get the on_end callback to send a message to my external program everytime the currently playing song ends. To do that, I have to have a way to print arbitrary text to the unix domain socket from within that callback. Then I can move away from polling liquidsoap and become purely event driven.

Does this help?

toots added a commit that referenced this issue Jun 27, 2018
toots added a commit that referenced this issue Jul 1, 2018
* Add server.wait() and server.partial_write to write interactive
commands.

Tentative implementation for #544

* Use broadcast not signal.

* Fix return type.

* Fix bytes.

* Add server.pause/server.write in the same fashion as if/then/else.

* s/partial_write/write/g

* Even better syntax.

* Cleanup, doc.

* Added read API, documentation.
@toots
Copy link
Member

toots commented Jul 1, 2018

Done now! See: http://www.liquidsoap.info/doc-dev/server.html

@toots toots closed this as completed Jul 1, 2018
@davehayes
Copy link
Author

Awesome! I like the condition variable stuff too. Thank you!

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

No branches or pull requests

2 participants