Expose framing config in serde_transport.

This commit is contained in:
Tim Kuehn
2020-08-18 02:34:41 -07:00
parent 54d6e0e3b6
commit aa7b875b1a
5 changed files with 51 additions and 16 deletions

View File

@@ -8,6 +8,8 @@ use clap::{App, Arg};
use std::{io, net::SocketAddr};
use tarpc::{client, context};
use tokio_serde::formats::Json;
use tokio_util::codec::LengthDelimitedCodec;
use tokio::net::TcpStream;
#[tokio::main]
async fn main() -> io::Result<()> {
@@ -43,7 +45,12 @@ async fn main() -> io::Result<()> {
let name = flags.value_of("name").unwrap().into();
let transport = tarpc::serde_transport::tcp::connect(server_addr, Json::default()).await?;
let conn = TcpStream::connect(server_addr).await?;
let transport = tarpc::serde_transport::new(
LengthDelimitedCodec::builder().max_frame_length(4294967296).new_framed(conn),
Json::default(),
);
// WorldClient is generated by the service attribute. It has a constructor `new` that takes a
// config and any Transport as input.

View File

@@ -57,8 +57,9 @@ async fn main() -> io::Result<()> {
// JSON transport is provided by the json_transport tarpc module. It makes it easy
// to start up a serde-powered json serialization strategy over TCP.
tarpc::serde_transport::tcp::listen(&server_addr, Json::default)
.await?
let mut listener = tarpc::serde_transport::tcp::listen(&server_addr, Json::default).await?;
listener.config_mut().max_frame_length(4294967296);
listener
// Ignore accept errors.
.filter_map(|r| future::ready(r.ok()))
.map(server::BaseChannel::with_defaults)