fn finish_acked() {
    let _guard = subscribe();
    let mut pair = Pair::default();
    let (client_ch, server_ch) = pair.connect();

    let s = pair.client_conn_mut(client_ch).open(Dir::Uni).unwrap();

    const MSG: &[u8] = b"hello";
    pair.client_conn_mut(client_ch).write(s, MSG).unwrap();
    info!("client sends data to server");
    pair.drive_client(); // send data to server
    info!("server acknowledges data");
    pair.drive_server(); // process data and send data ack

    // Receive data
    assert_matches!(
        pair.server_conn_mut(server_ch).poll(),
        Some(Event::Stream(StreamEvent::Opened { dir: Dir::Uni }))
    );
    assert_matches!(pair.server_conn_mut(server_ch).poll(), None);

    assert_matches!(pair.server_conn_mut(server_ch).accept(Dir::Uni), Some(stream) if stream == s);
    assert_matches!(
        pair.server_conn_mut(server_ch).read_unordered(s),
        Ok(Some((ref data, 0))) if data == MSG
    );
    assert_matches!(
        pair.server_conn_mut(server_ch).read_unordered(s),
        Err(ReadError::Blocked)
    );

    // Finish before receiving data ack
    pair.client_conn_mut(client_ch).finish(s).unwrap();
    // Send FIN, receive data ack
    info!("client receives ACK, sends FIN");
    pair.drive_client();
    // Check for premature finish from data ack
    assert_matches!(pair.client_conn_mut(client_ch).poll(), None);
    // Process FIN ack
    info!("server ACKs FIN");
    pair.drive();
    assert_matches!(
        pair.client_conn_mut(client_ch).poll(),
        Some(Event::Stream(StreamEvent::Finished { id })) if id == s
    );
    assert_matches!(pair.server_conn_mut(server_ch).read_unordered(s), Ok(None));
}
/// Ensure that we don't yield a finish event before the actual FIN is acked so the peer isn't left
/// hanging
Ensure that we don't yield a finish event before the actual FIN is acked so the peer isn't left
hanging
Ensure that we don ' t yield a finish event before the actual FIN is acked so the peer isn ' t left hanging
fn finish_acked() {
    let _guard = subscribe();
    let mut pair = Pair::default();
    let (client_ch, server_ch) = pair.connect();
    let s = pair.client_conn_mut(client_ch).open(Dir::Uni).unwrap();
    const MSG: &[u8] = b"hello";
    pair.client_conn_mut(client_ch).write(s, MSG).unwrap();
    info!("client sends data to server");
    pair.drive_client(); // send data to server
    info!("server acknowledges data");
    pair.drive_server(); // process data and send data ack
    // Receive data
    assert_matches!(
        pair.server_conn_mut(server_ch).poll(),
        Some(Event::Stream(StreamEvent::Opened { dir: Dir::Uni }))
    );
    assert_matches!(pair.server_conn_mut(server_ch).poll(), None);
    assert_matches!(pair.server_conn_mut(server_ch).accept(Dir::Uni), Some(stream) if stream == s);
    assert_matches!(
        pair.server_conn_mut(server_ch).read_unordered(s),
        Ok(Some((ref data, 0))) if data == MSG
    );
    assert_matches!(
        pair.server_conn_mut(server_ch).read_unordered(s),
        Err(ReadError::Blocked)
    );
    // Finish before receiving data ack
    pair.client_conn_mut(client_ch).finish(s).unwrap();
    // Send FIN, receive data ack
    info!("client receives ACK, sends FIN");
    pair.drive_client();
    // Check for premature finish from data ack
    assert_matches!(pair.client_conn_mut(client_ch).poll(), None);
    // Process FIN ack
    info!("server ACKs FIN");
    pair.drive();
    assert_matches!(
        pair.client_conn_mut(client_ch).poll(),
        Some(Event::Stream(StreamEvent::Finished { id })) if id == s
    );
    assert_matches!(pair.server_conn_mut(server_ch).read_unordered(s), Ok(None));
}
fn finish_acked ( ) { let _guard = subscribe ( ) ; let mut pair = Pair :: default ( ) ; let ( client_ch , server_ch ) = pair . connect ( ) ; let s = pair . client_conn_mut ( client_ch ) . open ( Dir :: Uni ) . unwrap ( ) ; const MSG : & [ u8 ] = b" " ; pair . client_conn_mut ( client_ch ) . write ( s , MSG ) . unwrap ( ) ; info ! ( " " ) ; pair . drive_client ( ) ; // send data to server info ! ( " " ) ; pair . drive_server ( ) ; // process data and send data ack // Receive data assert_matches ! ( pair server_conn_mut ( server_ch ) poll ( ) Some ( Event Stream ( StreamEvent Opened { dir Dir Uni } ) ) ) ; assert_matches ! ( pair server_conn_mut ( server_ch ) poll ( ) None ) ; assert_matches ! ( pair server_conn_mut ( server_ch ) accept ( Dir Uni ) Some ( stream ) if stream s ) ; assert_matches ! ( pair server_conn_mut ( server_ch ) read_unordered ( s ) Ok ( Some ( ( ref data 0 ) ) ) if data MSG ) ; assert_matches ! ( pair server_conn_mut ( server_ch ) read_unordered ( s ) Err ( ReadError Blocked ) ) ; // Finish before receiving data ack pair . client_conn_mut ( client_ch ) . finish ( s ) . unwrap ( ) ; // Send FIN, receive data ack info ! ( " " ) ; pair . drive_client ( ) ; // Check for premature finish from data ack assert_matches ! ( pair client_conn_mut ( client_ch ) poll ( ) None ) ; // Process FIN ack info ! ( " " ) ; pair . drive ( ) ; assert_matches ! ( pair client_conn_mut ( client_ch ) poll ( ) Some ( Event Stream ( StreamEvent Finished { id } ) ) if id s ) ; assert_matches ! ( pair server_conn_mut ( server_ch ) read_unordered ( s ) Ok ( None ) ) ; }
Ensure that we don't yield a finish event before the actual FIN is acked so the peer isn't left
hanging
Ensure that we don ' t yield a finish event before the actual FIN is acked so the peer isn ' t left hanging