-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(win32)!: allow install and just no-op unsupported operations (#288)
* feat: allow windows installs all the methods are no-op on windows always returning false * feat: run actions on windows * chore: update docs * feat!: guard against nullish descriptors
- Loading branch information
Showing
11 changed files
with
12,004 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,65 @@ | ||
'use strict' | ||
const { platform } = require('os') | ||
const { errnoException } = require('./commons') | ||
const Ref = require('ref-napi') | ||
const FFI = require('ffi-napi') | ||
|
||
const Ref = require('ref-napi'), | ||
FFI = require('ffi-napi'), | ||
Commons = require('./commons') | ||
const createFFI = () => { | ||
const cInt = Ref.types.int | ||
const cVoid = Ref.types.void | ||
|
||
const cInt = Ref.types.int, | ||
cVoid = Ref.types.void | ||
return FFI.Library(null, { | ||
//name ret 1 2 3 4 5 | ||
setsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), cInt]], | ||
getsockopt: [ | ||
cInt, | ||
[cInt, cInt, cInt, Ref.refType(cVoid), Ref.refType(cInt)], | ||
], | ||
}) | ||
} | ||
|
||
const ffi = FFI.Library(null, { | ||
//name ret 1 2 3 4 5 | ||
setsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), cInt]], | ||
getsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), Ref.refType(cInt)]], | ||
}) | ||
const ffi = (() => { | ||
let instance | ||
return () => { | ||
if (!instance) { | ||
instance = createFFI() | ||
} | ||
return instance | ||
} | ||
})() | ||
|
||
const setsockopt = (fd, level, name, value, valueLength) => { | ||
const err = ffi.setsockopt(fd, level, name, value, valueLength) | ||
if(fd == null) { | ||
return false | ||
} | ||
|
||
const err = ffi().setsockopt(fd, level, name, value, valueLength) | ||
|
||
if (err !== 0) { | ||
let errno = FFI.errno() | ||
throw Commons.errnoException(errno, 'setsockopt') | ||
const errno = FFI.errno() | ||
throw errnoException(errno, 'setsockopt') | ||
} | ||
|
||
return true | ||
} | ||
|
||
const getsockopt = (fd, level, name, value, valueLength) => { | ||
const err = ffi.getsockopt(fd, level, name, value, valueLength) | ||
if(fd == null) { | ||
return false | ||
} | ||
|
||
const err = ffi().getsockopt(fd, level, name, value, valueLength) | ||
|
||
if (err !== 0) { | ||
let errno = FFI.errno() | ||
throw Commons.errnoException(errno, 'getsockopt') | ||
const errno = FFI.errno() | ||
throw errnoException(errno, 'getsockopt') | ||
} | ||
return true | ||
} | ||
|
||
const noop = () => false | ||
const isWin32 = platform() === 'win32' | ||
|
||
module.exports = { | ||
setsockopt, | ||
getsockopt, | ||
setsockopt: isWin32 ? noop : setsockopt, | ||
getsockopt: isWin32 ? noop : getsockopt, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.