From dd40e5077b6d0f9b412115ce89a05c11e2e93264 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 17:22:21 +0000 Subject: [PATCH] Deploy to GitHub pages --- index.html | 10 ++++- index.js.html | 82 +++++++++++++++++++++++++++++++-------- module-net-keepalive.html | 12 +++--- 3 files changed, 79 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index dcdd189..d3a65db 100644 --- a/index.html +++ b/index.html @@ -124,11 +124,16 @@

Code Quality License

-

All Contributors

+

All Contributors

πŸ”— net-keepalive

NPM

-

The Missing (TCP_KEEPINTVL and TCP_KEEPCNT) SO_KEEPALIVE socket option setters and getters for Node using ffi-napi module.

+
+

ℹ️ Since libuv v1.35.0 (Node v13.12.0 & v12.17.0) both TCP_KEEPINTVL and TCP_KEEPCNT have somewhat predictable values +This package allows you to tweak those values per each socket but at a cost of having to deal with FFI overhead and it's dependencies. +Check the latest node docs for socket.setKeepaliveEnable, if the default values are good enough for you then you don't need to use this package.

+
+

The Missing (TCP_KEEPINTVL and TCP_KEEPCNT) SO_KEEPALIVE socket option setters and getters for Node using FFI.

Tested on 🐧 linux & 🍏 osx (both amd64 and arm64), should work on 😈 freebsd and others. Installs on πŸ„ win32 πŸŽ‰ but methods are no-ops (pull requests welcome).

There's also support for getting & setting the TCP_USER_TIMEOUT (🐧 linux and 🍏 osx only) option, which is closely related to keep-alive.

@@ -276,6 +281,7 @@

Contributors ✨

Mario Kozjak
Mario Kozjak

πŸ› Lukas Knuth
Lukas Knuth

πŸ’» Ivan
Ivan

πŸ› + OtΓ‘vio Jacobi
OtΓ‘vio Jacobi

πŸ› diff --git a/index.js.html b/index.js.html index 4eddbef..9c537c9 100644 --- a/index.js.html +++ b/index.js.html @@ -102,7 +102,7 @@

index.js

/**
  * The Missing (TCP_KEEPINTVL and TCP_KEEPCNT) SO_KEEPALIVE socket option setters and getters for Node using
- * ffi-napi module.
+ * ffi-rs module.
  *
  * Note: For methods provided by this module to work you must enable SO_KEEPALIVE and set the TCP_KEEPIDLE options for
  * socket using Net.Socket-s built in method socket.setKeepAlive([enable][, initialDelay]) !
@@ -124,7 +124,7 @@ 

index.js

Net = require('net'), OS = require('os'), Constants = require('./constants'), - Ref = require('ref-napi'), + { DataType, createPointer, restorePointer } = require('ffi-rs'), FFIBindings = require('./ffi-bindings') const _isSocket = (socket) => socket instanceof Net.Socket @@ -177,8 +177,12 @@

index.js

const fd = _getSocketFD(socket), seconds = ~~(msecs / 1000), - intvlVal = Ref.alloc('int', seconds), - intvlValLn = intvlVal.type.size + dataType = DataType.I32, + [intvlVal] = createPointer({ + paramsType: [dataType], + paramsValue: [seconds], + }), + intvlValLn = 4 // sizeof int return FFIBindings.setsockopt( fd, @@ -216,8 +220,15 @@

index.js

) const fd = _getSocketFD(socket), - intvlVal = Ref.alloc(Ref.types.uint32), - intvlValLn = Ref.alloc(Ref.types.uint32, intvlVal.type.size) + dataType = DataType.I32, + [intvlVal] = createPointer({ + paramsType: [dataType], + paramsValue: [0], + }), + [intvlValLn] = createPointer({ + paramsType: [DataType.I32], + paramsValue: [4], // sizeof int + }) FFIBindings.getsockopt( fd, @@ -227,7 +238,12 @@

index.js

intvlValLn ) - return intvlVal.deref() * 1000 + const [value] = restorePointer({ + retType: [dataType], + paramsValue: [intvlVal], + }) + + return value * 1000 } /** @@ -266,8 +282,12 @@

index.js

const fd = _getSocketFD(socket), count = ~~cnt, - cntVal = Ref.alloc('int', count), - cntValLn = cntVal.type.size + dataType = DataType.I32, + [cntVal] = createPointer({ + paramsType: [dataType], + paramsValue: [count], + }), + cntValLn = 4 // sizeof int return FFIBindings.setsockopt( fd, @@ -305,8 +325,15 @@

index.js

) const fd = _getSocketFD(socket), - cntVal = Ref.alloc(Ref.types.int), - cntValLn = Ref.alloc(Ref.types.int, cntVal.type.size) + dataType = DataType.I32, + [cntVal] = createPointer({ + paramsType: [dataType], + paramsValue: [0], + }), + [cntValLn] = createPointer({ + paramsType: [DataType.I32], + paramsValue: [4], // sizeof int + }) FFIBindings.getsockopt( fd, @@ -316,7 +343,12 @@

index.js

cntValLn ) - return cntVal.deref() + const [value] = restorePointer({ + retType: [dataType], + paramsValue: [cntVal], + }) + + return value } /** @@ -366,8 +398,12 @@

index.js

const fd = _getSocketFD(socket), msecInt = ~~msecs, - msecVal = Ref.alloc('int', msecInt), - msecValLn = msecVal.type.size + dataType = DataType.I32, + [msecVal] = createPointer({ + paramsType: [dataType], + paramsValue: [msecInt], + }), + msecValLn = 4 // sizeof int return FFIBindings.setsockopt( fd, @@ -412,8 +448,15 @@

index.js

) const fd = _getSocketFD(socket), - msecVal = Ref.alloc(Ref.types.uint32), - msecValLn = Ref.alloc(Ref.types.uint32, msecVal.type.size) + dataType = DataType.I32, + [msecVal] = createPointer({ + paramsType: [dataType], + paramsValue: [0], + }), + [msecValLn] = createPointer({ + paramsType: [DataType.I32], + paramsValue: [4], // sizeof int + }) FFIBindings.getsockopt( fd, @@ -423,7 +466,12 @@

index.js

msecValLn ) - return msecVal.deref() + const [value] = restorePointer({ + retType: [dataType], + paramsValue: [msecVal], + }) + + return value }
diff --git a/module-net-keepalive.html b/module-net-keepalive.html index 7238e09..5d7ce48 100644 --- a/module-net-keepalive.html +++ b/module-net-keepalive.html @@ -111,7 +111,7 @@

net-keepalive

The Missing (TCP_KEEPINTVL and TCP_KEEPCNT) SO_KEEPALIVE socket option setters and getters for Node using -ffi-napi module.

+ffi-rs module.

Note: For methods provided by this module to work you must enable SO_KEEPALIVE and set the TCP_KEEPIDLE options for socket using Net.Socket-s built in method socket.setKeepAlive([enable][, initialDelay]) !

@@ -371,7 +371,7 @@
Parameters:

View Source - index.js, line 105 + index.js, line 109

@@ -614,7 +614,7 @@
Parameters:

View Source - index.js, line 194 + index.js, line 214

@@ -858,7 +858,7 @@
Parameters:

View Source - index.js, line 297 + index.js, line 333

@@ -1423,7 +1423,7 @@
Parameters:

View Source - index.js, line 149 + index.js, line 165

@@ -1718,7 +1718,7 @@
Parameters:

View Source - index.js, line 245 + index.js, line 277