Skip to content

Commit

Permalink
Fix upgrade async with cork
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Dec 23, 2023
1 parent b4d73a2 commit 77a6f42
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/AsyncSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ struct AsyncSocket {
getLoopData()->corkedSocket = this;
}

/* Returns the corked socket or nullptr */
void *corkedSocket() {
return getLoopData()->corkedSocket;
}

/* Returns wheter we are corked or not */
bool isCorked() {
return getLoopData()->corkedSocket == this;
Expand Down
3 changes: 2 additions & 1 deletion src/HttpResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,14 @@ struct HttpResponse : public AsyncSocket<SSL> {
/* Corks the response if possible. Leaves already corked socket be. */
HttpResponse *cork(MoveOnlyFunction<void()> &&handler) {
if (!Super::isCorked() && Super::canCork()) {
LoopData *loopData = Super::getLoopData();
Super::cork();
handler();

/* The only way we could possibly have changed the corked socket during handler call, would be if
* the HTTP socket was upgraded to WebSocket and caused a realloc. Because of this we cannot use "this"
* from here downwards. The corking is done with corkUnchecked() in upgrade. It steals cork. */
auto *newCorkedSocket = Super::corkedSocket();
auto *newCorkedSocket = loopData->corkedSocket;

/* If nobody is corked, it means most probably that large amounts of data has
* been written and the cork buffer has already been sent off and uncorked.
Expand Down

0 comments on commit 77a6f42

Please sign in to comment.