diff --git a/src/AsyncSocket.h b/src/AsyncSocket.h index 7a9360817..cd71f1230 100644 --- a/src/AsyncSocket.h +++ b/src/AsyncSocket.h @@ -130,7 +130,7 @@ struct AsyncSocket { } /* Cork this socket. Only one socket may ever be corked per-loop at any given time */ - void cork() { + void cork(char *sendBuffer = nullptr) { /* Extra check for invalid corking of others */ if (getLoopData()->corkOffset && getLoopData()->corkedSocket != this) { std::cerr << "Error: Cork buffer must not be acquired without checking canCork!" << std::endl; @@ -139,6 +139,15 @@ struct AsyncSocket { /* What if another socket is corked? */ getLoopData()->corkedSocket = this; + + if (sendBuffer) { + setCorkBuffer(sendBuffer, 0); + } + } + + void setCorkBuffer(char *buffer, int offset) { + getLoopData()->corkBuffer = buffer; + getLoopData()->corkOffset = offset; } /* Returns the corked socket or nullptr */ diff --git a/src/HttpContext.h b/src/HttpContext.h index 5b4c87581..9f76c18c2 100644 --- a/src/HttpContext.h +++ b/src/HttpContext.h @@ -122,7 +122,7 @@ struct HttpContext { HttpResponseData *httpResponseData = (HttpResponseData *) us_socket_ext(SSL, s); /* Cork this socket */ - ((AsyncSocket *) s)->cork(); + ((AsyncSocket *) s)->cork(us_socket_send_buffer(0, s)); /* Mark that we are inside the parser now */ httpContextData->isParsingHttp = true; diff --git a/src/WebSocketContext.h b/src/WebSocketContext.h index c49a6ac96..17dc8f1a7 100644 --- a/src/WebSocketContext.h +++ b/src/WebSocketContext.h @@ -300,7 +300,7 @@ struct WebSocketContext { webSocketData->hasTimedOut = false; /* We always cork on data */ - asyncSocket->cork(); + asyncSocket->cork(us_socket_send_buffer(0, s)); /* This parser has virtually no overhead */ WebSocketProtocol>::consume(data, (unsigned int) length, (WebSocketState *) webSocketData, s); diff --git a/uSockets b/uSockets index 42fc26522..726cedf46 160000 --- a/uSockets +++ b/uSockets @@ -1 +1 @@ -Subproject commit 42fc2652263a66b328b746d50448568d25a2bc6f +Subproject commit 726cedf461be2975a14af54b48aeee0d94919dc8