From f4353892ef05077c8cc738c5cdcdc2185022309d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Michel?= Date: Wed, 12 Jul 2023 12:58:16 +0200 Subject: [PATCH] transport trait: add shared methods on connection --- transport/src/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/transport/src/lib.rs b/transport/src/lib.rs index c33ab0f..0982496 100644 --- a/transport/src/lib.rs +++ b/transport/src/lib.rs @@ -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(conn: &mut C) -> anyhow::Result(conn: Arc>) -> anyhow::Result, Error> { + Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_accept_recv(cx)).await?) + +} + pub async fn accept_bidi(conn: &mut C) -> anyhow::Result, Error> { Ok(std::future::poll_fn(|cx| conn.poll_accept_bidi(cx)).await?) } +pub async fn accept_bidi_shared(conn: Arc>) -> anyhow::Result, Error> { + Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_accept_bidi(cx)).await?) + +} + pub async fn open_send(conn: &mut C) -> anyhow::Result { Ok(std::future::poll_fn(|cx| conn.poll_open_send(cx)).await?) } +pub async fn open_send_shared(conn: Arc>) -> anyhow::Result { + Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_open_send(cx)).await?) + +} + pub async fn open_bidi(conn: &mut C) -> anyhow::Result { Ok(std::future::poll_fn(|cx| conn.poll_open_bidi(cx)).await?) } +pub async fn open_bidi_shared(conn: Arc>) -> anyhow::Result { + Ok(std::future::poll_fn(|cx| conn.lock().unwrap().poll_open_bidi(cx)).await?) + +} + pub async fn recv>(recv: &mut R , outbuf: &mut BM) -> anyhow::Result {