Skip to content

UdpFramed type socket keeps producing Poll:ready after receiving the first frame #3875

Answered by pranav-bhatt
pranav-bhatt asked this question in Q&A
Discussion options

You must be logged in to vote

So the issue was that the implementation of Stream for Decoder in tokio_util v0.2 automatically handled the advancing of the read pointer as soon as a frame eof was hit:

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
    let pin = self.get_mut();

    pin.rd.reserve(INITIAL_RD_CAPACITY);

    let (_n, addr) = unsafe {
        // Read into the buffer without having to initialize the memory.
        //
        // safety: we know tokio::net::UdpSocket never reads from the memory
        // during a recv
        let res = {
            let bytes = &mut *(pin.rd.bytes_mut() as *mut _ as *mut [u8]);
            ready!(Pin::new(&mut pin.socket).poll_recv_from

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@pranav-bhatt
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by pranav-bhatt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants