pub struct Server<I: Invoker> {
pub invoker: Arc<I>,
/* private fields */
}Expand description
Server for handling incoming RPC connections.
The Server routes incoming RPC calls to the appropriate handler via the provided Invoker (typically a Mux).
§Example
use starpc::{Server, Mux};
let mux = Arc::new(Mux::new());
mux.register(Arc::new(MyServiceHandler))?;
let server = Server::new(mux);
server.handle_stream(tcp_stream).await?;Fields§
§invoker: Arc<I>The invoker for routing RPC calls.
Implementations§
Source§impl<I: Invoker + 'static> Server<I>
impl<I: Invoker + 'static> Server<I>
Sourcepub fn with_config(self, config: ServerConfig) -> Self
pub fn with_config(self, config: ServerConfig) -> Self
Sets the server configuration.
Sourcepub fn with_error_handler<F>(self, handler: F) -> Self
pub fn with_error_handler<F>(self, handler: F) -> Self
Sets an error handler for connection errors.
The handler is called when an error occurs during stream handling. This is useful for logging or metrics.
Sourcepub async fn handle_stream<T>(&self, transport: T) -> Result<()>
pub async fn handle_stream<T>(&self, transport: T) -> Result<()>
Handles a single stream connection.
This reads packets from the stream, routes the RPC call to the appropriate handler, and writes responses back.
The method returns when the RPC completes or an error occurs.
Sourcepub async fn serve<L, T>(&self, listener: L) -> Result<()>
pub async fn serve<L, T>(&self, listener: L) -> Result<()>
Accepts and handles connections in a loop.
This is a convenience method that accepts connections from a listener and spawns a task to handle each one.
Errors from individual connections are reported via the error handler (if configured) but don’t stop the server.