pub struct ServerManager<F> { /* private fields */ }
Expand description
Title: ServerManager structure for managing the server process
Parameters:
- None
Returns:
- None
This structure encapsulates the server management operations and holds the user-provided configuration and the server function.
Implementations§
Source§impl<F, Fut> ServerManager<F>
impl<F, Fut> ServerManager<F>
Sourcepub fn new(config: ServerManagerConfig, server_fn: F) -> ServerManager<F>
pub fn new(config: ServerManagerConfig, server_fn: F) -> ServerManager<F>
Title: Create a new ServerManager instance
Parameters:
config
: The server configuration containing PID file path and log paths.server_fn
: A closure representing the asynchronous server function.
Returns:
ServerManager<F>
: A new instance of ServerManager.
Sourcepub async fn start(&self)
pub async fn start(&self)
Title: Start the server in foreground mode
Parameters:
- None
Returns:
()
: No return value.
This function writes the current process ID to the PID file specified in the configuration and then runs the server function asynchronously.
Sourcepub fn stop(&self) -> Result<(), Box<dyn Error>>
pub fn stop(&self) -> Result<(), Box<dyn Error>>
Title: Stop the server
Parameters:
- None
Returns:
Result<(), Box<dyn std::error::Error>>
: Operation result.
This function reads the process ID from the PID file and attempts to kill the process using a SIGTERM signal.
Sourcepub fn start_daemon(&self) -> Result<(), Box<dyn Error>>
pub fn start_daemon(&self) -> Result<(), Box<dyn Error>>
Start the server in daemon (background) mode on Unix platforms. Title: Start the server in daemon mode on non-Unix platforms
Parameters:
- None
Returns:
Result<(), Box<dyn std::error::Error>>
: Operation result.
This function returns an error because daemon mode is not supported on non-Unix platforms.