transport trait: add shared methods on connection
This commit is contained in:
parent
72d11851e1
commit
f4353892ef
|
@ -1,7 +1,7 @@
|
|||
// Coming from https://github.com/hyperium/h3, the goal is to
|
||||
// do a PR with the changes afterwards
|
||||
|
||||
use std::task::{self, Poll};
|
||||
use std::{task::{self, Poll}, sync::Arc};
|
||||
use bytes::{Buf, BufMut};
|
||||
use anyhow::Error;
|
||||
|
||||
|
@ -131,21 +131,41 @@ pub async fn accept_recv<C: Connection>(conn: &mut C) -> anyhow::Result<Option<C
|
|||
|
||||
}
|
||||
|
||||
pub async fn accept_recv_shared<C: Connection>(conn: Arc<std::sync::Mutex<C>>) -> anyhow::Result<Option<C::RecvStream>, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_accept_recv(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
pub async fn accept_bidi<C: Connection>(conn: &mut C) -> anyhow::Result<Option<C::BidiStream>, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.poll_accept_bidi(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
pub async fn accept_bidi_shared<C: Connection>(conn: Arc<std::sync::Mutex<C>>) -> anyhow::Result<Option<C::BidiStream>, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_accept_bidi(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
pub async fn open_send<C: Connection>(conn: &mut C) -> anyhow::Result<C::SendStream, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.poll_open_send(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
pub async fn open_send_shared<C: Connection>(conn: Arc<std::sync::Mutex<C>>) -> anyhow::Result<C::SendStream, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_open_send(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
pub async fn open_bidi<C: Connection>(conn: &mut C) -> anyhow::Result<C::BidiStream, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.poll_open_bidi(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
pub async fn open_bidi_shared<C: Connection>(conn: Arc<std::sync::Mutex<C>>) -> anyhow::Result<C::BidiStream, Error> {
|
||||
Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_open_bidi(cx)).await?)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub async fn recv<B: Buf, BM: BufMut, R: RecvStream<Buf = B>>(recv: &mut R , outbuf: &mut BM) -> anyhow::Result<bool> {
|
||||
|
|
Loading…
Reference in New Issue