esp-rs / esp-mbedtls

mbedtls for ESP32 bare-metal
Apache License 2.0
17 stars 7 forks source link

Implement `edge_nal::TcpAccept` trait from `edge-net` #38

Closed AnthonyGrondin closed 1 month ago

AnthonyGrondin commented 1 month ago

This PR provides an implementation of edge_nal::TcpAccept to use esp-mbedtls with edge-net.

As for now, the trait is simply a wrapper over the edge_nal::TcpAccept implementation from edge-nal-embassy.

I also provided an example that uses edge-http in server mode for testing, and ensuring compatibility.

Further down the line, other traits will also get their implementation, in subsequent PRs, as I (or any contributor) come around a use case for them.

AnthonyGrondin commented 1 month ago

I'll write this here to document the behavior, but there is currently an issue with how esp-wifi, esp-mbedtls, edge-net act together.

Specifically, if a client sends a request with the header "Connection": "Close", the server implementation of edge-net requests a read() from esp-mbedtls (It won't if the body type is something else). Since the client has sent all its data, async_internal_read() will hang on reading data from socket. This is due to esp-wifi's read impl that blocks on read until there is data.

ivmarkov commented 1 month ago

I'll write this here to document the behavior, but there is currently an issue with how esp-wifi, esp-mbedtls, edge-net act together.

Specifically, if a client sends a request with the header "Connection": "Close", the server implementation of edge-net requests a read() from esp-mbedtls (It won't if the body type is something else). Since the client has sent all its data, async_internal_read() will hang on reading data from socket. This is due to esp-wifi's read impl that blocks on read until there is data.

I'm not sure I follow 100% but regardless, are you using the master version of edge-http? There is a fix in master I did recently which avoids a similar (yet, the opposite) problem, where if there are multiple requests scheduled over a single TCP connection, the processing of the first request might read a bit into the second request.