Created
June 14, 2019 23:25
-
-
Save ymjing/2185baf69bea18298732ecdea73b8ff2 to your computer and use it in GitHub Desktop.
A simple brpc-rs service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use brpc_sys::proto_gen; | |
fn main() { | |
match proto_gen::compile_protos(&["proto/echo.proto"]) { | |
Ok(_) => (), | |
Err(e) => println!("{:?}", e), | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "brpc_server_demo" | |
version = "0.1.0" | |
edition = "2018" | |
build = "build.rs" | |
[dependencies] | |
brpc-sys = { path = "../brpc-sys" } | |
cc = "1.0.37" | |
[build-dependencies] | |
brpc-sys = { path = "../brpc-sys" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use brpc_sys::{Server, ServerOptions}; | |
pub mod echo { | |
include!(concat!(env!("OUT_DIR"), "/proto/echo.rs")); | |
} | |
fn main() { | |
unsafe { | |
let mut service = echo::EchoService::new(); | |
service.set_echo_handler(&mut move |f, t| { | |
let req = f.into_bytes(); | |
println!("{:?}", std::str::from_utf8(&req).unwrap()); | |
t.append_from_bytes(b"hello world\n\0"); | |
Ok(()) | |
}); | |
let mut server = Server::new(); | |
let mut options = ServerOptions::new(); | |
options.set_idle_timeout_ms(1000); | |
server.add_service(&service, 1); | |
server.start(50000, &options); | |
server.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is this?
Some kind of ping server?