@@ -69,7 +69,7 @@ impl DuplexSocket {
6969 socket
7070 }
7171
72- pub ( crate ) async fn setup ( & mut self , setup : SetupPayload ) {
72+ pub ( crate ) async fn setup ( & mut self , setup : SetupPayload ) -> Result < ( ) > {
7373 let mut bu = frame:: Setup :: builder ( 0 , 0 ) ;
7474 if let Some ( s) = setup. data_mime_type ( ) {
7575 bu = bu. set_mime_data ( s) ;
@@ -86,7 +86,7 @@ impl DuplexSocket {
8686 if let Some ( b) = m {
8787 bu = bu. set_metadata ( b) ;
8888 }
89- self . tx . send ( bu. build ( ) ) . expect ( "Send setup failed" ) ;
89+ self . tx . send ( bu. build ( ) ) . map_err ( |e| e . into ( ) )
9090 }
9191
9292 #[ inline]
@@ -128,7 +128,9 @@ impl DuplexSocket {
128128 . set_code ( error:: ERR_REJECT_SETUP )
129129 . set_data ( Bytes :: from ( errmsg) )
130130 . build ( ) ;
131- self . tx . send ( sending) . expect ( "Reject setup failed" ) ;
131+ if let Err ( _) = self . tx . send ( sending) {
132+ error ! ( "Reject setup failed" ) ;
133+ }
132134 return ;
133135 }
134136 }
@@ -261,13 +263,28 @@ impl DuplexSocket {
261263 self . joiners . remove ( & sid) ;
262264 // pick handler
263265 if let Some ( ( _, handler) ) = self . handlers . remove ( & sid) {
264- let desc = input. get_data_utf8 ( ) . unwrap ( ) . to_owned ( ) ;
266+ let desc = input
267+ . get_data_utf8 ( )
268+ . map ( |it| it. to_string ( ) )
269+ . unwrap_or_default ( ) ;
265270 let e = RSocketError :: must_new_from_code ( input. get_code ( ) , desc) ;
266271 match handler {
267- Handler :: ReqRR ( tx) => tx. send ( Err ( e. into ( ) ) ) . expect ( "Send RR failed" ) ,
272+ Handler :: ReqRR ( tx) => {
273+ if let Err ( _) = tx. send ( Err ( e. into ( ) ) ) {
274+ error ! ( "respond with error for REQUEST_RESPONSE failed!" ) ;
275+ }
276+ }
268277 Handler :: ResRR ( _) => unreachable ! ( ) ,
269- Handler :: ReqRS ( tx) => tx. send ( Err ( e. into ( ) ) ) . await . expect ( "Send RS failed" ) ,
270- Handler :: ReqRC ( tx) => tx. send ( Err ( e. into ( ) ) ) . await . expect ( "Send RC failed" ) ,
278+ Handler :: ReqRS ( tx) => {
279+ if let Err ( _) = tx. send ( Err ( e. into ( ) ) ) . await {
280+ error ! ( "respond with error for REQUEST_STREAM failed!" ) ;
281+ } ;
282+ }
283+ Handler :: ReqRC ( tx) => {
284+ if let Err ( _) = tx. send ( Err ( e. into ( ) ) ) . await {
285+ error ! ( "respond with error for REQUEST_CHANNEL failed!" ) ;
286+ }
287+ }
271288 }
272289 }
273290 }
@@ -281,7 +298,9 @@ impl DuplexSocket {
281298 match handler {
282299 Handler :: ReqRR ( sender) => {
283300 info ! ( "REQUEST_RESPONSE {} cancelled!" , sid) ;
284- sender. send ( e) . unwrap ( ) ;
301+ if let Err ( _) = sender. send ( e) {
302+ error ! ( "notify cancel for REQUEST_RESPONSE failed: sid={}" , sid) ;
303+ }
285304 }
286305 Handler :: ResRR ( c) => {
287306 let lefts = c. count_down ( ) ;
@@ -305,21 +324,26 @@ impl DuplexSocket {
305324 Handler :: ReqRR ( _) => match o. remove ( ) {
306325 Handler :: ReqRR ( sender) => {
307326 if flag & Frame :: FLAG_NEXT != 0 {
308- sender. send ( Ok ( Some ( input) ) ) . unwrap ( ) ;
327+ if let Err ( _) = sender. send ( Ok ( Some ( input) ) ) {
328+ error ! ( "response successful payload for REQUEST_RESPONSE failed: sid={}" , sid) ;
329+ }
309330 } else {
310- sender. send ( Ok ( None ) ) . unwrap ( ) ;
331+ if let Err ( _) = sender. send ( Ok ( None ) ) {
332+ error ! ( "response successful payload for REQUEST_RESPONSE failed: sid={}" , sid) ;
333+ }
311334 }
312335 }
313336 _ => unreachable ! ( ) ,
314337 } ,
315338 Handler :: ResRR ( c) => unreachable ! ( ) ,
316339 Handler :: ReqRS ( sender) => {
317340 if flag & Frame :: FLAG_NEXT != 0 {
318- sender
319- . clone ( )
320- . send ( Ok ( input) )
321- . await
322- . expect ( "Send payload response failed." ) ;
341+ if let Err ( e) = sender. send ( Ok ( input) ) . await {
342+ error ! (
343+ "response successful payload for REQUEST_STREAM failed: sid={}" ,
344+ sid
345+ ) ;
346+ }
323347 }
324348 if flag & Frame :: FLAG_COMPLETE != 0 {
325349 o. remove ( ) ;
@@ -328,11 +352,9 @@ impl DuplexSocket {
328352 Handler :: ReqRC ( sender) => {
329353 // TODO: support channel
330354 if flag & Frame :: FLAG_NEXT != 0 {
331- sender
332- . clone ( )
333- . send ( Ok ( input) )
334- . await
335- . expect ( "Send payload response failed" ) ;
355+ if let Err ( _) = sender. clone ( ) . send ( Ok ( input) ) . await {
356+ error ! ( "response successful payload for REQUEST_CHANNEL failed: sid={}" , sid) ;
357+ }
336358 }
337359 if flag & Frame :: FLAG_COMPLETE != 0 {
338360 o. remove ( ) ;
@@ -396,7 +418,9 @@ impl DuplexSocket {
396418 }
397419
398420 // async remove canceller
399- canceller. send ( sid) . await . expect ( "Send canceller failed" ) ;
421+ if let Err ( _) = canceller. send ( sid) . await {
422+ error ! ( "Send canceller failed: sid={}" , sid) ;
423+ }
400424
401425 match result {
402426 Ok ( Some ( res) ) => {
0 commit comments