-
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.
* Initial replace ffi with ffi-napi * Include node 9 & 10 for travis * Repalce ref with ref-napi * Update package.json and readme * Sync appveyor and travis configs * Refactor for node v4 and later * Initial replace ffi with ffi-napi * Repalce ref with ref-napi * Update package.json and readme * Refactor for node v4 and later * Refactoring * Refactoring
- Loading branch information
Showing
10 changed files
with
141 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./lib'); | ||
module.exports = require('./lib') |
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,46 +1,40 @@ | ||
var UV = null | ||
, Util = require('util') | ||
|
||
function tryGetUV() { | ||
if (UV === null) { | ||
try { | ||
UV = typeof process.binding === "function" ? process.binding('uv') : undefined | ||
} catch (ex) { | ||
"use strict" | ||
|
||
const Util = require('util') | ||
|
||
const tryGetUV = (() => { | ||
let UV = null | ||
return () => { | ||
if (UV === null) { | ||
try { | ||
UV = typeof process.binding === "function" ? process.binding('uv') : undefined | ||
} catch (ex) { | ||
} | ||
} | ||
return UV | ||
} | ||
return UV | ||
} | ||
})() | ||
|
||
function uvErrName(errno) { | ||
var UV = tryGetUV() | ||
, errName = "UNKNOWN" | ||
|
||
if (UV && UV.errname) { | ||
errName = UV.errname(errno) | ||
} | ||
|
||
return errName | ||
const uvErrName = (errno) => { | ||
const UV = tryGetUV() | ||
return UV && UV.errname ? UV.errname(errno) : "UNKNOWN" | ||
} | ||
|
||
function errnoException(errno, syscall, original) { | ||
const errnoException = (errno, syscall, original) => { | ||
if (Util._errnoException) { | ||
return Util._errnoException(-errno, syscall, original) | ||
} | ||
|
||
var errname = uvErrName(-errno) | ||
, message = syscall + " " + errname + " (" + errno + ")" | ||
|
||
if (original) { | ||
message += " " + original; | ||
} | ||
const errname = uvErrName(-errno) | ||
, message = original ? `${syscall} ${errname} (${errno}) ${original}` : `${syscall} ${errname} (${errno})` | ||
|
||
var e = new Error(message); | ||
e.code = errname; | ||
e.errno = errname; | ||
e.syscall = syscall; | ||
return e; | ||
const e = new Error(message) | ||
e.code = errname | ||
e.errno = errname | ||
e.syscall = syscall | ||
return e | ||
} | ||
|
||
module.exports = { | ||
errnoException: errnoException | ||
errnoException | ||
} |
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,29 +1,30 @@ | ||
var OS = require('os') | ||
"use strict" | ||
|
||
var Constants = { | ||
const OS = require('os') | ||
|
||
const Constants = { | ||
SOL_TCP: 6, | ||
TCP_KEEPINTVL: undefined, | ||
TCP_KEEPCNT: undefined | ||
} | ||
|
||
var platform = OS.platform(); | ||
switch(platform) { | ||
switch (OS.platform()) { | ||
|
||
case 'darwin': | ||
Constants.TCP_KEEPINTVL = 0x101 | ||
Constants.TCP_KEEPCNT = 0x102 | ||
break | ||
case 'darwin': | ||
Constants.TCP_KEEPINTVL = 0x101 | ||
Constants.TCP_KEEPCNT = 0x102 | ||
break | ||
|
||
case 'freebsd': | ||
Constants.TCP_KEEPINTVL = 512 | ||
Constants.TCP_KEEPCNT = 1024 | ||
break | ||
case 'freebsd': | ||
Constants.TCP_KEEPINTVL = 512 | ||
Constants.TCP_KEEPCNT = 1024 | ||
break | ||
|
||
case 'linux': | ||
default: | ||
Constants.TCP_KEEPINTVL = 5 | ||
Constants.TCP_KEEPCNT = 6 | ||
break | ||
case 'linux': | ||
default: | ||
Constants.TCP_KEEPINTVL = 5 | ||
Constants.TCP_KEEPCNT = 6 | ||
break | ||
} | ||
|
||
module.exports = Constants |
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,38 +1,41 @@ | ||
var Ref = require('ref-napi') | ||
"use strict" | ||
|
||
const Ref = require('ref-napi') | ||
, FFI = require('ffi-napi') | ||
, Commons = require('./commons') | ||
|
||
|
||
var ffi = FFI.Library(null, { | ||
// name ret 1 2 3 4 5 | ||
setsockopt: [Ref.types.int, [Ref.types.int, Ref.types.int, Ref.types.int, Ref.refType(Ref.types.void), Ref.types.int]], | ||
getsockopt: [Ref.types.int, [Ref.types.int, Ref.types.int, Ref.types.int, Ref.refType(Ref.types.void), Ref.refType(Ref.types.int)]] | ||
}); | ||
const cInt = Ref.types.int | ||
, cVoid = Ref.types.void | ||
|
||
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)]] | ||
}) | ||
|
||
function setsockopt(fd, level, name, value, valueLength) { | ||
var err = ffi.setsockopt(fd, level, name, value, valueLength) | ||
, errno | ||
const setsockopt = (fd, level, name, value, valueLength) => { | ||
const err = ffi.setsockopt(fd, level, name, value, valueLength) | ||
|
||
if (err !== 0) { | ||
errno = FFI.errno() | ||
let errno = FFI.errno() | ||
throw Commons.errnoException(errno, 'setsockopt') | ||
} | ||
|
||
return true | ||
} | ||
|
||
function getsockopt(fd, level, name, value, valueLength) { | ||
var err = ffi.getsockopt(fd, level, name, value, valueLength) | ||
, errno | ||
const getsockopt = (fd, level, name, value, valueLength) => { | ||
const err = ffi.getsockopt(fd, level, name, value, valueLength) | ||
|
||
if (err !== 0) { | ||
errno = FFI.errno() | ||
let errno = FFI.errno() | ||
throw Commons.errnoException(errno, 'getsockopt') | ||
} | ||
return true | ||
} | ||
|
||
module.exports = { | ||
setsockopt: setsockopt, | ||
getsockopt: getsockopt | ||
setsockopt, | ||
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
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.