Struct thrift::server::TSimpleServer [] [src]

pub struct TSimpleServer<PR: TProcessor> { /* fields omitted */ }

Single-threaded blocking Thrift socket server.

A TSimpleServer listens on a given address and services accepted connections synchronously and sequentially - i.e. in a blocking manner, one at a time - on the main thread. Each accepted connection has an input half and an output half, each of which uses a TTransport and TProtocol to translate messages to and from byes. Any combination of TProtocol and TTransport may be used.

Examples

Creating and running a TSimpleServer using Thrift-compiler-generated service code.

use thrift;
use thrift::protocol::{TInputProtocolFactory, TOutputProtocolFactory};
use thrift::protocol::{TBinaryInputProtocolFactory, TBinaryOutputProtocolFactory};
use thrift::protocol::{TInputProtocol, TOutputProtocol};
use thrift::transport::{TBufferedTransportFactory, TTransportFactory};
use thrift::server::{TProcessor, TSimpleServer};

//
// auto-generated
//

// processor for `SimpleService`
struct SimpleServiceSyncProcessor;
impl SimpleServiceSyncProcessor {
    fn new<H: SimpleServiceSyncHandler>(processor: H) -> SimpleServiceSyncProcessor {
        unimplemented!();
    }
}

// `TProcessor` implementation for `SimpleService`
impl TProcessor for SimpleServiceSyncProcessor {
    fn process(&mut self, i: &mut TInputProtocol, o: &mut TOutputProtocol) -> thrift::Result<()> {
        unimplemented!();
    }
}

// service functions for SimpleService
trait SimpleServiceSyncHandler {
    fn service_call(&mut self) -> thrift::Result<()>;
}

//
// user-code follows
//

// define a handler that will be invoked when `service_call` is received
struct SimpleServiceHandlerImpl;
impl SimpleServiceSyncHandler for SimpleServiceHandlerImpl {
    fn service_call(&mut self) -> thrift::Result<()> {
        unimplemented!();
    }
}

// instantiate the processor
let processor = SimpleServiceSyncProcessor::new(SimpleServiceHandlerImpl {});

// instantiate the server
let i_tr_fact: Box<TTransportFactory> = Box::new(TBufferedTransportFactory::new());
let i_pr_fact: Box<TInputProtocolFactory> = Box::new(TBinaryInputProtocolFactory::new());
let o_tr_fact: Box<TTransportFactory> = Box::new(TBufferedTransportFactory::new());
let o_pr_fact: Box<TOutputProtocolFactory> = Box::new(TBinaryOutputProtocolFactory::new());

let mut server = TSimpleServer::new(
    i_tr_fact,
    i_pr_fact,
    o_tr_fact,
    o_pr_fact,
    processor
);

// start listening for incoming connections
match server.listen("127.0.0.1:8080") {
  Ok(_)  => println!("listen completed"),
  Err(e) => println!("listen failed with error {:?}", e),
}

Methods

impl<PR: TProcessor> TSimpleServer<PR>
[src]

Create a TSimpleServer.

Each accepted connection has an input and output half, each of which requires a TTransport and TProtocol. TSimpleServer uses input_transport_factory and input_protocol_factory to create implementations for the input, and output_transport_factory and output_protocol_factory to create implementations for the output.

Listen for incoming connections on listen_address.

listen_address should be in the form host:port, for example: 127.0.0.1:8080.

Return () if successful.

Return Err when the server cannot bind to listen_address or there is an unrecoverable error.