Ipc serialization & protocol fixes (#1188)

* serialization and codegen fixes from branch

* nano lib fixes

* fixes error encoding & comment

* another comment fix

* client timeout -> const
This commit is contained in:
Nikolay Volf
2016-06-02 19:04:42 +02:00
committed by Gav Wood
parent 0318bb9fe9
commit 81d8dafd9e
4 changed files with 71 additions and 26 deletions

View File

@@ -30,6 +30,7 @@ use nanomsg::{Socket, Protocol, Error, Endpoint, PollRequest, PollFd, PollInOut}
use std::ops::Deref;
const POLL_TIMEOUT: isize = 100;
const CLIENT_CONNECTION_TIMEOUT: isize = 2500;
/// Generic worker to handle service (binded) sockets
pub struct Worker<S> where S: IpcInterface<S> {
@@ -46,6 +47,12 @@ pub struct GuardedSocket<S> where S: WithSocket<Socket> {
_endpoint: Endpoint,
}
impl<S> GuardedSocket<S> where S: WithSocket<Socket> {
pub fn service(&self) -> Arc<S> {
self.client.clone()
}
}
impl<S> Deref for GuardedSocket<S> where S: WithSocket<Socket> {
type Target = S;
@@ -63,6 +70,9 @@ pub fn init_duplex_client<S>(socket_addr: &str) -> Result<GuardedSocket<S>, Sock
SocketError::DuplexLink
}));
// 2500 ms default timeout
socket.set_receive_timeout(CLIENT_CONNECTION_TIMEOUT).unwrap();
let endpoint = try!(socket.connect(socket_addr).map_err(|e| {
warn!(target: "ipc", "Failed to bind socket to address '{}': {:?}", socket_addr, e);
SocketError::DuplexLink
@@ -83,6 +93,9 @@ pub fn init_client<S>(socket_addr: &str) -> Result<GuardedSocket<S>, SocketError
SocketError::RequestLink
}));
// 2500 ms default timeout
socket.set_receive_timeout(CLIENT_CONNECTION_TIMEOUT).unwrap();
let endpoint = try!(socket.connect(socket_addr).map_err(|e| {
warn!(target: "ipc", "Failed to bind socket to address '{}': {:?}", socket_addr, e);
SocketError::RequestLink