fn poll()

in tools/xdp/s2n-quic-xdp/src/io/tx.rs [48:91]


    fn poll(
        &mut self,
        tx: &mut ring::Tx,
        completion: &mut ring::Completion,
        cx: &mut Context,
    ) -> Option<bool> {
        // record if either of the rings were empty to start
        let was_empty = tx.is_empty() || completion.is_empty();

        // iterate twice to avoid waker registration races
        for i in 0..2 {
            let count = completion.acquire(u32::MAX);
            let count = tx.acquire(count).min(count);

            trace!("acquired {count} entries");

            // return if we have entries in both rings
            if count > 0 {
                return Some(was_empty);
            }

            // if the peer's handle is closed, then shut down the task
            if !self.is_open() {
                return None;
            }

            // only register wakers if it's the first iteration and it started out empty
            if i > 0 || !was_empty {
                continue;
            }

            trace!("registering waker");
            self.register(cx.waker());
            trace!("waking waker");
            self.wake(tx, completion);
        }

        // we need to keep polling until we have at least one item here
        if tx.needs_wakeup() || completion.is_empty() || tx.is_empty() {
            atomic_waker::Handle::wake(self);
        }

        Some(false)
    }