@@ -29,7 +29,7 @@ pub(crate) fn parse_names<T: Stream<Item = io::Result<ResponseData>> + Unpin + S
29
29
Some ( Ok ( name) )
30
30
}
31
31
_ => {
32
- handle_unilateral ( resp, unsolicited) . await ;
32
+ handle_unilateral ( resp, unsolicited) ;
33
33
None
34
34
}
35
35
} ,
@@ -79,7 +79,7 @@ pub(crate) fn parse_fetches<T: Stream<Item = io::Result<ResponseData>> + Unpin +
79
79
Ok ( resp) => match resp. parsed ( ) {
80
80
Response :: Fetch ( ..) => Some ( Ok ( Fetch :: new ( resp) ) ) ,
81
81
_ => {
82
- handle_unilateral ( resp, unsolicited) . await ;
82
+ handle_unilateral ( resp, unsolicited) ;
83
83
None
84
84
}
85
85
} ,
@@ -157,7 +157,7 @@ pub(crate) async fn parse_status<T: Stream<Item = io::Result<ResponseData>> + Un
157
157
}
158
158
}
159
159
_ => {
160
- handle_unilateral ( resp, unsolicited. clone ( ) ) . await ;
160
+ handle_unilateral ( resp, unsolicited. clone ( ) ) ;
161
161
}
162
162
}
163
163
}
@@ -182,7 +182,7 @@ pub(crate) fn parse_expunge<T: Stream<Item = io::Result<ResponseData>> + Unpin +
182
182
Ok ( resp) => match resp. parsed ( ) {
183
183
Response :: Expunge ( id) => Some ( Ok ( * id) ) ,
184
184
_ => {
185
- handle_unilateral ( resp, unsolicited) . await ;
185
+ handle_unilateral ( resp, unsolicited) ;
186
186
None
187
187
}
188
188
} ,
@@ -213,7 +213,7 @@ pub(crate) async fn parse_capabilities<T: Stream<Item = io::Result<ResponseData>
213
213
}
214
214
}
215
215
_ => {
216
- handle_unilateral ( resp, unsolicited. clone ( ) ) . await ;
216
+ handle_unilateral ( resp, unsolicited. clone ( ) ) ;
217
217
}
218
218
}
219
219
}
@@ -232,7 +232,7 @@ pub(crate) async fn parse_noop<T: Stream<Item = io::Result<ResponseData>> + Unpi
232
232
. await
233
233
{
234
234
let resp = resp?;
235
- handle_unilateral ( resp, unsolicited. clone ( ) ) . await ;
235
+ handle_unilateral ( resp, unsolicited. clone ( ) ) ;
236
236
}
237
237
238
238
Ok ( ( ) )
@@ -338,7 +338,7 @@ pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + U
338
338
}
339
339
}
340
340
Response :: MailboxData ( m) => match m {
341
- MailboxDatum :: Status { .. } => handle_unilateral ( resp, unsolicited. clone ( ) ) . await ,
341
+ MailboxDatum :: Status { .. } => handle_unilateral ( resp, unsolicited. clone ( ) ) ,
342
342
MailboxDatum :: Exists ( e) => {
343
343
mailbox. exists = * e;
344
344
}
@@ -358,7 +358,7 @@ pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + U
358
358
_ => { }
359
359
} ,
360
360
_ => {
361
- handle_unilateral ( resp, unsolicited. clone ( ) ) . await ;
361
+ handle_unilateral ( resp, unsolicited. clone ( ) ) ;
362
362
}
363
363
}
364
364
}
@@ -386,7 +386,7 @@ pub(crate) async fn parse_ids<T: Stream<Item = io::Result<ResponseData>> + Unpin
386
386
}
387
387
}
388
388
_ => {
389
- handle_unilateral ( resp, unsolicited. clone ( ) ) . await ;
389
+ handle_unilateral ( resp, unsolicited. clone ( ) ) ;
390
390
}
391
391
}
392
392
}
@@ -421,57 +421,44 @@ pub(crate) async fn parse_metadata<T: Stream<Item = io::Result<ResponseData>> +
421
421
// [Unsolicited METADATA Response without Values](https://datatracker.ietf.org/doc/html/rfc5464.html#section-4.4.2),
422
422
// they go to unsolicited channel with other unsolicited responses.
423
423
_ => {
424
- handle_unilateral ( resp, unsolicited. clone ( ) ) . await ;
424
+ handle_unilateral ( resp, unsolicited. clone ( ) ) ;
425
425
}
426
426
}
427
427
}
428
428
Ok ( res_values)
429
429
}
430
430
431
- // check if this is simply a unilateral server response
432
- // (see Section 7 of RFC 3501):
433
- pub ( crate ) async fn handle_unilateral (
431
+ // Sends unilateral server response
432
+ // (see Section 7 of RFC 3501)
433
+ // into the channel.
434
+ //
435
+ // If the channel is full or closed,
436
+ // i.e. the responses are not being consumed,
437
+ // ignores new responses.
438
+ pub ( crate ) fn handle_unilateral (
434
439
res : ResponseData ,
435
440
unsolicited : channel:: Sender < UnsolicitedResponse > ,
436
441
) {
437
- // ignore these if they are not being consumed
438
- if unsolicited. is_full ( ) {
439
- return ;
440
- }
441
-
442
442
match res. parsed ( ) {
443
443
Response :: MailboxData ( MailboxDatum :: Status { mailbox, status } ) => {
444
444
unsolicited
445
- . send ( UnsolicitedResponse :: Status {
445
+ . try_send ( UnsolicitedResponse :: Status {
446
446
mailbox : ( mailbox. as_ref ( ) ) . into ( ) ,
447
447
attributes : status. to_vec ( ) ,
448
448
} )
449
- . await
450
- . expect ( "Channel closed unexpectedly" ) ;
449
+ . ok ( ) ;
451
450
}
452
451
Response :: MailboxData ( MailboxDatum :: Recent ( n) ) => {
453
- unsolicited
454
- . send ( UnsolicitedResponse :: Recent ( * n) )
455
- . await
456
- . expect ( "Channel closed unexpectedly" ) ;
452
+ unsolicited. try_send ( UnsolicitedResponse :: Recent ( * n) ) . ok ( ) ;
457
453
}
458
454
Response :: MailboxData ( MailboxDatum :: Exists ( n) ) => {
459
- unsolicited
460
- . send ( UnsolicitedResponse :: Exists ( * n) )
461
- . await
462
- . expect ( "Channel closed unexpectedly" ) ;
455
+ unsolicited. try_send ( UnsolicitedResponse :: Exists ( * n) ) . ok ( ) ;
463
456
}
464
457
Response :: Expunge ( n) => {
465
- unsolicited
466
- . send ( UnsolicitedResponse :: Expunge ( * n) )
467
- . await
468
- . expect ( "Channel closed unexpectedly" ) ;
458
+ unsolicited. try_send ( UnsolicitedResponse :: Expunge ( * n) ) . ok ( ) ;
469
459
}
470
460
_ => {
471
- unsolicited
472
- . send ( UnsolicitedResponse :: Other ( res) )
473
- . await
474
- . expect ( "Channel closed unexpectedly" ) ;
461
+ unsolicited. try_send ( UnsolicitedResponse :: Other ( res) ) . ok ( ) ;
475
462
}
476
463
}
477
464
}
0 commit comments