From 27012c1572e113f8bc9c6592bfb7de2ed8d009ec Mon Sep 17 00:00:00 2001 From: George Hertz Date: Mon, 15 Apr 2024 14:22:21 +0200 Subject: [PATCH] fix: expose errorno from ffi-rs (#316) --- lib/ffi-bindings.js | 20 +++--- package-lock.json | 147 ++++++++++++++++++++++---------------------- package.json | 2 +- 3 files changed, 83 insertions(+), 86 deletions(-) diff --git a/lib/ffi-bindings.js b/lib/ffi-bindings.js index 033e2cb..dbe8e32 100644 --- a/lib/ffi-bindings.js +++ b/lib/ffi-bindings.js @@ -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] }, } } @@ -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') } @@ -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 diff --git a/package-lock.json b/package-lock.json index e8cace8..3a08db5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.0.0", "license": "MIT", "dependencies": { - "ffi-rs": "1.0.58" + "ffi-rs": "1.0.60" }, "devDependencies": { "@commitlint/cli": "^18.0.0", @@ -2372,9 +2372,9 @@ "dev": true }, "node_modules/@yuuang/ffi-rs-darwin-arm64": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-arm64/-/ffi-rs-darwin-arm64-1.0.58.tgz", - "integrity": "sha512-oxSKQ11nP9CTqS1aMmh4giKl5wvqlgWzE/97CJjKpGtY66VdgNe3lyZLnre2OfvSmSYdaWSE33OVlFjOocwUZA==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-arm64/-/ffi-rs-darwin-arm64-1.0.60.tgz", + "integrity": "sha512-j65NaD0MpR71bxe85PpygYUoGMFM1xlo9Pq+nIRdF7JLlkEhVukkKVBXPannVIg8hXSdBCMrLMwtQpCVMfEvEw==", "cpu": [ "arm64" ], @@ -2387,9 +2387,9 @@ } }, "node_modules/@yuuang/ffi-rs-darwin-x64": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-x64/-/ffi-rs-darwin-x64-1.0.58.tgz", - "integrity": "sha512-m7khCgmnomWBeRJyUza1qQ0rQP1P1OuUoywpTAoUjtCcLM0Wg6mLq1rGReg+2BF5K6goZ6wgT9DOA0GIJpWvWQ==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-x64/-/ffi-rs-darwin-x64-1.0.60.tgz", + "integrity": "sha512-UCA9CHG+hqIYsysEAcIqfGGnRyUg6oJPnzdI3SbKtzHAgpFP13qzMHqUJKoU5bOXynDQOCR66e8djk+K9Lm9Dw==", "cpu": [ "x64" ], @@ -2402,9 +2402,9 @@ } }, "node_modules/@yuuang/ffi-rs-linux-arm64-gnu": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-gnu/-/ffi-rs-linux-arm64-gnu-1.0.58.tgz", - "integrity": "sha512-NKem6MNPjmGYuez4Q3r0sltdSw99wVaZtWo+zZaz+j622BWaM0r58hKm0dQ7ebR+2TPEKZa+LyZztyYEr1a+nw==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-gnu/-/ffi-rs-linux-arm64-gnu-1.0.60.tgz", + "integrity": "sha512-1zV6Ztjjvi5eUMm8EoOk8WRkS1bFnDw/J/hzsiz+TsnKplkIY/wus+zDfeh+U4jZVGYA1YT/jmUEn5gy3REBdg==", "cpu": [ "arm64" ], @@ -2417,9 +2417,9 @@ } }, "node_modules/@yuuang/ffi-rs-linux-arm64-musl": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-musl/-/ffi-rs-linux-arm64-musl-1.0.58.tgz", - "integrity": "sha512-YVTByY75vTInS0O1zyZYOpDeZY0pM2mjQY1M1J/foSyUg42yOAOGi+RsDEWjtfN78oAAt/Qj9k51kWSrQGK2TQ==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-musl/-/ffi-rs-linux-arm64-musl-1.0.60.tgz", + "integrity": "sha512-c2MyETnYnAGmhZF1QFoQW/PiGoYAvHoN1cHDAqmtBbTZanJs7wgqHh5mQBrKs/wS4bVJ6qShQAZS/WVYlkdRPg==", "cpu": [ "arm64" ], @@ -2432,9 +2432,9 @@ } }, "node_modules/@yuuang/ffi-rs-linux-x64-gnu": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-gnu/-/ffi-rs-linux-x64-gnu-1.0.58.tgz", - "integrity": "sha512-R+xf4RYQSqnc6DVwFX/ObTLkyPKfJJ7+D84ZH/FJsSEzO1ZlxMrtR7smvfiaDXIgiAr5KveUIB4WSxUr5otNlA==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-gnu/-/ffi-rs-linux-x64-gnu-1.0.60.tgz", + "integrity": "sha512-e0BcbVE/RF/HcMe9vn7zKB6fRaZhECCU98DFE7UbpuZ6wrYNzl6T6Pw9PwTN6euTXBeOvpbbaH+Hno13uYlFZA==", "cpu": [ "x64" ], @@ -2447,9 +2447,9 @@ } }, "node_modules/@yuuang/ffi-rs-linux-x64-musl": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-musl/-/ffi-rs-linux-x64-musl-1.0.58.tgz", - "integrity": "sha512-LnVLw10G7rOswReskpkU31MxgnoqNe8QYDTnUF6r+pNsscblYdnrowKkt6ag0t8ZXMR4j1QnS0jIoD9ROSQVZQ==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-musl/-/ffi-rs-linux-x64-musl-1.0.60.tgz", + "integrity": "sha512-o6DeN9M/icR9lrPAuNsyB4yXQVDjLylWZCkkJbSk4w4DLL9Q0+BZkN4EnoefXTzZrwqjjQ+0mRs+BHrKZIvEjA==", "cpu": [ "x64" ], @@ -2462,9 +2462,9 @@ } }, "node_modules/@yuuang/ffi-rs-win32-ia32-msvc": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-ia32-msvc/-/ffi-rs-win32-ia32-msvc-1.0.58.tgz", - "integrity": "sha512-7HJ2nf38xdmakX9/tpe1IOke8UUJqJFWTBLW2JHHkdd0VoeZghGTVZ3gIUVx7zuboczVjx5Nyt3zDebntXvIVw==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-ia32-msvc/-/ffi-rs-win32-ia32-msvc-1.0.60.tgz", + "integrity": "sha512-y8/biNxm8DvPFo2QtYKUru3Dq4n3aJmaKg0E63vDz4A+pQBaa+qnntRYSvmapXVvcVIu9l3iIsHyboIy9O7lvg==", "cpu": [ "x64", "ia32" @@ -2478,9 +2478,9 @@ } }, "node_modules/@yuuang/ffi-rs-win32-x64-msvc": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-x64-msvc/-/ffi-rs-win32-x64-msvc-1.0.58.tgz", - "integrity": "sha512-RLOIfEqfmEDZXoK0lXz+wum/sYgPM9hcspP0mSzD4GHp0/RbekK7ThgVCFfd9uf0y8uWGYvpZ2/P5LDJnDqhJg==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-x64-msvc/-/ffi-rs-win32-x64-msvc-1.0.60.tgz", + "integrity": "sha512-TM3zctfU7q9JHHNk/FG9clMweHOyo6wJRB9VN3xdFJiZ8dJEhVUGWNTHBL7boyIZE/8xNvf8x2yNoSTAO8acTw==", "cpu": [ "x64" ], @@ -4436,21 +4436,18 @@ } }, "node_modules/ffi-rs": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/ffi-rs/-/ffi-rs-1.0.58.tgz", - "integrity": "sha512-TqBPItoDk5cO7d0x5aGwPSoCiE+mLFnff7ZD6wkvLuiddp73PeWqOcwIEB214xPH1d3ZGf5NC0ls8qsdvSWNWA==", - "engines": { - "node": ">= 16" - }, + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/ffi-rs/-/ffi-rs-1.0.60.tgz", + "integrity": "sha512-uA83OfKSYS7Pvkot/22iT7nWqWgY+sTEJmMBVh1U7JKbxSmDDZ8UaoX+Z/ssZSl2Fx98RD9Acv3f7Ajr++JIFA==", "optionalDependencies": { - "@yuuang/ffi-rs-darwin-arm64": "1.0.58", - "@yuuang/ffi-rs-darwin-x64": "1.0.58", - "@yuuang/ffi-rs-linux-arm64-gnu": "1.0.58", - "@yuuang/ffi-rs-linux-arm64-musl": "1.0.58", - "@yuuang/ffi-rs-linux-x64-gnu": "1.0.58", - "@yuuang/ffi-rs-linux-x64-musl": "1.0.58", - "@yuuang/ffi-rs-win32-ia32-msvc": "1.0.58", - "@yuuang/ffi-rs-win32-x64-msvc": "1.0.58" + "@yuuang/ffi-rs-darwin-arm64": "1.0.60", + "@yuuang/ffi-rs-darwin-x64": "1.0.60", + "@yuuang/ffi-rs-linux-arm64-gnu": "1.0.60", + "@yuuang/ffi-rs-linux-arm64-musl": "1.0.60", + "@yuuang/ffi-rs-linux-x64-gnu": "1.0.60", + "@yuuang/ffi-rs-linux-x64-musl": "1.0.60", + "@yuuang/ffi-rs-win32-ia32-msvc": "1.0.60", + "@yuuang/ffi-rs-win32-x64-msvc": "1.0.60" } }, "node_modules/figures": { @@ -15220,51 +15217,51 @@ "dev": true }, "@yuuang/ffi-rs-darwin-arm64": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-arm64/-/ffi-rs-darwin-arm64-1.0.58.tgz", - "integrity": "sha512-oxSKQ11nP9CTqS1aMmh4giKl5wvqlgWzE/97CJjKpGtY66VdgNe3lyZLnre2OfvSmSYdaWSE33OVlFjOocwUZA==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-arm64/-/ffi-rs-darwin-arm64-1.0.60.tgz", + "integrity": "sha512-j65NaD0MpR71bxe85PpygYUoGMFM1xlo9Pq+nIRdF7JLlkEhVukkKVBXPannVIg8hXSdBCMrLMwtQpCVMfEvEw==", "optional": true }, "@yuuang/ffi-rs-darwin-x64": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-x64/-/ffi-rs-darwin-x64-1.0.58.tgz", - "integrity": "sha512-m7khCgmnomWBeRJyUza1qQ0rQP1P1OuUoywpTAoUjtCcLM0Wg6mLq1rGReg+2BF5K6goZ6wgT9DOA0GIJpWvWQ==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-x64/-/ffi-rs-darwin-x64-1.0.60.tgz", + "integrity": "sha512-UCA9CHG+hqIYsysEAcIqfGGnRyUg6oJPnzdI3SbKtzHAgpFP13qzMHqUJKoU5bOXynDQOCR66e8djk+K9Lm9Dw==", "optional": true }, "@yuuang/ffi-rs-linux-arm64-gnu": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-gnu/-/ffi-rs-linux-arm64-gnu-1.0.58.tgz", - "integrity": "sha512-NKem6MNPjmGYuez4Q3r0sltdSw99wVaZtWo+zZaz+j622BWaM0r58hKm0dQ7ebR+2TPEKZa+LyZztyYEr1a+nw==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-gnu/-/ffi-rs-linux-arm64-gnu-1.0.60.tgz", + "integrity": "sha512-1zV6Ztjjvi5eUMm8EoOk8WRkS1bFnDw/J/hzsiz+TsnKplkIY/wus+zDfeh+U4jZVGYA1YT/jmUEn5gy3REBdg==", "optional": true }, "@yuuang/ffi-rs-linux-arm64-musl": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-musl/-/ffi-rs-linux-arm64-musl-1.0.58.tgz", - "integrity": "sha512-YVTByY75vTInS0O1zyZYOpDeZY0pM2mjQY1M1J/foSyUg42yOAOGi+RsDEWjtfN78oAAt/Qj9k51kWSrQGK2TQ==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-musl/-/ffi-rs-linux-arm64-musl-1.0.60.tgz", + "integrity": "sha512-c2MyETnYnAGmhZF1QFoQW/PiGoYAvHoN1cHDAqmtBbTZanJs7wgqHh5mQBrKs/wS4bVJ6qShQAZS/WVYlkdRPg==", "optional": true }, "@yuuang/ffi-rs-linux-x64-gnu": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-gnu/-/ffi-rs-linux-x64-gnu-1.0.58.tgz", - "integrity": "sha512-R+xf4RYQSqnc6DVwFX/ObTLkyPKfJJ7+D84ZH/FJsSEzO1ZlxMrtR7smvfiaDXIgiAr5KveUIB4WSxUr5otNlA==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-gnu/-/ffi-rs-linux-x64-gnu-1.0.60.tgz", + "integrity": "sha512-e0BcbVE/RF/HcMe9vn7zKB6fRaZhECCU98DFE7UbpuZ6wrYNzl6T6Pw9PwTN6euTXBeOvpbbaH+Hno13uYlFZA==", "optional": true }, "@yuuang/ffi-rs-linux-x64-musl": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-musl/-/ffi-rs-linux-x64-musl-1.0.58.tgz", - "integrity": "sha512-LnVLw10G7rOswReskpkU31MxgnoqNe8QYDTnUF6r+pNsscblYdnrowKkt6ag0t8ZXMR4j1QnS0jIoD9ROSQVZQ==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-musl/-/ffi-rs-linux-x64-musl-1.0.60.tgz", + "integrity": "sha512-o6DeN9M/icR9lrPAuNsyB4yXQVDjLylWZCkkJbSk4w4DLL9Q0+BZkN4EnoefXTzZrwqjjQ+0mRs+BHrKZIvEjA==", "optional": true }, "@yuuang/ffi-rs-win32-ia32-msvc": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-ia32-msvc/-/ffi-rs-win32-ia32-msvc-1.0.58.tgz", - "integrity": "sha512-7HJ2nf38xdmakX9/tpe1IOke8UUJqJFWTBLW2JHHkdd0VoeZghGTVZ3gIUVx7zuboczVjx5Nyt3zDebntXvIVw==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-ia32-msvc/-/ffi-rs-win32-ia32-msvc-1.0.60.tgz", + "integrity": "sha512-y8/biNxm8DvPFo2QtYKUru3Dq4n3aJmaKg0E63vDz4A+pQBaa+qnntRYSvmapXVvcVIu9l3iIsHyboIy9O7lvg==", "optional": true }, "@yuuang/ffi-rs-win32-x64-msvc": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-x64-msvc/-/ffi-rs-win32-x64-msvc-1.0.58.tgz", - "integrity": "sha512-RLOIfEqfmEDZXoK0lXz+wum/sYgPM9hcspP0mSzD4GHp0/RbekK7ThgVCFfd9uf0y8uWGYvpZ2/P5LDJnDqhJg==", + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-x64-msvc/-/ffi-rs-win32-x64-msvc-1.0.60.tgz", + "integrity": "sha512-TM3zctfU7q9JHHNk/FG9clMweHOyo6wJRB9VN3xdFJiZ8dJEhVUGWNTHBL7boyIZE/8xNvf8x2yNoSTAO8acTw==", "optional": true }, "acorn": { @@ -16731,18 +16728,18 @@ } }, "ffi-rs": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/ffi-rs/-/ffi-rs-1.0.58.tgz", - "integrity": "sha512-TqBPItoDk5cO7d0x5aGwPSoCiE+mLFnff7ZD6wkvLuiddp73PeWqOcwIEB214xPH1d3ZGf5NC0ls8qsdvSWNWA==", - "requires": { - "@yuuang/ffi-rs-darwin-arm64": "1.0.58", - "@yuuang/ffi-rs-darwin-x64": "1.0.58", - "@yuuang/ffi-rs-linux-arm64-gnu": "1.0.58", - "@yuuang/ffi-rs-linux-arm64-musl": "1.0.58", - "@yuuang/ffi-rs-linux-x64-gnu": "1.0.58", - "@yuuang/ffi-rs-linux-x64-musl": "1.0.58", - "@yuuang/ffi-rs-win32-ia32-msvc": "1.0.58", - "@yuuang/ffi-rs-win32-x64-msvc": "1.0.58" + "version": "1.0.60", + "resolved": "https://registry.npmjs.org/ffi-rs/-/ffi-rs-1.0.60.tgz", + "integrity": "sha512-uA83OfKSYS7Pvkot/22iT7nWqWgY+sTEJmMBVh1U7JKbxSmDDZ8UaoX+Z/ssZSl2Fx98RD9Acv3f7Ajr++JIFA==", + "requires": { + "@yuuang/ffi-rs-darwin-arm64": "1.0.60", + "@yuuang/ffi-rs-darwin-x64": "1.0.60", + "@yuuang/ffi-rs-linux-arm64-gnu": "1.0.60", + "@yuuang/ffi-rs-linux-arm64-musl": "1.0.60", + "@yuuang/ffi-rs-linux-x64-gnu": "1.0.60", + "@yuuang/ffi-rs-linux-x64-musl": "1.0.60", + "@yuuang/ffi-rs-win32-ia32-msvc": "1.0.60", + "@yuuang/ffi-rs-win32-x64-msvc": "1.0.60" } }, "figures": { diff --git a/package.json b/package.json index 0e01794..9269e60 100644 --- a/package.json +++ b/package.json @@ -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",