tls: server: Document readData() socket/callback handling

This commit is contained in:
Martin Rubli 2024-06-01 16:17:04 +02:00
parent e03134c073
commit 1ca0896b53

View file

@ -141,9 +141,12 @@ class TlsMonitorType extends MonitorType {
readData(aborter, socket) {
return new Promise((resolve, reject) => {
const cleanup = function () {
// Pause reading of data (i.e. emission of 'data' events), so that we don't lose
// any data between now and the next call to readData() while there are no event
// listeners installed.
socket.pause();
socket.removeListener("error", onError);
socket.removeListener("data", onData);
socket.pause();
aborter.removeEventListener("abort", onAbort);
};
@ -168,6 +171,7 @@ class TlsMonitorType extends MonitorType {
aborter.addEventListener("abort", onAbort, { once: true });
// Register event callbacks and resume the socket. We are ready to receive data.
socket.on("error", onError);
socket.on("data", onData);
socket.resume();