Skip to content

Add isWritable() so a handler can tell a slow client from a gone one (#175) - #176

Merged
EdmondDantes merged 3 commits into
mainfrom
175-is-writable
Aug 19, 2026
Merged

EdmondDantes merged 3 commits into
mainfrom
175-is-writable

Conversation

@EdmondDantes

Copy link
Copy Markdown
Contributor

Closes #175. First code step of the response body contract in dev/PLAN.md.

sendable() folds four questions into one bool — closed, sealed, no stream ops, queue full — and only the last is transient, so a streaming loop cannot tell "yield and continue" from "stop". isClosed() does not help: it reports that this code called end().

isWritable() answers the liveness half, and every input is a one-way latch, so a false answer never turns true again. Backed by a new optional is_alive op in http_response_stream_ops_t; no transport needed new state except HTTP/1.

On HTTP/1 a departed peer is only visible when a write fails — TCP offers no earlier signal — so h1_stream_append_chunk now records that discovery on the request context and is_alive answers from it, rather than making the caller find out with a second doomed write. H2 reads peer_closed and write_timed_out, H3 the four conditions its append refuses on, the worker path the stream credit.

Evidence: tests/phpt/server/h1/027-h1-is-writable.phpt — the handler asks before the stream, after the commit, and again after catching the 499 from a peer that aborted with SO_LINGER 0; the answer flips exactly once. Suites: h1 + core, 98 passed, 0 failed.

@EdmondDantes
EdmondDantes merged commit b1ebe47 into main Aug 19, 2026
8 checks passed
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total lines: 82.26% → 82.17% (-0.10 pp)

File Baseline Current Δ Touched
src/core/http_connection.c 75.45% 75.26% -0.19 pp
src/core/http_connection.h 81.82% 81.82% +0.00 pp ●
src/core/worker_dispatch.c 79.32% 78.43% -0.89 pp ●
src/http1/http1_stream.c 70.00% 69.57% -0.43 pp ●
src/http2/http2_strategy.c 83.82% 83.33% -0.48 pp ●
src/http3/http3_callbacks.c 84.09% 82.62% -1.47 pp ●
src/http3/http3_static_response.c 75.11% 76.37% +1.27 pp
src/http_response.c 86.20% 86.11% -0.09 pp ●
src/http_server_class.c 75.03% 75.07% +0.04 pp
src/websocket/ws_session.c 90.41% 90.04% -0.37 pp

❌ Regression in touched files (> 1.0 pp drop)

  • src/http3/http3_callbacks.c dropped -1.47 pp

Add [coverage-drop-ok] to a commit message in this PR to override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A handler cannot ask whether the client is still there

1 participant