Repository navigation
Commit 84d5411
committed
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
The embedded HttpServer mishandled nonblocking send()/recv() results:
- sendMore() fell through to sendBuffer.erase(0, sent) when send() returned
-1 (EWOULDBLOCK). With sent == -1 the erase count becomes SIZE_MAX and the
whole unsent response is wiped. It now never erases on a failed send, and
re-registers for writability on a would-block so the buffer is kept.
Fixes #4281.
- onSocketReadable() closed the connection on any recv() <= 0, including the
transient -1/EWOULDBLOCK case. It now closes only on an orderly shutdown
(recv() == 0) or a real error, and ignores a transient would-block.
Fixes #4282.
- Both paths capture the socket error immediately after send()/recv(), before
LOG_TRACE can clobber errno / the Winsock last error.
EWOULDBLOCK and EAGAIN have the same value on all supported platforms, so a
single ErrorWouldBlock check is used (checking both is redundant and trips
clang-tidy misc-redundant-expression).
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>1 parent 9d38caf commit 84d5411
2 files changed
Lines changed: 22 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
285 | 286 | | |
286 | | - | |
| 287 | + | |
287 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
288 | 296 | | |
289 | | - | |
290 | 297 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | 298 | | |
295 | 299 | | |
296 | 300 | | |
| |||
340 | 344 | | |
341 | 345 | | |
342 | 346 | | |
| 347 | + | |
343 | 348 | | |
344 | | - | |
| 349 | + | |
345 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
346 | 358 | | |
347 | 359 | | |
348 | | - | |
| 360 | + | |
349 | 361 | | |
350 | 362 | | |
351 | 363 | | |
| |||
0 commit comments