Skip to main content

nxtquic_api/
stream.rs

1//! QUIC stream types implementing Tokio async I/O traits.
2
3use std::pin::Pin;
4use std::task::{Context, Poll};
5use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
6
7/// A stream that can be written to.
8pub struct SendStream {
9    // Inner state
10}
11
12impl SendStream {
13    /// Creates a new send stream internally.
14    pub(crate) fn new() -> Self {
15        Self {}
16    }
17}
18
19impl AsyncWrite for SendStream {
20    fn poll_write(
21        self: Pin<&mut Self>,
22        _cx: &mut Context<'_>,
23        buf: &[u8],
24    ) -> Poll<Result<usize, std::io::Error>> {
25        Poll::Ready(Ok(buf.len()))
26    }
27
28    fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
29        Poll::Ready(Ok(()))
30    }
31
32    fn poll_shutdown(
33        self: Pin<&mut Self>,
34        _cx: &mut Context<'_>,
35    ) -> Poll<Result<(), std::io::Error>> {
36        Poll::Ready(Ok(()))
37    }
38}
39
40/// A stream that can be read from.
41pub struct RecvStream {
42    // Inner state
43}
44
45impl RecvStream {
46    /// Creates a new recv stream internally.
47    pub(crate) fn new() -> Self {
48        Self {}
49    }
50}
51
52impl AsyncRead for RecvStream {
53    fn poll_read(
54        self: Pin<&mut Self>,
55        _cx: &mut Context<'_>,
56        _buf: &mut ReadBuf<'_>,
57    ) -> Poll<std::io::Result<()>> {
58        // Mocking read completion. Real implementation would copy data into buf.
59        Poll::Ready(Ok(()))
60    }
61}