Skip to content
Merged
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
6 changes: 3 additions & 3 deletions edge-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async fn request<'b, const N: usize, T: TcpConnect>(

```rust
use edge_http::io::server::{Connection, DefaultServer, Handler};
use edge_http::io::Error;
use edge_http::Method;
use edge_nal::TcpBind;

Expand All @@ -130,7 +131,7 @@ pub async fn run(server: &mut DefaultServer) -> Result<(), anyhow::Error> {
.bind(addr.parse().unwrap())
.await?;

server.run(acceptor, HttpHandler, None).await?;
server.run(acceptor, HttpHandler, None, None).await?;

Ok(())
}
Expand All @@ -140,9 +141,8 @@ struct HttpHandler;
impl<'b, T, const N: usize> Handler<'b, T, N> for HttpHandler
where
T: Read + Write,
T::Error: Send + Sync + std::error::Error + 'static,
{
type Error = anyhow::Error;
type Error = Error<T::Error>;

async fn handle(&self, conn: &mut Connection<'b, T, N>) -> Result<(), Self::Error> {
let headers = conn.headers()?;
Expand Down
2 changes: 0 additions & 2 deletions edge-http/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub enum Error<E> {
IncompleteHeaders,
IncompleteBody,
InvalidState,
Timeout,
ConnectionClosed,
HeadersMismatchError(HeadersMismatchError),
WsUpgradeError(UpgradeError),
Expand Down Expand Up @@ -87,7 +86,6 @@ where
Self::IncompleteHeaders => write!(f, "HTTP headers section is incomplete"),
Self::IncompleteBody => write!(f, "HTTP body is incomplete"),
Self::InvalidState => write!(f, "Connection is not in requested state"),
Self::Timeout => write!(f, "Timeout"),
Self::HeadersMismatchError(e) => write!(f, "Headers mismatch: {e}"),
Self::WsUpgradeError(e) => write!(f, "WebSocket upgrade error: {e}"),
Self::ConnectionClosed => write!(f, "Connection closed"),
Expand Down
21 changes: 16 additions & 5 deletions edge-http/src/io/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::str;

use embedded_io_async::{ErrorType, Read, Write};

use edge_nal::TcpConnect;
use edge_nal::{Close, TcpConnect, TcpShutdown};

use crate::{
ws::{upgrade_request_headers, MAX_BASE64_KEY_LEN, MAX_BASE64_KEY_RESPONSE_LEN, NONCE_LEN},
Expand Down Expand Up @@ -39,6 +39,11 @@ where
{
/// Create a new client connection.
///
/// Note that the connection does not have any built-in read/write timeouts:
/// - To add a timeout on each IO operation, wrap the `socket` type with the `edge_nal::WithTimeout` wrapper.
/// - To add a global request-response timeout, wrap your complete request-response processing
/// logic with the `edge_nal::with_timeout` function.
///
/// Parameters:
/// - `buf`: A buffer to use for reading and writing data.
/// - `socket`: The TCP stack to use for the connection.
Expand Down Expand Up @@ -234,11 +239,17 @@ where
let mut state = self.unbind();

match result {
Ok(true) | Err(_) => state.io = None,
_ => (),
};
Ok(true) | Err(_) => {
let mut io = state.io.take().unwrap();
*self = Self::Unbound(state);

*self = Self::Unbound(state);
io.close(Close::Both).await.map_err(Error::Io)?;
let _ = io.abort().await;
}
_ => {
*self = Self::Unbound(state);
}
};

result?;

Expand Down
Loading
Loading