node: Test control socket

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent 12dd6d4a5d
commit 400ba8d935
4 changed files with 90 additions and 10 deletions
+17 -4
View File
@@ -53,14 +53,14 @@ pub struct Handle<R: Reactor> {
pub(crate) listening: chan::Receiver<net::SocketAddr>,
}
impl<R: Reactor> Handle<R> {
impl<R: Reactor> traits::Handle for Handle<R> {
/// Notify the client that a project has been updated.
pub fn updated(&self, id: ProjId) -> Result<(), Error> {
fn updated(&self, id: ProjId) -> Result<(), Error> {
self.command(protocol::Command::AnnounceInventory(id))
}
/// Send a command to the command channel, and wake up the event loop.
pub fn command(&self, cmd: protocol::Command) -> Result<(), Error> {
fn command(&self, cmd: protocol::Command) -> Result<(), Error> {
self.commands.send(cmd)?;
R::wake(&self.waker)?;
@@ -68,10 +68,23 @@ impl<R: Reactor> Handle<R> {
}
/// Ask the client to shutdown.
pub fn shutdown(self) -> Result<(), Error> {
fn shutdown(self) -> Result<(), Error> {
self.shutdown.send(())?;
R::wake(&self.waker)?;
Ok(())
}
}
pub mod traits {
use super::*;
pub trait Handle {
/// Notify the client that a project has been updated.
fn updated(&self, id: ProjId) -> Result<(), Error>;
/// Send a command to the command channel, and wake up the event loop.
fn command(&self, cmd: protocol::Command) -> Result<(), Error>;
/// Ask the client to shutdown.
fn shutdown(self) -> Result<(), Error>;
}
}