Skip to content

Commit

Permalink
Use SendStreamLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2424 committed Apr 3, 2024
1 parent 44e0af4 commit 8e1d6d8
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
"h3",
"h3-quinn",
"h3-webtransport",
# "h3-webtransport",

# Internal
"examples",
Expand Down
6 changes: 3 additions & 3 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ path = "client.rs"
name = "server"
path = "server.rs"

[[example]]
name = "webtransport_server"
path = "webtransport_server.rs"
# [[example]]
# name = "webtransport_server"
# path = "webtransport_server.rs"
10 changes: 5 additions & 5 deletions h3-webtransport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//! WebTransport over HTTP/3: <https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/>
#![deny(missing_docs)]

/// Server side WebTransport session support
pub mod server;
/// Webtransport stream types
pub mod stream;
// Server side WebTransport session support
//pub mod server;
// Webtransport stream types
//pub mod stream;

pub use h3::webtransport::SessionId;
//pub use h3::webtransport::SessionId;
11 changes: 7 additions & 4 deletions h3-webtransport/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<S, B> SendStream<S, B> {

impl<S, B> quic::SendStreamUnframed<B> for SendStream<S, B>
where
S: quic::SendStreamUnframed<B>,
S: quic::SendStreamUnframed<B> + quic::SendStream<B>,
B: Buf + Send,
{
fn poll_send<D: Buf>(
Expand Down Expand Up @@ -129,7 +129,10 @@ where
self.stream.send_id()
}

async fn send_data<T: Into<h3::stream::WriteBuf<B>> + Send>(&mut self, data: T) -> Result<(), Self::Error> {
async fn send_data<T: Into<h3::stream::WriteBuf<B>> + Send>(
&mut self,
data: T,
) -> Result<(), Self::Error> {
self.stream.send_data(data).await
}
}
Expand Down Expand Up @@ -240,7 +243,7 @@ where

impl<S, B> quic::SendStreamUnframed<B> for BidiStream<S, B>
where
S: quic::SendStreamUnframed<B>,
S: quic::SendStreamUnframed<B> + quic::SendStream<B>,
B: Buf + Send,
{
fn poll_send<D: Buf>(
Expand Down Expand Up @@ -275,7 +278,7 @@ impl<S: quic::RecvStream, B> quic::RecvStream for BidiStream<S, B> {

impl<S, B> quic::BidiStream<B> for BidiStream<S, B>
where
S: quic::BidiStream<B>,
S: quic::BidiStream<B> + quic::SendStream<B>,
B: Buf + Send,
{
type SendStream = SendStream<S::SendStream, B>;
Expand Down
2 changes: 1 addition & 1 deletion h3/src/client/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ where

impl<S, B> RequestStream<S, B>
where
S: quic::SendStream<B>,
S: quic::SendStreamLocal<B>,
B: Buf + Send,
{
/// Send some data on the request body.
Expand Down
4 changes: 2 additions & 2 deletions h3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
varint::VarInt,
},
qpack,
quic::{self, SendStream as _},
quic::{self, SendStreamLocal as _},
stream::{self, AcceptRecvStream, AcceptedRecvStream, BufRecvStream, UniStreamHeader},
webtransport::SessionId,
};
Expand Down Expand Up @@ -752,7 +752,7 @@ where

impl<S, B> RequestStream<S, B>
where
S: quic::SendStream<B>,
S: quic::SendStreamLocal<B>,
B: Buf + Send,
{
/// Send some data on the response body.
Expand Down
11 changes: 7 additions & 4 deletions h3/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytes::Buf;

use tracing::trace;

use crate::quic::SendStream;
use crate::quic::{SendStream, SendStreamLocal};

Check warning on line 7 in h3/src/frame.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `SendStream`

Check warning on line 7 in h3/src/frame.rs

View workflow job for this annotation

GitHub Actions / Test stable ubuntu-latest

unused import: `SendStream`
use crate::stream::{BufRecvStream, WriteBuf};
use crate::{
buf::BufList,
Expand Down Expand Up @@ -150,10 +150,13 @@ where

impl<T, B> FrameStream<T, B>
where
T: SendStream<B> + Send,
B: Buf + Send,
T: SendStreamLocal<B>,
B: Buf,
{
pub async fn send_data<D: Into<WriteBuf<B>> + Send>(&mut self, data: D) -> Result<(), T::Error> {
pub async fn send_data<D: Into<WriteBuf<B>> + Send>(
&mut self,
data: D,
) -> Result<(), T::Error> {
self.stream.send_data(data).await
}

Expand Down
19 changes: 8 additions & 11 deletions h3/src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
/// Trait representing a QUIC connection.
pub trait Connection<B: Buf> {
/// The type produced by `poll_accept_bidi()`
type BidiStream: SendStream<B> + RecvStream;
type BidiStream: SendStreamLocal<B> + RecvStream;
/// The type of the sending part of `BidiStream`
type SendStream: SendStream<B>;
type SendStream: SendStreamLocal<B>;
/// The type produced by `poll_accept_recv()`
type RecvStream: RecvStream;
/// A producer of outgoing Unidirectional and Bidirectional streams.
Expand Down Expand Up @@ -114,9 +114,9 @@ pub trait RecvDatagramExt {
/// Trait for opening outgoing streams
pub trait OpenStreams<B: Buf> {
/// The type produced by `poll_open_bidi()`
type BidiStream: SendStream<B> + RecvStream;
type BidiStream: SendStreamLocal<B> + RecvStream;
/// The type produced by `poll_open_send()`
type SendStream: SendStream<B>;
type SendStream: SendStreamLocal<B>;
/// The type of the receiving part of `BidiStream`
type RecvStream: RecvStream;
/// Error type yielded by these trait methods
Expand Down Expand Up @@ -151,10 +151,7 @@ pub trait SendStreamLocal<B> {
//fn set_data<T: Into<WriteBuf<B>>>(&mut self, data: T) -> Result<(), Self::Error>;

/// Sends data on the stream.
async fn send_data<T: Into<WriteBuf<B>> + Send>(
&mut self,
data: T,
) -> Result<(), Self::Error>;
async fn send_data<T: Into<WriteBuf<B>> + Send>(&mut self, data: T) -> Result<(), Self::Error>;

/// Poll to finish the sending side of the stream.
fn poll_finish(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;
Expand All @@ -167,7 +164,7 @@ pub trait SendStreamLocal<B> {
}

/// Allows sending unframed pure bytes to a stream. Similar to [`AsyncWrite`](https://docs.rs/tokio/latest/tokio/io/trait.AsyncWrite.html)
pub trait SendStreamUnframed<B: Buf>: SendStream<B> {
pub trait SendStreamUnframed<B: Buf>: SendStreamLocal<B> {
/// Attempts write data into the stream.
///
/// Returns the number of bytes written.
Expand Down Expand Up @@ -204,9 +201,9 @@ pub trait RecvStream {
}

/// Optional trait to allow "splitting" a bidirectional stream into two sides.
pub trait BidiStream<B: Buf>: SendStream<B> + RecvStream {
pub trait BidiStream<B: Buf>: SendStreamLocal<B> + RecvStream {
/// The type for the send half.
type SendStream: SendStream<B>;
type SendStream: SendStreamLocal<B>;
/// The type for the receive half.
type RecvStream: RecvStream;

Expand Down
2 changes: 1 addition & 1 deletion h3/src/server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
push::PushId,
},
qpack,
quic::{self, RecvDatagramExt, SendDatagramExt, SendStream as _},
quic::{self, RecvDatagramExt, SendDatagramExt, SendStreamLocal as _},
stream::BufRecvStream,
};

Expand Down
5 changes: 3 additions & 2 deletions h3/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
//!
//! It allows to accept incoming requests, and send responses.
//!
//! # Examples
//! # Examplesm
//!
//! ## Simple example
//! ```rust
//! async fn doc<C>(conn: C)
//! where
//! C: h3::quic::Connection<bytes::Bytes>,
//! <C as h3::quic::Connection<bytes::Bytes>>::BidiStream: Send + 'static
//! <C as h3::quic::Connection<bytes::Bytes>>::BidiStream: h3::quic::SendStream<bytes::Bytes> + Send + 'static,
//! <C as h3::quic::Connection<bytes::Bytes>>::SendStream: h3::quic::SendStream<bytes::Bytes> + Send + 'static,
//! {
//! let mut server_builder = h3::server::builder();
//! // Build the Connection
Expand Down
2 changes: 1 addition & 1 deletion h3/src/server/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where

impl<S, B> RequestStream<S, B>
where
S: quic::SendStream<B>,
S: quic::SendStreamLocal<B>,
B: Buf + Send,
{
/// Send the HTTP/3 response
Expand Down
14 changes: 7 additions & 7 deletions h3/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
stream::StreamType,
varint::VarInt,
},
quic::{self, BidiStream, RecvStream, SendStream, SendStreamUnframed},
quic::{self, BidiStream, RecvStream, SendStream, SendStreamLocal, SendStreamUnframed},

Check warning on line 22 in h3/src/stream.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `SendStream`

Check warning on line 22 in h3/src/stream.rs

View workflow job for this annotation

GitHub Actions / Test stable ubuntu-latest

unused import: `SendStream`
webtransport::SessionId,
Error,
};
Expand All @@ -28,7 +28,7 @@ use crate::{
/// Transmits data by encoding in wire format.
pub(crate) async fn write<S, D, B>(stream: &mut S, data: D) -> Result<(), Error>
where
S: SendStream<B>,
S: SendStreamLocal<B>,
D: Into<WriteBuf<B>> + Send,
B: Buf,
{
Expand Down Expand Up @@ -493,8 +493,8 @@ impl<S: RecvStream, B> RecvStream for BufRecvStream<S, B> {

impl<S, B> BufRecvStream<S, B>
where
B: Buf + Send,
S: SendStream<B> + Send,
B: Buf,
S: SendStreamLocal<B>,
{
pub fn poll_finish(&mut self, cx: &mut std::task::Context<'_>) -> Poll<Result<(), S::Error>> {
self.stream.poll_finish(cx)
Expand All @@ -518,8 +518,8 @@ where

impl<S, B> BufRecvStream<S, B>
where
B: Buf + Send,
S: SendStreamUnframed<B> + Send,
B: Buf,
S: SendStreamUnframed<B>,
{
#[inline]
pub fn poll_send<D: Buf>(
Expand All @@ -534,7 +534,7 @@ where
impl<S, B> BufRecvStream<S, B>
where
B: Buf + Send,
S: BidiStream<B> + Send,
S: BidiStream<B>,
{
pub fn split(
self,
Expand Down
2 changes: 1 addition & 1 deletion h3/src/tests/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ where

async fn response<S, B>(mut stream: server::RequestStream<S, B>)
where
S: quic::RecvStream + SendStream<B>,
S: quic::RecvStream + SendStreamLocal<B>,
B: Buf + Send,
{
stream
Expand Down

0 comments on commit 8e1d6d8

Please sign in to comment.