Commit b5f9d68
committed
tests: client/server rewrites
For `server.c` the changes are fairly minor since it was already
a relatively straight-forward and self-contained example:
* Handle a potential `EAGAIN` `demo_result` from `write_tls()`.
* Log data written with the correct format string pattern.
* Add a `server.h` that is presently unused, but allows keeping the
compilation rules simple by treating server/client symmetrically.
* Break the connection handling loop when we've both sent a response
and the rustls connection requires no more writes. This effectively
closes the connection after a response has been written, without
waiting on the peer to do so. We want to do this since we don't
process the HTTP request to learn if the client wanted `Connection:
keep-alive` or `Connection: close`.
For `client.c`, the changes are more extensive:
* Add a `client.h` so we can forward declare everything interesting.
This allows `client.c` to match our preferred Rust standard of "top
down ordering"
* Extract out a `demo_client_options` struct and a `options_from_env()`
function for handling options based on the environment.
* Extract out a `new_tls_config()` function that takes a pointer to
`demo_client_options` and returns a `rustls_client_config`.
* Extract out a `demo_client_request_options` struct for per-request
options (hostname, port, path, whether to use vectored I/O).
* Pull out a `demo_client_connection` struct for managing the state
associated with a connection (socket fd, rustls_connection, conndata,
closing stae, etc).
* Rework existing logic around the new types.
* Simplify the request handling to better match tls-client-mio.rs in the
Rustls examples. Notably we _do not_ process the HTTP response,
instead we just read whatever data we get and blast it to stdout.
A new timeout on `select()` ensures that if the server doesn't close
the connection after writing a response we will time out waiting for
more data and do it ourselves. With the update to server.c to close
the connection after writing a response this won't kick in, but is
helpful for testing against servers that may let the conn linger even
though we send `Connection: close`.
* Care is taken to still treat unclean closure as an error condition.
* Various other small improvements are made where possible.1 parent 67e68cd commit b5f9d68
7 files changed
+808
-387
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
0 commit comments