mirror of
https://github.com/fuse-friends/fuse-native
synced 2024-10-27 18:34:01 +00:00
fix timeout code and make it opt-out
This commit is contained in:
parent
b63edfd61e
commit
38a4a52231
10
index.js
10
index.js
@ -12,8 +12,7 @@ const IS_OSX = os.platform() === 'darwin'
|
|||||||
const OSX_FOLDER_ICON = '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericFolderIcon.icns'
|
const OSX_FOLDER_ICON = '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericFolderIcon.icns'
|
||||||
const HAS_FOLDER_ICON = IS_OSX && fs.existsSync(OSX_FOLDER_ICON)
|
const HAS_FOLDER_ICON = IS_OSX && fs.existsSync(OSX_FOLDER_ICON)
|
||||||
const DEFAULT_TIMEOUT = 15 * 1000
|
const DEFAULT_TIMEOUT = 15 * 1000
|
||||||
const TIMEOUT_ERRNO = IS_OSX ? -110 : -60
|
const TIMEOUT_ERRNO = IS_OSX ? -60 : -110
|
||||||
|
|
||||||
const ENOTCONN = IS_OSX ? -57 : -107
|
const ENOTCONN = IS_OSX ? -57 : -107
|
||||||
|
|
||||||
const OpcodesAndDefaults = new Map([
|
const OpcodesAndDefaults = new Map([
|
||||||
@ -139,7 +138,7 @@ class Fuse extends Nanoresource {
|
|||||||
this.opts = opts
|
this.opts = opts
|
||||||
this.mnt = path.resolve(mnt)
|
this.mnt = path.resolve(mnt)
|
||||||
this.ops = ops
|
this.ops = ops
|
||||||
this.timeout = opts.timeout || DEFAULT_TIMEOUT
|
this.timeout = opts.timeout === false ? 0 : (opts.timeout || DEFAULT_TIMEOUT)
|
||||||
|
|
||||||
this._force = !!opts.force
|
this._force = !!opts.force
|
||||||
this._mkdir = !!opts.mkdir
|
this._mkdir = !!opts.mkdir
|
||||||
@ -204,7 +203,7 @@ class Fuse extends Nanoresource {
|
|||||||
_makeHandlerArray () {
|
_makeHandlerArray () {
|
||||||
const self = this
|
const self = this
|
||||||
const handlers = new Array(OpcodesAndDefaults.size)
|
const handlers = new Array(OpcodesAndDefaults.size)
|
||||||
const to = this.timeout || DEFAULT_TIMEOUT
|
const to = this.timeout
|
||||||
|
|
||||||
for (const [name, { op, defaults }] of OpcodesAndDefaults) {
|
for (const [name, { op, defaults }] of OpcodesAndDefaults) {
|
||||||
const nativeSignal = binding[`fuse_native_signal_${name}`]
|
const nativeSignal = binding[`fuse_native_signal_${name}`]
|
||||||
@ -217,7 +216,8 @@ class Fuse extends Nanoresource {
|
|||||||
|
|
||||||
function makeHandler (name, op, defaults, nativeSignal) {
|
function makeHandler (name, op, defaults, nativeSignal) {
|
||||||
return function (nativeHandler, opCode, ...args) {
|
return function (nativeHandler, opCode, ...args) {
|
||||||
const boundSignal = autoTimeout(signal.bind(null, nativeHandler))
|
const sig = signal.bind(null, nativeHandler)
|
||||||
|
const boundSignal = to ? autoTimeout(sig) : sig
|
||||||
const funcName = `_op_${name}`
|
const funcName = `_op_${name}`
|
||||||
if (!self[funcName] || !self._implemented.has(op)) return boundSignal(-1, ...defaults)
|
if (!self[funcName] || !self._implemented.has(op)) return boundSignal(-1, ...defaults)
|
||||||
return self[funcName].apply(self, [boundSignal, ...args])
|
return self[funcName].apply(self, [boundSignal, ...args])
|
||||||
|
Loading…
Reference in New Issue
Block a user