Skip to content

Commit

Permalink
fix: expose errorno from ffi-rs (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
hertzg committed Apr 15, 2024
1 parent 5271914 commit 27012c1
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 86 deletions.
20 changes: 10 additions & 10 deletions lib/ffi-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ const createFFI = () => {

return {
setsockopt: (fd, level, name, value, valueLength) => {
const ret = load({
const { value: ret, errnoCode } = load({
library: LIBRARY_NAME,
funcName: 'setsockopt',
retType: cInt,
paramsType: [cInt, cInt, cInt, cVoidRef, cInt],
paramsValue: [fd, level, name, value, valueLength],
errno: true,
})
return ret
return [ret, errnoCode]
},
getsockopt: (fd, level, name, value, valueLength) => {
const ret = load({
const { value: ret, errnoCode } = load({
library: LIBRARY_NAME,
funcName: 'getsockopt',
retType: cInt,
paramsType: [cInt, cInt, cInt, cVoidRef, cVoidRef],
paramsValue: [fd, level, name, value, valueLength],
errno: true,
})
return ret
return [ret, errnoCode]
},
}
}
Expand All @@ -51,10 +53,9 @@ const setsockopt = (fd, level, name, value, valueLength) => {
return false
}

const err = ffi().setsockopt(fd, level, name, value, valueLength)
const [ret, errno] = ffi().setsockopt(fd, level, name, value, valueLength)

if (err !== 0) {
const errno = 9 // FIXME: there's no FFI.errno() in ffi-rs
if (ret !== 0) {
throw errnoException(errno, 'setsockopt')
}

Expand All @@ -66,10 +67,9 @@ const getsockopt = (fd, level, name, value, valueLength) => {
return false
}

const err = ffi().getsockopt(fd, level, name, value, valueLength)
const [ret, errno] = ffi().getsockopt(fd, level, name, value, valueLength)

if (err !== 0) {
const errno = 9 // FIXME: there's no FFI.errno() in ffi-rs
if (ret !== 0) {
throw errnoException(errno, 'getsockopt')
}
return true
Expand Down
147 changes: 72 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"homepage": "https://hertzg.github.io/node-net-keepalive/",
"dependencies": {
"ffi-rs": "1.0.58"
"ffi-rs": "1.0.60"
},
"devDependencies": {
"@commitlint/cli": "^18.0.0",
Expand Down

0 comments on commit 27012c1

Please sign in to comment.