Clean-up and fix HttpResponse::cork behavior

This commit is contained in:
Alex Hultman
2019-12-26 17:17:33 +01:00
parent bdac60a177
commit 3fb870ac55
2 changed files with 13 additions and 13 deletions
+3 -2
View File
@@ -218,12 +218,13 @@ private:
return nullptr; return nullptr;
}); });
// basically we need to uncork in all cases, except for nullptr /* We need to uncork in all cases, except for nullptr (closed socket, or upgraded socket) */
if (returnedSocket != nullptr) { if (returnedSocket != nullptr) {
/* Timeout on uncork failure */ /* Timeout on uncork failure */
auto [written, failed] = ((AsyncSocket<SSL> *) returnedSocket)->uncork(); auto [written, failed] = ((AsyncSocket<SSL> *) returnedSocket)->uncork();
if (failed) { if (failed) {
// do we have the same timeout for websockets? /* All Http sockets timeout by this, and this behavior match the one in HttpResponse::cork */
/* Warning: both HTTP_IDLE_TIMEOUT_S and HTTP_TIMEOUT_S are 10 seconds and both are used the same */
((AsyncSocket<SSL> *) s)->timeout(HTTP_IDLE_TIMEOUT_S); ((AsyncSocket<SSL> *) s)->timeout(HTTP_IDLE_TIMEOUT_S);
} }
+10 -11
View File
@@ -268,23 +268,22 @@ public:
return !(httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING); return !(httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING);
} }
/* EXPERIMENTAL - corks the response if possible */ /* Corks the response if possible. Leaves already corked socket be. */
HttpResponse *cork(fu2::unique_function<void()> &&handler) { HttpResponse *cork(fu2::unique_function<void()> &&handler) {
bool corked = Super::isCorked(); if (!Super::isCorked() && Super::canCork()) {
if (!corked && Super::canCork()) {
Super::cork(); Super::cork();
corked = true; handler();
}
handler(); /* Timeout on uncork failure, since most writes will succeed while corked */
if (corked) {
/* Timeout on uncork failure (EXPERIMENTAL) */
auto [written, failed] = Super::uncork(); auto [written, failed] = Super::uncork();
if (failed) { if (failed) {
// do we have the same timeout for websockets? /* For now we only have one single timeout so let's use it */
Super::timeout(10); // this is completely wrong! /* This behavior should equal the behavior in HttpContext when uncorking fails */
Super::timeout(HTTP_TIMEOUT_S);
} }
} else {
/* We are already corked, or can't cork so let's just call the handler */
handler();
} }
return this; return this;