Aggiungi override probe TCP keepalive
This commit is contained in:
1 parent
6b19a8a606
commit
cc4a3ed9c1
9 files changed
+154
-3
No files matched your search
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
let native = null;
|
||||
|
||||
try {
|
||||
native = require("../../native/tcp_keepalive/build/Release/tcp_keepalive_native");
|
||||
} catch (err) {
|
||||
native = null;
|
||||
}
|
||||
|
||||
function parseKeepAliveProbes(value) {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
return 0;
|
||||
}
|
||||
|
||||
value = Number(value);
|
||||
if (!Number.isFinite(value) || value < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.floor(value);
|
||||
}
|
||||
|
||||
function setKeepAliveProbes(socket, probes) {
|
||||
if (!native || probes <= 0 || !socket || !socket._handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const fd = socket._handle.fd;
|
||||
if (!Number.isInteger(fd) || fd < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return native.setKeepAliveProbes(fd, probes) === true;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
available: !!native,
|
||||
parseKeepAliveProbes,
|
||||
setKeepAliveProbes
|
||||
};
|
||||
Reference in new issue
Block a user