Skip to content

Commit 6ee013e

Browse files
committed
Merge remote-tracking branch 'origin/master' into server-ffi
2 parents 9116dbc + 47f614f commit 6ee013e

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

.github/workflows/CI.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,23 @@ jobs:
9494
args: --benches ${{ matrix.features }}
9595

9696
msrv:
97-
name: Check MSRV (${{ matrix.rust }})
97+
name: Check MSRV
9898
needs: [style]
99-
strategy:
100-
matrix:
101-
rust:
102-
- 1.56 # keep in sync with MSRV.md dev doc
103-
104-
os:
105-
- ubuntu-latest
10699

107-
runs-on: ${{ matrix.os }}
100+
runs-on: ubuntu-latest
108101

109102
steps:
110103
- name: Checkout
111104
uses: actions/checkout@v3
112105

113-
- name: Install Rust (${{ matrix.rust }})
106+
- name: Get MSRV from package metadata
107+
id: msrv
108+
run: grep rust-version Cargo.toml | cut -d'"' -f2 | sed 's/^/version=/' >> $GITHUB_OUTPUT
109+
110+
- name: Install Rust (${{ steps.msrv.outputs.version }})
114111
uses: dtolnay/rust-toolchain@master
115112
with:
116-
toolchain: ${{ matrix.rust }}
113+
toolchain: ${{ steps.msrv.outputs.version }}
117114

118115
- name: Check
119116
uses: actions-rs/cargo@v1

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ authors = ["Sean McArthur <sean@seanmonstar.com>"]
1111
keywords = ["http", "hyper", "hyperium"]
1212
categories = ["network-programming", "web-programming::http-client", "web-programming::http-server"]
1313
edition = "2018"
14+
rust-version = "1.56" # keep in sync with MSRV.md dev doc
1415

1516
include = [
1617
"Cargo.toml",

examples/hello.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use hyper::service::service_fn;
1010
use hyper::{Request, Response};
1111
use tokio::net::TcpListener;
1212

13+
// An async function that consumes a request, does nothing with it and returns a
14+
// response.
1315
async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
1416
Ok(Response::new(Full::new(Bytes::from("Hello World!"))))
1517
}
@@ -18,14 +20,29 @@ async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>
1820
pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
1921
pretty_env_logger::init();
2022

23+
// This address is localhost
2124
let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
2225

26+
// Bind to the port and listen for incoming TCP connections
2327
let listener = TcpListener::bind(addr).await?;
2428
println!("Listening on http://{}", addr);
2529
loop {
30+
// When an incoming TCP connection is received grab a TCP stream for
31+
// client<->server communication.
32+
//
33+
// Note, this is a .await point, this loop will loop forever but is not a busy loop. The
34+
// .await point allows the Tokio runtime to pull the task off of the thread until the task
35+
// has work to do. In this case, a connection arrives on the port we are listening on and
36+
// the task is woken up, at which point the task is then put back on a thread, and is
37+
// driven forward by the runtime, eventually yielding a TCP stream.
2638
let (stream, _) = listener.accept().await?;
2739

40+
// Spin up a new task in Tokio so we can continue to listen for new TCP connection on the
41+
// current task without waiting for the processing of the HTTP1 connection we just received
42+
// to finish
2843
tokio::task::spawn(async move {
44+
// Handle the connection from the client using HTTP1 and pass any
45+
// HTTP requests received on that connection to the `hello` function
2946
if let Err(err) = http1::Builder::new()
3047
.serve_connection(stream, service_fn(hello))
3148
.await

0 commit comments

Comments
 (0)