Skip to content

Commit d23c5cb

Browse files
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()`. * 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 debdc40 commit d23c5cb

File tree

5 files changed

+774
-365
lines changed

5 files changed

+774
-365
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ src/rustls.h: src/*.rs cbindgen.toml
6969
target/$(PROFILE)/librustls_ffi.a: src/*.rs Cargo.toml
7070
RUSTFLAGS="-C metadata=rustls-ffi" ${CARGO} build $(CARGOFLAGS)
7171

72-
target/%.o: tests/%.c tests/common.h | target
72+
target/%.o: tests/%.c tests/%.h tests/common.h | target
7373
$(CC) -o $@ -c $< $(CFLAGS)
7474

7575
target/client: target/client.o target/common.o target/$(PROFILE)/librustls_ffi.a

0 commit comments

Comments
 (0)