The problem with making a custom web server is that you take responsibility for re-solving all the non-obvious security vulnerabilities. I always try to delegate as much network-facing code as possible to a mature implementation someone else wrote for that reason.
Here's how I'd implement it, based on stuff I've done before:
- Start with either Actix Web or Axum for the server itself.
- Use
std::thread
to bring up mpv in a separate thread. - Use an async-capable channel implementation like flume as a bridge between the async and sync worlds.
- If the async side needs to wait on the sync side, include the sending side of a
tokio::sync::oneshot
in the "job order" object your async code drops into the channel and then have the async taskawait
the receiving side. That way, you can have the async task block on the some kind of completion signal from the sync thread without blocking the thread(s) underlying the task executor.