Skip to content

Commit d8be72b

Browse files
committed
Add TcpSplit to the TcpAccept trait (omission)
1 parent 4efdbb2 commit d8be72b

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

edge-http/src/io/server.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use core::fmt::{self, Debug, Display};
22
use core::mem::{self, MaybeUninit};
33
use core::pin::pin;
44

5-
use edge_nal::{with_timeout, Close, Readable, TcpShutdown, WithTimeout, WithTimeoutError};
5+
use edge_nal::{
6+
with_timeout, Close, Readable, TcpShutdown, TcpSplit, WithTimeout, WithTimeoutError,
7+
};
68

79
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
810
use embassy_sync::mutex::Mutex;
@@ -361,7 +363,7 @@ pub trait Handler {
361363
connection: &mut Connection<'_, T, N>,
362364
) -> Result<(), Self::Error<T::Error>>
363365
where
364-
T: Read + Write;
366+
T: Read + Write + TcpSplit;
365367
}
366368

367369
impl<H> Handler for &H
@@ -379,7 +381,7 @@ where
379381
connection: &mut Connection<'_, T, N>,
380382
) -> Result<(), Self::Error<T::Error>>
381383
where
382-
T: Read + Write,
384+
T: Read + Write + TcpSplit,
383385
{
384386
(**self).handle(task_id, connection).await
385387
}
@@ -400,7 +402,7 @@ where
400402
connection: &mut Connection<'_, T, N>,
401403
) -> Result<(), Self::Error<T::Error>>
402404
where
403-
T: Read + Write,
405+
T: Read + Write + TcpSplit,
404406
{
405407
(**self).handle(task_id, connection).await
406408
}
@@ -421,7 +423,7 @@ where
421423
connection: &mut Connection<'_, T, N>,
422424
) -> Result<(), Self::Error<T::Error>>
423425
where
424-
T: Read + Write,
426+
T: Read + Write + TcpSplit,
425427
{
426428
let mut io = pin!(self.io().handle(task_id, connection));
427429

@@ -463,7 +465,7 @@ pub async fn handle_connection<H, T, const N: usize>(
463465
handler: H,
464466
) where
465467
H: Handler,
466-
T: Read + Write + Readable + TcpShutdown,
468+
T: Read + Write + Readable + TcpSplit + TcpShutdown,
467469
{
468470
let close = loop {
469471
debug!("Handler task {task_id}: Waiting for a new request");
@@ -584,7 +586,7 @@ pub async fn handle_request<H, T, const N: usize>(
584586
) -> Result<bool, HandlerError<T::Error, H::Error<T::Error>>>
585587
where
586588
H: Handler,
587-
T: Read + Write,
589+
T: Read + Write + TcpSplit,
588590
{
589591
let mut connection = Connection::<_, N>::new(buf, io).await?;
590592

edge-nal/src/stack/tcp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub trait TcpAccept {
8181
type Socket<'a>: Read<Error = Self::Error>
8282
+ Write<Error = Self::Error>
8383
+ Readable<Error = Self::Error>
84+
+ TcpSplit<Error = Self::Error>
8485
+ TcpShutdown<Error = Self::Error>
8586
where
8687
Self: 'a;

edge-nal/src/timeout.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use core::{
1616
use embassy_time::Duration;
1717
use embedded_io_async::{ErrorKind, ErrorType, Read, Write};
1818

19-
use crate::{Readable, TcpAccept, TcpConnect, TcpShutdown};
19+
use crate::{Readable, TcpAccept, TcpConnect, TcpShutdown, TcpSplit};
2020

2121
/// Error type for the `with_timeout` function and `WithTimeout` struct.
2222
#[derive(Debug)]
@@ -175,6 +175,26 @@ where
175175
}
176176
}
177177

178+
impl<T> TcpSplit for WithTimeout<T>
179+
where
180+
T: TcpSplit,
181+
{
182+
type Read<'a>
183+
= WithTimeout<T::Read<'a>>
184+
where
185+
Self: 'a;
186+
187+
type Write<'a>
188+
= WithTimeout<T::Write<'a>>
189+
where
190+
Self: 'a;
191+
192+
fn split(&mut self) -> (Self::Read<'_>, Self::Write<'_>) {
193+
let (r, w) = self.0.split();
194+
(WithTimeout::new(self.1, r), WithTimeout::new(self.1, w))
195+
}
196+
}
197+
178198
impl<T> TcpShutdown for WithTimeout<T>
179199
where
180200
T: TcpShutdown,

0 commit comments

Comments
 (0)