Compare commits

...

1 Commits

Author SHA1 Message Date
cirospaciari
86aa78e5c6 enable auto-corking 2024-04-09 14:06:59 -03:00
3 changed files with 21 additions and 6 deletions

View File

@@ -242,7 +242,7 @@ public:
/* Write in three levels of prioritization: cork-buffer, syscall, socket-buffer. Always drain if possible.
* Returns pair of bytes written (anywhere) and wheter or not this call resulted in the polling for
* writable (or we are in a state that implies polling for writable). */
std::pair<int, bool> write(const char *src, int length, bool optionally = false, int nextLength = 0) {
std::pair<int, bool> write(const char *src, int length, bool optionally = false, int nextLength = 0, bool autoCork = true) {
/* Fake success if closed, simple fix to allow uncork of closed socket to succeed */
if (us_socket_is_closed(SSL, (us_socket_t *) this)) {
return {length, false};
@@ -275,7 +275,12 @@ public:
}
if (length) {
if (loopData->corkedSocket == this) {
auto isCorked = loopData->corkedSocket == this;
if (isCorked || autoCork) {
if(!isCorked) {
/* Make sure that we are indead corked and auto-uncork any other socket*/
cork();
}
/* We are corked */
if (LoopData::CORK_BUFFER_SIZE - loopData->corkOffset >= (unsigned int) length) {
/* If the entire chunk fits in cork buffer */
@@ -337,7 +342,7 @@ public:
if (loopData->corkOffset) {
/* Corked data is already accounted for via its write call */
auto [written, failed] = write(loopData->corkBuffer, (int) loopData->corkOffset, false, length);
auto [written, failed] = write(loopData->corkBuffer, (int) loopData->corkOffset, false, length, false);
loopData->corkOffset = 0;
if (failed && optionally) {
@@ -347,7 +352,7 @@ public:
}
/* We should only return with new writes, not things written to cork already */
return write(src, length, optionally, 0);
return write(src, length, optionally, 0, false);
} else {
/* We are not even corked! */
return {0, false};

View File

@@ -15,13 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// clang-format off
#ifndef UWS_LOOP_H
#define UWS_LOOP_H
/* The loop is lazily created per-thread and run with run() */
#include "LoopData.h"
#include "AsyncSocket.h"
#include <libusockets.h>
#include <iostream>
@@ -58,6 +59,15 @@ private:
for (auto &p : loopData->postHandlers) {
p.second((Loop *) loop);
}
/* auto-uncork corked socket if needed*/
if (loopData->corkOffset && loopData->corkedSocket != nullptr) {
if(loopData->corkedSocketIsSSL) {
((AsyncSocket<true> *) loopData->corkedSocket)->uncork();
} else {
((AsyncSocket<false> *) loopData->corkedSocket)->uncork();
}
}
}
Loop() = delete;

View File

@@ -3,7 +3,7 @@ $npm_client = "npm"
# & ${npm_client} i
$root = Join-Path (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) "..\"
$esbuild = Join-Path $root "node_modules\.bin\esbuild.cmd"
$esbuild = Join-Path $root "node_modules\.bin\esbuild.exe"
$env:NODE_ENV = "production"