Skip to content

Commit

Permalink
Make HTTP server more robust
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Feb 5, 2024
1 parent e9dd69c commit 6f1de06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 5 additions & 6 deletions crates/examples/microkit/http-server/pds/server/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ async fn use_socket_for_https<D: fat::BlockDevice + 'static, T: fat::TimeSource
tls_config: Arc<ServerConfig>,
mut socket: TcpSocket,
) -> Result<(), ClosedError<AsyncRustlsError<TcpSocketError>>> {
socket.accept(HTTPS_PORT).await.unwrap(); // TODO

let mut conn = ServerConnector::from(tls_config)
.connect(socket)
.unwrap()
socket
.accept(HTTPS_PORT)
.await
.unwrap();
.map_err(AsyncRustlsError::TransitError)?;

let mut conn = ServerConnector::from(tls_config).connect(socket)?.await?;

server.handle_connection(&mut conn).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
let mut i = 0;
loop {
let n = conn.read(&mut buf[i..]).await?;
assert_ne!(n, 0);
if n == 0 {
return Err(ClosedError::Closed);
}
i += n;
if is_request_complete(&buf[..i]).unwrap_or(false) {
break;
Expand Down

0 comments on commit 6f1de06

Please sign in to comment.