fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
        // check if there is any packet available in the receive queue
        let numdeq = self.device.rxq[0].can_dequeue(false);

        if numdeq > 0 {
            // Get a packet, for now just one
            let packet = self.device.rxq[0].dequeue().expect("numdeq was >0");
            assert!(self.device.rxq[0].flush().is_ok());

            // Enqueue another buffer for future receives
            // TODO: maybe we need to enqueue more than one?

            // info!("RX: new rx buffer chain");
            let layout = Layout::from_size_align(MAX_PACKET_SZ, 128).expect("Correct Layout");
            let mut bufs = IOBufChain::new(0, 2).expect("Can't make chain?");
            let seg0 = IOBuf::new(layout).expect("Can't make packet?");
            let seg1 = IOBuf::new(layout).expect("Can't make packet?");
            bufs.append(seg0);
            bufs.append(seg1);
            let enq = self.device.rxq[0].enqueue(bufs);
            assert!(enq.is_ok());

            // construct the RX token
            let rx_token = RxPacket::new(packet, &mut self.pool_rx);

            // get an empty TX token from the pool...
            // TODO: make sure we can actually send something!
            let numdeq = self.device.txq[0].can_dequeue(false);
            let iobuf = if numdeq > 0 {
                // info!("TX: reusing buffer chain");
                self.device.txq[0].dequeue().expect("Couldn't dequeue?")
            } else {
                // info!("TX: new buffer chain");
                let mut iobuf = IOBufChain::new(0, 2).expect("Can't create chain?");
                let layout = Layout::from_size_align(MAX_PACKET_SZ, 128).expect("Correct Layout");
                let seg0 = IOBuf::new(layout).expect("Can't make packet?");
                let seg1 = IOBuf::new(layout).expect("Can't make packet?");

                iobuf.append(seg0);
                iobuf.append(seg1);
                iobuf
            };

            // let iobuf = self.get_tx_iobuf_chain();
            // let mut iobuf = IOBufChain::new(0, 1).expect("Can't make chain?");
            // let buf2 = self.pool_tx.get_buf().expect("Can't get buffer?");
            // iobuf.append(buf2);
            let tx_token = TxPacket::new(iobuf, &mut self.device.txq[0], &mut self.pool_tx);

            Some((rx_token, tx_token))
        } else {
            // info!("Nothing to receive!");
            assert!(self.device.rxq[0].flush().is_ok());
            None
        }
    }
/// Obtains a receive buffer along a side a send buffer for replies (e.g., ping...)
Obtains a receive buffer along a side a send buffer for replies
Obtains a receive buffer along a side a send buffer for replies
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
        // check if there is any packet available in the receive queue
        let numdeq = self.device.rxq[0].can_dequeue(false);
        if numdeq > 0 {
            // Get a packet, for now just one
            let packet = self.device.rxq[0].dequeue().expect("numdeq was >0");
            assert!(self.device.rxq[0].flush().is_ok());
            // Enqueue another buffer for future receives
            // TODO: maybe we need to enqueue more than one?
            // info!("RX: new rx buffer chain");
            let layout = Layout::from_size_align(MAX_PACKET_SZ, 128).expect("Correct Layout");
            let mut bufs = IOBufChain::new(0, 2).expect("Can't make chain?");
            let seg0 = IOBuf::new(layout).expect("Can't make packet?");
            let seg1 = IOBuf::new(layout).expect("Can't make packet?");
            bufs.append(seg0);
            bufs.append(seg1);
            let enq = self.device.rxq[0].enqueue(bufs);
            assert!(enq.is_ok());
            // construct the RX token
            let rx_token = RxPacket::new(packet, &mut self.pool_rx);
            // get an empty TX token from the pool...
            // TODO: make sure we can actually send something!
            let numdeq = self.device.txq[0].can_dequeue(false);
            let iobuf = if numdeq > 0 {
                // info!("TX: reusing buffer chain");
                self.device.txq[0].dequeue().expect("Couldn't dequeue?")
            } else {
                // info!("TX: new buffer chain");
                let mut iobuf = IOBufChain::new(0, 2).expect("Can't create chain?");
                let layout = Layout::from_size_align(MAX_PACKET_SZ, 128).expect("Correct Layout");
                let seg0 = IOBuf::new(layout).expect("Can't make packet?");
                let seg1 = IOBuf::new(layout).expect("Can't make packet?");
                iobuf.append(seg0);
                iobuf.append(seg1);
                iobuf
            };
            // let iobuf = self.get_tx_iobuf_chain();
            // let mut iobuf = IOBufChain::new(0, 1).expect("Can't make chain?");
            // let buf2 = self.pool_tx.get_buf().expect("Can't get buffer?");
            // iobuf.append(buf2);
            let tx_token = TxPacket::new(iobuf, &mut self.device.txq[0], &mut self.pool_tx);
            Some((rx_token, tx_token))
        } else {
            // info!("Nothing to receive!");
            assert!(self.device.rxq[0].flush().is_ok());
            None
        }
    }
fn receive ( & ' a mut self ) -> Option < ( Self :: RxToken , Self :: TxToken ) > { // check if there is any packet available in the receive queue let numdeq = self . device . rxq [ 0 ] . can_dequeue ( false ) ; if numdeq > 0 { // Get a packet, for now just one let packet = self . device . rxq [ 0 ] . dequeue ( ) . expect ( " " ) ; assert ! ( self device rxq [ 0 ] flush ( ) is_ok ( ) ) ; // Enqueue another buffer for future receives // TODO: maybe we need to enqueue more than one? // info!("RX: new rx buffer chain"); let layout = Layout :: from_size_align ( MAX_PACKET_SZ , 128 ) . expect ( " " ) ; let mut bufs = IOBufChain :: new ( 0 , 2 ) . expect ( " " ) ; let seg0 = IOBuf :: new ( layout ) . expect ( " " ) ; let seg1 = IOBuf :: new ( layout ) . expect ( " " ) ; bufs . append ( seg0 ) ; bufs . append ( seg1 ) ; let enq = self . device . rxq [ 0 ] . enqueue ( bufs ) ; assert ! ( enq is_ok ( ) ) ; // construct the RX token let rx_token = RxPacket :: new ( packet , & mut self . pool_rx ) ; // get an empty TX token from the pool... // TODO: make sure we can actually send something! let numdeq = self . device . txq [ 0 ] . can_dequeue ( false ) ; let iobuf = if numdeq > 0 { // info!("TX: reusing buffer chain"); self . device . txq [ 0 ] . dequeue ( ) . expect ( " " ) } else { // info!("TX: new buffer chain"); let mut iobuf = IOBufChain :: new ( 0 , 2 ) . expect ( " " ) ; let layout = Layout :: from_size_align ( MAX_PACKET_SZ , 128 ) . expect ( " " ) ; let seg0 = IOBuf :: new ( layout ) . expect ( " " ) ; let seg1 = IOBuf :: new ( layout ) . expect ( " " ) ; iobuf . append ( seg0 ) ; iobuf . append ( seg1 ) ; iobuf } ; // let iobuf = self.get_tx_iobuf_chain(); // let mut iobuf = IOBufChain::new(0, 1).expect("Can't make chain?"); // let buf2 = self.pool_tx.get_buf().expect("Can't get buffer?"); // iobuf.append(buf2); let tx_token = TxPacket :: new ( iobuf , & mut self . device . txq [ 0 ] , & mut self . pool_tx ) ; Some ( ( rx_token , tx_token ) ) } else { // info!("Nothing to receive!"); assert ! ( self device rxq [ 0 ] flush ( ) is_ok ( ) ) ; None } }
Obtains a receive buffer along a side a send buffer for replies (e.g., ping...)
Obtains a receive buffer along a side a send buffer for replies ( e . g . ping ... )
&'a mut self
&'a mut self