Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions h3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ edition = "2018"
bytes = "1"
futures-util = { version = "0.3", default-features = false }
http = "0.2.3"
tokio = { version = "1", features = ["sync"] }
tokio = { version = "1", features = ["sync"], optional = true }
async-channel = { version = "1", optional = true }
tracing = "0.1.18"
fastrand = "1.7.0"

Expand All @@ -27,11 +28,14 @@ quinn = { version = "0.8.0", default-features = false, features = [
quinn-proto = { version = "0.8.0", default-features = false }
rcgen = "0.9"
rustls = "0.20"
tokio = { version = "1", features = ["rt", "macros", "io-util", "io-std"] }
tokio = { version = "1", features = ["rt", "macros", "io-util", "io-std", "sync"] }
tracing-subscriber = { version = "0.3", default-features = false, features = [
"fmt",
"ansi",
"env-filter",
"time",
"tracing-log",
] }

[features]
default = ["tokio"]
33 changes: 32 additions & 1 deletion h3/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use bytes::{Buf, BytesMut};
use futures_util::future;
use http::{response, HeaderMap, Request, Response, StatusCode};
use quic::StreamId;
use tokio::sync::mpsc;

use crate::{
connection::{self, ConnectionInner, ConnectionState, SharedStateRef},
Expand All @@ -74,6 +73,38 @@ use crate::{
};
use tracing::{error, trace, warn};

#[cfg(all(feature = "tokio", not(feature = "async-channel")))]
use tokio::sync::mpsc;

#[cfg(feature = "async-channel")]
mod mpsc {
use futures_util::StreamExt;
use std::task::{Context, Poll};

pub fn unbounded_channel<T>() -> (UnboundedSender<T>, UnboundedReceiver<T>) {
let (sender, receiver) = async_channel::unbounded();
(UnboundedSender(sender), UnboundedReceiver(receiver))
}

#[derive(Clone)]
pub struct UnboundedSender<T>(async_channel::Sender<T>);

impl<T> UnboundedSender<T> {
pub fn send(&self, msg: T) -> Result<(), async_channel::TrySendError<T>> {
self.0.try_send(msg)
}
}

#[derive(Clone)]
pub struct UnboundedReceiver<T>(async_channel::Receiver<T>);

impl<T> UnboundedReceiver<T> {
pub fn poll_recv(&mut self, cx: &mut Context) -> Poll<Option<T>> {
self.0.poll_next_unpin(cx)
}
}
}

/// Create a builder of HTTP/3 server connections
///
/// This function creates a [`Builder`] that carries settings that can
Expand Down