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 @@
/**
* 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 @@