Module portunusd::door [−][src]
Expand description
Define connection handlers for your PortunusD Apps!
In PortunusD, every incoming connection is forwarded to an external application via
illumos Doors. You can use the derive_server_procedure!
macro defined in this module to
convert a Fn: &[u8] -> Vec<u8>
function into a PortunusD function handler.
Below is an example of an application that accepts a user’s name in the request body and returns a polite greeting:
use portunusd::derive_server_procedure; use portunusd::door; use std::fmt::format; use std::str::from_utf8; // Consider the function `hello`, which returns a polite greeting to a client: fn hello(request: &[u8]) -> Vec<u8> { match from_utf8(request) { Err(_) => b"I couldn't understand your name!".to_vec(), Ok(name) => { let response = format!("Hello, {}!", name); response.into_bytes() } } } // We can turn that function into a special type (one that implements ServerProcedure) which // knows how to make the function available via a "door" on the filesystem: derive_server_procedure!(hello as Hello); // make the `hello` function available on the filesystem let hello_server = Hello::install("portunusd_test.04683b").unwrap(); // Now a client (even one in another process!) can call this procedure: let hello_client = door::Client::new("portunusd_test.04683b").unwrap(); let greeting = hello_client.call(b"Portunus").unwrap(); assert_eq!(greeting, b"Hello, Portunus!");
Structs
Client | A Client handle for a door. Used by PortunusD to call your application. |
ClientRef | |
Server | A server procedure which has been attached to the filesystem. |
Enums
Error | Door problems. |
Traits
ServerProcedure | Trait for types derived from the |