@@ -148,6 +148,8 @@ impl<T: RemoteBackend + Send + Sync + 'static> Server<T> {
148148 }
149149}
150150
151+ const MAX_FRAME_LENGTH : usize = 2 * 1024 * 1024 * 1024 ; // 2 GB
152+
151153async fn handle_connection < T : RemoteBackend + Send + Sync + ' static > (
152154 stream : UnixStream ,
153155 writer_pool : Arc < WriterPool > ,
@@ -156,9 +158,14 @@ async fn handle_connection<T: RemoteBackend + Send + Sync + 'static>(
156158 cache : Arc < Cache > ,
157159 chunk_size : usize ,
158160) -> tokio:: io:: Result < ( ) > {
159- let ( read_half, write_half) = split ( stream) ;
160- let mut reader = FramedRead :: new ( read_half, LengthDelimitedCodec :: new ( ) ) ;
161- let writer = Arc :: new ( Mutex :: new ( FramedWrite :: new ( write_half, LengthDelimitedCodec :: new ( ) ) ) ) ;
161+ let ( read_half, write_half) = tokio:: io:: split ( stream) ;
162+
163+ let codec = LengthDelimitedCodec :: builder ( )
164+ . max_frame_length ( MAX_FRAME_LENGTH )
165+ . new_codec ( ) ;
166+
167+ let mut reader = FramedRead :: new ( read_half, codec. clone ( ) ) ;
168+ let writer = Arc :: new ( Mutex :: new ( FramedWrite :: new ( write_half, codec) ) ) ;
162169
163170 while let Some ( frame) = reader. next ( ) . await {
164171 let f = frame. map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , format ! ( "frame read failed: {}" , e) ) ) ?;
@@ -169,7 +176,7 @@ async fn handle_connection<T: RemoteBackend + Send + Sync + 'static>(
169176
170177 match msg {
171178 Ok ( ( request, _) ) => {
172- // println!("Received: {:?}", request );
179+ println ! ( "Received req" ) ;
173180 match request {
174181 request:: Request :: Get ( req) => {
175182 if let Err ( e) = req. validate ( chunk_size) {
@@ -259,11 +266,11 @@ async fn handle_connection<T: RemoteBackend + Send + Sync + 'static>(
259266 return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , format ! ( "remote.get failed: {}" , e) ) ) ;
260267 }
261268 } ;
262-
269+
263270 let encoded = bincode:: serde:: encode_to_vec (
264271 request:: GetResponse :: Response ( resp. clone ( ) ) ,
265272 bincode:: config:: standard ( )
266- ) . unwrap ( ) ;
273+ ) . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , format ! ( "serialization failed: {}" , e ) ) ) ? ;
267274 {
268275 let mut w = writer. lock ( ) . await ;
269276 w. send ( Bytes :: from ( encoded) ) . await . map_err ( |e| {
0 commit comments