// Receives buffer from session and echoes back. It copies the content from
// half of the buffers, round robin on index.
Receives buffer from session and echoes back. It copies the content from
half of the buffers, round robin on index.
Receives buffer from session and echoes back . It copies the content from half of the buffers round robin on index .
async fn echo(session: Session, port: Port, frame_count: u32) {
    for i in 0..frame_count {
        let mut buffer = session.recv().await.expect("failed to recv from session");
        assert_eq!(buffer.cap(), DATA_LEN);
        let mut bytes = [0u8; DATA_LEN];
        assert_eq!(buffer.read(&mut bytes[..]).unwrap(), DATA_LEN);
        assert_eq!(u32::from_le_bytes(bytes), i);
        if i % 2 == 0 {
            let buffer = buffer.into_tx().await;
            session
                .send(buffer)
                .await
                .expect("failed to send the buffer back on the zero-copy path");
        } else {
            let mut buffer =
                session.alloc_tx_buffer(DATA_LEN).await.expect("no tx buffer available");
            buffer.set_frame_type(netdev::FrameType::Ethernet);
            buffer.set_port(port);
            assert_eq!(buffer.write(&bytes).unwrap(), DATA_LEN);
            session.send(buffer).await.expect("failed to send the buffer back on the copying path");
        }
    }
}
async fn echo ( session : Session , port : Port , frame_count : u32 ) { for i in 0 .. frame_count { let mut buffer = session . recv ( ) . await . expect ( " " ) ; assert_eq ! ( buffer cap ( ) DATA_LEN ) ; let mut bytes = [ 0u8 ; DATA_LEN ] ; assert_eq ! ( buffer read ( mut bytes [ ] ) unwrap ( ) DATA_LEN ) ; assert_eq ! ( u32 from_le_bytes ( bytes ) i ) ; if i % 2 == 0 { let buffer = buffer . into_tx ( ) . await ; session . send ( buffer ) . await . expect ( " " ) ; } else { let mut buffer = session . alloc_tx_buffer ( DATA_LEN ) . await . expect ( " " ) ; buffer . set_frame_type ( netdev :: FrameType :: Ethernet ) ; buffer . set_port ( port ) ; assert_eq ! ( buffer write ( bytes ) unwrap ( ) DATA_LEN ) ; session . send ( buffer ) . await . expect ( " " ) ; } } }
Receives buffer from session and echoes back.
Receives buffer from session and echoes back .
session
Session
port
Port
frame_count
u32