@@ -36,7 +36,7 @@ struct Responder {
3636
3737#[ derive( Debug ) ]
3838enum Handler {
39- ReqRR ( oneshot:: Sender < Result < Payload > > ) ,
39+ ReqRR ( oneshot:: Sender < Result < Option < Payload > > > ) ,
4040 ResRR ( Counter ) ,
4141 ReqRS ( mpsc:: Sender < Result < Payload > > ) ,
4242 ReqRC ( mpsc:: Sender < Result < Payload > > ) ,
@@ -261,12 +261,12 @@ impl DuplexSocket {
261261 // pick handler
262262 if let Some ( ( _, handler) ) = self . handlers . remove ( & sid) {
263263 let desc = input. get_data_utf8 ( ) . unwrap ( ) . to_owned ( ) ;
264- let e: Result < _ > = Err ( RSocketError :: must_new_from_code ( input. get_code ( ) , desc) . into ( ) ) ;
264+ let e = RSocketError :: must_new_from_code ( input. get_code ( ) , desc) ;
265265 match handler {
266- Handler :: ReqRR ( tx) => tx. send ( e ) . expect ( "Send RR failed" ) ,
266+ Handler :: ReqRR ( tx) => tx. send ( Err ( e . into ( ) ) ) . expect ( "Send RR failed" ) ,
267267 Handler :: ResRR ( _) => unreachable ! ( ) ,
268- Handler :: ReqRS ( tx) => tx. send ( e ) . await . expect ( "Send RS failed" ) ,
269- Handler :: ReqRC ( tx) => tx. send ( e ) . await . expect ( "Send RC failed" ) ,
268+ Handler :: ReqRS ( tx) => tx. send ( Err ( e . into ( ) ) ) . await . expect ( "Send RS failed" ) ,
269+ Handler :: ReqRC ( tx) => tx. send ( Err ( e . into ( ) ) ) . await . expect ( "Send RC failed" ) ,
270270 }
271271 }
272272 }
@@ -303,7 +303,11 @@ impl DuplexSocket {
303303 match o. get ( ) {
304304 Handler :: ReqRR ( _) => match o. remove ( ) {
305305 Handler :: ReqRR ( sender) => {
306- sender. send ( Ok ( input) ) . unwrap ( ) ;
306+ if flag & Frame :: FLAG_NEXT != 0 {
307+ sender. send ( Ok ( Some ( input) ) ) . unwrap ( ) ;
308+ } else {
309+ sender. send ( Ok ( None ) ) . unwrap ( ) ;
310+ }
307311 }
308312 _ => unreachable ! ( ) ,
309313 } ,
@@ -394,7 +398,7 @@ impl DuplexSocket {
394398 canceller. send ( sid) . await . expect ( "Send canceller failed" ) ;
395399
396400 match result {
397- Ok ( res) => {
401+ Ok ( Some ( res) ) => {
398402 Self :: try_send_payload (
399403 & splitter,
400404 & mut tx,
@@ -404,6 +408,9 @@ impl DuplexSocket {
404408 )
405409 . await ;
406410 }
411+ Ok ( None ) => {
412+ Self :: try_send_complete ( & mut tx, sid, Frame :: FLAG_COMPLETE ) . await ;
413+ }
407414 Err ( e) => {
408415 let sending = frame:: Error :: builder ( sid, 0 )
409416 . set_code ( error:: ERR_APPLICATION )
@@ -570,6 +577,14 @@ impl DuplexSocket {
570577 }
571578 }
572579
580+ #[ inline]
581+ async fn try_send_complete ( tx : & mut mpsc:: Sender < Frame > , sid : u32 , flag : u16 ) {
582+ let sending = frame:: Payload :: builder ( sid, flag) . build ( ) ;
583+ if let Err ( e) = tx. send ( sending) . await {
584+ error ! ( "respond failed: {}" , e) ;
585+ }
586+ }
587+
573588 #[ inline]
574589 async fn try_send_payload (
575590 splitter : & Option < Splitter > ,
@@ -697,8 +712,8 @@ impl RSocket for DuplexSocket {
697712 Ok ( ( ) )
698713 }
699714
700- async fn request_response ( & self , req : Payload ) -> Result < Payload > {
701- let ( tx, rx) = oneshot:: channel :: < Result < Payload > > ( ) ;
715+ async fn request_response ( & self , req : Payload ) -> Result < Option < Payload > > {
716+ let ( tx, rx) = oneshot:: channel :: < Result < Option < Payload > > > ( ) ;
702717 let sid = self . seq . next ( ) ;
703718 let handlers = self . handlers . clone ( ) ;
704719 let sender = self . tx . clone ( ) ;
@@ -911,7 +926,7 @@ impl RSocket for Responder {
911926 ( * inner) . fire_and_forget ( req) . await
912927 }
913928
914- async fn request_response ( & self , req : Payload ) -> Result < Payload > {
929+ async fn request_response ( & self , req : Payload ) -> Result < Option < Payload > > {
915930 let inner = self . inner . read ( ) . await ;
916931 ( * inner) . request_response ( req) . await
917932 }
0 commit comments