pub struct ServerBinding { /* private fields */ }Expand description
Manages the lifecycle of an RPC server.
This struct handles the low-level details of registering an RPC interface with the Windows RPC runtime and managing the listen/stop lifecycle.
§Note
You typically don’t create ServerBinding directly. Instead, use the
generated {Interface}Server struct which manages this for you.
§Example
use windows_rpc::rpc_interface;
#[rpc_interface(guid(0x12345678_1234_1234_1234_123456789abc), version(1.0))]
trait MyInterface {
fn hello() -> i32;
}
struct MyImpl;
impl MyInterfaceServerImpl for MyImpl {
fn hello() -> i32 { 42 }
}
let mut server = MyInterfaceServer::<MyImpl>::new();
server.register("my_endpoint")?;
server.listen_async()?;
// ... server is now accepting calls ...
server.stop()?;Implementations§
Source§impl ServerBinding
impl ServerBinding
Sourcepub fn new(
protocol: ProtocolSequence,
endpoint: impl Into<String>,
interface_handle: *const c_void,
) -> Result<Self, Error>
pub fn new( protocol: ProtocolSequence, endpoint: impl Into<String>, interface_handle: *const c_void, ) -> Result<Self, Error>
Creates a new server binding for the specified endpoint.
This registers the protocol sequence and endpoint with the RPC runtime,
but does not yet register the interface. Call register()
to complete the registration.
§Arguments
protocol- The protocol sequence to useendpoint- The endpoint name clients will connect tointerface_handle- Pointer to the RPC interface specification
§Errors
Returns an error if the protocol sequence and endpoint cannot be registered.
Sourcepub fn register(&mut self) -> Result<(), Error>
pub fn register(&mut self) -> Result<(), Error>
Registers the RPC interface with the runtime.
After registration, the server can begin accepting calls. This method is idempotent - calling it multiple times has no effect.
§Errors
Returns an error if the interface cannot be registered.
Sourcepub fn listen(&self) -> Result<(), Error>
pub fn listen(&self) -> Result<(), Error>
Starts listening for RPC calls (blocking).
This method blocks the current thread until stop() is called
from another thread. Use listen_async() for non-blocking
operation.
§Errors
Returns an error if:
- The interface has not been registered
- The RPC runtime fails to start listening
Sourcepub fn listen_async(&self) -> Result<(), Error>
pub fn listen_async(&self) -> Result<(), Error>
Starts listening for RPC calls (non-blocking).
Returns immediately while RPC calls are processed in background threads
managed by the Windows RPC runtime. Call stop() to shut
down the server.
This is the recommended mode for most applications as it allows the main thread to continue other work or wait for a shutdown signal.
§Errors
Returns an error if:
- The interface has not been registered
- The RPC runtime fails to start listening
Sourcepub fn unregister(&mut self) -> Result<(), Error>
pub fn unregister(&mut self) -> Result<(), Error>
Unregisters the RPC interface.
This is called automatically when the ServerBinding is dropped.
§Errors
Returns an error if the interface cannot be unregistered.
Sourcepub fn protocol(&self) -> ProtocolSequence
pub fn protocol(&self) -> ProtocolSequence
Returns the protocol sequence.