Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added argument to drain that provides the list of packets that are drained #5362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bytenik wants to merge 3 commits into socketio:main
base: main
Choose a base branch
Loading
from thinkalpha:drain-param
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/engine.io/lib/socket.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export interface SendOptions {

type ReadyState = "opening" | "open" | "closing" | "closed";

type SendCallback = (transport: Transport) => void;
type SendCallback = (
transport: Transport,
packets: Packet[] | undefined,
) => void;

export class Socket extends EventEmitter {
/**
Expand Down Expand Up @@ -272,13 +275,13 @@ export class Socket extends EventEmitter {
*
* @private
*/
private onDrain() {
private onDrain(packets: Packet[] | undefined) {
if (this.sentCallbackFn.length > 0) {
debug("executing batch send callback");
const seqFn = this.sentCallbackFn.shift();
if (seqFn) {
for (let i = 0; i < seqFn.length; i++) {
seqFn[i](this.transport);
seqFn[i](this.transport, packets);
}
}
}
Expand Down Expand Up @@ -526,8 +529,8 @@ export class Socket extends EventEmitter {
}

this.transport.send(wbuf);
this.emit("drain");
this.server.emit("drain", this);
this.emit("drain", wbuf);
this.server.emit("drain", this, wbuf);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/engine.io/lib/transport.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as parser_v3 from "./parser-v3/index";
import debugModule from "debug";
import type { IncomingMessage, ServerResponse } from "http";
import { Packet, RawData } from "engine.io-parser";
import type * as Parser from "engine.io-parser";
import type { WebSocket } from "ws";

const debug = debugModule("engine:transport");
Expand Down
7 changes: 4 additions & 3 deletions packages/engine.io/lib/transports-uws/polling.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createGzip, createDeflate } from "zlib";
import * as accepts from "accepts";
import debugModule from "debug";
import { HttpRequest, HttpResponse } from "uWebSockets.js";
import { Packet } from "engine.io-parser";
import type * as parser_v4 from "engine.io-parser";
import type * as parser_v3 from "../parser-v3/index";

Expand Down Expand Up @@ -255,7 +256,7 @@ export class Polling extends Transport {
* @param {Object} packet
* @private
*/
send(packets) {
send(packets: Packet[]) {
this.writable = false;

if (this.shouldClose) {
Expand All @@ -269,7 +270,7 @@ export class Polling extends Transport {
const compress = packets.some((packet) => {
return packet.options && packet.options.compress;
});
this.write(data, { compress });
this.write(data, { compress, source: packets });
};

if (this.protocol === 3) {
Expand All @@ -294,7 +295,7 @@ export class Polling extends Transport {
debug('writing "%s"', data);
this.doWrite(data, options, () => {
this.req.cleanup();
this.emit("drain");
this.emit("drain", options.source);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/engine.io/lib/transports-uws/websocket.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class WebSocket extends Transport {
this.socket.send(data, isBinary, compress);

if (isLast) {
this.emit("drain");
this.emit("drain", packets);
this.writable = true;
this.emit("ready");
}
Expand Down
8 changes: 4 additions & 4 deletions packages/engine.io/lib/transports/polling.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class Polling extends Transport {
const compress = packets.some((packet) => {
return packet.options && packet.options.compress;
});
this.write(data, { compress });
this.write(data, { compress, source: packets });
};

if (this.protocol === 3) {
Expand All @@ -256,7 +256,7 @@ export class Polling extends Transport {
debug('writing "%s"', data);
this.doWrite(data, options, () => {
this.req.cleanup();
this.emit("drain");
this.emit("drain", options.source);
});
}

Expand All @@ -280,8 +280,8 @@ export class Polling extends Transport {
headers["Content-Length"] =
"string" === typeof data ? Buffer.byteLength(data) : data.length;
this.res.writeHead(200, this.headers(this.req, headers));
this.res.once("finish", callback);
this.res.end(data);
callback();
};

if (!this.httpCompression || !options.compress) {
Expand All @@ -304,8 +304,8 @@ export class Polling extends Transport {
this.compress(data, encoding, (err, data) => {
if (err) {
this.res.writeHead(500);
this.res.once("finish", callback);
this.res.end();
callback(err);
return;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/engine.io/lib/transports/websocket.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { PerMessageDeflateOptions, WebSocket as WsWebSocket } from "ws";
const debug = debugModule("engine:ws");

export class WebSocket extends Transport {
private currentPackets: Packet[] | undefined;
perMessageDeflate?: boolean | PerMessageDeflateOptions;
private socket: WsWebSocket;

Expand Down Expand Up @@ -45,6 +46,8 @@ export class WebSocket extends Transport {
send(packets: Packet[]) {
this.writable = false;

this.currentPackets = packets;

for (let i = 0; i < packets.length; i++) {
const packet = packets[i];
const isLast = i + 1 === packets.length;
Expand Down Expand Up @@ -99,8 +102,9 @@ export class WebSocket extends Transport {
if (err) {
this.onError("write error", err.stack);
} else {
this.emit("drain");
this.emit("drain", this.currentPackets);
this.writable = true;
this.currentPackets = undefined;
this.emit("ready");
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/engine.io/lib/transports/webtransport.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class WebTransport extends Transport {
debug("error while writing: %s", e.message);
}

this.emit("drain");
this.emit("drain", packets);
this.writable = true;
this.emit("ready");
}
Expand Down

AltStyle によって変換されたページ (->オリジナル) /