| 324 | // Register before starting the body stream, which can synchronously emit buffered body data. |
| 325 | struct AfterWrite |
| 326 | { |
| 327 | HttpAsyncServer& pself; |
| 328 | HttpConnection& client; |
| 329 | |
| 330 | void operator()() |
| 331 | { |
| 332 | SC_HTTP_ASSERT_RELEASE(client.response.getWritableStream().eventFinish.removeListener(*this)); |
| 333 | |
| 334 | // Determine if we should keep the connection alive |
| 335 | const bool underMaxRequests = |
| 336 | (pself.maxRequestsPerConnection == 0) or (client.requestCount + 1 < pself.maxRequestsPerConnection); |
| 337 | const bool shouldKeepAlive = client.response.getKeepAlive() and underMaxRequests and |
| 338 | not client.getReadableTransportStream().isEnded(); |
| 339 | |
| 340 | if (shouldKeepAlive and pself.state == State::Started) // We may get some after-writes after server stop |
| 341 | { |
| 342 | SC_HTTP_ASSERT_RELEASE(client.socket.isValid()); |
| 343 | // Increment request count |
| 344 | client.requestCount++; |
| 345 | |
| 346 | // Reset request and response for next request |
| 347 | client.request.setHeaderMemory(client.getHeaderMemory()); |
| 348 | client.response.reset(); |
| 349 | |
| 350 | if (&client.getWritableTransportStream() == &client.writableSocketStream) |
| 351 | { |
| 352 | Result writableRes = |
| 353 | client.writableSocketStream.init(client.buffersPool, *pself.eventLoop, client.socket); |
| 354 | SC_HTTP_TRUST_RESULT(writableRes); |
| 355 | } |
| 356 | |
| 357 | // Resume reading in any case to avoid deadlocking |
| 358 | client.getReadableTransportStream().resumeReading(); |
| 359 | |
| 360 | // Re-register for next request headers |
| 361 | EventDataListener dataListener{pself, client}; |
no test coverage detected