Skip to content

Commit

Permalink
test(eio): bump uWebSockets.js to version 20.48.0
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Sep 19, 2024
1 parent 19c48a4 commit da61381
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"ts-node": "^10.9.2",
"tsd": "^0.31.1",
"typescript": "^5.5.3",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.30.0",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.48.0",
"wdio-geckodriver-service": "^5.0.2"
}
}
11 changes: 11 additions & 0 deletions packages/engine.io/test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ const { Socket } =
? require("engine.io-client-v3")
: require("engine.io-client");

switch (process.env.EIO_WS_ENGINE) {
case "uws":
console.log(
"[WARN] testing with uWebSockets.js instead of Node.js built-in HTTP server",
);
break;
case "eiows":
console.log("[WARN] testing with eiows instead of ws");
break;
}

/**
* Listen shortcut that fires a callback on an ephemeral port.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/engine.io/test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ describe("server", () => {
.end((err, res) => {
if (process.env.EIO_WS_ENGINE === "uws") {
expect(err).to.not.be(null);
expect(err.message).to.be("socket hang up");
expect(err.status).to.be(404);
} else {
expect(err).to.be(null);
// this should not work, but it is kept for backward-compatibility
Expand Down
32 changes: 17 additions & 15 deletions packages/socket.io/lib/uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,27 @@ export function serveFile(res /* : HttpResponse */, filepath: string) {
const onDataChunk = (chunk: Buffer) => {
const arrayBufferChunk = toArrayBuffer(chunk);

const lastOffset = res.getWriteOffset();
const [ok, done] = res.tryEnd(arrayBufferChunk, size);
res.cork(() => {
const lastOffset = res.getWriteOffset();
const [ok, done] = res.tryEnd(arrayBufferChunk, size);

if (!done && !ok) {
readStream.pause();
if (!done && !ok) {
readStream.pause();

res.onWritable((offset) => {
const [ok, done] = res.tryEnd(
arrayBufferChunk.slice(offset - lastOffset),
size,
);
res.onWritable((offset) => {
const [ok, done] = res.tryEnd(
arrayBufferChunk.slice(offset - lastOffset),
size,
);

if (!done && ok) {
readStream.resume();
}
if (!done && ok) {
readStream.resume();
}

return ok;
});
}
return ok;
});
}
});
};

res.onAborted(destroyReadStream);
Expand Down

0 comments on commit da61381

Please sign in to comment.