Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipc: Allow specifying different event loop reactor in server builder #459

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ipc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct ServerBuilder<M: Metadata = (), S: Middleware<M> = middleware::Noop>
meta_extractor: Arc<dyn MetaExtractor<M>>,
session_stats: Option<Arc<dyn session::SessionStats>>,
executor: reactor::UninitializedExecutor,
reactor: Option<Handle>,
incoming_separator: codecs::Separator,
outgoing_separator: codecs::Separator,
security_attributes: SecurityAttributes,
Expand Down Expand Up @@ -78,6 +79,7 @@ impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S> {
meta_extractor: Arc::new(extractor),
session_stats: None,
executor: reactor::UninitializedExecutor::Unspawned,
reactor: None,
incoming_separator: codecs::Separator::Empty,
outgoing_separator: codecs::Separator::default(),
security_attributes: SecurityAttributes::empty(),
Expand All @@ -91,6 +93,12 @@ impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S> {
self
}

/// Sets different event loop I/O reactor.
pub fn event_loop_reactor(mut self, reactor: Handle) -> Self {
self.reactor = Some(reactor);
self
}

/// Sets session metadata extractor.
pub fn session_meta_extractor<X>(mut self, meta_extractor: X) -> Self
where
Expand Down Expand Up @@ -128,6 +136,7 @@ impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S> {
/// Creates a new server from the given endpoint.
pub fn start(self, path: &str) -> std::io::Result<Server> {
let executor = self.executor.initialize()?;
let reactor = self.reactor;
let rpc_handler = self.handler;
let endpoint_addr = path.to_owned();
let meta_extractor = self.meta_extractor;
Expand All @@ -151,8 +160,9 @@ impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S> {
}
}

let endpoint_handle = Handle::default();
let connections = match endpoint.incoming(&endpoint_handle) {
// Make sure to construct Handle::default() inside Tokio runtime
let reactor = reactor.unwrap_or_else(Handle::default);
let connections = match endpoint.incoming(&reactor) {
Ok(connections) => connections,
Err(e) => {
start_signal
Expand Down