Skip to main content

razor_rpc_tcp/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(docsrs, allow(unused_attributes))]
3
4//! # razor-rpc-tcp
5//!
6//! This crate provides a TCP transport implementation for [`razor-stream`](https://docs.rs/razor-stream).
7//! It is used for both client and server communication over TCP.
8
9#[macro_use]
10extern crate captains_log;
11mod client;
12pub use client::*;
13mod server;
14pub use server::*;
15
16#[macro_export(local_inner_macros)]
17macro_rules! io_with_timeout {
18    ($IO: path, $timeout: expr, $f: expr) => {{
19        if $timeout == Duration::from_secs(0) {
20            $f.await
21        } else {
22            // the crate reference make this macro not exportable
23            match <$IO as orb::time::AsyncTime>::timeout($timeout, $f).await {
24                Ok(Ok(r)) => Ok(r),
25                Ok(Err(e)) => Err(e),
26                Err(_) => Err(std::io::ErrorKind::TimedOut.into()),
27            }
28        }
29    }};
30}