Skip to content

Commit

Permalink
implement wakable
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed May 12, 2024
1 parent 791f294 commit 022cc98
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 22 deletions.
87 changes: 87 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/libs/msquic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2021"
tokio = {version = "1", features = ["sync"]}
tracing = { version = "0.1.40", features = ["log"] }
bytes = "*"
h3 = "*"

[dev-dependencies]
# env_logger = "0.10.1"
Expand Down
2 changes: 2 additions & 0 deletions crates/libs/msquic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub mod stream;
pub mod sync;
mod utils;

// pub mod msh3;

// Some useful defs
pub const QUIC_STATUS_PENDING: u32 = 0x703e5;
pub const QUIC_STATUS_SUCCESS: u32 = 0;
Expand Down
192 changes: 192 additions & 0 deletions crates/libs/msquic/src/msh3/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// h3 wrappings for msquic

use std::{fmt::Display, future::Future, pin::{self, pin}, sync::Arc};

use bytes::{Buf, BytesMut};
use h3::quic::{BidiStream, Connection, OpenStreams, RecvStream, SendStream, StreamId};

use crate::{conn::QConnection, stream::QStream};

#[derive(Debug)]
pub struct H3Error {
status: std::io::Error,
error_code: Option<u64>,
}

impl h3::quic::Error for H3Error {
fn is_timeout(&self) -> bool {
self.status.kind() == std::io::ErrorKind::TimedOut
}

fn err_code(&self) -> Option<u64> {
self.error_code
}
}

impl std::error::Error for H3Error {}

impl Display for H3Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}

pub struct H3Conn {
inner: QConnection,
}

impl<B: Buf> OpenStreams<B> for H3Conn {
type BidiStream = H3Stream;

type SendStream = H3Stream;

type RecvStream = H3Stream;

type Error = H3Error;

fn poll_open_bidi(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Self::BidiStream, Self::Error>> {
todo!()
}

fn poll_open_send(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Self::SendStream, Self::Error>> {
todo!()
}

fn close(&mut self, code: h3::error::Code, reason: &[u8]) {
todo!()
}
}

impl<B: Buf> Connection<B> for H3Conn {
type BidiStream = H3Stream;

type SendStream = H3Stream;

type RecvStream = H3Stream;

type OpenStreams = H3Conn;

type Error = H3Error;

fn poll_accept_recv(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Option<Self::RecvStream>, Self::Error>> {
todo!()
}

fn poll_accept_bidi(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Option<Self::BidiStream>, Self::Error>> {
todo!()
}

fn poll_open_bidi(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Self::BidiStream, Self::Error>> {
todo!()
}

fn poll_open_send(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Self::SendStream, Self::Error>> {
todo!()
}

fn opener(&self) -> Self::OpenStreams {
todo!()
}

fn close(&mut self, code: h3::error::Code, reason: &[u8]) {
todo!()
}
}

pub struct H3Stream {
inner: Arc<QStream>,
id: h3::quic::StreamId,
//read:
}

impl H3Stream {
fn new(s: Arc<QStream>, id: StreamId) -> Self {
Self { inner: s, id }
}
}

impl<B: Buf> SendStream<B> for H3Stream {
type Error = H3Error;

fn poll_ready(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
todo!()
}

fn send_data<T: Into<h3::quic::WriteBuf<B>>>(&mut self, data: T) -> Result<(), Self::Error> {
todo!()
}

fn poll_finish(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
todo!()
}

fn reset(&mut self, reset_code: u64) {
todo!()
}

fn send_id(&self) -> h3::quic::StreamId {
todo!()
}
}

impl RecvStream for H3Stream {
type Buf = BytesMut;

type Error = H3Error;

fn poll_data(
&mut self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Option<Self::Buf>, Self::Error>> {
// let fu = self.inner.receive();
// let innner = <Receiver<T> as Future>::poll(Pin::new(&mut self.rx), _cx);
//Pin::new(&mut fu).poll(cx);
// let mut pinned_fut = pin!(fu);
// pinned_fut.poll(cx);
todo!()
}

fn stop_sending(&mut self, error_code: u64) {
self.inner.stop_sending(error_code);
}

fn recv_id(&self) -> h3::quic::StreamId {
self.id
}
}

impl<B: Buf> BidiStream<B> for H3Stream {
type SendStream = H3Stream;

type RecvStream = H3Stream;

fn split(self) -> (Self::SendStream, Self::RecvStream) {
let cp = self.inner.clone();
let id = self.id.clone();
(self, H3Stream::new(cp, id))
}
}
Loading

0 comments on commit 022cc98

Please sign in to comment.