Trait varlink::ConnectionHandler[][src]

pub trait ConnectionHandler {
    fn handle(
        &self,
        bufreader: &mut dyn BufRead,
        writer: &mut dyn Write,
        upgraded_iface: Option<String>
    ) -> Result<(Vec<u8>, Option<String>)>; }

Required methods

fn handle(
    &self,
    bufreader: &mut dyn BufRead,
    writer: &mut dyn Write,
    upgraded_iface: Option<String>
) -> Result<(Vec<u8>, Option<String>)>
[src]

Loading content...

Implementors

impl ConnectionHandler for VarlinkService[src]

fn handle(
    &self,
    bufreader: &mut dyn BufRead,
    writer: &mut dyn Write,
    upgraded_last_interface: Option<String>
) -> Result<(Vec<u8>, Option<String>)>
[src]

handle() consumes every null terminated message from reader and writes the reply to writer.

This method can be used to implement your own server. Pass it one or more null terminated received messages in a BufReader and reply to the sender with the filled writer buffer.

Returns Ok(true), if the connection is upgraded. For upgraded connections messages are in legacy format and

Examples

use varlink::{ConnectionHandler, VarlinkService};
let service = VarlinkService::new(
    "org.varlink",
    "test service",
    "0.1",
    "http://varlink.org",
    vec![], // more interfaces ...
);
let mut in_buf = io::BufReader::new("received null terminated message(s) go here \000".as_bytes());
let mut out: Vec<u8> = Vec::new();
assert!(service.handle(&mut in_buf, &mut out, None).is_ok());
Loading content...