diff --git a/node/.gitignore b/node/.gitignore new file mode 100644 index 0000000..d046cdd --- /dev/null +++ b/node/.gitignore @@ -0,0 +1,2 @@ +./node_modules/ + diff --git a/node/Makefile b/node/Makefile new file mode 100644 index 0000000..e202264 --- /dev/null +++ b/node/Makefile @@ -0,0 +1,11 @@ + + + + + + + +test: *.js + rm -rf /tmp/*.ipc + node index.js "A" & node index.js "B" & node index.js "C" + diff --git a/node/config.js b/node/config.js new file mode 100644 index 0000000..6a354c2 --- /dev/null +++ b/node/config.js @@ -0,0 +1,9 @@ + +module.exports = { + "A": { roles: [1], types: "send send recv 4 recv 5"}, + "B": { roles: [2], types: "recv 1 recv 1 recv 4 recv 5"}, + "C": { roles: [3,4,5], types: "recv 1 recv 1 send send"} + // "a": { roles: [3], types: "recv 1 recv 1 recv 4 recv 5"}, + // "b": { roles: [4], types: "recv 1 recv 1 send recv 5"}, + // "c": { roles: [1,2,5], types: "send send recv 4"} +} \ No newline at end of file diff --git a/node/consensus.js b/node/consensus.js new file mode 100644 index 0000000..014fc1c --- /dev/null +++ b/node/consensus.js @@ -0,0 +1,161 @@ +"use strict" + +let Msg = require("./msg.js") +let Socket = require("./socket.js") + + +/** + * Simple leader election. + */ +class Consensus { + + /** + * @param {Socket} sock a pre-connected bus socket + * @param {uuid} id the uuid of myself + * @param {object} metadata anything that's attached to this id + * @param {Function} callback invoked when it becomes leader, or when leader sends first command + */ + constructor(sock, id, metadata, callback) { + this.sock = sock + + this.id = id + this.meta = metadata // may contain roles and stype + + this.state = "follower" // follower | candidate | leader + this.members = {} + + this.members[this.id] = this.meta + + this.timer = this.reset_timer() + this.pinger = setInterval(() => this.ping(), 150) + this.callback = callback + + // this will remove all other handlers + // and use ours exclusively + this.sock.onmessage = msg => this.on_message(msg) + } + + /** + * Send ping messages to gossip what metadata I have + */ + ping() { + this.sock.send(new Msg("ping", this.id, {meta: this.meta})) + } + + /** + * Reset the election timer + */ + reset_timer() { + clearTimeout(this.timer) + + if (this.state != "leader") { + // [150, 300) ms recommended timeouts from RAFT + this.timer = setTimeout(() => this.on_timeout(), Math.random() * 150 + 150) + } else { + // 150 ms for leader heartbeat + this.timer = setTimeout(() => this.on_timeout(), 150) + } + } + + /** + * As a leader, send out a sync command to sync metadata about all the members. + * @param {Object} meta metadata to by synced + * @param {Array of uuid} receivers intended receivers + */ + syncmeta(meta, receivers) { + this.meta = meta + this.sock.send(new Msg("sync", this.id, {meta: this.meta, receivers: receivers})) + } + + /** + * Election timeouts + */ + on_timeout() { + switch (this.state) { + // if a follower times out, it becomes candidate + // if there is a leader, the heartbeat should keep it within follower + case "follower": + this.state = "candidate" + this.sock.send(new Msg("candidate", this.id, {meta: this.meta})) + this.reset_timer() + break + + // if a candidate times out, it becomes leader + // if there is a leader, the hearbeat should force it to become a follower + case "candidate": + this.sock.send(new Msg("leader", this.id, {meta: this.meta})) + this.state = "leader" + this.reset_timer() + break + + // if a leader times out, it heartbeats + case "leader": + this.sock.send(new Msg("leader", this.id, {meta: this.meta})) + this.reset_timer() + this.callback(this) + break + } + } + + /** + * On consensus messages or leader commands + * @param {Msg} msg + */ + on_message(msg) { + + switch (msg.label) { + // ping message to update members list + // reset timer if it comes from a smaller id + case "ping": + this.members[msg.sender] = msg.payload.meta + if (msg.sender < this.id) { + this.state = "follower" + this.reset_timer() + } + break + + // if the sender is smaller, help it become leader + // otherwise, promote myself to be the leader + case "candidate": + // if the candidate is smaller than me + if (msg.sender < this.id) { + this.state = "follower" + } else { + this.state = "candidate" + this.sock.send(new Msg("candidate", this.id, {meta: this.meta})) + } + this.reset_timer() + break + + // as long as I'm not a leader, I will be follower. + // If I'm also a leader, we need to compare our id + case "leader": + if (this.state == "leader") { + if (msg.sender < this.id) { + // I should not be the leader + this.state = "follower" + } else { + // I should, but let's re-elect + this.state = "candidate" + this.sock.send(new Msg("candidate", this.id, {meta: this.meta})) + } + } else { + // just follow the leader + this.state = "follower" + } + this.reset_timer() + break + + // the leader sends out this command + case "sync": + if (this.state != "leader" && msg.payload.receivers.includes(this.id)) { + this.meta = msg.payload.meta + clearTimeout(this.timer) + clearInterval(this.pinger) + this.callback(this) + } + } + } +} + +module.exports = Consensus \ No newline at end of file diff --git a/node/endpoint.js b/node/endpoint.js new file mode 100644 index 0000000..3ec9749 --- /dev/null +++ b/node/endpoint.js @@ -0,0 +1,164 @@ +"use strict" + +let nanomsg = require("nanomsg") +let uuidv4 = require("uuid/v4") +let Mailbox = require("./mailbox.js") +let Socket = require("./socket.js") +let Msg = require("./msg.js") +let Consensus = require("./consensus.js") + +class Endpoint { + /** + * local states: + * - id: endpoint id + * - roles: self roles within the session + * - peers: peer roles and peer endpoint id's + * - mbox: message box for received msgs + * - sock: pre-connected socket in "bus/broadcast" mode + */ + + + /** + * Construct an endpoint that wraps around a pre-connected + * broadcasting socket. + * @param {Socket} sock + * @param {[int]} roles + */ + constructor(sock, roles) { + this.id = uuidv4(); + this.roles = roles.sort(); + this.peers = {} // a map where peers[role] = peer_uuid + this.mbox = new Mailbox() + this.sock = sock + this.state = "init" // init | ready | active + + this.handler = + msg => + msg.sender in this.peers ? this.mbox.put(msg) : "" + } + + + async init(fullroles) { + + fullroles.sort() + + let req = new Promise((resolve, reject) => { + let consensus = new Consensus(this.sock, this.id, this.roles, obj => { + + switch (obj.state) { + + // becomes a leader + case "leader": + // reset this.peers + this.peers = {} + + // add peers, from the smallest id to the largest id + let keys = Object.keys(obj.members) + keys.sort() + keys.forEach(id => { + // non-overlapping roles + if (obj.members[id].every(role => !(role in this.peers))) { + obj.members[id].forEach(role => this.peers[role] = id) + } + }) + + // check for all the roles + keys = Object.keys(this.peers) + keys.sort() + if (keys.length == fullroles.length && + keys.reduce((acc, cur, idx) => acc && (cur == fullroles[idx]), true)) { + + // leader elected, stop the timer, replace message handler, and sync peers + clearTimeout(obj.timer) + clearInterval(obj.pinger) + this.sock.onmessage = this.handler + obj.syncmeta(this.peers, Object.values(this.peers)) + resolve(obj) + } else { + obj.state = "candidate" + } + break + + // some leader is elected, and received "sync" message + default: + clearTimeout(obj.timer) + clearInterval(obj.pinger) + this.peers = obj.meta + this.sock.onmessage = this.handler + resolve(obj) + } + }) + }) + + + let consensus = await req + } + + /** + * Broadcast a payload to all + * @param {anything} payload + * @return {void} + */ + broadcast(payload) { + let msg = new Msg("send", this.id, payload) + this.sock.send(msg) + } + + /** + * Receive a message from a particular sender. + * @param {role} sender + * @return {anything} + */ + async receive(sender) { + let promises = [this.mbox.match("send", this.peers[sender.toString()]), + this.mbox.match("link", null)] + let msg = await promises.race() + + switch (msg.label) { + case "send": + return msg + case "link": + this.peers = msg.payload + return this.receive(sender) + } + } + + close() { + this.sock.close() + this.mbox = null + } + + static async partialcut(ep1, ep2) { + let intersection_roles = ep1.roles.filter(role => ep2.includes(role)) + let direction = await ep1.mbox.isempty() // true: ep1 <- ep2, false: ep1 -> ep2 + + let ep = new Endpoint(this.sock, intersection_roles) + ep.sock.onmessage = ep.handler + + let peers = {} + intersection_roles.forEach(role => peers[role] = ep.id) + + Object.keys(ep1.peers).forEach(role => (!ep1.roles.includes(role)) ? peers[role] = ep1.peers[role] : "") + Object.keys(ep2.peers).forEach(role => (!ep2.roles.includes(role)) ? peers[role] = ep2.peers[role] : "") + + ep1.sock.send(new Msg("link", ep1.id, peers)) + ep2.sock.send(new Msg("link", ep2.id, peers)) + + if (direction) { + while (!ep2.mbox.isempty()) { + let msg = await ep2.mbox.get() + ep1.sock.send(msg) + } + } else { + while (!ep1.mbox.isempty()) { + let msg = await ep1.mbox.get() + ep2.sock.send(msg) + } + } + + return ep + } + +} + +module.exports = Endpoint \ No newline at end of file diff --git a/node/index.js b/node/index.js new file mode 100644 index 0000000..6ce9bde --- /dev/null +++ b/node/index.js @@ -0,0 +1,62 @@ +"use strict" + +let Socket = require("./socket.js") +let Endpoint = require("./endpoint.js") +let Msg = require("./msg.js") + + +async function main() { + let socket = new Socket("bus") + socket.bind("ws://127.0.0.1:440") + let ep = new Endpoint(socket, [2,3]) + await ep.init([1,2,3]) + let msg = await ep.receive(1) + let msg2 = await ep.receive(1) + ep.send("world") + ep.close() +} + +// main() + + + + + + + + + +let nanomsg = require("nanomsg") +let config = require("./config.js") + +async function test(proc) { + + console.log(`${proc} started`) + let socket = new Socket("bus") + + socket.bind(`ipc:///tmp/test${proc}.ipc`) + Object.keys(config).forEach(p => p != proc ? socket.connect("ipc:///tmp/test${p}.ipc") : "") + + let ep = new Endpoint(socket, config[proc].roles) + await ep.init([1,2,3,4,5]) + + let type = config[proc].types.split(" ") + for (index in type) { + switch (type[index]) { + case "send": + ep.send(`sent from ${proc}`) + break + case "recv": + let reply = await ep.receive(type[index+1]) + console.log(`${proc} received a msg ${reply}`) + break + } + } + + ep.close() +} + + +test(process.argv[2]) + + diff --git a/node/mailbox.js b/node/mailbox.js new file mode 100644 index 0000000..a9d4bef --- /dev/null +++ b/node/mailbox.js @@ -0,0 +1,117 @@ +"use strict" + +let nanomsg = require("nanomsg") +let Socket = require("./socket.js") +let uuidv4 = require("uuid/v4") +let Msg = require("./msg.js") + +let sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) + +class MailboxWorker { + constructor(addr) { + this.mbox = [] + // setInterval(() => console.log(this.mbox), 1000) + this.sock = new Socket("pair") + this.sock.connect(addr) + this.sock.onmessage = msg => this.dispatch(msg) + } + + on_put(msg) { + this.mbox.push(msg.payload) + } + + async on_get() { + while (this.mbox.length == 0) { + await sleep(1) + } + return this.mbox.shift() + } + + async on_match(msg) { + let label = msg.payload.label, + sender = msg.payload.sender + + while (true) { + let index = this.mbox.findIndex(m => m.label == label && m.sender == sender) + while (index < 0) { + await sleep(1) + index = this.mbox.findIndex(m => m.label == label && m.sender == sender) + } + return this.mbox.splice(index, 1)[0] + } + } + + on_close() { + delete this.mbox + this.sock.close() + } + + async dispatch(msg) { + switch (msg.label) { + case "put": + this.on_put(msg) + break + case "get": + this.sock.send(await this.on_get()) + break + case "match": + this.sock.send(await this.on_match(msg)) + break + case "close": + this.on_close() + break + case "length": + this.sock.send(this.mbox.length) + } + } +} + + +class Mailbox { + constructor() { + let addr = `inproc://${uuidv4()}` + + this.sock = new Socket("pair") + this.sock.bind(addr) + + this.worker = new MailboxWorker(addr) + } + + put(msg) { + this.sock.send(new Msg("put", null, msg)) + } + + get() { + let request = new Promise((resolve, reject) => { + this.sock.onmessage = msg => resolve(msg) + this.sock.send(new Msg("get", null, null)) + }) + + return request + } + + match(label, sender) { + let request = new Promise((resolve, reject) => { + this.sock.onmessage = msg => resolve(msg) + this.sock.send(new Msg("match", null, {label:label, sender:sender})) + }) + + return request + } + + close() { + this.sock.send(new Msg("close", null, null)) + this.sock.close() + } + + isempty() { + return new Promise((resolve, reject) => { + this.sock.onmessage = msg => resolve(msg == 0) + this.sock.send(new Msg("length", null, null)) + }) + } +} + +module.exports = Mailbox + + diff --git a/node/msg.js b/node/msg.js new file mode 100644 index 0000000..a0401d1 --- /dev/null +++ b/node/msg.js @@ -0,0 +1,9 @@ +class Msg { + constructor(label, sender, payload) { + this.label = label + this.sender = sender + this.payload = payload + } +} + +module.exports = Msg \ No newline at end of file diff --git a/node/node_modules/.bin/uuid b/node/node_modules/.bin/uuid new file mode 120000 index 0000000..b3e45bc --- /dev/null +++ b/node/node_modules/.bin/uuid @@ -0,0 +1 @@ +../uuid/bin/uuid \ No newline at end of file diff --git a/node/node_modules/bindings/README.md b/node/node_modules/bindings/README.md new file mode 100644 index 0000000..585cf51 --- /dev/null +++ b/node/node_modules/bindings/README.md @@ -0,0 +1,97 @@ +node-bindings +============= +### Helper module for loading your native module's .node file + +This is a helper module for authors of Node.js native addon modules. +It is basically the "swiss army knife" of `require()`ing your native module's +`.node` file. + +Throughout the course of Node's native addon history, addons have ended up being +compiled in a variety of different places, depending on which build tool and which +version of node was used. To make matters worse, now the _gyp_ build tool can +produce either a _Release_ or _Debug_ build, each being built into different +locations. + +This module checks _all_ the possible locations that a native addon would be built +at, and returns the first one that loads successfully. + + +Installation +------------ + +Install with `npm`: + +``` bash +$ npm install bindings +``` + +Or add it to the `"dependencies"` section of your _package.json_ file. + + +Example +------- + +`require()`ing the proper bindings file for the current node version, platform +and architecture is as simple as: + +``` js +var bindings = require('bindings')('binding.node') + +// Use your bindings defined in your C files +bindings.your_c_function() +``` + + +Nice Error Output +----------------- + +When the `.node` file could not be loaded, `node-bindings` throws an Error with +a nice error message telling you exactly what was tried. You can also check the +`err.tries` Array property. + +``` +Error: Could not load the bindings file. Tried: + → /Users/nrajlich/ref/build/binding.node + → /Users/nrajlich/ref/build/Debug/binding.node + → /Users/nrajlich/ref/build/Release/binding.node + → /Users/nrajlich/ref/out/Debug/binding.node + → /Users/nrajlich/ref/Debug/binding.node + → /Users/nrajlich/ref/out/Release/binding.node + → /Users/nrajlich/ref/Release/binding.node + → /Users/nrajlich/ref/build/default/binding.node + → /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node + at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13) + at Object. (/Users/nrajlich/ref/lib/ref.js:5:47) + at Module._compile (module.js:449:26) + at Object.Module._extensions..js (module.js:467:10) + at Module.load (module.js:356:32) + at Function.Module._load (module.js:312:12) + ... +``` + + +License +------- + +(The MIT License) + +Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node/node_modules/bindings/bindings.js b/node/node_modules/bindings/bindings.js new file mode 100644 index 0000000..93dcf85 --- /dev/null +++ b/node/node_modules/bindings/bindings.js @@ -0,0 +1,166 @@ + +/** + * Module dependencies. + */ + +var fs = require('fs') + , path = require('path') + , join = path.join + , dirname = path.dirname + , exists = fs.existsSync || path.existsSync + , defaults = { + arrow: process.env.NODE_BINDINGS_ARROW || ' → ' + , compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled' + , platform: process.platform + , arch: process.arch + , version: process.versions.node + , bindings: 'bindings.node' + , try: [ + // node-gyp's linked version in the "build" dir + [ 'module_root', 'build', 'bindings' ] + // node-waf and gyp_addon (a.k.a node-gyp) + , [ 'module_root', 'build', 'Debug', 'bindings' ] + , [ 'module_root', 'build', 'Release', 'bindings' ] + // Debug files, for development (legacy behavior, remove for node v0.9) + , [ 'module_root', 'out', 'Debug', 'bindings' ] + , [ 'module_root', 'Debug', 'bindings' ] + // Release files, but manually compiled (legacy behavior, remove for node v0.9) + , [ 'module_root', 'out', 'Release', 'bindings' ] + , [ 'module_root', 'Release', 'bindings' ] + // Legacy from node-waf, node <= 0.4.x + , [ 'module_root', 'build', 'default', 'bindings' ] + // Production "Release" buildtype binary (meh...) + , [ 'module_root', 'compiled', 'version', 'platform', 'arch', 'bindings' ] + ] + } + +/** + * The main `bindings()` function loads the compiled bindings for a given module. + * It uses V8's Error API to determine the parent filename that this function is + * being invoked from, which is then used to find the root directory. + */ + +function bindings (opts) { + + // Argument surgery + if (typeof opts == 'string') { + opts = { bindings: opts } + } else if (!opts) { + opts = {} + } + opts.__proto__ = defaults + + // Get the module root + if (!opts.module_root) { + opts.module_root = exports.getRoot(exports.getFileName()) + } + + // Ensure the given bindings name ends with .node + if (path.extname(opts.bindings) != '.node') { + opts.bindings += '.node' + } + + var tries = [] + , i = 0 + , l = opts.try.length + , n + , b + , err + + for (; i::Set(uint32_t i) for pre_12 3a18f9bdce29826e0e4c217854bc476918241a58 + - Performance: Remove unneeeded nullptr checks b715ef44887931c94f0d1605b3b1a4156eebece9 + +### 2.2.0 Jan 9 2016 + + - Feature: Add Function::Call wrapper 4c157474dacf284d125c324177b45aa5dabc08c6 + - Feature: Rename GC*logueCallback to GCCallback for > 4.0 3603435109f981606d300eb88004ca101283acec + - Bugfix: Fix Global::Pass for old versions 367e82a60fbaa52716232cc89db1cc3f685d77d9 + - Bugfix: Remove weird MaybeLocal wrapping of what already is a MaybeLocal 23b4590db10c2ba66aee2338aebe9751c4cb190b + +### 2.1.0 Oct 8 2015 + + - Deprecation: Deprecate NanErrnoException in favor of ErrnoException 0af1ca4cf8b3f0f65ed31bc63a663ab3319da55c + - Feature: added helper class for accessing contents of typedarrays 17b51294c801e534479d5463697a73462d0ca555 + - Feature: [Maybe types] Add MakeMaybe(...) 48d7b53d9702b0c7a060e69ea10fea8fb48d814d + - Feature: new: allow utf16 string with length 66ac6e65c8ab9394ef588adfc59131b3b9d8347b + - Feature: Introduce SetCallHandler and SetCallAsFunctionHandler 7764a9a115d60ba10dc24d86feb0fbc9b4f75537 + - Bugfix: Enable creating Locals from Globals under Node 0.10. 9bf9b8b190821af889790fdc18ace57257e4f9ff + - Bugfix: Fix issue #462 where PropertyCallbackInfo data is not stored safely. 55f50adedd543098526c7b9f4fffd607d3f9861f + +### 2.0.9 Sep 8 2015 + + - Bugfix: EscapableHandleScope in Nan::NewBuffer for Node 0.8 and 0.10 b1654d7 + +### 2.0.8 Aug 28 2015 + + - Work around duplicate linking bug in clang 11902da + +### 2.0.7 Aug 26 2015 + + - Build: Repackage + +### 2.0.6 Aug 26 2015 + + - Bugfix: Properly handle null callback in FunctionTemplate factory 6e99cb1 + - Bugfix: Remove unused static std::map instances 525bddc + - Bugfix: Make better use of maybe versions of APIs bfba85b + - Bugfix: Fix shadowing issues with handle in ObjectWrap 0a9072d + +### 2.0.5 Aug 10 2015 + + - Bugfix: Reimplement weak callback in ObjectWrap 98d38c1 + - Bugfix: Make sure callback classes are not assignable, copyable or movable 81f9b1d + +### 2.0.4 Aug 6 2015 + + - Build: Repackage + +### 2.0.3 Aug 6 2015 + + - Bugfix: Don't use clang++ / g++ syntax extension. 231450e + +### 2.0.2 Aug 6 2015 + + - Build: Repackage + +### 2.0.1 Aug 6 2015 + + - Bugfix: Add workaround for missing REPLACE_INVALID_UTF8 60d6687 + - Bugfix: Reimplement ObjectWrap from scratch to prevent memory leaks 6484601 + - Bugfix: Fix Persistent leak in FunctionCallbackInfo and PropertyCallbackInfo 641ef5f + - Bugfix: Add missing overload for Nan::NewInstance that takes argc/argv 29450ed + +### 2.0.0 Jul 31 2015 + + - Change: Renamed identifiers with leading underscores b5932b4 + - Change: Replaced NanObjectWrapHandle with class NanObjectWrap 464f1e1 + - Change: Replace NanScope and NanEscpableScope macros with classes 47751c4 + - Change: Rename NanNewBufferHandle to NanNewBuffer 6745f99 + - Change: Rename NanBufferUse to NanNewBuffer 3e8b0a5 + - Change: Rename NanNewBuffer to NanCopyBuffer d6af78d + - Change: Remove Nan prefix from all names 72d1f67 + - Change: Update Buffer API for new upstream changes d5d3291 + - Change: Rename Scope and EscapableScope to HandleScope and EscapableHandleScope 21a7a6a + - Change: Get rid of Handles e6c0daf + - Feature: Support io.js 3 with V8 4.4 + - Feature: Introduce NanPersistent 7fed696 + - Feature: Introduce NanGlobal 4408da1 + - Feature: Added NanTryCatch 10f1ca4 + - Feature: Update for V8 v4.3 4b6404a + - Feature: Introduce NanNewOneByteString c543d32 + - Feature: Introduce namespace Nan 67ed1b1 + - Removal: Remove NanLocker and NanUnlocker dd6e401 + - Removal: Remove string converters, except NanUtf8String, which now follows the node implementation b5d00a9 + - Removal: Remove NanReturn* macros d90a25c + - Removal: Remove HasInstance e8f84fe + + +### 1.9.0 Jul 31 2015 + + - Feature: Added `NanFatalException` 81d4a2c + - Feature: Added more error types 4265f06 + - Feature: Added dereference and function call operators to NanCallback c4b2ed0 + - Feature: Added indexed GetFromPersistent and SaveToPersistent edd510c + - Feature: Added more overloads of SaveToPersistent and GetFromPersistent 8b1cef6 + - Feature: Added NanErrnoException dd87d9e + - Correctness: Prevent assign, copy, and move for classes that do not support it 1f55c59, 4b808cb, c96d9b2, fba4a29, 3357130 + - Deprecation: Deprecate `NanGetPointerSafe` and `NanSetPointerSafe` 81d4a2c + - Deprecation: Deprecate `NanBooleanOptionValue` and `NanUInt32OptionValue` 0ad254b + +### 1.8.4 Apr 26 2015 + + - Build: Repackage + +### 1.8.3 Apr 26 2015 + + - Bugfix: Include missing header 1af8648 + +### 1.8.2 Apr 23 2015 + + - Build: Repackage + +### 1.8.1 Apr 23 2015 + + - Bugfix: NanObjectWrapHandle should take a pointer 155f1d3 + +### 1.8.0 Apr 23 2015 + + - Feature: Allow primitives with NanReturnValue 2e4475e + - Feature: Added comparison operators to NanCallback 55b075e + - Feature: Backport thread local storage 15bb7fa + - Removal: Remove support for signatures with arguments 8a2069d + - Correcteness: Replaced NanObjectWrapHandle macro with function 0bc6d59 + +### 1.7.0 Feb 28 2015 + + - Feature: Made NanCallback::Call accept optional target 8d54da7 + - Feature: Support atom-shell 0.21 0b7f1bb + +### 1.6.2 Feb 6 2015 + + - Bugfix: NanEncode: fix argument type for node::Encode on io.js 2be8639 + +### 1.6.1 Jan 23 2015 + + - Build: version bump + +### 1.5.3 Jan 23 2015 + + - Build: repackage + +### 1.6.0 Jan 23 2015 + + - Deprecated `NanNewContextHandle` in favor of `NanNew` 49259af + - Support utility functions moved in newer v8 versions (Node 0.11.15, io.js 1.0) a0aa179 + - Added `NanEncode`, `NanDecodeBytes` and `NanDecodeWrite` 75e6fb9 + +### 1.5.2 Jan 23 2015 + + - Bugfix: Fix non-inline definition build error with clang++ 21d96a1, 60fadd4 + - Bugfix: Readded missing String constructors 18d828f + - Bugfix: Add overload handling NanNew(..) 5ef813b + - Bugfix: Fix uv_work_cb versioning 997e4ae + - Bugfix: Add function factory and test 4eca89c + - Bugfix: Add object template factory and test cdcb951 + - Correctness: Lifted an io.js related typedef c9490be + - Correctness: Make explicit downcasts of String lengths 00074e6 + - Windows: Limit the scope of disabled warning C4530 83d7deb + +### 1.5.1 Jan 15 2015 + + - Build: version bump + +### 1.4.3 Jan 15 2015 + + - Build: version bump + +### 1.4.2 Jan 15 2015 + + - Feature: Support io.js 0dbc5e8 + +### 1.5.0 Jan 14 2015 + + - Feature: Support io.js b003843 + - Correctness: Improved NanNew internals 9cd4f6a + - Feature: Implement progress to NanAsyncWorker 8d6a160 + +### 1.4.1 Nov 8 2014 + + - Bugfix: Handle DEBUG definition correctly + - Bugfix: Accept int as Boolean + +### 1.4.0 Nov 1 2014 + + - Feature: Added NAN_GC_CALLBACK 6a5c245 + - Performance: Removed unnecessary local handle creation 18a7243, 41fe2f8 + - Correctness: Added constness to references in NanHasInstance 02c61cd + - Warnings: Fixed spurious warnings from -Wundef and -Wshadow, 541b122, 99d8cb6 + - Windoze: Shut Visual Studio up when compiling 8d558c1 + - License: Switch to plain MIT from custom hacked MIT license 11de983 + - Build: Added test target to Makefile e232e46 + - Performance: Removed superfluous scope in NanAsyncWorker f4b7821 + - Sugar/Feature: Added NanReturnThis() and NanReturnHolder() shorthands 237a5ff, d697208 + - Feature: Added suitable overload of NanNew for v8::Integer::NewFromUnsigned b27b450 + +### 1.3.0 Aug 2 2014 + + - Added NanNew(std::string) + - Added NanNew(std::string&) + - Added NanAsciiString helper class + - Added NanUtf8String helper class + - Added NanUcs2String helper class + - Deprecated NanRawString() + - Deprecated NanCString() + - Added NanGetIsolateData(v8::Isolate *isolate) + - Added NanMakeCallback(v8::Handle target, v8::Handle func, int argc, v8::Handle* argv) + - Added NanMakeCallback(v8::Handle target, v8::Handle symbol, int argc, v8::Handle* argv) + - Added NanMakeCallback(v8::Handle target, const char* method, int argc, v8::Handle* argv) + - Added NanSetTemplate(v8::Handle templ, v8::Handle name , v8::Handle value, v8::PropertyAttribute attributes) + - Added NanSetPrototypeTemplate(v8::Local templ, v8::Handle name, v8::Handle value, v8::PropertyAttribute attributes) + - Added NanSetInstanceTemplate(v8::Local templ, const char *name, v8::Handle value) + - Added NanSetInstanceTemplate(v8::Local templ, v8::Handle name, v8::Handle value, v8::PropertyAttribute attributes) + +### 1.2.0 Jun 5 2014 + + - Add NanSetPrototypeTemplate + - Changed NAN_WEAK_CALLBACK internals, switched _NanWeakCallbackData to class, + introduced _NanWeakCallbackDispatcher + - Removed -Wno-unused-local-typedefs from test builds + - Made test builds Windows compatible ('Sleep()') + +### 1.1.2 May 28 2014 + + - Release to fix more stuff-ups in 1.1.1 + +### 1.1.1 May 28 2014 + + - Release to fix version mismatch in nan.h and lack of changelog entry for 1.1.0 + +### 1.1.0 May 25 2014 + + - Remove nan_isolate, use v8::Isolate::GetCurrent() internally instead + - Additional explicit overloads for NanNew(): (char*,int), (uint8_t*[,int]), + (uint16_t*[,int), double, int, unsigned int, bool, v8::String::ExternalStringResource*, + v8::String::ExternalAsciiStringResource* + - Deprecate NanSymbol() + - Added SetErrorMessage() and ErrorMessage() to NanAsyncWorker + +### 1.0.0 May 4 2014 + + - Heavy API changes for V8 3.25 / Node 0.11.13 + - Use cpplint.py + - Removed NanInitPersistent + - Removed NanPersistentToLocal + - Removed NanFromV8String + - Removed NanMakeWeak + - Removed NanNewLocal + - Removed NAN_WEAK_CALLBACK_OBJECT + - Removed NAN_WEAK_CALLBACK_DATA + - Introduce NanNew, replaces NanNewLocal, NanPersistentToLocal, adds many overloaded typed versions + - Introduce NanUndefined, NanNull, NanTrue and NanFalse + - Introduce NanEscapableScope and NanEscapeScope + - Introduce NanMakeWeakPersistent (requires a special callback to work on both old and new node) + - Introduce NanMakeCallback for node::MakeCallback + - Introduce NanSetTemplate + - Introduce NanGetCurrentContext + - Introduce NanCompileScript and NanRunScript + - Introduce NanAdjustExternalMemory + - Introduce NanAddGCEpilogueCallback, NanAddGCPrologueCallback, NanRemoveGCEpilogueCallback, NanRemoveGCPrologueCallback + - Introduce NanGetHeapStatistics + - Rename NanAsyncWorker#SavePersistent() to SaveToPersistent() + +### 0.8.0 Jan 9 2014 + + - NanDispose -> NanDisposePersistent, deprecate NanDispose + - Extract _NAN_*_RETURN_TYPE, pull up NAN_*() + +### 0.7.1 Jan 9 2014 + + - Fixes to work against debug builds of Node + - Safer NanPersistentToLocal (avoid reinterpret_cast) + - Speed up common NanRawString case by only extracting flattened string when necessary + +### 0.7.0 Dec 17 2013 + + - New no-arg form of NanCallback() constructor. + - NanCallback#Call takes Handle rather than Local + - Removed deprecated NanCallback#Run method, use NanCallback#Call instead + - Split off _NAN_*_ARGS_TYPE from _NAN_*_ARGS + - Restore (unofficial) Node 0.6 compatibility at NanCallback#Call() + - Introduce NanRawString() for char* (or appropriate void*) from v8::String + (replacement for NanFromV8String) + - Introduce NanCString() for null-terminated char* from v8::String + +### 0.6.0 Nov 21 2013 + + - Introduce NanNewLocal(v8::Handle value) for use in place of + v8::Local::New(...) since v8 started requiring isolate in Node 0.11.9 + +### 0.5.2 Nov 16 2013 + + - Convert SavePersistent and GetFromPersistent in NanAsyncWorker from protected and public + +### 0.5.1 Nov 12 2013 + + - Use node::MakeCallback() instead of direct v8::Function::Call() + +### 0.5.0 Nov 11 2013 + + - Added @TooTallNate as collaborator + - New, much simpler, "include_dirs" for binding.gyp + - Added full range of NAN_INDEX_* macros to match NAN_PROPERTY_* macros + +### 0.4.4 Nov 2 2013 + + - Isolate argument from v8::Persistent::MakeWeak removed for 0.11.8+ + +### 0.4.3 Nov 2 2013 + + - Include node_object_wrap.h, removed from node.h for Node 0.11.8. + +### 0.4.2 Nov 2 2013 + + - Handle deprecation of v8::Persistent::Dispose(v8::Isolate* isolate)) for + Node 0.11.8 release. + +### 0.4.1 Sep 16 2013 + + - Added explicit `#include ` as it was removed from node.h for v0.11.8 + +### 0.4.0 Sep 2 2013 + + - Added NAN_INLINE and NAN_DEPRECATED and made use of them + - Added NanError, NanTypeError and NanRangeError + - Cleaned up code + +### 0.3.2 Aug 30 2013 + + - Fix missing scope declaration in GetFromPersistent() and SaveToPersistent + in NanAsyncWorker + +### 0.3.1 Aug 20 2013 + + - fix "not all control paths return a value" compile warning on some platforms + +### 0.3.0 Aug 19 2013 + + - Made NAN work with NPM + - Lots of fixes to NanFromV8String, pulling in features from new Node core + - Changed node::encoding to Nan::Encoding in NanFromV8String to unify the API + - Added optional error number argument for NanThrowError() + - Added NanInitPersistent() + - Added NanReturnNull() and NanReturnEmptyString() + - Added NanLocker and NanUnlocker + - Added missing scopes + - Made sure to clear disposed Persistent handles + - Changed NanAsyncWorker to allocate error messages on the heap + - Changed NanThrowError(Local) to NanThrowError(Handle) + - Fixed leak in NanAsyncWorker when errmsg is used + +### 0.2.2 Aug 5 2013 + + - Fixed usage of undefined variable with node::BASE64 in NanFromV8String() + +### 0.2.1 Aug 5 2013 + + - Fixed 0.8 breakage, node::BUFFER encoding type not available in 0.8 for + NanFromV8String() + +### 0.2.0 Aug 5 2013 + + - Added NAN_PROPERTY_GETTER, NAN_PROPERTY_SETTER, NAN_PROPERTY_ENUMERATOR, + NAN_PROPERTY_DELETER, NAN_PROPERTY_QUERY + - Extracted _NAN_METHOD_ARGS, _NAN_GETTER_ARGS, _NAN_SETTER_ARGS, + _NAN_PROPERTY_GETTER_ARGS, _NAN_PROPERTY_SETTER_ARGS, + _NAN_PROPERTY_ENUMERATOR_ARGS, _NAN_PROPERTY_DELETER_ARGS, + _NAN_PROPERTY_QUERY_ARGS + - Added NanGetInternalFieldPointer, NanSetInternalFieldPointer + - Added NAN_WEAK_CALLBACK, NAN_WEAK_CALLBACK_OBJECT, + NAN_WEAK_CALLBACK_DATA, NanMakeWeak + - Renamed THROW_ERROR to _NAN_THROW_ERROR + - Added NanNewBufferHandle(char*, size_t, node::smalloc::FreeCallback, void*) + - Added NanBufferUse(char*, uint32_t) + - Added NanNewContextHandle(v8::ExtensionConfiguration*, + v8::Handle, v8::Handle) + - Fixed broken NanCallback#GetFunction() + - Added optional encoding and size arguments to NanFromV8String() + - Added NanGetPointerSafe() and NanSetPointerSafe() + - Added initial test suite (to be expanded) + - Allow NanUInt32OptionValue to convert any Number object + +### 0.1.0 Jul 21 2013 + + - Added `NAN_GETTER`, `NAN_SETTER` + - Added `NanThrowError` with single Local argument + - Added `NanNewBufferHandle` with single uint32_t argument + - Added `NanHasInstance(Persistent&, Handle)` + - Added `Local NanCallback#GetFunction()` + - Added `NanCallback#Call(int, Local[])` + - Deprecated `NanCallback#Run(int, Local[])` in favour of Call diff --git a/node/node_modules/nan/LICENSE.md b/node/node_modules/nan/LICENSE.md new file mode 100644 index 0000000..e4fc412 --- /dev/null +++ b/node/node_modules/nan/LICENSE.md @@ -0,0 +1,13 @@ +The MIT License (MIT) +===================== + +Copyright (c) 2016 NAN contributors +----------------------------------- + +*NAN contributors listed at * + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node/node_modules/nan/README.md b/node/node_modules/nan/README.md new file mode 100644 index 0000000..7f163b6 --- /dev/null +++ b/node/node_modules/nan/README.md @@ -0,0 +1,403 @@ +Native Abstractions for Node.js +=============================== + +**A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10, 0.12, 1, 4, 5 and 6.** + +***Current version: 2.4.0*** + +*(See [CHANGELOG.md](https://github.com/nodejs/nan/blob/master/CHANGELOG.md) for complete ChangeLog)* + +[![NPM](https://nodei.co/npm/nan.png?downloads=true&downloadRank=true)](https://nodei.co/npm/nan/) [![NPM](https://nodei.co/npm-dl/nan.png?months=6&height=3)](https://nodei.co/npm/nan/) + +[![Build Status](https://api.travis-ci.org/nodejs/nan.svg?branch=master)](http://travis-ci.org/nodejs/nan) +[![Build status](https://ci.appveyor.com/api/projects/status/kh73pbm9dsju7fgh)](https://ci.appveyor.com/project/RodVagg/nan) + +Thanks to the crazy changes in V8 (and some in Node core), keeping native addons compiling happily across versions, particularly 0.10 to 0.12 to 4.0, is a minor nightmare. The goal of this project is to store all logic necessary to develop native Node.js addons without having to inspect `NODE_MODULE_VERSION` and get yourself into a macro-tangle. + +This project also contains some helper utilities that make addon development a bit more pleasant. + + * **[News & Updates](#news)** + * **[Usage](#usage)** + * **[Example](#example)** + * **[API](#api)** + * **[Tests](#tests)** + * **[Governance & Contributing](#governance)** + + +## News & Updates + + +## Usage + +Simply add **NAN** as a dependency in the *package.json* of your Node addon: + +``` bash +$ npm install --save nan +``` + +Pull in the path to **NAN** in your *binding.gyp* so that you can use `#include ` in your *.cpp* files: + +``` python +"include_dirs" : [ + "` when compiling your addon. + + +## Example + +Just getting started with Nan? Take a look at the **[Node Add-on Examples](https://github.com/nodejs/node-addon-examples)**. + +Refer to a [quick-start **Nan** Boilerplate](https://github.com/fcanas/node-native-boilerplate) for a ready-to-go project that utilizes basic Nan functionality. + +For a simpler example, see the **[async pi estimation example](https://github.com/nodejs/nan/tree/master/examples/async_pi_estimate)** in the examples directory for full code and an explanation of what this Monte Carlo Pi estimation example does. Below are just some parts of the full example that illustrate the use of **NAN**. + +Yet another example is **[nan-example-eol](https://github.com/CodeCharmLtd/nan-example-eol)**. It shows newline detection implemented as a native addon. + +Also take a look at our comprehensive **[C++ test suite](https://github.com/nodejs/nan/tree/master/test/cpp)** which has a plehora of code snippets for your pasting pleasure. + + +## API + +Additional to the NAN documentation below, please consult: + +* [The V8 Getting Started Guide](https://developers.google.com/v8/get_started) +* [The V8 Embedders Guide](https://developers.google.com/v8/embed) +* [V8 API Documentation](http://v8docs.nodesource.com/) +* [Node Add-on Documentation](https://nodejs.org/api/addons.html) + + + +### JavaScript-accessible methods + +A _template_ is a blueprint for JavaScript functions and objects in a context. You can use a template to wrap C++ functions and data structures within JavaScript objects so that they can be manipulated from JavaScript. See the V8 Embedders Guide section on [Templates](https://developers.google.com/v8/embed#templates) for further information. + +In order to expose functionality to JavaScript via a template, you must provide it to V8 in a form that it understands. Across the versions of V8 supported by NAN, JavaScript-accessible method signatures vary widely, NAN fully abstracts method declaration and provides you with an interface that is similar to the most recent V8 API but is backward-compatible with older versions that still use the now-deceased `v8::Argument` type. + +* **Method argument types** + - Nan::FunctionCallbackInfo + - Nan::PropertyCallbackInfo + - Nan::ReturnValue +* **Method declarations** + - Method declaration + - Getter declaration + - Setter declaration + - Property getter declaration + - Property setter declaration + - Property enumerator declaration + - Property deleter declaration + - Property query declaration + - Index getter declaration + - Index setter declaration + - Index enumerator declaration + - Index deleter declaration + - Index query declaration +* Method and template helpers + - Nan::SetMethod() + - Nan::SetPrototypeMethod() + - Nan::SetAccessor() + - Nan::SetNamedPropertyHandler() + - Nan::SetIndexedPropertyHandler() + - Nan::SetTemplate() + - Nan::SetPrototypeTemplate() + - Nan::SetInstanceTemplate() + - Nan::SetCallHandler() + - Nan::SetCallAsFunctionHandler() + +### Scopes + +A _local handle_ is a pointer to an object. All V8 objects are accessed using handles, they are necessary because of the way the V8 garbage collector works. + +A handle scope can be thought of as a container for any number of handles. When you've finished with your handles, instead of deleting each one individually you can simply delete their scope. + +The creation of `HandleScope` objects is different across the supported versions of V8. Therefore, NAN provides its own implementations that can be used safely across these. + + - Nan::HandleScope + - Nan::EscapableHandleScope + +Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://developers.google.com/v8/embed#handles). + +### Persistent references + +An object reference that is independent of any `HandleScope` is a _persistent_ reference. Where a `Local` handle only lives as long as the `HandleScope` in which it was allocated, a `Persistent` handle remains valid until it is explicitly disposed. + +Due to the evolution of the V8 API, it is necessary for NAN to provide a wrapper implementation of the `Persistent` classes to supply compatibility across the V8 versions supported. + + - Nan::PersistentBase & v8::PersistentBase + - Nan::NonCopyablePersistentTraits & v8::NonCopyablePersistentTraits + - Nan::CopyablePersistentTraits & v8::CopyablePersistentTraits + - Nan::Persistent + - Nan::Global + - Nan::WeakCallbackInfo + - Nan::WeakCallbackType + +Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://developers.google.com/v8/embed#handles). + +### New + +NAN provides a `Nan::New()` helper for the creation of new JavaScript objects in a way that's compatible across the supported versions of V8. + + - Nan::New() + - Nan::Undefined() + - Nan::Null() + - Nan::True() + - Nan::False() + - Nan::EmptyString() + + +### Converters + +NAN contains functions that convert `v8::Value`s to other `v8::Value` types and native types. Since type conversion is not guaranteed to succeed, they return `Nan::Maybe` types. These converters can be used in place of `value->ToX()` and `value->XValue()` (where `X` is one of the types, e.g. `Boolean`) in a way that provides a consistent interface across V8 versions. Newer versions of V8 use the new `v8::Maybe` and `v8::MaybeLocal` types for these conversions, older versions don't have this functionality so it is provided by NAN. + + - Nan::To() + +### Maybe Types + +The `Nan::MaybeLocal` and `Nan::Maybe` types are monads that encapsulate `v8::Local` handles that _may be empty_. + +* **Maybe Types** + - Nan::MaybeLocal + - Nan::Maybe + - Nan::Nothing + - Nan::Just +* **Maybe Helpers** + - Nan::Call() + - Nan::ToDetailString() + - Nan::ToArrayIndex() + - Nan::Equals() + - Nan::NewInstance() + - Nan::GetFunction() + - Nan::Set() + - Nan::ForceSet() + - Nan::Get() + - Nan::GetPropertyAttributes() + - Nan::Has() + - Nan::Delete() + - Nan::GetPropertyNames() + - Nan::GetOwnPropertyNames() + - Nan::SetPrototype() + - Nan::ObjectProtoToString() + - Nan::HasOwnProperty() + - Nan::HasRealNamedProperty() + - Nan::HasRealIndexedProperty() + - Nan::HasRealNamedCallbackProperty() + - Nan::GetRealNamedPropertyInPrototypeChain() + - Nan::GetRealNamedProperty() + - Nan::CallAsFunction() + - Nan::CallAsConstructor() + - Nan::GetSourceLine() + - Nan::GetLineNumber() + - Nan::GetStartColumn() + - Nan::GetEndColumn() + - Nan::CloneElementAt() + - Nan::MakeMaybe() + +### Script + +NAN provides a `v8::Script` helpers as the API has changed over the supported versions of V8. + + - Nan::CompileScript() + - Nan::RunScript() + + +### Errors + +NAN includes helpers for creating, throwing and catching Errors as much of this functionality varies across the supported versions of V8 and must be abstracted. + +Note that an Error object is simply a specialized form of `v8::Value`. + +Also consult the V8 Embedders Guide section on [Exceptions](https://developers.google.com/v8/embed#exceptions) for more information. + + - Nan::Error() + - Nan::RangeError() + - Nan::ReferenceError() + - Nan::SyntaxError() + - Nan::TypeError() + - Nan::ThrowError() + - Nan::ThrowRangeError() + - Nan::ThrowReferenceError() + - Nan::ThrowSyntaxError() + - Nan::ThrowTypeError() + - Nan::FatalException() + - Nan::ErrnoException() + - Nan::TryCatch + + +### Buffers + +NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility. + + - Nan::NewBuffer() + - Nan::CopyBuffer() + - Nan::FreeCallback() + +### Nan::Callback + +`Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution. + + - Nan::Callback + +### Asynchronous work helpers + +`Nan::AsyncWorker` and `Nan::AsyncProgressWorker` are helper classes that make working with asynchronous code easier. + + - Nan::AsyncWorker + - Nan::AsyncProgressWorkerBase & Nan::AsyncProgressWorker + - Nan::AsyncQueueWorker + +### Strings & Bytes + +Miscellaneous string & byte encoding and decoding functionality provided for compatibility across supported versions of V8 and Node. Implemented by NAN to ensure that all encoding types are supported, even for older versions of Node where they are missing. + + - Nan::Encoding + - Nan::Encode() + - Nan::DecodeBytes() + - Nan::DecodeWrite() + + +### Object Wrappers + +The `ObjectWrap` class can be used to make wrapped C++ objects and a factory of wrapped objects. + + - Nan::ObjectWrap + + +### V8 internals + +The hooks to access V8 internals—including GC and statistics—are different across the supported versions of V8, therefore NAN provides its own hooks that call the appropriate V8 methods. + + - NAN_GC_CALLBACK() + - Nan::AddGCEpilogueCallback() + - Nan::RemoveGCEpilogueCallback() + - Nan::AddGCPrologueCallback() + - Nan::RemoveGCPrologueCallback() + - Nan::GetHeapStatistics() + - Nan::SetCounterFunction() + - Nan::SetCreateHistogramFunction() + - Nan::SetAddHistogramSampleFunction() + - Nan::IdleNotification() + - Nan::LowMemoryNotification() + - Nan::ContextDisposedNotification() + - Nan::GetInternalFieldPointer() + - Nan::SetInternalFieldPointer() + - Nan::AdjustExternalMemory() + + +### Miscellaneous V8 Helpers + + - Nan::Utf8String + - Nan::GetCurrentContext() + - Nan::SetIsolateData() + - Nan::GetIsolateData() + - Nan::TypedArrayContents + + +### Miscellaneous Node Helpers + + - Nan::MakeCallback() + - NAN_MODULE_INIT() + - Nan::Export() + + + + + +### Tests + +To run the NAN tests do: + +``` sh +npm install +npm run-script rebuild-tests +npm test +``` + +Or just: + +``` sh +npm install +make test +``` + + +## Governance & Contributing + +NAN is governed by the [io.js](https://iojs.org/) Addon API Working Group + +### Addon API Working Group (WG) + +The NAN project is jointly governed by a Working Group which is responsible for high-level guidance of the project. + +Members of the WG are also known as Collaborators, there is no distinction between the two, unlike other io.js projects. + +The WG has final authority over this project including: + +* Technical direction +* Project governance and process (including this policy) +* Contribution policy +* GitHub repository hosting +* Maintaining the list of additional Collaborators + +For the current list of WG members, see the project [README.md](./README.md#collaborators). + +Individuals making significant and valuable contributions are made members of the WG and given commit-access to the project. These individuals are identified by the WG and their addition to the WG is discussed via GitHub and requires unanimous consensus amongst those WG members participating in the discussion with a quorum of 50% of WG members required for acceptance of the vote. + +_Note:_ If you make a significant contribution and are not considered for commit-access log an issue or contact a WG member directly. + +For the current list of WG members / Collaborators, see the project [README.md](./README.md#collaborators). + +### Consensus Seeking Process + +The WG follows a [Consensus Seeking](http://en.wikipedia.org/wiki/Consensus-seeking_decision-making) decision making model. + +Modifications of the contents of the NAN repository are made on a collaborative basis. Anybody with a GitHub account may propose a modification via pull request and it will be considered by the WG. All pull requests must be reviewed and accepted by a WG member with sufficient expertise who is able to take full responsibility for the change. In the case of pull requests proposed by an existing WG member, an additional WG member is required for sign-off. Consensus should be sought if additional WG members participate and there is disagreement around a particular modification. + +If a change proposal cannot reach a consensus, a WG member can call for a vote amongst the members of the WG. Simple majority wins. + + +## Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +* (a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +* (b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +* (c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +* (d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. + + +### WG Members / Collaborators + + + + + + + + + +
Rod VaggGitHub/rvaggTwitter/@rvagg
Benjamin ByholmGitHub/kkoopa-
Trevor NorrisGitHub/trevnorrisTwitter/@trevnorris
Nathan RajlichGitHub/TooTallNateTwitter/@TooTallNate
Brett LawsonGitHub/brett19Twitter/@brett19x
Ben NoordhuisGitHub/bnoordhuisTwitter/@bnoordhuis
David SiegelGitHub/agnat-
+ +## Licence & copyright + +Copyright (c) 2016 NAN WG Members / Collaborators (listed above). + +Native Abstractions for Node.js is licensed under an MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details. diff --git a/node/node_modules/nan/doc/asyncworker.md b/node/node_modules/nan/doc/asyncworker.md new file mode 100644 index 0000000..6bc4cce --- /dev/null +++ b/node/node_modules/nan/doc/asyncworker.md @@ -0,0 +1,103 @@ +## Asynchronous work helpers + +`Nan::AsyncWorker` and `Nan::AsyncProgressWorker` are helper classes that make working with asynchronous code easier. + + - Nan::AsyncWorker + - Nan::AsyncProgressWorker + - Nan::AsyncQueueWorker + + +### Nan::AsyncWorker + +`Nan::AsyncWorker` is an _abstract_ class that you can subclass to have much of the annoying asynchronous queuing and handling taken care of for you. It can even store arbitrary V8 objects for you and have them persist while the asynchronous work is in progress. + +Definition: + +```c++ +class AsyncWorker { + public: + explicit AsyncWorker(Callback *callback_); + + virtual ~AsyncWorker(); + + virtual void WorkComplete(); + + void SaveToPersistent(const char *key, const v8::Local &value); + + void SaveToPersistent(const v8::Local &key, + const v8::Local &value); + + void SaveToPersistent(uint32_t index, + const v8::Local &value); + + v8::Local GetFromPersistent(const char *key) const; + + v8::Local GetFromPersistent(const v8::Local &key) const; + + v8::Local GetFromPersistent(uint32_t index) const; + + virtual void Execute() = 0; + + uv_work_t request; + + virtual void Destroy(); + + protected: + Persistent persistentHandle; + + Callback *callback; + + virtual void HandleOKCallback(); + + virtual void HandleErrorCallback(); + + void SetErrorMessage(const char *msg); + + const char* ErrorMessage(); +}; +``` + + +### Nan::AsyncProgressWorkerBase & Nan::AsyncProgressWorker + +`Nan::AsyncProgressWorkerBase` is an _abstract_ class template that extends `Nan::AsyncWorker` and adds additional progress reporting callbacks that can be used during the asynchronous work execution to provide progress data back to JavaScript. + +Previously the definiton of `Nan::AsyncProgressWorker` only allowed sending `const char` data. Now extending `Nan::AsyncProgressWorker` will yield an instance of the implicit `Nan::AsyncProgressWorkerBase` template with type `` for compatibility. + +Definition: + +```c++ +template +class AsyncProgressWorkerBase : public AsyncWorker { + public: + explicit AsyncProgressWorker(Callback *callback_); + + virtual ~AsyncProgressWorker(); + + void WorkProgress(); + + class ExecutionProgress { + public: + void Signal() const; + void Send(const T* data, size_t size) const; + }; + + virtual void Execute(const ExecutionProgress& progress) = 0; + + virtual void HandleProgressCallback(const T *data, size_t size) = 0; + + virtual void Destroy(); + +typedef AsyncProgressWorkerBase AsyncProgressWorker; +``` + + +### Nan::AsyncQueueWorker + +`Nan::AsyncQueueWorker` will run a `Nan::AsyncWorker` asynchronously via libuv. Both the `execute` and `after_work` steps are taken care of for you. Most of the logic for this is embedded in `Nan::AsyncWorker`. + +Definition: + +```c++ +void AsyncQueueWorker(AsyncWorker *); +``` diff --git a/node/node_modules/nan/doc/buffers.md b/node/node_modules/nan/doc/buffers.md new file mode 100644 index 0000000..8d8d25c --- /dev/null +++ b/node/node_modules/nan/doc/buffers.md @@ -0,0 +1,54 @@ +## Buffers + +NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility. + + - Nan::NewBuffer() + - Nan::CopyBuffer() + - Nan::FreeCallback() + + +### Nan::NewBuffer() + +Allocate a new `node::Buffer` object with the specified size and optional data. Calls `node::Buffer::New()`. + +Note that when creating a `Buffer` using `Nan::NewBuffer()` and an existing `char*`, it is assumed that the ownership of the pointer is being transferred to the new `Buffer` for management. +When a `node::Buffer` instance is garbage collected and a `FreeCallback` has not been specified, `data` will be disposed of via a call to `free()`. +You _must not_ free the memory space manually once you have created a `Buffer` in this way. + +Signature: + +```c++ +Nan::MaybeLocal Nan::NewBuffer(uint32_t size) +Nan::MaybeLocal Nan::NewBuffer(char* data, uint32_t size) +Nan::MaybeLocal Nan::NewBuffer(char *data, + size_t length, + Nan::FreeCallback callback, + void *hint) +``` + + + +### Nan::CopyBuffer() + +Similar to [`Nan::NewBuffer()`](#api_nan_new_buffer) except that an implicit memcpy will occur within Node. Calls `node::Buffer::Copy()`. + +Management of the `char*` is left to the user, you should manually free the memory space if necessary as the new `Buffer` will have its own copy. + +Signature: + +```c++ +Nan::MaybeLocal Nan::CopyBuffer(const char *data, uint32_t size) +``` + + + +### Nan::FreeCallback() + +A free callback that can be provided to [`Nan::NewBuffer()`](#api_nan_new_buffer). +The supplied callback will be invoked when the `Buffer` undergoes garbage collection. + +Signature: + +```c++ +typedef void (*FreeCallback)(char *data, void *hint); +``` diff --git a/node/node_modules/nan/doc/callback.md b/node/node_modules/nan/doc/callback.md new file mode 100644 index 0000000..46de1d7 --- /dev/null +++ b/node/node_modules/nan/doc/callback.md @@ -0,0 +1,56 @@ +## Nan::Callback + +`Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution. + + - Nan::Callback + + +### Nan::Callback + +```c++ +class Callback { + public: + Callback(); + + explicit Callback(const v8::Local &fn); + + ~Callback(); + + bool operator==(const Callback &other) const; + + bool operator!=(const Callback &other) const; + + v8::Local operator*() const; + + v8::Local operator()(v8::Local target, + int argc = 0, + v8::Local argv[] = 0) const; + + v8::Local operator()(int argc = 0, + v8::Local argv[] = 0) const; + + void SetFunction(const v8::Local &fn); + + v8::Local GetFunction() const; + + bool IsEmpty() const; + + void Reset(const v8::Local &fn); + + void Reset(); + + v8::Local Call(v8::Local target, + int argc, + v8::Local argv[]) const; + + v8::Local Call(int argc, v8::Local argv[]) const; +}; +``` + +Example usage: + +```c++ +v8::Local function; +Nan::Callback callback(function); +callback.Call(0, 0); +``` diff --git a/node/node_modules/nan/doc/converters.md b/node/node_modules/nan/doc/converters.md new file mode 100644 index 0000000..d20861b --- /dev/null +++ b/node/node_modules/nan/doc/converters.md @@ -0,0 +1,41 @@ +## Converters + +NAN contains functions that convert `v8::Value`s to other `v8::Value` types and native types. Since type conversion is not guaranteed to succeed, they return `Nan::Maybe` types. These converters can be used in place of `value->ToX()` and `value->XValue()` (where `X` is one of the types, e.g. `Boolean`) in a way that provides a consistent interface across V8 versions. Newer versions of V8 use the new `v8::Maybe` and `v8::MaybeLocal` types for these conversions, older versions don't have this functionality so it is provided by NAN. + + - Nan::To() + + +### Nan::To() + +Converts a `v8::Local` to a different subtype of `v8::Value` or to a native data type. Returns a `Nan::MaybeLocal<>` or a `Nan::Maybe<>` accordingly. + +See [maybe_types.md](./maybe_types.md) for more information on `Nan::Maybe` types. + +Signatures: + +```c++ +// V8 types +Nan::MaybeLocal Nan::To(v8::Local val); +Nan::MaybeLocal Nan::To(v8::Local val); +Nan::MaybeLocal Nan::To(v8::Local val); +Nan::MaybeLocal Nan::To(v8::Local val); +Nan::MaybeLocal Nan::To(v8::Local val); +Nan::MaybeLocal Nan::To(v8::Local val); +Nan::MaybeLocal Nan::To(v8::Local val); + +// Native types +Nan::Maybe Nan::To(v8::Local val); +Nan::Maybe Nan::To(v8::Local val); +Nan::Maybe Nan::To(v8::Local val); +Nan::Maybe Nan::To(v8::Local val); +Nan::Maybe Nan::To(v8::Local val); +``` + +### Example + +```c++ +v8::Local val; +Nan::MaybeLocal str = Nan::To(val); +Nan::Maybe d = Nan::To(val); +``` + diff --git a/node/node_modules/nan/doc/errors.md b/node/node_modules/nan/doc/errors.md new file mode 100644 index 0000000..aac6e08 --- /dev/null +++ b/node/node_modules/nan/doc/errors.md @@ -0,0 +1,226 @@ +## Errors + +NAN includes helpers for creating, throwing and catching Errors as much of this functionality varies across the supported versions of V8 and must be abstracted. + +Note that an Error object is simply a specialized form of `v8::Value`. + +Also consult the V8 Embedders Guide section on [Exceptions](https://developers.google.com/v8/embed#exceptions) for more information. + + - Nan::Error() + - Nan::RangeError() + - Nan::ReferenceError() + - Nan::SyntaxError() + - Nan::TypeError() + - Nan::ThrowError() + - Nan::ThrowRangeError() + - Nan::ThrowReferenceError() + - Nan::ThrowSyntaxError() + - Nan::ThrowTypeError() + - Nan::FatalException() + - Nan::ErrnoException() + - Nan::TryCatch + + + +### Nan::Error() + +Create a new Error object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. + +Note that an Error object is simply a specialized form of `v8::Value`. + +Signature: + +```c++ +v8::Local Nan::Error(const char *msg); +v8::Local Nan::Error(v8::Local msg); +``` + + + +### Nan::RangeError() + +Create a new RangeError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. + +Note that an RangeError object is simply a specialized form of `v8::Value`. + +Signature: + +```c++ +v8::Local Nan::RangeError(const char *msg); +v8::Local Nan::RangeError(v8::Local msg); +``` + + + +### Nan::ReferenceError() + +Create a new ReferenceError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. + +Note that an ReferenceError object is simply a specialized form of `v8::Value`. + +Signature: + +```c++ +v8::Local Nan::ReferenceError(const char *msg); +v8::Local Nan::ReferenceError(v8::Local msg); +``` + + + +### Nan::SyntaxError() + +Create a new SyntaxError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. + +Note that an SyntaxError object is simply a specialized form of `v8::Value`. + +Signature: + +```c++ +v8::Local Nan::SyntaxError(const char *msg); +v8::Local Nan::SyntaxError(v8::Local msg); +``` + + + +### Nan::TypeError() + +Create a new TypeError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. + +Note that an TypeError object is simply a specialized form of `v8::Value`. + +Signature: + +```c++ +v8::Local Nan::TypeError(const char *msg); +v8::Local Nan::TypeError(v8::Local msg); +``` + + + +### Nan::ThrowError() + +Throw an Error object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new Error object will be created. + +Signature: + +```c++ +void Nan::ThrowError(const char *msg); +void Nan::ThrowError(v8::Local msg); +void Nan::ThrowError(v8::Local error); +``` + + + +### Nan::ThrowRangeError() + +Throw an RangeError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new RangeError object will be created. + +Signature: + +```c++ +void Nan::ThrowRangeError(const char *msg); +void Nan::ThrowRangeError(v8::Local msg); +void Nan::ThrowRangeError(v8::Local error); +``` + + + +### Nan::ThrowReferenceError() + +Throw an ReferenceError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new ReferenceError object will be created. + +Signature: + +```c++ +void Nan::ThrowReferenceError(const char *msg); +void Nan::ThrowReferenceError(v8::Local msg); +void Nan::ThrowReferenceError(v8::Local error); +``` + + + +### Nan::ThrowSyntaxError() + +Throw an SyntaxError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new SyntaxError object will be created. + +Signature: + +```c++ +void Nan::ThrowSyntaxError(const char *msg); +void Nan::ThrowSyntaxError(v8::Local msg); +void Nan::ThrowSyntaxError(v8::Local error); +``` + + + +### Nan::ThrowTypeError() + +Throw an TypeError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new TypeError object will be created. + +Signature: + +```c++ +void Nan::ThrowTypeError(const char *msg); +void Nan::ThrowTypeError(v8::Local msg); +void Nan::ThrowTypeError(v8::Local error); +``` + + +### Nan::FatalException() + +Replaces `node::FatalException()` which has a different API across supported versions of Node. For use with [`Nan::TryCatch`](#api_nan_try_catch). + +Signature: + +```c++ +void Nan::FatalException(const Nan::TryCatch& try_catch); +``` + + +### Nan::ErrnoException() + +Replaces `node::ErrnoException()` which has a different API across supported versions of Node. + +Signature: + +```c++ +v8::Local Nan::ErrnoException(int errorno, + const char* syscall = NULL, + const char* message = NULL, + const char* path = NULL); +``` + + + +### Nan::TryCatch + +A simple wrapper around [`v8::TryCatch`](https://v8docs.nodesource.com/io.js-3.0/d4/dc6/classv8_1_1_try_catch.html) compatible with all supported versions of V8. Can be used as a direct replacement in most cases. See also [`Nan::FatalException()`](#api_nan_fatal_exception) for an internal use compatible with `node::FatalException`. + +Signature: + +```c++ +class Nan::TryCatch { + public: + Nan::TryCatch(); + + bool HasCaught() const; + + bool CanContinue() const; + + v8::Local ReThrow(); + + v8::Local Exception() const; + + // Nan::MaybeLocal for older versions of V8 + v8::MaybeLocal StackTrace() const; + + v8::Local Message() const; + + void Reset(); + + void SetVerbose(bool value); + + void SetCaptureMessage(bool value); +}; +``` + diff --git a/node/node_modules/nan/doc/maybe_types.md b/node/node_modules/nan/doc/maybe_types.md new file mode 100644 index 0000000..9ca9cee --- /dev/null +++ b/node/node_modules/nan/doc/maybe_types.md @@ -0,0 +1,512 @@ +## Maybe Types + +The `Nan::MaybeLocal` and `Nan::Maybe` types are monads that encapsulate `v8::Local` handles that _may be empty_. + +* **Maybe Types** + - Nan::MaybeLocal + - Nan::Maybe + - Nan::Nothing + - Nan::Just +* **Maybe Helpers** + - Nan::Call() + - Nan::ToDetailString() + - Nan::ToArrayIndex() + - Nan::Equals() + - Nan::NewInstance() + - Nan::GetFunction() + - Nan::Set() + - Nan::ForceSet() + - Nan::Get() + - Nan::GetPropertyAttributes() + - Nan::Has() + - Nan::Delete() + - Nan::GetPropertyNames() + - Nan::GetOwnPropertyNames() + - Nan::SetPrototype() + - Nan::ObjectProtoToString() + - Nan::HasOwnProperty() + - Nan::HasRealNamedProperty() + - Nan::HasRealIndexedProperty() + - Nan::HasRealNamedCallbackProperty() + - Nan::GetRealNamedPropertyInPrototypeChain() + - Nan::GetRealNamedProperty() + - Nan::CallAsFunction() + - Nan::CallAsConstructor() + - Nan::GetSourceLine() + - Nan::GetLineNumber() + - Nan::GetStartColumn() + - Nan::GetEndColumn() + - Nan::CloneElementAt() + - Nan::MakeMaybe() + + +### Nan::MaybeLocal + +A `Nan::MaybeLocal` is a wrapper around [`v8::Local`](https://v8docs.nodesource.com/io.js-3.0/de/deb/classv8_1_1_local.html) that enforces a check that determines whether the `v8::Local` is empty before it can be used. + +If an API method returns a `Nan::MaybeLocal`, the API method can potentially fail either because an exception is thrown, or because an exception is pending, e.g. because a previous API call threw an exception that hasn't been caught yet, or because a `v8::TerminateExecution` exception was thrown. In that case, an empty `Nan::MaybeLocal` is returned. + +Definition: + +```c++ +template class Nan::MaybeLocal { + public: + MaybeLocal(); + + template MaybeLocal(v8::Local that); + + bool IsEmpty() const; + + template bool ToLocal(v8::Local *out); + + // Will crash if the MaybeLocal<> is empty. + v8::Local ToLocalChecked(); + + template v8::Local FromMaybe(v8::Local default_value) const; +}; +``` + +See the documentation for [`v8::MaybeLocal`](https://v8docs.nodesource.com/io.js-3.0/d8/d7d/classv8_1_1_maybe_local.html) for further details. + + +### Nan::Maybe + +A simple `Nan::Maybe` type, representing an object which may or may not have a value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html. + +If an API method returns a `Nan::Maybe<>`, the API method can potentially fail either because an exception is thrown, or because an exception is pending, e.g. because a previous API call threw an exception that hasn't been caught yet, or because a `v8::TerminateExecution` exception was thrown. In that case, a "Nothing" value is returned. + +Definition: + +```c++ +template class Nan::Maybe { + public: + bool IsNothing() const; + bool IsJust() const; + + // Will crash if the Maybe<> is nothing. + T FromJust(); + + T FromMaybe(const T& default_value); + + bool operator==(const Maybe &other); + + bool operator!=(const Maybe &other); +}; +``` + +See the documentation for [`v8::Maybe`](https://v8docs.nodesource.com/io.js-3.0/d9/d4b/classv8_1_1_maybe.html) for further details. + + +### Nan::Nothing + +Construct an empty `Nan::Maybe` type representing _nothing_. + +```c++ +template Nan::Maybe Nan::Nothing(); +``` + + +### Nan::Just + +Construct a `Nan::Maybe` type representing _just_ a value. + +```c++ +template Nan::Maybe Nan::Just(const T &t); +``` + + +### Nan::Call() + +A helper method for calling [`v8::Function#Call()`](https://v8docs.nodesource.com/io.js-3.0/d5/d54/classv8_1_1_function.html#a468a89f737af0612db10132799c827c0) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::Call(v8::Local fun, v8::Local recv, int argc, v8::Local argv[]); +``` + + + +### Nan::ToDetailString() + +A helper method for calling [`v8::Value#ToDetailString()`](https://v8docs.nodesource.com/io.js-3.0/dc/d0a/classv8_1_1_value.html#a2f9770296dc2c8d274bc8cc0dca243e5) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::ToDetailString(v8::Local val); +``` + + + +### Nan::ToArrayIndex() + +A helper method for calling [`v8::Value#ToArrayIndex()`](https://v8docs.nodesource.com/io.js-3.0/dc/d0a/classv8_1_1_value.html#acc5bbef3c805ec458470c0fcd6f13493) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::ToArrayIndex(v8::Local val); +``` + + + +### Nan::Equals() + +A helper method for calling [`v8::Value#Equals()`](https://v8docs.nodesource.com/io.js-3.0/dc/d0a/classv8_1_1_value.html#a0d9616ab2de899d4e3047c30a10c9285) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::Equals(v8::Local a, v8::Local(b)); +``` + + + +### Nan::NewInstance() + +A helper method for calling [`v8::Function#NewInstance()`](https://v8docs.nodesource.com/io.js-3.0/d5/d54/classv8_1_1_function.html#a691b13f7a553069732cbacf5ac8c62ec) and [`v8::ObjectTemplate#NewInstance()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ad605a7543cfbc5dab54cdb0883d14ae4) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::NewInstance(v8::Local h); +Nan::MaybeLocal Nan::NewInstance(v8::Local h, int argc, v8::Local argv[]); +Nan::MaybeLocal Nan::NewInstance(v8::Local h); +``` + + + +### Nan::GetFunction() + +A helper method for calling [`v8::FunctionTemplate#GetFunction()`](https://v8docs.nodesource.com/io.js-3.0/d8/d83/classv8_1_1_function_template.html#a56d904662a86eca78da37d9bb0ed3705) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::GetFunction(v8::Local t); +``` + + + +### Nan::Set() + +A helper method for calling [`v8::Object#Set()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a67604ea3734f170c66026064ea808f20) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::Set(v8::Local obj, + v8::Local key, + v8::Local value) +Nan::Maybe Nan::Set(v8::Local obj, + uint32_t index, + v8::Local value); +``` + + + +### Nan::ForceSet() + +A helper method for calling [`v8::Object#ForceSet()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a796b7b682896fb64bf1872747734e836) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::ForceSet(v8::Local obj, + v8::Local key, + v8::Local value, + v8::PropertyAttribute attribs = v8::None); +``` + + + +### Nan::Get() + +A helper method for calling [`v8::Object#Get()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a2565f03e736694f6b1e1cf22a0b4eac2) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::Get(v8::Local obj, + v8::Local key); +Nan::MaybeLocal Nan::Get(v8::Local obj, uint32_t index); +``` + + + +### Nan::GetPropertyAttributes() + +A helper method for calling [`v8::Object#GetPropertyAttributes()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a9b898894da3d1db2714fd9325a54fe57) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::GetPropertyAttributes( + v8::Local obj, + v8::Local key); +``` + + + +### Nan::Has() + +A helper method for calling [`v8::Object#Has()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#ab3c3d89ea7c2f9afd08965bd7299a41d) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::Has(v8::Local obj, v8::Local key); +Nan::Maybe Nan::Has(v8::Local obj, uint32_t index); +``` + + + +### Nan::Delete() + +A helper method for calling [`v8::Object#Delete()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a2fa0f5a592582434ed1ceceff7d891ef) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::Delete(v8::Local obj, + v8::Local key); +Nan::Maybe Nan::Delete(v8::Local obj, uint32_t index); +``` + + + +### Nan::GetPropertyNames() + +A helper method for calling [`v8::Object#GetPropertyNames()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#aced885270cfd2c956367b5eedc7fbfe8) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::GetPropertyNames(v8::Local obj); +``` + + + +### Nan::GetOwnPropertyNames() + +A helper method for calling [`v8::Object#GetOwnPropertyNames()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a79a6e4d66049b9aa648ed4dfdb23e6eb) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::GetOwnPropertyNames(v8::Local obj); +``` + + + +### Nan::SetPrototype() + +A helper method for calling [`v8::Object#SetPrototype()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a442706b22fceda6e6d1f632122a9a9f4) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::SetPrototype(v8::Local obj, + v8::Local prototype); +``` + + + +### Nan::ObjectProtoToString() + +A helper method for calling [`v8::Object#ObjectProtoToString()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#ab7a92b4dcf822bef72f6c0ac6fea1f0b) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::ObjectProtoToString(v8::Local obj); +``` + + + +### Nan::HasOwnProperty() + +A helper method for calling [`v8::Object#HasOwnProperty()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#ab7b7245442ca6de1e1c145ea3fd653ff) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::HasOwnProperty(v8::Local obj, + v8::Local key); +``` + + + +### Nan::HasRealNamedProperty() + +A helper method for calling [`v8::Object#HasRealNamedProperty()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#ad8b80a59c9eb3c1e6c3cd6c84571f767) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::HasRealNamedProperty(v8::Local obj, + v8::Local key); +``` + + + +### Nan::HasRealIndexedProperty() + +A helper method for calling [`v8::Object#HasRealIndexedProperty()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#af94fc1135a5e74a2193fb72c3a1b9855) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::HasRealIndexedProperty(v8::Local obj, + uint32_t index); +``` + + + +### Nan::HasRealNamedCallbackProperty() + +A helper method for calling [`v8::Object#HasRealNamedCallbackProperty()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#af743b7ea132b89f84d34d164d0668811) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::HasRealNamedCallbackProperty( + v8::Local obj, + v8::Local key); +``` + + + +### Nan::GetRealNamedPropertyInPrototypeChain() + +A helper method for calling [`v8::Object#GetRealNamedPropertyInPrototypeChain()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a8700b1862e6b4783716964ba4d5e6172) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::GetRealNamedPropertyInPrototypeChain( + v8::Local obj, + v8::Local key); +``` + + + +### Nan::GetRealNamedProperty() + +A helper method for calling [`v8::Object#GetRealNamedProperty()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a84471a824576a5994fdd0ffcbf99ccc0) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::GetRealNamedProperty(v8::Local obj, + v8::Local key); +``` + + + +### Nan::CallAsFunction() + +A helper method for calling [`v8::Object#CallAsFunction()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a9ef18be634e79b4f0cdffa1667a29f58) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::CallAsFunction(v8::Local obj, + v8::Local recv, + int argc, + v8::Local argv[]); +``` + + + +### Nan::CallAsConstructor() + +A helper method for calling [`v8::Object#CallAsConstructor()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a50d571de50d0b0dfb28795619d07a01b) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::CallAsConstructor(v8::Local obj, + int argc, + v8::Local argv[]); +``` + + + +### Nan::GetSourceLine() + +A helper method for calling [`v8::Message#GetSourceLine()`](https://v8docs.nodesource.com/io.js-3.0/d9/d28/classv8_1_1_message.html#a849f7a6c41549d83d8159825efccd23a) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::GetSourceLine(v8::Local msg); +``` + + + +### Nan::GetLineNumber() + +A helper method for calling [`v8::Message#GetLineNumber()`](https://v8docs.nodesource.com/io.js-3.0/d9/d28/classv8_1_1_message.html#adbe46c10a88a6565f2732a2d2adf99b9) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::GetLineNumber(v8::Local msg); +``` + + + +### Nan::GetStartColumn() + +A helper method for calling [`v8::Message#GetStartColumn()`](https://v8docs.nodesource.com/io.js-3.0/d9/d28/classv8_1_1_message.html#a60ede616ba3822d712e44c7a74487ba6) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::GetStartColumn(v8::Local msg); +``` + + + +### Nan::GetEndColumn() + +A helper method for calling [`v8::Message#GetEndColumn()`](https://v8docs.nodesource.com/io.js-3.0/d9/d28/classv8_1_1_message.html#aaa004cf19e529da980bc19fcb76d93be) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::Maybe Nan::GetEndColumn(v8::Local msg); +``` + + + +### Nan::CloneElementAt() + +A helper method for calling [`v8::Array#CloneElementAt()`](https://v8docs.nodesource.com/io.js-3.0/d3/d32/classv8_1_1_array.html#a1d3a878d4c1c7cae974dd50a1639245e) in a way compatible across supported versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::CloneElementAt(v8::Local array, uint32_t index); +``` + + +### Nan::MakeMaybe() + +Wraps a `v8::Local<>` in a `Nan::MaybeLocal<>`. When called with a `Nan::MaybeLocal<>` it just returns its argument. This is useful in generic template code that builds on NAN. + +Synopsis: + +```c++ + MaybeLocal someNumber = MakeMaybe(New(3.141592654)); + MaybeLocal someString = MakeMaybe(New("probably")); +``` + +Signature: + +```c++ +template class MaybeMaybe> +Nan::MaybeLocal Nan::MakeMaybe(MaybeMaybe v); +``` diff --git a/node/node_modules/nan/doc/methods.md b/node/node_modules/nan/doc/methods.md new file mode 100644 index 0000000..0411a70 --- /dev/null +++ b/node/node_modules/nan/doc/methods.md @@ -0,0 +1,659 @@ +## JavaScript-accessible methods + +A _template_ is a blueprint for JavaScript functions and objects in a context. You can use a template to wrap C++ functions and data structures within JavaScript objects so that they can be manipulated from JavaScript. See the V8 Embedders Guide section on [Templates](https://developers.google.com/v8/embed#templates) for further information. + +In order to expose functionality to JavaScript via a template, you must provide it to V8 in a form that it understands. Across the versions of V8 supported by NAN, JavaScript-accessible method signatures vary widely, NAN fully abstracts method declaration and provides you with an interface that is similar to the most recent V8 API but is backward-compatible with older versions that still use the now-deceased `v8::Argument` type. + +* **Method argument types** + - Nan::FunctionCallbackInfo + - Nan::PropertyCallbackInfo + - Nan::ReturnValue +* **Method declarations** + - Method declaration + - Getter declaration + - Setter declaration + - Property getter declaration + - Property setter declaration + - Property enumerator declaration + - Property deleter declaration + - Property query declaration + - Index getter declaration + - Index setter declaration + - Index enumerator declaration + - Index deleter declaration + - Index query declaration +* Method and template helpers + - Nan::SetMethod() + - Nan::SetPrototypeMethod() + - Nan::SetAccessor() + - Nan::SetNamedPropertyHandler() + - Nan::SetIndexedPropertyHandler() + - Nan::SetTemplate() + - Nan::SetPrototypeTemplate() + - Nan::SetInstanceTemplate() + - Nan::SetCallHandler() + - Nan::SetCallAsFunctionHandler() + + +### Nan::FunctionCallbackInfo + +`Nan::FunctionCallbackInfo` should be used in place of [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/dd/d0d/classv8_1_1_function_callback_info.html), even with older versions of Node where `v8::FunctionCallbackInfo` does not exist. + +Definition: + +```c++ +template class FunctionCallbackInfo { + public: + ReturnValue GetReturnValue() const; + v8::Local Callee(); + v8::Local Data(); + v8::Local Holder(); + bool IsConstructCall(); + int Length() const; + v8::Local operator[](int i) const; + v8::Local This() const; + v8::Isolate *GetIsolate() const; +}; +``` + +See the [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/dd/d0d/classv8_1_1_function_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from methods. + + +### Nan::PropertyCallbackInfo + +`Nan::PropertyCallbackInfo` should be used in place of [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d7/dc5/classv8_1_1_property_callback_info.html), even with older versions of Node where `v8::PropertyCallbackInfo` does not exist. + +Definition: + +```c++ +template class PropertyCallbackInfo : public PropertyCallbackInfoBase { + public: + ReturnValue GetReturnValue() const; + v8::Isolate* GetIsolate() const; + v8::Local Data() const; + v8::Local This() const; + v8::Local Holder() const; +}; +``` + +See the [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d7/dc5/classv8_1_1_property_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from property accessor methods. + + +### Nan::ReturnValue + +`Nan::ReturnValue` is used in place of [`v8::ReturnValue`](https://v8docs.nodesource.com/io.js-3.0/da/da7/classv8_1_1_return_value.html) on both [`Nan::FunctionCallbackInfo`](#api_nan_function_callback_info) and [`Nan::PropertyCallbackInfo`](#api_nan_property_callback_info) as the return type of `GetReturnValue()`. + +Example usage: + +```c++ +void EmptyArray(const Nan::FunctionCallbackInfo& info) { + info.GetReturnValue().Set(Nan::New()); +} +``` + +Definition: + +```c++ +template class ReturnValue { + public: + // Handle setters + template void Set(const v8::Local &handle); + template void Set(const Nan::Global &handle); + + // Fast primitive setters + void Set(bool value); + void Set(double i); + void Set(int32_t i); + void Set(uint32_t i); + + // Fast JS primitive setters + void SetNull(); + void SetUndefined(); + void SetEmptyString(); + + // Convenience getter for isolate + v8::Isolate *GetIsolate() const; +}; +``` + +See the documentation on [`v8::ReturnValue`](https://v8docs.nodesource.com/io.js-3.0/da/da7/classv8_1_1_return_value.html) for further information on this. + + +### Method declaration + +JavaScript-accessible methods should be declared with the following signature to form a `Nan::FunctionCallback`: + +```c++ +typedef void(*FunctionCallback)(const FunctionCallbackInfo&); +``` + +Example: + +```c++ +void MethodName(const Nan::FunctionCallbackInfo& info) { + ... +} +``` + +You do not need to declare a new `HandleScope` within a method as one is implicitly created for you. + +**Example usage** + +```c++ +// .h: +class Foo : public Nan::ObjectWrap { + ... + + static void Bar(const Nan::FunctionCallbackInfo& info); + static void Baz(const Nan::FunctionCallbackInfo& info); +} + + +// .cc: +void Foo::Bar(const Nan::FunctionCallbackInfo& info) { + ... +} + +void Foo::Baz(const Nan::FunctionCallbackInfo& info) { + ... +} +``` + +A helper macro `NAN_METHOD(methodname)` exists, compatible with NAN v1 method declarations. + +**Example usage with `NAN_METHOD(methodname)`** + +```c++ +// .h: +class Foo : public Nan::ObjectWrap { + ... + + static NAN_METHOD(Bar); + static NAN_METHOD(Baz); +} + + +// .cc: +NAN_METHOD(Foo::Bar) { + ... +} + +NAN_METHOD(Foo::Baz) { + ... +} +``` + +Use [`Nan::SetPrototypeMethod`](#api_nan_set_prototype_method) to attach a method to a JavaScript function prototype or [`Nan::SetMethod`](#api_nan_set_method) to attach a method directly on a JavaScript object. + + +### Getter declaration + +JavaScript-accessible getters should be declared with the following signature to form a `Nan::GetterCallback`: + +```c++ +typedef void(*GetterCallback)(v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void GetterName(v8::Local property, + const Nan::PropertyCallbackInfo& info) { + ... +} +``` + +You do not need to declare a new `HandleScope` within a getter as one is implicitly created for you. + +A helper macro `NAN_GETTER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors). + + +### Setter declaration + +JavaScript-accessible setters should be declared with the following signature to form a Nan::SetterCallback: + +```c++ +typedef void(*SetterCallback)(v8::Local, + v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void SetterName(v8::Local property, + v8::Local value, + const Nan::PropertyCallbackInfo& info) { + ... +} +``` + +You do not need to declare a new `HandleScope` within a setter as one is implicitly created for you. + +A helper macro `NAN_SETTER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors). + + +### Property getter declaration + +JavaScript-accessible property getters should be declared with the following signature to form a Nan::PropertyGetterCallback: + +```c++ +typedef void(*PropertyGetterCallback)(v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void PropertyGetterName(v8::Local property, + const Nan::PropertyCallbackInfo& info) { + ... +} +``` + +You do not need to declare a new `HandleScope` within a property getter as one is implicitly created for you. + +A helper macro `NAN_PROPERTY_GETTER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Property setter declaration + +JavaScript-accessible property setters should be declared with the following signature to form a Nan::PropertySetterCallback: + +```c++ +typedef void(*PropertySetterCallback)(v8::Local, + v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void PropertySetterName(v8::Local property, + v8::Local value, + const Nan::PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a property setter as one is implicitly created for you. + +A helper macro `NAN_PROPERTY_SETTER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Property enumerator declaration + +JavaScript-accessible property enumerators should be declared with the following signature to form a Nan::PropertyEnumeratorCallback: + +```c++ +typedef void(*PropertyEnumeratorCallback)(const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void PropertyEnumeratorName(const Nan::PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a property enumerator as one is implicitly created for you. + +A helper macro `NAN_PROPERTY_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Property deleter declaration + +JavaScript-accessible property deleters should be declared with the following signature to form a Nan::PropertyDeleterCallback: + +```c++ +typedef void(*PropertyDeleterCallback)(v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void PropertyDeleterName(v8::Local property, + const Nan::PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a property deleter as one is implicitly created for you. + +A helper macro `NAN_PROPERTY_DELETER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Property query declaration + +JavaScript-accessible property query methods should be declared with the following signature to form a Nan::PropertyQueryCallback: + +```c++ +typedef void(*PropertyQueryCallback)(v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void PropertyQueryName(v8::Local property, + const Nan::PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a property query method as one is implicitly created for you. + +A helper macro `NAN_PROPERTY_QUERY(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Index getter declaration + +JavaScript-accessible index getter methods should be declared with the following signature to form a Nan::IndexGetterCallback: + +```c++ +typedef void(*IndexGetterCallback)(uint32_t, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void IndexGetterName(uint32_t index, const PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a index getter as one is implicitly created for you. + +A helper macro `NAN_INDEX_GETTER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Index setter declaration + +JavaScript-accessible index setter methods should be declared with the following signature to form a Nan::IndexSetterCallback: + +```c++ +typedef void(*IndexSetterCallback)(uint32_t, + v8::Local, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void IndexSetterName(uint32_t index, + v8::Local value, + const PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a index setter as one is implicitly created for you. + +A helper macro `NAN_INDEX_SETTER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Index enumerator declaration + +JavaScript-accessible index enumerator methods should be declared with the following signature to form a Nan::IndexEnumeratorCallback: + +```c++ +typedef void(*IndexEnumeratorCallback)(const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void IndexEnumeratorName(const PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a index enumerator as one is implicitly created for you. + +A helper macro `NAN_INDEX_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Index deleter declaration + +JavaScript-accessible index deleter methods should be declared with the following signature to form a Nan::IndexDeleterCallback: + +```c++ +typedef void(*IndexDeleterCallback)(uint32_t, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void IndexDeleterName(uint32_t index, const PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a index deleter as one is implicitly created for you. + +A helper macro `NAN_INDEX_DELETER(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Index query declaration + +JavaScript-accessible index query methods should be declared with the following signature to form a Nan::IndexQueryCallback: + +```c++ +typedef void(*IndexQueryCallback)(uint32_t, + const PropertyCallbackInfo&); +``` + +Example: + +```c++ +void IndexQueryName(uint32_t index, const PropertyCallbackInfo& info); +``` + +You do not need to declare a new `HandleScope` within a index query method as one is implicitly created for you. + +A helper macro `NAN_INDEX_QUERY(methodname)` exists, compatible with NAN v1 method declarations. + +Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors). + + +### Nan::SetMethod() + +Sets a method with a given name directly on a JavaScript object where the method has the `Nan::FunctionCallback` signature (see Method declaration). + +Signature: + +```c++ +void Nan::SetMethod(v8::Local recv, + const char *name, + Nan::FunctionCallback callback) +void Nan::SetMethod(v8::Local templ, + const char *name, + Nan::FunctionCallback callback) +``` + + +### Nan::SetPrototypeMethod() + +Sets a method with a given name on a `FunctionTemplate`'s prototype where the method has the `Nan::FunctionCallback` signature (see Method declaration). + +Signature: + +```c++ +void Nan::SetPrototypeMethod(v8::Local recv, + const char* name, + Nan::FunctionCallback callback) +``` + + +### Nan::SetAccessor() + +Sets getters and setters for a property with a given name on an `ObjectTemplate` or a plain `Object`. Accepts getters with the `Nan::GetterCallback` signature (see Getter declaration) and setters with the `Nan::SetterCallback` signature (see Setter declaration). + +Signature: + +```c++ +void SetAccessor(v8::Local tpl, + v8::Local name, + Nan::GetterCallback getter, + Nan::SetterCallback setter = 0, + v8::Local data = v8::Local(), + v8::AccessControl settings = v8::DEFAULT, + v8::PropertyAttribute attribute = v8::None, + imp::Sig signature = imp::Sig()); +bool SetAccessor(v8::Local obj, + v8::Local name, + Nan::GetterCallback getter, + Nan::SetterCallback setter = 0, + v8::Local data = v8::Local(), + v8::AccessControl settings = v8::DEFAULT, + v8::PropertyAttribute attribute = v8::None) +``` + +See the V8 [`ObjectTemplate#SetAccessor()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#aa90691622f01269c6a11391d372ca0c5) and [`Object#SetAccessor()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a3f9dee085f5ec346465f1dc924325043) for further information about how to use `Nan::SetAccessor()`. + + +### Nan::SetNamedPropertyHandler() + +Sets named property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts: + +* Property getters with the `Nan::PropertyGetterCallback` signature (see Property getter declaration) +* Property setters with the `Nan::PropertySetterCallback` signature (see Property setter declaration) +* Property query methods with the `Nan::PropertyQueryCallback` signature (see Property query declaration) +* Property deleters with the `Nan::PropertyDeleterCallback` signature (see Property deleter declaration) +* Property enumerators with the `Nan::PropertyEnumeratorCallback` signature (see Property enumerator declaration) + +Signature: + +```c++ +void SetNamedPropertyHandler(v8::Local tpl, + Nan::PropertyGetterCallback getter, + Nan::PropertySetterCallback setter = 0, + Nan::PropertyQueryCallback query = 0, + Nan::PropertyDeleterCallback deleter = 0, + Nan::PropertyEnumeratorCallback enumerator = 0, + v8::Local data = v8::Local()) +``` + +See the V8 [`ObjectTemplate#SetNamedPropertyHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#a34d1cc45b642cd131706663801aadd76) for further information about how to use `Nan::SetNamedPropertyHandler()`. + + +### Nan::SetIndexedPropertyHandler() + +Sets indexed property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts: + +* Indexed property getters with the `Nan::IndexGetterCallback` signature (see Index getter declaration) +* Indexed property setters with the `Nan::IndexSetterCallback` signature (see Index setter declaration) +* Indexed property query methods with the `Nan::IndexQueryCallback` signature (see Index query declaration) +* Indexed property deleters with the `Nan::IndexDeleterCallback` signature (see Index deleter declaration) +* Indexed property enumerators with the `Nan::IndexEnumeratorCallback` signature (see Index enumerator declaration) + +Signature: + +```c++ +void SetIndexedPropertyHandler(v8::Local tpl, + Nan::IndexGetterCallback getter, + Nan::IndexSetterCallback setter = 0, + Nan::IndexQueryCallback query = 0, + Nan::IndexDeleterCallback deleter = 0, + Nan::IndexEnumeratorCallback enumerator = 0, + v8::Local data = v8::Local()) +``` + +See the V8 [`ObjectTemplate#SetIndexedPropertyHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ac0234cbede45d51778bb5f6a32a9e125) for further information about how to use `Nan::SetIndexedPropertyHandler()`. + + +### Nan::SetTemplate() + +Adds properties on an `Object`'s or `Function`'s template. + +Signature: + +```c++ +void Nan::SetTemplate(v8::Local templ, + const char *name, + v8::Local value); +void Nan::SetTemplate(v8::Local templ, + v8::Local name, + v8::Local value, + v8::PropertyAttribute attributes) +``` + +Calls the `Template`'s [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf). + + +### Nan::SetPrototypeTemplate() + +Adds properties on an `Object`'s or `Function`'s prototype template. + +Signature: + +```c++ +void Nan::SetPrototypeTemplate(v8::Local templ, + const char *name, + v8::Local value); +void Nan::SetPrototypeTemplate(v8::Local templ, + v8::Local name, + v8::Local value, + v8::PropertyAttribute attributes) +``` + +Calls the `FunctionTemplate`'s _PrototypeTemplate's_ [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf). + + +### Nan::SetInstanceTemplate() + +Use to add instance properties on `FunctionTemplate`'s. + +Signature: + +```c++ +void Nan::SetInstanceTemplate(v8::Local templ, + const char *name, + v8::Local value); +void Nan::SetInstanceTemplate(v8::Local templ, + v8::Local name, + v8::Local value, + v8::PropertyAttribute attributes) +``` + +Calls the `FunctionTemplate`'s _InstanceTemplate's_ [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf). + + +### Nan::SetCallHandler() + +Set the call-handler callback for a `v8::FunctionTemplate`. +This callback is called whenever the function created from this FunctionTemplate is called. + +Signature: + +```c++ +void Nan::SetCallHandler(v8::Local templ, Nan::FunctionCallback callback, v8::Local data = v8::Local()) +``` + +Calls the `FunctionTemplate`'s [`SetCallHandler()`](https://v8docs.nodesource.com/io.js-3.0/d8/d83/classv8_1_1_function_template.html#a26cf14e36aa1a47091b98536d08ea821). + + +### Nan::SetCallAsFunctionHandler() + +Sets the callback to be used when calling instances created from the `v8::ObjectTemplate` as a function. +If no callback is set, instances behave like normal JavaScript objects that cannot be called as a function. + +Signature: + +```c++ +void Nan::SetCallAsFunctionHandler(v8::Local templ, Nan::FunctionCallback callback, v8::Local data = v8::Local()) +``` + +Calls the `ObjectTemplate`'s [`SetCallAsFunctionHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ae0a0e72fb0c5e5f32e255fe5bcc7316a). + diff --git a/node/node_modules/nan/doc/new.md b/node/node_modules/nan/doc/new.md new file mode 100644 index 0000000..c0734bd --- /dev/null +++ b/node/node_modules/nan/doc/new.md @@ -0,0 +1,147 @@ +## New + +NAN provides a `Nan::New()` helper for the creation of new JavaScript objects in a way that's compatible across the supported versions of V8. + + - Nan::New() + - Nan::Undefined() + - Nan::Null() + - Nan::True() + - Nan::False() + - Nan::EmptyString() + + + +### Nan::New() + +`Nan::New()` should be used to instantiate new JavaScript objects. + +Refer to the specific V8 type in the [V8 documentation](https://v8docs.nodesource.com/io.js-3.0/d1/d83/classv8_1_1_data.html) for information on the types of arguments required for instantiation. + +Signatures: + +Return types are mostly omitted from the signatures for simplicity. In most cases the type will be contained within a `v8::Local`. The following types will be contained within a `Nan::MaybeLocal`: `v8::String`, `v8::Date`, `v8::RegExp`, `v8::Script`, `v8::UnboundScript`. + +Empty objects: + +```c++ +Nan::New(); +``` + +Generic single and multiple-argument: + +```c++ +Nan::New(A0 arg0); +Nan::New(A0 arg0, A1 arg1); +Nan::New(A0 arg0, A1 arg1, A2 arg2); +Nan::New(A0 arg0, A1 arg1, A2 arg2, A3 arg3); +``` + +For creating `v8::FunctionTemplate` and `v8::Function` objects: + +_The definition of `Nan::FunctionCallback` can be found in the [Method declaration](./methods.md#api_nan_method) documentation._ + +```c++ +Nan::New(Nan::FunctionCallback callback, + v8::Local data = v8::Local()); +Nan::New(Nan::FunctionCallback callback, + v8::Local data = v8::Local(), + A2 a2 = A2()); +``` + +Native number types: + +```c++ +v8::Local Nan::New(bool value); +v8::Local Nan::New(int32_t value); +v8::Local Nan::New(uint32_t value); +v8::Local Nan::New(double value); +``` + +String types: + +```c++ +Nan::MaybeLocal Nan::New(std::string const& value); +Nan::MaybeLocal Nan::New(const char * value, int length); +Nan::MaybeLocal Nan::New(const char * value); +Nan::MaybeLocal Nan::New(const uint16_t * value); +Nan::MaybeLocal Nan::New(const uint16_t * value, int length); +``` + +Specialized types: + +```c++ +v8::Local Nan::New(v8::String::ExternalStringResource * value); +v8::Local Nan::New(Nan::ExternalOneByteStringResource * value); +v8::Local Nan::New(v8::Local pattern, v8::RegExp::Flags flags); +``` + +Note that `Nan::ExternalOneByteStringResource` maps to [`v8::String::ExternalOneByteStringResource`](https://v8docs.nodesource.com/io.js-3.0/d9/db3/classv8_1_1_string_1_1_external_one_byte_string_resource.html), and `v8::String::ExternalAsciiStringResource` in older versions of V8. + + + +### Nan::Undefined() + +A helper method to reference the `v8::Undefined` object in a way that is compatible across all supported versions of V8. + +Signature: + +```c++ +v8::Local Nan::Undefined() +``` + + +### Nan::Null() + +A helper method to reference the `v8::Null` object in a way that is compatible across all supported versions of V8. + +Signature: + +```c++ +v8::Local Nan::Null() +``` + + +### Nan::True() + +A helper method to reference the `v8::Boolean` object representing the `true` value in a way that is compatible across all supported versions of V8. + +Signature: + +```c++ +v8::Local Nan::True() +``` + + +### Nan::False() + +A helper method to reference the `v8::Boolean` object representing the `false` value in a way that is compatible across all supported versions of V8. + +Signature: + +```c++ +v8::Local Nan::False() +``` + + +### Nan::EmptyString() + +Call [`v8::String::Empty`](https://v8docs.nodesource.com/io.js-3.0/d2/db3/classv8_1_1_string.html#a7c1bc8886115d7ee46f1d571dd6ebc6d) to reference the empty string in a way that is compatible across all supported versions of V8. + +Signature: + +```c++ +v8::Local Nan::EmptyString() +``` + + + +### Nan::NewOneByteString() + +An implementation of [`v8::String::NewFromOneByte()`](https://v8docs.nodesource.com/io.js-3.0/d2/db3/classv8_1_1_string.html#a5264d50b96d2c896ce525a734dc10f09) provided for consistent availability and API across supported versions of V8. Allocates a new string from Latin-1 data. + +Signature: + +```c++ +Nan::MaybeLocal Nan::NewOneByteString(const uint8_t * value, + int length = -1) +``` diff --git a/node/node_modules/nan/doc/node_misc.md b/node/node_modules/nan/doc/node_misc.md new file mode 100644 index 0000000..8aa080f --- /dev/null +++ b/node/node_modules/nan/doc/node_misc.md @@ -0,0 +1,63 @@ +## Miscellaneous Node Helpers + + - Nan::MakeCallback() + - NAN_MODULE_INIT() + - Nan::Export() + + + +### Nan::MakeCallback() + +Wrappers around `node::MakeCallback()` providing a consistent API across all supported versions of Node. + +Use `MakeCallback()` rather than using `v8::Function#Call()` directly in order to properly process internal Node functionality including domains, async hooks, the microtask queue, and other debugging functionality. + +Signatures: + +```c++ +v8::Local Nan::MakeCallback(v8::Local target, + v8::Local func, + int argc, + v8::Local* argv); +v8::Local Nan::MakeCallback(v8::Local target, + v8::Local symbol, + int argc, + v8::Local* argv); +v8::Local Nan::MakeCallback(v8::Local target, + const char* method, + int argc, + v8::Local* argv); +``` + + + +### NAN_MODULE_INIT() + +Used to define the entry point function to a Node add-on. Creates a function with a given `name` that receives a `target` object representing the equivalent of the JavaScript `exports` object. + +See example below. + + +### Nan::Export() + +A simple helper to register a `v8::FunctionTemplate` from a JavaScript-accessible method (see [Methods](./methods.md)) as a property on an object. Can be used in a way similar to assigning properties to `module.exports` in JavaScript. + +Signature: + +```c++ +void Export(v8::Local target, const char *name, Nan::FunctionCallback f) +``` + +Also available as the shortcut `NAN_EXPORT` macro. + +Example: + +```c++ +NAN_METHOD(Foo) { + ... +} + +NAN_MODULE_INIT(Init) { + NAN_EXPORT(target, Foo); +} +``` diff --git a/node/node_modules/nan/doc/object_wrappers.md b/node/node_modules/nan/doc/object_wrappers.md new file mode 100644 index 0000000..27b0636 --- /dev/null +++ b/node/node_modules/nan/doc/object_wrappers.md @@ -0,0 +1,263 @@ +## Object Wrappers + +The `ObjectWrap` class can be used to make wrapped C++ objects and a factory of wrapped objects. + + - Nan::ObjectWrap + + + +### Nan::ObjectWrap() + +A reimplementation of `node::ObjectWrap` that adds some API not present in older versions of Node. Should be preferred over `node::ObjectWrap` in all cases for consistency. + +Definition: + +```c++ +class ObjectWrap { + public: + ObjectWrap(); + + virtual ~ObjectWrap(); + + template + static inline T* Unwrap(v8::Local handle); + + inline v8::Local handle(); + + inline Nan::Persistent& persistent(); + + protected: + inline void Wrap(v8::Local handle); + + inline void MakeWeak(); + + /* Ref() marks the object as being attached to an event loop. + * Refed objects will not be garbage collected, even if + * all references are lost. + */ + virtual void Ref(); + + /* Unref() marks an object as detached from the event loop. This is its + * default state. When an object with a "weak" reference changes from + * attached to detached state it will be freed. Be careful not to access + * the object after making this call as it might be gone! + * (A "weak reference" means an object that only has a + * persistant handle.) + * + * DO NOT CALL THIS FROM DESTRUCTOR + */ + virtual void Unref(); + + int refs_; // ro +}; +``` + +See the Node documentation on [Wrapping C++ Objects](https://nodejs.org/api/addons.html#addons_wrapping_c_objects) for more details. + +### This vs. Holder + +When calling `Unwrap`, it is important that the argument is indeed some JavaScript object which got wrapped by a `Wrap` call for this class or any derived class. +The `Signature` installed by [`Nan::SetPrototypeMethod()`](methods.md#api_nan_set_prototype_method) does ensure that `info.Holder()` is just such an instance. +In Node 0.12 and later, `info.This()` will also be of such a type, since otherwise the invocation will get rejected. +However, in Node 0.10 and before it was possible to invoke a method on a JavaScript object which just had the extension type in its prototype chain. +In such a situation, calling `Unwrap` on `info.This()` will likely lead to a failed assertion causing a crash, but could lead to even more serious corruption. + +On the other hand, calling `Unwrap` in an [accessor](methods.md#api_nan_set_accessor) should not use `Holder()` if the accessor is defined on the prototype. +So either define your accessors on the instance template, +or use `This()` after verifying that it is indeed a valid object. + +### Examples + +#### Basic + +```c++ +class MyObject : public Nan::ObjectWrap { + public: + static NAN_MODULE_INIT(Init) { + v8::Local tpl = Nan::New(New); + tpl->SetClassName(Nan::New("MyObject").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + SetPrototypeMethod(tpl, "getHandle", GetHandle); + SetPrototypeMethod(tpl, "getValue", GetValue); + + constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked()); + Nan::Set(target, Nan::New("MyObject").ToLocalChecked(), + Nan::GetFunction(tpl).ToLocalChecked()); + } + + private: + explicit MyObject(double value = 0) : value_(value) {} + ~MyObject() {} + + static NAN_METHOD(New) { + if (info.IsConstructCall()) { + double value = info[0]->IsUndefined() ? 0 : Nan::To(info[0]).FromJust(); + MyObject *obj = new MyObject(value); + obj->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + } else { + const int argc = 1; + v8::Local argv[argc] = {info[0]}; + v8::Local cons = Nan::New(constructor()); + info.GetReturnValue().Set(cons->NewInstance(argc, argv)); + } + } + + static NAN_METHOD(GetHandle) { + MyObject* obj = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(obj->handle()); + } + + static NAN_METHOD(GetValue) { + MyObject* obj = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(obj->value_); + } + + static inline Nan::Persistent & constructor() { + static Nan::Persistent my_constructor; + return my_constructor; + } + + double value_; +}; + +NODE_MODULE(objectwrapper, MyObject::Init) +``` + +To use in Javascript: + +```Javascript +var objectwrapper = require('bindings')('objectwrapper'); + +var obj = new objectwrapper.MyObject(5); +console.log('Should be 5: ' + obj.getValue()); +``` + +#### Factory of wrapped objects + +```c++ +class MyFactoryObject : public Nan::ObjectWrap { + public: + static NAN_MODULE_INIT(Init) { + v8::Local tpl = Nan::New(New); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + Nan::SetPrototypeMethod(tpl, "getValue", GetValue); + + constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked()); + } + + static NAN_METHOD(NewInstance) { + v8::Local cons = Nan::New(constructor()); + double value = info[0]->IsNumber() ? Nan::To(info[0]).FromJust() : 0; + const int argc = 1; + v8::Local argv[1] = {Nan::New(value)}; + info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked()); + } + + // Needed for the next example: + inline double value() const { + return value_; + } + + private: + explicit MyFactoryObject(double value = 0) : value_(value) {} + ~MyFactoryObject() {} + + static NAN_METHOD(New) { + if (info.IsConstructCall()) { + double value = info[0]->IsNumber() ? Nan::To(info[0]).FromJust() : 0; + MyFactoryObject * obj = new MyFactoryObject(value); + obj->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + } else { + const int argc = 1; + v8::Local argv[argc] = {info[0]}; + v8::Local cons = Nan::New(constructor()); + info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked()); + } + } + + static NAN_METHOD(GetValue) { + MyFactoryObject* obj = ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(obj->value_); + } + + static inline Nan::Persistent & constructor() { + static Nan::Persistent my_constructor; + return my_constructor; + } + + double value_; +}; + +NAN_MODULE_INIT(Init) { + MyFactoryObject::Init(target); + Nan::Set(target, + Nan::New("newFactoryObjectInstance").ToLocalChecked(), + Nan::GetFunction( + Nan::New(MyFactoryObject::NewInstance)).ToLocalChecked() + ); +} + +NODE_MODULE(wrappedobjectfactory, Init) +``` + +To use in Javascript: + +```Javascript +var wrappedobjectfactory = require('bindings')('wrappedobjectfactory'); + +var obj = wrappedobjectfactory.newFactoryObjectInstance(10); +console.log('Should be 10: ' + obj.getValue()); +``` + +#### Passing wrapped objects around + +Use the `MyFactoryObject` class above along with the following: + +```c++ +static NAN_METHOD(Sum) { + Nan::MaybeLocal maybe1 = Nan::To(info[0]); + Nan::MaybeLocal maybe2 = Nan::To(info[1]); + + // Quick check: + if (maybe1.IsEmpty() || maybe2.IsEmpty()) { + // return value is undefined by default + return; + } + + MyFactoryObject* obj1 = + Nan::ObjectWrap::Unwrap(maybe1.ToLocalChecked()); + MyFactoryObject* obj2 = + Nan::ObjectWrap::Unwrap(maybe2.ToLocalChecked()); + + info.GetReturnValue().Set(Nan::New(obj1->value() + obj2->value())); +} + +NAN_MODULE_INIT(Init) { + MyFactoryObject::Init(target); + Nan::Set(target, + Nan::New("newFactoryObjectInstance").ToLocalChecked(), + Nan::GetFunction( + Nan::New(MyFactoryObject::NewInstance)).ToLocalChecked() + ); + Nan::Set(target, + Nan::New("sum").ToLocalChecked(), + Nan::GetFunction(Nan::New(Sum)).ToLocalChecked() + ); +} + +NODE_MODULE(myaddon, Init) +``` + +To use in Javascript: + +```Javascript +var myaddon = require('bindings')('myaddon'); + +var obj1 = myaddon.newFactoryObjectInstance(5); +var obj2 = myaddon.newFactoryObjectInstance(10); +console.log('sum of object values: ' + myaddon.sum(obj1, obj2)); +``` diff --git a/node/node_modules/nan/doc/persistent.md b/node/node_modules/nan/doc/persistent.md new file mode 100644 index 0000000..743b44a --- /dev/null +++ b/node/node_modules/nan/doc/persistent.md @@ -0,0 +1,295 @@ +## Persistent references + +An object reference that is independent of any `HandleScope` is a _persistent_ reference. Where a `Local` handle only lives as long as the `HandleScope` in which it was allocated, a `Persistent` handle remains valid until it is explicitly disposed. + +Due to the evolution of the V8 API, it is necessary for NAN to provide a wrapper implementation of the `Persistent` classes to supply compatibility across the V8 versions supported. + + - Nan::PersistentBase & v8::PersistentBase + - Nan::NonCopyablePersistentTraits & v8::NonCopyablePersistentTraits + - Nan::CopyablePersistentTraits & v8::CopyablePersistentTraits + - Nan::Persistent + - Nan::Global + - Nan::WeakCallbackInfo + - Nan::WeakCallbackType + +Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://developers.google.com/v8/embed#handles). + + +### Nan::PersistentBase & v8::PersistentBase + +A persistent handle contains a reference to a storage cell in V8 which holds an object value and which is updated by the garbage collector whenever the object is moved. A new storage cell can be created using the constructor or `Nan::PersistentBase::Reset()`. Existing handles can be disposed using an argument-less `Nan::PersistentBase::Reset()`. + +Definition: + +_(note: this is implemented as `Nan::PersistentBase` for older versions of V8 and the native `v8::PersistentBase` is used for newer versions of V8)_ + +```c++ +template class PersistentBase { + public: + /** + * If non-empty, destroy the underlying storage cell + */ + void Reset(); + + /** + * If non-empty, destroy the underlying storage cell and create a new one with + * the contents of another if it is also non-empty + */ + template void Reset(const v8::Local &other); + + /** + * If non-empty, destroy the underlying storage cell and create a new one with + * the contents of another if it is also non-empty + */ + template void Reset(const PersistentBase &other); + + /** + * If non-empty, destroy the underlying storage cell + * IsEmpty() will return true after this call. + */ + bool IsEmpty(); + + void Empty(); + + template bool operator==(const PersistentBase &that); + + template bool operator==(const v8::Local &that); + + template bool operator!=(const PersistentBase &that); + + template bool operator!=(const v8::Local &that); + + /** + * Install a finalization callback on this object. + * NOTE: There is no guarantee as to *when* or even *if* the callback is + * invoked. The invocation is performed solely on a best effort basis. + * As always, GC-based finalization should *not* be relied upon for any + * critical form of resource management! At the moment you can either + * specify a parameter for the callback or the location of two internal + * fields in the dying object. + */ + template + void SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type); + + void ClearWeak(); + + /** + * Marks the reference to this object independent. Garbage collector is free + * to ignore any object groups containing this object. Weak callback for an + * independent handle should not assume that it will be preceded by a global + * GC prologue callback or followed by a global GC epilogue callback. + */ + void MarkIndependent() const; + + bool IsIndependent() const; + + /** Checks if the handle holds the only reference to an object. */ + bool IsNearDeath() const; + + /** Returns true if the handle's reference is weak. */ + bool IsWeak() const +}; +``` + +See the V8 documentation for [`PersistentBase`](https://v8docs.nodesource.com/io.js-3.0/d4/dca/classv8_1_1_persistent_base.html) for further information. + +**Tip:** To get a `v8::Local` reference to the original object back from a `PersistentBase` or `Persistent` object: + +```c++ +v8::Local object = Nan::New(persistent); +``` + + +### Nan::NonCopyablePersistentTraits & v8::NonCopyablePersistentTraits + +Default traits for `Nan::Persistent`. This class does not allow use of the a copy constructor or assignment operator. At present `kResetInDestructor` is not set, but that will change in a future version. + +Definition: + +_(note: this is implemented as `Nan::NonCopyablePersistentTraits` for older versions of V8 and the native `v8::NonCopyablePersistentTraits` is used for newer versions of V8)_ + +```c++ +template class NonCopyablePersistentTraits { + public: + typedef Persistent > NonCopyablePersistent; + + static const bool kResetInDestructor = false; + + template + static void Copy(const Persistent &source, + NonCopyablePersistent *dest); + + template static void Uncompilable(); +}; +``` + +See the V8 documentation for [`NonCopyablePersistentTraits`](https://v8docs.nodesource.com/io.js-3.0/de/d73/classv8_1_1_non_copyable_persistent_traits.html) for further information. + + +### Nan::CopyablePersistentTraits & v8::CopyablePersistentTraits + +A helper class of traits to allow copying and assignment of `Persistent`. This will clone the contents of storage cell, but not any of the flags, etc.. + +Definition: + +_(note: this is implemented as `Nan::CopyablePersistentTraits` for older versions of V8 and the native `v8::NonCopyablePersistentTraits` is used for newer versions of V8)_ + +```c++ +template +class CopyablePersistentTraits { + public: + typedef Persistent > CopyablePersistent; + + static const bool kResetInDestructor = true; + + template + static void Copy(const Persistent &source, + CopyablePersistent *dest); +}; +``` + +See the V8 documentation for [`CopyablePersistentTraits`](https://v8docs.nodesource.com/io.js-3.0/da/d5c/structv8_1_1_copyable_persistent_traits.html) for further information. + + +### Nan::Persistent + +A type of `PersistentBase` which allows copy and assignment. Copy, assignment and destructor behavior is controlled by the traits class `M`. + +Definition: + +```c++ +template > +class Persistent; + +template class Persistent : public PersistentBase { + public: + /** + * A Persistent with no storage cell. + */ + Persistent(); + + /** + * Construct a Persistent from a v8::Local. When the v8::Local is non-empty, a + * new storage cell is created pointing to the same object, and no flags are + * set. + */ + template Persistent(v8::Local that); + + /** + * Construct a Persistent from a Persistent. When the Persistent is non-empty, + * a new storage cell is created pointing to the same object, and no flags are + * set. + */ + Persistent(const Persistent &that); + + /** + * The copy constructors and assignment operator create a Persistent exactly + * as the Persistent constructor, but the Copy function from the traits class + * is called, allowing the setting of flags based on the copied Persistent. + */ + Persistent &operator=(const Persistent &that); + + template + Persistent &operator=(const Persistent &that); + + /** + * The destructor will dispose the Persistent based on the kResetInDestructor + * flags in the traits class. Since not calling dispose can result in a + * memory leak, it is recommended to always set this flag. + */ + ~Persistent(); +}; +``` + +See the V8 documentation for [`Persistent`](https://v8docs.nodesource.com/io.js-3.0/d2/d78/classv8_1_1_persistent.html) for further information. + + +### Nan::Global + +A type of `PersistentBase` which has move semantics. + +```c++ +template class Global : public PersistentBase { + public: + /** + * A Global with no storage cell. + */ + Global(); + + /** + * Construct a Global from a v8::Local. When the v8::Local is non-empty, a new + * storage cell is created pointing to the same object, and no flags are set. + */ + template Global(v8::Local that); + /** + * Construct a Global from a PersistentBase. When the Persistent is non-empty, + * a new storage cell is created pointing to the same object, and no flags are + * set. + */ + template Global(const PersistentBase &that); + + /** + * Pass allows returning globals from functions, etc. + */ + Global Pass(); +}; +``` + +See the V8 documentation for [`Global`](https://v8docs.nodesource.com/io.js-3.0/d5/d40/classv8_1_1_global.html) for further information. + + +### Nan::WeakCallbackInfo + +`Nan::WeakCallbackInfo` is used as an argument when setting a persistent reference as weak. You may need to free any external resources attached to the object. It is a mirror of `v8:WeakCallbackInfo` as found in newer versions of V8. + +Definition: + +```c++ +template class WeakCallbackInfo { + public: + typedef void (*Callback)(const WeakCallbackInfo& data); + + v8::Isolate *GetIsolate() const; + + /** + * Get the parameter that was associated with the weak handle. + */ + T *GetParameter() const; + + /** + * Get pointer from internal field, index can be 0 or 1. + */ + void *GetInternalField(int index) const; +}; +``` + +Example usage: + +```c++ +void weakCallback(const WeakCallbackInfo &data) { + int *parameter = data.GetParameter(); + delete parameter; +} + +Persistent obj; +int *data = new int(0); +obj.SetWeak(data, callback, WeakCallbackType::kParameter); +``` + +See the V8 documentation for [`WeakCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d8/d06/classv8_1_1_weak_callback_info.html) for further information. + + +### Nan::WeakCallbackType + +Represents the type of a weak callback. +A weak callback of type `kParameter` makes the supplied parameter to `Nan::PersistentBase::SetWeak` available through `WeakCallbackInfo::GetParameter`. +A weak callback of type `kInternalFields` uses up to two internal fields at indices 0 and 1 on the `Nan::PersistentBase` being made weak. +Note that only `v8::Object`s and derivatives can have internal fields. + +Definition: + +```c++ +enum class WeakCallbackType { kParameter, kInternalFields }; +``` diff --git a/node/node_modules/nan/doc/scopes.md b/node/node_modules/nan/doc/scopes.md new file mode 100644 index 0000000..e9a35d0 --- /dev/null +++ b/node/node_modules/nan/doc/scopes.md @@ -0,0 +1,73 @@ +## Scopes + +A _local handle_ is a pointer to an object. All V8 objects are accessed using handles, they are necessary because of the way the V8 garbage collector works. + +A handle scope can be thought of as a container for any number of handles. When you've finished with your handles, instead of deleting each one individually you can simply delete their scope. + +The creation of `HandleScope` objects is different across the supported versions of V8. Therefore, NAN provides its own implementations that can be used safely across these. + + - Nan::HandleScope + - Nan::EscapableHandleScope + +Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://developers.google.com/v8/embed#handles). + + +### Nan::HandleScope + +A simple wrapper around [`v8::HandleScope`](https://v8docs.nodesource.com/io.js-3.0/d3/d95/classv8_1_1_handle_scope.html). + +Definition: + +```c++ +class Nan::HandleScope { + public: + Nan::HandleScope(); + static int NumberOfHandles(); +}; +``` + +Allocate a new `Nan::HandleScope` whenever you are creating new V8 JavaScript objects. Note that an implicit `HandleScope` is created for you on JavaScript-accessible methods so you do not need to insert one yourself. + +Example: + +```c++ +// new object is created, it needs a new scope: +void Pointless() { + Nan::HandleScope scope; + v8::Local obj = Nan::New(); +} + +// JavaScript-accessible method already has a HandleScope +NAN_METHOD(Pointless2) { + v8::Local obj = Nan::New(); +} +``` + + +### Nan::EscapableHandleScope + +Similar to [`Nan::HandleScope`](#api_nan_handle_scope) but should be used in cases where a function needs to return a V8 JavaScript type that has been created within it. + +Definition: + +```c++ +class Nan::EscapableHandleScope { + public: + Nan::EscapableHandleScope(); + static int NumberOfHandles(); + template v8::Local Escape(v8::Local value); +} +``` + +Use `Escape(value)` to return the object. + +Example: + +```c++ +v8::Local EmptyObj() { + Nan::EscapableHandleScope scope; + v8::Local obj = Nan::New(); + return scope.Escape(obj); +} +``` + diff --git a/node/node_modules/nan/doc/script.md b/node/node_modules/nan/doc/script.md new file mode 100644 index 0000000..1267b5e --- /dev/null +++ b/node/node_modules/nan/doc/script.md @@ -0,0 +1,38 @@ +## Script + +NAN provides a `v8::Script` helpers as the API has changed over the supported versions of V8. + + - Nan::CompileScript() + - Nan::RunScript() + + + +### Nan::CompileScript() + +A wrapper around [`v8::Script::Compile()`](https://v8docs.nodesource.com/io.js-3.0/da/da5/classv8_1_1_script_compiler.html#a93f5072a0db55d881b969e9fc98e564b). + +Note that `Nan::BoundScript` is an alias for `v8::Script`. + +Signature: + +```c++ +Nan::MaybeLocal Nan::CompileScript( + v8::Local s, + const v8::ScriptOrigin& origin); +Nan::MaybeLocal Nan::CompileScript(v8::Local s); +``` + + + +### Nan::RunScript() + +Calls `script->Run()` or `script->BindToCurrentContext()->Run(Nan::GetCurrentContext())`. + +Note that `Nan::BoundScript` is an alias for `v8::Script` and `Nan::UnboundScript` is an alias for `v8::UnboundScript` where available and `v8::Script` on older versions of V8. + +Signature: + +```c++ +Nan::MaybeLocal Nan::RunScript(v8::Local script) +Nan::MaybeLocal Nan::RunScript(v8::Local script) +``` diff --git a/node/node_modules/nan/doc/string_bytes.md b/node/node_modules/nan/doc/string_bytes.md new file mode 100644 index 0000000..7c1bd32 --- /dev/null +++ b/node/node_modules/nan/doc/string_bytes.md @@ -0,0 +1,62 @@ +## Strings & Bytes + +Miscellaneous string & byte encoding and decoding functionality provided for compatibility across supported versions of V8 and Node. Implemented by NAN to ensure that all encoding types are supported, even for older versions of Node where they are missing. + + - Nan::Encoding + - Nan::Encode() + - Nan::DecodeBytes() + - Nan::DecodeWrite() + + + +### Nan::Encoding + +An enum representing the supported encoding types. A copy of `node::encoding` that is consistent across versions of Node. + +Definition: + +```c++ +enum Nan::Encoding { ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER } +``` + + + +### Nan::Encode() + +A wrapper around `node::Encode()` that provides a consistent implementation across supported versions of Node. + +Signature: + +```c++ +v8::Local Nan::Encode(const void *buf, + size_t len, + enum Nan::Encoding encoding = BINARY); +``` + + + +### Nan::DecodeBytes() + +A wrapper around `node::DecodeBytes()` that provides a consistent implementation across supported versions of Node. + +Signature: + +```c++ +ssize_t Nan::DecodeBytes(v8::Local val, + enum Nan::Encoding encoding = BINARY); +``` + + + +### Nan::DecodeWrite() + +A wrapper around `node::DecodeWrite()` that provides a consistent implementation across supported versions of Node. + +Signature: + +```c++ +ssize_t Nan::DecodeWrite(char *buf, + size_t len, + v8::Local val, + enum Nan::Encoding encoding = BINARY); +``` diff --git a/node/node_modules/nan/doc/v8_internals.md b/node/node_modules/nan/doc/v8_internals.md new file mode 100644 index 0000000..8e6319b --- /dev/null +++ b/node/node_modules/nan/doc/v8_internals.md @@ -0,0 +1,199 @@ +## V8 internals + +The hooks to access V8 internals—including GC and statistics—are different across the supported versions of V8, therefore NAN provides its own hooks that call the appropriate V8 methods. + + - NAN_GC_CALLBACK() + - Nan::AddGCEpilogueCallback() + - Nan::RemoveGCEpilogueCallback() + - Nan::AddGCPrologueCallback() + - Nan::RemoveGCPrologueCallback() + - Nan::GetHeapStatistics() + - Nan::SetCounterFunction() + - Nan::SetCreateHistogramFunction() + - Nan::SetAddHistogramSampleFunction() + - Nan::IdleNotification() + - Nan::LowMemoryNotification() + - Nan::ContextDisposedNotification() + - Nan::GetInternalFieldPointer() + - Nan::SetInternalFieldPointer() + - Nan::AdjustExternalMemory() + + + +### NAN_GC_CALLBACK(callbackname) + +Use `NAN_GC_CALLBACK` to declare your callbacks for `Nan::AddGCPrologueCallback()` and `Nan::AddGCEpilogueCallback()`. Your new method receives the arguments `v8::GCType type` and `v8::GCCallbackFlags flags`. + +```c++ +static Nan::Persistent callback; + +NAN_GC_CALLBACK(gcPrologueCallback) { + v8::Local argv[] = { Nan::New("prologue").ToLocalChecked() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(callback), 1, argv); +} + +NAN_METHOD(Hook) { + callback.Reset(args[0].As()); + Nan::AddGCPrologueCallback(gcPrologueCallback); + info.GetReturnValue().Set(info.Holder()); +} +``` + + +### Nan::AddGCEpilogueCallback() + +Signature: + +```c++ +void Nan::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, v8::GCType gc_type_filter = v8::kGCTypeAll) +``` + +Calls V8's [`AddGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a90d1860babc76059c62514b422f56960). + + +### Nan::RemoveGCEpilogueCallback() + +Signature: + +```c++ +void Nan::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback) +``` + +Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a05c60859fd4b8e96bfcd451281ed6c7c). + + +### Nan::AddGCPrologueCallback() + +Signature: + +```c++ +void Nan::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback, v8::GCType gc_type_filter callback) +``` + +Calls V8's [`AddGCPrologueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ab4b87b8f9f8e5bf95eba4009357e001f). + + +### Nan::RemoveGCPrologueCallback() + +Signature: + +```c++ +void Nan::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback) +``` + +Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a9f6c51932811593f81ff30b949124186). + + +### Nan::GetHeapStatistics() + +Signature: + +```c++ +void Nan::GetHeapStatistics(v8::HeapStatistics *heap_statistics) +``` + +Calls V8's [`GetHeapStatistics()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a5593ac74687b713095c38987e5950b34). + + +### Nan::SetCounterFunction() + +Signature: + +```c++ +void Nan::SetCounterFunction(v8::CounterLookupCallback cb) +``` + +Calls V8's [`SetCounterFunction()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a045d7754e62fa0ec72ae6c259b29af94). + + +### Nan::SetCreateHistogramFunction() + +Signature: + +```c++ +void Nan::SetCreateHistogramFunction(v8::CreateHistogramCallback cb) +``` + +Calls V8's [`SetCreateHistogramFunction()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a542d67e85089cb3f92aadf032f99e732). + + +### Nan::SetAddHistogramSampleFunction() + +Signature: + +```c++ +void Nan::SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) +``` + +Calls V8's [`SetAddHistogramSampleFunction()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#aeb420b690bc2c216882d6fdd00ddd3ea). + + +### Nan::IdleNotification() + +Signature: + +```c++ +void Nan::IdleNotification(v8::HeapStatistics *heap_statistics) +``` + +Calls V8's [`IdleNotification()` or `IdleNotificationDeadline()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ad6a2a02657f5425ad460060652a5a118) depending on V8 version. + + +### Nan::LowMemoryNotification() + +Signature: + +```c++ +void Nan::LowMemoryNotification() +``` + +Calls V8's [`IdleNotification()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a24647f61d6b41f69668094bdcd6ea91f). + + +### Nan::ContextDisposedNotification() + +Signature: + +```c++ +void Nan::ContextDisposedNotification() +``` + +Calls V8's [`ContextDisposedNotification()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b). + + +### Nan::GetInternalFieldPointer() + +Gets a pointer to the internal field with at `index` from a V8 `Object` handle. + +Signature: + +```c++ +void* Nan::GetInternalFieldPointer(v8::Local object, int index) +``` + +Calls the Object's [`GetAlignedPointerFromInternalField()` or `GetPointerFromInternalField()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#ab3c57184263cf29963ef0017bec82281) depending on the version of V8. + + +### Nan::SetInternalFieldPointer() + +Sets the value of the internal field at `index` on a V8 `Object` handle. + +Signature: + +```c++ +void Nan::SetInternalFieldPointer(v8::Local object, int index, void* value) +``` + +Calls the Object's [`SetAlignedPointerInInternalField()` or `SetPointerInInternalField()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b) depending on the version of V8. + + +### Nan::AdjustExternalMemory() + +Signature: + +```c++ +int Nan::AdjustExternalMemory(int bytesChange) +``` + +Calls V8's [`AdjustAmountOfExternalAllocatedMemory()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ae1a59cac60409d3922582c4af675473e). + diff --git a/node/node_modules/nan/doc/v8_misc.md b/node/node_modules/nan/doc/v8_misc.md new file mode 100644 index 0000000..64f736d --- /dev/null +++ b/node/node_modules/nan/doc/v8_misc.md @@ -0,0 +1,85 @@ +## Miscellaneous V8 Helpers + + - Nan::Utf8String + - Nan::GetCurrentContext() + - Nan::SetIsolateData() + - Nan::GetIsolateData() + - Nan::TypedArrayContents + + + +### Nan::Utf8String + +Converts an object to a UTF-8-encoded character array. If conversion to a string fails (e.g. due to an exception in the toString() method of the object) then the length() method returns 0 and the * operator returns NULL. The underlying memory used for this object is managed by the object. + +An implementation of [`v8::String::Utf8Value`](https://v8docs.nodesource.com/io.js-3.0/d4/d1b/classv8_1_1_string_1_1_utf8_value.html) that is consistent across all supported versions of V8. + +Definition: + +```c++ +class Nan::Utf8String { + public: + Nan::Utf8String(v8::Local from); + + int length() const; + + char* operator*(); + const char* operator*() const; +}; +``` + + +### Nan::GetCurrentContext() + +A call to [`v8::Isolate::GetCurrent()->GetCurrentContext()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a81c7a1ed7001ae2a65e89107f75fd053) that works across all supported versions of V8. + +Signature: + +```c++ +v8::Local Nan::GetCurrentContext() +``` + + +### Nan::SetIsolateData() + +A helper to provide a consistent API to [`v8::Isolate#SetData()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a7acadfe7965997e9c386a05f098fbe36). + +Signature: + +```c++ +void Nan::SetIsolateData(v8::Isolate *isolate, T *data) +``` + + + +### Nan::GetIsolateData() + +A helper to provide a consistent API to [`v8::Isolate#GetData()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#aabd223436bc1100a787dadaa024c6257). + +Signature: + +```c++ +T *Nan::GetIsolateData(v8::Isolate *isolate) +``` + + +### Nan::TypedArrayContents + +A helper class for accessing the contents of an ArrayBufferView (aka a typedarray) from C++. If the input array is not a valid typedarray, then the data pointer of TypedArrayContents will default to `NULL` and the length will be 0. If the data pointer is not compatible with the alignment requirements of type, an assertion error will fail. + +Note that you must store a reference to the `array` object while you are accessing its contents. + +Definition: + +```c++ +template +class Nan::TypedArrayContents { + public: + TypedArrayContents(v8::Local array); + + size_t length() const; + + T* const operator*(); + const T* const operator*() const; +}; +``` diff --git a/node/node_modules/nan/include_dirs.js b/node/node_modules/nan/include_dirs.js new file mode 100644 index 0000000..4f1dfb4 --- /dev/null +++ b/node/node_modules/nan/include_dirs.js @@ -0,0 +1 @@ +console.log(require('path').relative('.', __dirname)); diff --git a/node/node_modules/nan/nan.h b/node/node_modules/nan/nan.h new file mode 100644 index 0000000..7176da1 --- /dev/null +++ b/node/node_modules/nan/nan.h @@ -0,0 +1,2274 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors: + * - Rod Vagg + * - Benjamin Byholm + * - Trevor Norris + * - Nathan Rajlich + * - Brett Lawson + * - Ben Noordhuis + * - David Siegel + * + * MIT License + * + * Version 2.4.0: current Node 6.3.0, Node 12: 0.12.15, Node 10: 0.10.46, iojs: 3.3.1 + * + * See https://github.com/nodejs/nan for the latest update to this file + **********************************************************************************/ + +#ifndef NAN_H_ +#define NAN_H_ + +#include + +#define NODE_0_10_MODULE_VERSION 11 +#define NODE_0_12_MODULE_VERSION 14 +#define ATOM_0_21_MODULE_VERSION 41 +#define IOJS_1_0_MODULE_VERSION 42 +#define IOJS_1_1_MODULE_VERSION 43 +#define IOJS_2_0_MODULE_VERSION 44 +#define IOJS_3_0_MODULE_VERSION 45 +#define NODE_4_0_MODULE_VERSION 46 +#define NODE_5_0_MODULE_VERSION 47 +#define NODE_6_0_MODULE_VERSION 48 + +#ifdef _MSC_VER +# define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800) +#else +# define NAN_HAS_CPLUSPLUS_11 (__cplusplus >= 201103L) +#endif + +#if NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION && !NAN_HAS_CPLUSPLUS_11 +# error This version of node/NAN/v8 requires a C++11 compiler +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(_MSC_VER) +# pragma warning( push ) +# pragma warning( disable : 4530 ) +# include +# include +# pragma warning( pop ) +#else +# include +# include +#endif + +// uv helpers +#ifdef UV_VERSION_MAJOR +# ifndef UV_VERSION_PATCH +# define UV_VERSION_PATCH 0 +# endif +# define NAUV_UVVERSION ((UV_VERSION_MAJOR << 16) | \ + (UV_VERSION_MINOR << 8) | \ + (UV_VERSION_PATCH)) +#else +# define NAUV_UVVERSION 0x000b00 +#endif + +#if NAUV_UVVERSION < 0x000b0b +# ifdef WIN32 +# include +# else +# include +# endif +#endif + +namespace Nan { + +#define NAN_INLINE inline // TODO(bnoordhuis) Remove in v3.0.0. + +#if defined(__GNUC__) && \ + !(defined(V8_DISABLE_DEPRECATIONS) && V8_DISABLE_DEPRECATIONS) +# define NAN_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) && \ + !(defined(V8_DISABLE_DEPRECATIONS) && V8_DISABLE_DEPRECATIONS) +# define NAN_DEPRECATED __declspec(deprecated) +#else +# define NAN_DEPRECATED +#endif + +#if NAN_HAS_CPLUSPLUS_11 +# define NAN_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS&) = delete; +# define NAN_DISALLOW_COPY(CLASS) CLASS(const CLASS&) = delete; +# define NAN_DISALLOW_MOVE(CLASS) \ + CLASS(CLASS&&) = delete; /* NOLINT(build/c++11) */ \ + void operator=(CLASS&&) = delete; +#else +# define NAN_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS&); +# define NAN_DISALLOW_COPY(CLASS) CLASS(const CLASS&); +# define NAN_DISALLOW_MOVE(CLASS) +#endif + +#define NAN_DISALLOW_ASSIGN_COPY(CLASS) \ + NAN_DISALLOW_ASSIGN(CLASS) \ + NAN_DISALLOW_COPY(CLASS) + +#define NAN_DISALLOW_ASSIGN_MOVE(CLASS) \ + NAN_DISALLOW_ASSIGN(CLASS) \ + NAN_DISALLOW_MOVE(CLASS) + +#define NAN_DISALLOW_COPY_MOVE(CLASS) \ + NAN_DISALLOW_COPY(CLASS) \ + NAN_DISALLOW_MOVE(CLASS) + +#define NAN_DISALLOW_ASSIGN_COPY_MOVE(CLASS) \ + NAN_DISALLOW_ASSIGN(CLASS) \ + NAN_DISALLOW_COPY(CLASS) \ + NAN_DISALLOW_MOVE(CLASS) + +#define TYPE_CHECK(T, S) \ + while (false) { \ + *(static_cast(0)) = static_cast(0); \ + } + +//=== RegistrationFunction ===================================================== + +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + typedef v8::Handle ADDON_REGISTER_FUNCTION_ARGS_TYPE; +#else + typedef v8::Local ADDON_REGISTER_FUNCTION_ARGS_TYPE; +#endif + +#define NAN_MODULE_INIT(name) \ + void name(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target) + +//=== CallbackInfo ============================================================= + +#include "nan_callbacks.h" // NOLINT(build/include) + +//============================================================================== + +#if (NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION) +typedef v8::Script UnboundScript; +typedef v8::Script BoundScript; +#else +typedef v8::UnboundScript UnboundScript; +typedef v8::Script BoundScript; +#endif + +#if (NODE_MODULE_VERSION < ATOM_0_21_MODULE_VERSION) +typedef v8::String::ExternalAsciiStringResource + ExternalOneByteStringResource; +#else +typedef v8::String::ExternalOneByteStringResource + ExternalOneByteStringResource; +#endif + +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) +template +class NonCopyablePersistentTraits : + public v8::NonCopyablePersistentTraits {}; +template +class CopyablePersistentTraits : + public v8::CopyablePersistentTraits {}; + +template +class PersistentBase : + public v8::PersistentBase {}; + +template > +class Persistent; +#else +template class NonCopyablePersistentTraits; +template class PersistentBase; +template class WeakCallbackData; +template > +class Persistent; +#endif // NODE_MODULE_VERSION + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +# include "nan_maybe_43_inl.h" // NOLINT(build/include) +#else +# include "nan_maybe_pre_43_inl.h" // NOLINT(build/include) +#endif + +#include "nan_converters.h" // NOLINT(build/include) +#include "nan_new.h" // NOLINT(build/include) + +#if NAUV_UVVERSION < 0x000b17 +#define NAUV_WORK_CB(func) \ + void func(uv_async_t *async, int) +#else +#define NAUV_WORK_CB(func) \ + void func(uv_async_t *async) +#endif + +#if NAUV_UVVERSION >= 0x000b0b + +typedef uv_key_t nauv_key_t; + +inline int nauv_key_create(nauv_key_t *key) { + return uv_key_create(key); +} + +inline void nauv_key_delete(nauv_key_t *key) { + uv_key_delete(key); +} + +inline void* nauv_key_get(nauv_key_t *key) { + return uv_key_get(key); +} + +inline void nauv_key_set(nauv_key_t *key, void *value) { + uv_key_set(key, value); +} + +#else + +/* Implement thread local storage for older versions of libuv. + * This is essentially a backport of libuv commit 5d2434bf + * written by Ben Noordhuis, adjusted for names and inline. + */ + +#ifndef WIN32 + +typedef pthread_key_t nauv_key_t; + +inline int nauv_key_create(nauv_key_t* key) { + return -pthread_key_create(key, NULL); +} + +inline void nauv_key_delete(nauv_key_t* key) { + if (pthread_key_delete(*key)) + abort(); +} + +inline void* nauv_key_get(nauv_key_t* key) { + return pthread_getspecific(*key); +} + +inline void nauv_key_set(nauv_key_t* key, void* value) { + if (pthread_setspecific(*key, value)) + abort(); +} + +#else + +typedef struct { + DWORD tls_index; +} nauv_key_t; + +inline int nauv_key_create(nauv_key_t* key) { + key->tls_index = TlsAlloc(); + if (key->tls_index == TLS_OUT_OF_INDEXES) + return UV_ENOMEM; + return 0; +} + +inline void nauv_key_delete(nauv_key_t* key) { + if (TlsFree(key->tls_index) == FALSE) + abort(); + key->tls_index = TLS_OUT_OF_INDEXES; +} + +inline void* nauv_key_get(nauv_key_t* key) { + void* value = TlsGetValue(key->tls_index); + if (value == NULL) + if (GetLastError() != ERROR_SUCCESS) + abort(); + return value; +} + +inline void nauv_key_set(nauv_key_t* key, void* value) { + if (TlsSetValue(key->tls_index, value) == FALSE) + abort(); +} + +#endif +#endif + +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION +template +v8::Local New(v8::Handle); +#endif + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + typedef v8::WeakCallbackType WeakCallbackType; +#else +struct WeakCallbackType { + enum E {kParameter, kInternalFields}; + E type; + WeakCallbackType(E other) : type(other) {} // NOLINT(runtime/explicit) + inline bool operator==(E other) { return other == this->type; } + inline bool operator!=(E other) { return !operator==(other); } +}; +#endif + +template class WeakCallbackInfo; + +#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +# include "nan_persistent_12_inl.h" // NOLINT(build/include) +#else +# include "nan_persistent_pre_12_inl.h" // NOLINT(build/include) +#endif + +namespace imp { + static const size_t kMaxLength = 0x3fffffff; + // v8::String::REPLACE_INVALID_UTF8 was introduced + // in node.js v0.10.29 and v0.8.27. +#if NODE_MAJOR_VERSION > 0 || \ + NODE_MINOR_VERSION > 10 || \ + NODE_MINOR_VERSION == 10 && NODE_PATCH_VERSION >= 29 || \ + NODE_MINOR_VERSION == 8 && NODE_PATCH_VERSION >= 27 + static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8; +#else + static const unsigned kReplaceInvalidUtf8 = 0; +#endif +} // end of namespace imp + +//=== HandleScope ============================================================== + +class HandleScope { + v8::HandleScope scope; + + public: +#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + inline HandleScope() : scope(v8::Isolate::GetCurrent()) {} + inline static int NumberOfHandles() { + return v8::HandleScope::NumberOfHandles(v8::Isolate::GetCurrent()); + } +#else + inline HandleScope() : scope() {} + inline static int NumberOfHandles() { + return v8::HandleScope::NumberOfHandles(); + } +#endif + + private: + // Make it hard to create heap-allocated or illegal handle scopes by + // disallowing certain operations. + HandleScope(const HandleScope &); + void operator=(const HandleScope &); + void *operator new(size_t size); + void operator delete(void *, size_t); +}; + +class EscapableHandleScope { + public: +#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + inline EscapableHandleScope() : scope(v8::Isolate::GetCurrent()) {} + + inline static int NumberOfHandles() { + return v8::EscapableHandleScope::NumberOfHandles(v8::Isolate::GetCurrent()); + } + + template + inline v8::Local Escape(v8::Local value) { + return scope.Escape(value); + } + + private: + v8::EscapableHandleScope scope; +#else + inline EscapableHandleScope() : scope() {} + + inline static int NumberOfHandles() { + return v8::HandleScope::NumberOfHandles(); + } + + template + inline v8::Local Escape(v8::Local value) { + return scope.Close(value); + } + + private: + v8::HandleScope scope; +#endif + + private: + // Make it hard to create heap-allocated or illegal handle scopes by + // disallowing certain operations. + EscapableHandleScope(const EscapableHandleScope &); + void operator=(const EscapableHandleScope &); + void *operator new(size_t size); + void operator delete(void *, size_t); +}; + +//=== TryCatch ================================================================= + +class TryCatch { + v8::TryCatch try_catch_; + friend void FatalException(const TryCatch&); + + public: +#if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION + TryCatch() : try_catch_(v8::Isolate::GetCurrent()) {} +#endif + + inline bool HasCaught() const { return try_catch_.HasCaught(); } + + inline bool CanContinue() const { return try_catch_.CanContinue(); } + + inline v8::Local ReThrow() { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + return New(try_catch_.ReThrow()); +#else + return try_catch_.ReThrow(); +#endif + } + + inline v8::Local Exception() const { + return try_catch_.Exception(); + } + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + inline v8::MaybeLocal StackTrace() const { + return try_catch_.StackTrace(GetCurrentContext()); + } +#else + inline MaybeLocal StackTrace() const { + return MaybeLocal(try_catch_.StackTrace()); + } +#endif + + inline v8::Local Message() const { + return try_catch_.Message(); + } + + inline void Reset() { try_catch_.Reset(); } + + inline void SetVerbose(bool value) { try_catch_.SetVerbose(value); } + + inline void SetCaptureMessage(bool value) { + try_catch_.SetCaptureMessage(value); + } +}; + +//============ ================================================================= + +/* node 0.12 */ +#if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION + inline + void SetCounterFunction(v8::CounterLookupCallback cb) { + v8::Isolate::GetCurrent()->SetCounterFunction(cb); + } + + inline + void SetCreateHistogramFunction(v8::CreateHistogramCallback cb) { + v8::Isolate::GetCurrent()->SetCreateHistogramFunction(cb); + } + + inline + void SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { + v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb); + } + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + inline bool IdleNotification(int idle_time_in_ms) { + return v8::Isolate::GetCurrent()->IdleNotificationDeadline( + idle_time_in_ms * 0.001); + } +# else + inline bool IdleNotification(int idle_time_in_ms) { + return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms); + } +#endif + + inline void LowMemoryNotification() { + v8::Isolate::GetCurrent()->LowMemoryNotification(); + } + + inline void ContextDisposedNotification() { + v8::Isolate::GetCurrent()->ContextDisposedNotification(); + } +#else + inline + void SetCounterFunction(v8::CounterLookupCallback cb) { + v8::V8::SetCounterFunction(cb); + } + + inline + void SetCreateHistogramFunction(v8::CreateHistogramCallback cb) { + v8::V8::SetCreateHistogramFunction(cb); + } + + inline + void SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { + v8::V8::SetAddHistogramSampleFunction(cb); + } + + inline bool IdleNotification(int idle_time_in_ms) { + return v8::V8::IdleNotification(idle_time_in_ms); + } + + inline void LowMemoryNotification() { + v8::V8::LowMemoryNotification(); + } + + inline void ContextDisposedNotification() { + v8::V8::ContextDisposedNotification(); + } +#endif + +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) // Node 0.12 + inline v8::Local Undefined() { +# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::Undefined(v8::Isolate::GetCurrent()))); +# else + return v8::Undefined(v8::Isolate::GetCurrent()); +# endif + } + + inline v8::Local Null() { +# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::Null(v8::Isolate::GetCurrent()))); +# else + return v8::Null(v8::Isolate::GetCurrent()); +# endif + } + + inline v8::Local True() { +# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::True(v8::Isolate::GetCurrent()))); +# else + return v8::True(v8::Isolate::GetCurrent()); +# endif + } + + inline v8::Local False() { +# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::False(v8::Isolate::GetCurrent()))); +# else + return v8::False(v8::Isolate::GetCurrent()); +# endif + } + + inline v8::Local EmptyString() { + return v8::String::Empty(v8::Isolate::GetCurrent()); + } + + inline int AdjustExternalMemory(int bc) { + return static_cast( + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(bc)); + } + + inline void SetTemplate( + v8::Local templ + , const char *name + , v8::Local value) { + templ->Set(v8::Isolate::GetCurrent(), name, value); + } + + inline void SetTemplate( + v8::Local templ + , v8::Local name + , v8::Local value + , v8::PropertyAttribute attributes) { + templ->Set(name, value, attributes); + } + + inline v8::Local GetCurrentContext() { + return v8::Isolate::GetCurrent()->GetCurrentContext(); + } + + inline void* GetInternalFieldPointer( + v8::Local object + , int index) { + return object->GetAlignedPointerFromInternalField(index); + } + + inline void SetInternalFieldPointer( + v8::Local object + , int index + , void* value) { + object->SetAlignedPointerInInternalField(index, value); + } + +# define NAN_GC_CALLBACK(name) \ + void name(v8::Isolate *isolate, v8::GCType type, v8::GCCallbackFlags flags) + +#if NODE_MODULE_VERSION <= NODE_4_0_MODULE_VERSION + typedef v8::Isolate::GCEpilogueCallback GCEpilogueCallback; + typedef v8::Isolate::GCPrologueCallback GCPrologueCallback; +#else + typedef v8::Isolate::GCCallback GCEpilogueCallback; + typedef v8::Isolate::GCCallback GCPrologueCallback; +#endif + + inline void AddGCEpilogueCallback( + GCEpilogueCallback callback + , v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::Isolate::GetCurrent()->AddGCEpilogueCallback(callback, gc_type_filter); + } + + inline void RemoveGCEpilogueCallback( + GCEpilogueCallback callback) { + v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback(callback); + } + + inline void AddGCPrologueCallback( + GCPrologueCallback callback + , v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::Isolate::GetCurrent()->AddGCPrologueCallback(callback, gc_type_filter); + } + + inline void RemoveGCPrologueCallback( + GCPrologueCallback callback) { + v8::Isolate::GetCurrent()->RemoveGCPrologueCallback(callback); + } + + inline void GetHeapStatistics( + v8::HeapStatistics *heap_statistics) { + v8::Isolate::GetCurrent()->GetHeapStatistics(heap_statistics); + } + +# define X(NAME) \ + inline v8::Local NAME(const char *msg) { \ + EscapableHandleScope scope; \ + return scope.Escape(v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ + \ + inline \ + v8::Local NAME(v8::Local msg) { \ + return v8::Exception::NAME(msg); \ + } \ + \ + inline void Throw ## NAME(const char *msg) { \ + HandleScope scope; \ + v8::Isolate::GetCurrent()->ThrowException( \ + v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ + \ + inline void Throw ## NAME(v8::Local msg) { \ + HandleScope scope; \ + v8::Isolate::GetCurrent()->ThrowException( \ + v8::Exception::NAME(msg)); \ + } + + X(Error) + X(RangeError) + X(ReferenceError) + X(SyntaxError) + X(TypeError) + +# undef X + + inline void ThrowError(v8::Local error) { + v8::Isolate::GetCurrent()->ThrowException(error); + } + + inline MaybeLocal NewBuffer( + char *data + , size_t length +#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION + , node::Buffer::FreeCallback callback +#else + , node::smalloc::FreeCallback callback +#endif + , void *hint + ) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(length <= imp::kMaxLength && "too large buffer"); +#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION + return node::Buffer::New( + v8::Isolate::GetCurrent(), data, length, callback, hint); +#else + return MaybeLocal(node::Buffer::New( + v8::Isolate::GetCurrent(), data, length, callback, hint)); +#endif + } + + inline MaybeLocal CopyBuffer( + const char *data + , uint32_t size + ) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); +#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION + return node::Buffer::Copy( + v8::Isolate::GetCurrent(), data, size); +#else + return MaybeLocal(node::Buffer::New( + v8::Isolate::GetCurrent(), data, size)); +#endif + } + + inline MaybeLocal NewBuffer(uint32_t size) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); +#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION + return node::Buffer::New( + v8::Isolate::GetCurrent(), size); +#else + return MaybeLocal(node::Buffer::New( + v8::Isolate::GetCurrent(), size)); +#endif + } + + inline MaybeLocal NewBuffer( + char* data + , uint32_t size + ) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); +#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION + return node::Buffer::New(v8::Isolate::GetCurrent(), data, size); +#else + return MaybeLocal( + node::Buffer::Use(v8::Isolate::GetCurrent(), data, size)); +#endif + } + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + inline MaybeLocal + NewOneByteString(const uint8_t * value, int length = -1) { + return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value, + v8::NewStringType::kNormal, length); + } + + inline MaybeLocal CompileScript( + v8::Local s + , const v8::ScriptOrigin& origin + ) { + v8::ScriptCompiler::Source source(s, origin); + return v8::ScriptCompiler::Compile(GetCurrentContext(), &source); + } + + inline MaybeLocal CompileScript( + v8::Local s + ) { + v8::ScriptCompiler::Source source(s); + return v8::ScriptCompiler::Compile(GetCurrentContext(), &source); + } + + inline MaybeLocal RunScript( + v8::Local script + ) { + return script->BindToCurrentContext()->Run(GetCurrentContext()); + } + + inline MaybeLocal RunScript( + v8::Local script + ) { + return script->Run(GetCurrentContext()); + } +#else + inline MaybeLocal + NewOneByteString(const uint8_t * value, int length = -1) { + return MaybeLocal( + v8::String::NewFromOneByte( + v8::Isolate::GetCurrent() + , value + , v8::String::kNormalString, length)); + } + + inline MaybeLocal CompileScript( + v8::Local s + , const v8::ScriptOrigin& origin + ) { + v8::ScriptCompiler::Source source(s, origin); + return MaybeLocal( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source)); + } + + inline MaybeLocal CompileScript( + v8::Local s + ) { + v8::ScriptCompiler::Source source(s); + return MaybeLocal( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source)); + } + + inline MaybeLocal RunScript( + v8::Local script + ) { + return MaybeLocal(script->BindToCurrentContext()->Run()); + } + + inline MaybeLocal RunScript( + v8::Local script + ) { + return MaybeLocal(script->Run()); + } +#endif + + inline v8::Local MakeCallback( + v8::Local target + , v8::Local func + , int argc + , v8::Local* argv) { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + return New(node::MakeCallback( + v8::Isolate::GetCurrent(), target, func, argc, argv)); +#else + return node::MakeCallback( + v8::Isolate::GetCurrent(), target, func, argc, argv); +#endif + } + + inline v8::Local MakeCallback( + v8::Local target + , v8::Local symbol + , int argc + , v8::Local* argv) { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + return New(node::MakeCallback( + v8::Isolate::GetCurrent(), target, symbol, argc, argv)); +#else + return node::MakeCallback( + v8::Isolate::GetCurrent(), target, symbol, argc, argv); +#endif + } + + inline v8::Local MakeCallback( + v8::Local target + , const char* method + , int argc + , v8::Local* argv) { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + return New(node::MakeCallback( + v8::Isolate::GetCurrent(), target, method, argc, argv)); +#else + return node::MakeCallback( + v8::Isolate::GetCurrent(), target, method, argc, argv); +#endif + } + + inline void FatalException(const TryCatch& try_catch) { + node::FatalException(v8::Isolate::GetCurrent(), try_catch.try_catch_); + } + + inline v8::Local ErrnoException( + int errorno + , const char* syscall = NULL + , const char* message = NULL + , const char* path = NULL) { + return node::ErrnoException(v8::Isolate::GetCurrent(), errorno, syscall, + message, path); + } + + NAN_DEPRECATED inline v8::Local NanErrnoException( + int errorno + , const char* syscall = NULL + , const char* message = NULL + , const char* path = NULL) { + return ErrnoException(errorno, syscall, message, path); + } + + template + inline void SetIsolateData( + v8::Isolate *isolate + , T *data + ) { + isolate->SetData(0, data); + } + + template + inline T *GetIsolateData( + v8::Isolate *isolate + ) { + return static_cast(isolate->GetData(0)); + } + +class Utf8String { + public: + inline explicit Utf8String(v8::Local from) : + length_(0), str_(str_st_) { + if (!from.IsEmpty()) { + v8::Local string = from->ToString(); + if (!string.IsEmpty()) { + size_t len = 3 * string->Length() + 1; + assert(len <= INT_MAX); + if (len > sizeof (str_st_)) { + str_ = static_cast(malloc(len)); + assert(str_ != 0); + } + const int flags = + v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8; + length_ = string->WriteUtf8(str_, static_cast(len), 0, flags); + str_[length_] = '\0'; + } + } + } + + inline int length() const { + return length_; + } + + inline char* operator*() { return str_; } + inline const char* operator*() const { return str_; } + + inline ~Utf8String() { + if (str_ != str_st_) { + free(str_); + } + } + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(Utf8String) + + int length_; + char *str_; + char str_st_[1024]; +}; + +#else // Node 0.8 and 0.10 + inline v8::Local Undefined() { + EscapableHandleScope scope; + return scope.Escape(New(v8::Undefined())); + } + + inline v8::Local Null() { + EscapableHandleScope scope; + return scope.Escape(New(v8::Null())); + } + + inline v8::Local True() { + EscapableHandleScope scope; + return scope.Escape(New(v8::True())); + } + + inline v8::Local False() { + EscapableHandleScope scope; + return scope.Escape(New(v8::False())); + } + + inline v8::Local EmptyString() { + return v8::String::Empty(); + } + + inline int AdjustExternalMemory(int bc) { + return static_cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(bc)); + } + + inline void SetTemplate( + v8::Local templ + , const char *name + , v8::Local value) { + templ->Set(name, value); + } + + inline void SetTemplate( + v8::Local templ + , v8::Local name + , v8::Local value + , v8::PropertyAttribute attributes) { + templ->Set(name, value, attributes); + } + + inline v8::Local GetCurrentContext() { + return v8::Context::GetCurrent(); + } + + inline void* GetInternalFieldPointer( + v8::Local object + , int index) { + return object->GetPointerFromInternalField(index); + } + + inline void SetInternalFieldPointer( + v8::Local object + , int index + , void* value) { + object->SetPointerInInternalField(index, value); + } + +# define NAN_GC_CALLBACK(name) \ + void name(v8::GCType type, v8::GCCallbackFlags flags) + + inline void AddGCEpilogueCallback( + v8::GCEpilogueCallback callback + , v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::V8::AddGCEpilogueCallback(callback, gc_type_filter); + } + inline void RemoveGCEpilogueCallback( + v8::GCEpilogueCallback callback) { + v8::V8::RemoveGCEpilogueCallback(callback); + } + inline void AddGCPrologueCallback( + v8::GCPrologueCallback callback + , v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::V8::AddGCPrologueCallback(callback, gc_type_filter); + } + inline void RemoveGCPrologueCallback( + v8::GCPrologueCallback callback) { + v8::V8::RemoveGCPrologueCallback(callback); + } + inline void GetHeapStatistics( + v8::HeapStatistics *heap_statistics) { + v8::V8::GetHeapStatistics(heap_statistics); + } + +# define X(NAME) \ + inline v8::Local NAME(const char *msg) { \ + EscapableHandleScope scope; \ + return scope.Escape(v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ + \ + inline \ + v8::Local NAME(v8::Local msg) { \ + return v8::Exception::NAME(msg); \ + } \ + \ + inline void Throw ## NAME(const char *msg) { \ + HandleScope scope; \ + v8::ThrowException(v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ + \ + inline \ + void Throw ## NAME(v8::Local errmsg) { \ + v8::ThrowException(v8::Exception::NAME(errmsg)); \ + } + + X(Error) + X(RangeError) + X(ReferenceError) + X(SyntaxError) + X(TypeError) + +# undef X + + inline void ThrowError(v8::Local error) { + v8::ThrowException(error); + } + + inline MaybeLocal NewBuffer( + char *data + , size_t length + , node::Buffer::free_callback callback + , void *hint + ) { + EscapableHandleScope scope; + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(length <= imp::kMaxLength && "too large buffer"); + return MaybeLocal(scope.Escape( + New(node::Buffer::New(data, length, callback, hint)->handle_))); + } + + inline MaybeLocal CopyBuffer( + const char *data + , uint32_t size + ) { + EscapableHandleScope scope; + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); +#if NODE_MODULE_VERSION >= NODE_0_10_MODULE_VERSION + return MaybeLocal( + scope.Escape(New(node::Buffer::New(data, size)->handle_))); +#else + return MaybeLocal(scope.Escape( + New(node::Buffer::New(const_cast(data), size)->handle_))); +#endif + } + + inline MaybeLocal NewBuffer(uint32_t size) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + assert(size <= imp::kMaxLength && "too large buffer"); + return MaybeLocal( + scope.Escape(New(node::Buffer::New(size)->handle_))); + } + + inline void FreeData(char *data, void *hint) { + (void) hint; // unused + delete[] data; + } + + inline MaybeLocal NewBuffer( + char* data + , uint32_t size + ) { + EscapableHandleScope scope; + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); + return MaybeLocal(scope.Escape(New( + node::Buffer::New(data, size, FreeData, NULL)->handle_))); + } + +namespace imp { +inline void +widenString(std::vector *ws, const uint8_t *s, int l) { + size_t len = static_cast(l); + if (l < 0) { + len = strlen(reinterpret_cast(s)); + } + assert(len <= INT_MAX && "string too long"); + ws->resize(len); + std::copy(s, s + len, ws->begin()); // NOLINT(build/include_what_you_use) +} +} // end of namespace imp + + inline MaybeLocal + NewOneByteString(const uint8_t * value, int length = -1) { + std::vector wideString; // NOLINT(build/include_what_you_use) + imp::widenString(&wideString, value, length); + return imp::Factory::return_t(v8::String::New( + &wideString.front(), static_cast(wideString.size()))); + } + + inline MaybeLocal CompileScript( + v8::Local s + , const v8::ScriptOrigin& origin + ) { + return MaybeLocal( + v8::Script::Compile(s, const_cast(&origin))); + } + + inline MaybeLocal CompileScript( + v8::Local s + ) { + return MaybeLocal(v8::Script::Compile(s)); + } + + inline + MaybeLocal RunScript(v8::Local script) { + return MaybeLocal(script->Run()); + } + + inline v8::Local MakeCallback( + v8::Local target + , v8::Local func + , int argc + , v8::Local* argv) { + return New(node::MakeCallback(target, func, argc, argv)); + } + + inline v8::Local MakeCallback( + v8::Local target + , v8::Local symbol + , int argc + , v8::Local* argv) { + return New(node::MakeCallback(target, symbol, argc, argv)); + } + + inline v8::Local MakeCallback( + v8::Local target + , const char* method + , int argc + , v8::Local* argv) { + return New(node::MakeCallback(target, method, argc, argv)); + } + + inline void FatalException(const TryCatch& try_catch) { + node::FatalException(const_cast(try_catch.try_catch_)); + } + + inline v8::Local ErrnoException( + int errorno + , const char* syscall = NULL + , const char* message = NULL + , const char* path = NULL) { + return node::ErrnoException(errorno, syscall, message, path); + } + + NAN_DEPRECATED inline v8::Local NanErrnoException( + int errorno + , const char* syscall = NULL + , const char* message = NULL + , const char* path = NULL) { + return ErrnoException(errorno, syscall, message, path); + } + + + template + inline void SetIsolateData( + v8::Isolate *isolate + , T *data + ) { + isolate->SetData(data); + } + + template + inline T *GetIsolateData( + v8::Isolate *isolate + ) { + return static_cast(isolate->GetData()); + } + +class Utf8String { + public: + inline explicit Utf8String(v8::Local from) : + length_(0), str_(str_st_) { + if (!from.IsEmpty()) { + v8::Local string = from->ToString(); + if (!string.IsEmpty()) { + size_t len = 3 * string->Length() + 1; + assert(len <= INT_MAX); + if (len > sizeof (str_st_)) { + str_ = static_cast(malloc(len)); + assert(str_ != 0); + } + const int flags = + v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8; + length_ = string->WriteUtf8(str_, static_cast(len), 0, flags); + str_[length_] = '\0'; + } + } + } + + inline int length() const { + return length_; + } + + inline char* operator*() { return str_; } + inline const char* operator*() const { return str_; } + + inline ~Utf8String() { + if (str_ != str_st_) { + free(str_); + } + } + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(Utf8String) + + int length_; + char *str_; + char str_st_[1024]; +}; + +#endif // NODE_MODULE_VERSION + +typedef void (*FreeCallback)(char *data, void *hint); + +typedef const FunctionCallbackInfo& NAN_METHOD_ARGS_TYPE; +typedef void NAN_METHOD_RETURN_TYPE; + +typedef const PropertyCallbackInfo& NAN_GETTER_ARGS_TYPE; +typedef void NAN_GETTER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& NAN_SETTER_ARGS_TYPE; +typedef void NAN_SETTER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_PROPERTY_GETTER_ARGS_TYPE; +typedef void NAN_PROPERTY_GETTER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_PROPERTY_SETTER_ARGS_TYPE; +typedef void NAN_PROPERTY_SETTER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_PROPERTY_ENUMERATOR_ARGS_TYPE; +typedef void NAN_PROPERTY_ENUMERATOR_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_PROPERTY_DELETER_ARGS_TYPE; +typedef void NAN_PROPERTY_DELETER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_PROPERTY_QUERY_ARGS_TYPE; +typedef void NAN_PROPERTY_QUERY_RETURN_TYPE; + +typedef const PropertyCallbackInfo& NAN_INDEX_GETTER_ARGS_TYPE; +typedef void NAN_INDEX_GETTER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& NAN_INDEX_SETTER_ARGS_TYPE; +typedef void NAN_INDEX_SETTER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_INDEX_ENUMERATOR_ARGS_TYPE; +typedef void NAN_INDEX_ENUMERATOR_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_INDEX_DELETER_ARGS_TYPE; +typedef void NAN_INDEX_DELETER_RETURN_TYPE; + +typedef const PropertyCallbackInfo& + NAN_INDEX_QUERY_ARGS_TYPE; +typedef void NAN_INDEX_QUERY_RETURN_TYPE; + +#define NAN_METHOD(name) \ + Nan::NAN_METHOD_RETURN_TYPE name(Nan::NAN_METHOD_ARGS_TYPE info) +#define NAN_GETTER(name) \ + Nan::NAN_GETTER_RETURN_TYPE name( \ + v8::Local property \ + , Nan::NAN_GETTER_ARGS_TYPE info) +#define NAN_SETTER(name) \ + Nan::NAN_SETTER_RETURN_TYPE name( \ + v8::Local property \ + , v8::Local value \ + , Nan::NAN_SETTER_ARGS_TYPE info) +#define NAN_PROPERTY_GETTER(name) \ + Nan::NAN_PROPERTY_GETTER_RETURN_TYPE name( \ + v8::Local property \ + , Nan::NAN_PROPERTY_GETTER_ARGS_TYPE info) +#define NAN_PROPERTY_SETTER(name) \ + Nan::NAN_PROPERTY_SETTER_RETURN_TYPE name( \ + v8::Local property \ + , v8::Local value \ + , Nan::NAN_PROPERTY_SETTER_ARGS_TYPE info) +#define NAN_PROPERTY_ENUMERATOR(name) \ + Nan::NAN_PROPERTY_ENUMERATOR_RETURN_TYPE name( \ + Nan::NAN_PROPERTY_ENUMERATOR_ARGS_TYPE info) +#define NAN_PROPERTY_DELETER(name) \ + Nan::NAN_PROPERTY_DELETER_RETURN_TYPE name( \ + v8::Local property \ + , Nan::NAN_PROPERTY_DELETER_ARGS_TYPE info) +#define NAN_PROPERTY_QUERY(name) \ + Nan::NAN_PROPERTY_QUERY_RETURN_TYPE name( \ + v8::Local property \ + , Nan::NAN_PROPERTY_QUERY_ARGS_TYPE info) +# define NAN_INDEX_GETTER(name) \ + Nan::NAN_INDEX_GETTER_RETURN_TYPE name( \ + uint32_t index \ + , Nan::NAN_INDEX_GETTER_ARGS_TYPE info) +#define NAN_INDEX_SETTER(name) \ + Nan::NAN_INDEX_SETTER_RETURN_TYPE name( \ + uint32_t index \ + , v8::Local value \ + , Nan::NAN_INDEX_SETTER_ARGS_TYPE info) +#define NAN_INDEX_ENUMERATOR(name) \ + Nan::NAN_INDEX_ENUMERATOR_RETURN_TYPE \ + name(Nan::NAN_INDEX_ENUMERATOR_ARGS_TYPE info) +#define NAN_INDEX_DELETER(name) \ + Nan::NAN_INDEX_DELETER_RETURN_TYPE name( \ + uint32_t index \ + , Nan::NAN_INDEX_DELETER_ARGS_TYPE info) +#define NAN_INDEX_QUERY(name) \ + Nan::NAN_INDEX_QUERY_RETURN_TYPE name( \ + uint32_t index \ + , Nan::NAN_INDEX_QUERY_ARGS_TYPE info) + +class Callback { + public: + Callback() {} + + explicit Callback(const v8::Local &fn) : handle_(fn) {} + + ~Callback() { + handle_.Reset(); + } + + bool operator==(const Callback &other) const { + return handle_ == other.handle_; + } + + bool operator!=(const Callback &other) const { + return !operator==(other); + } + + inline + v8::Local operator*() const { return GetFunction(); } + + inline v8::Local operator()( + v8::Local target + , int argc = 0 + , v8::Local argv[] = 0) const { + return this->Call(target, argc, argv); + } + + inline v8::Local operator()( + int argc = 0 + , v8::Local argv[] = 0) const { + return this->Call(argc, argv); + } + + // TODO(kkoopa): remove + inline void SetFunction(const v8::Local &fn) { + Reset(fn); + } + + inline void Reset(const v8::Local &fn) { + handle_.Reset(fn); + } + + inline void Reset() { + handle_.Reset(); + } + + inline v8::Local GetFunction() const { + return New(handle_); + } + + inline bool IsEmpty() const { + return handle_.IsEmpty(); + } + + inline v8::Local + Call(v8::Local target + , int argc + , v8::Local argv[]) const { +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + return Call_(isolate, target, argc, argv); +#else + return Call_(target, argc, argv); +#endif + } + + inline v8::Local + Call(int argc, v8::Local argv[]) const { +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + return Call_(isolate, isolate->GetCurrentContext()->Global(), argc, argv); +#else + return Call_(v8::Context::GetCurrent()->Global(), argc, argv); +#endif + } + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(Callback) + Persistent handle_; + +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + v8::Local Call_(v8::Isolate *isolate + , v8::Local target + , int argc + , v8::Local argv[]) const { + EscapableHandleScope scope; + + v8::Local callback = New(handle_); +# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + return scope.Escape(New(node::MakeCallback( + isolate + , target + , callback + , argc + , argv + ))); +# else + return scope.Escape(node::MakeCallback( + isolate + , target + , callback + , argc + , argv + )); +# endif + } +#else + v8::Local Call_(v8::Local target + , int argc + , v8::Local argv[]) const { + EscapableHandleScope scope; + + v8::Local callback = New(handle_); + return scope.Escape(New(node::MakeCallback( + target + , callback + , argc + , argv + ))); + } +#endif +}; + +/* abstract */ class AsyncWorker { + public: + explicit AsyncWorker(Callback *callback_) + : callback(callback_), errmsg_(NULL) { + request.data = this; + + HandleScope scope; + v8::Local obj = New(); + persistentHandle.Reset(obj); + } + + virtual ~AsyncWorker() { + HandleScope scope; + + if (!persistentHandle.IsEmpty()) + persistentHandle.Reset(); + delete callback; + delete[] errmsg_; + } + + virtual void WorkComplete() { + HandleScope scope; + + if (errmsg_ == NULL) + HandleOKCallback(); + else + HandleErrorCallback(); + delete callback; + callback = NULL; + } + + inline void SaveToPersistent( + const char *key, const v8::Local &value) { + HandleScope scope; + New(persistentHandle)->Set(New(key).ToLocalChecked(), value); + } + + inline void SaveToPersistent( + const v8::Local &key, const v8::Local &value) { + HandleScope scope; + New(persistentHandle)->Set(key, value); + } + + inline void SaveToPersistent( + uint32_t index, const v8::Local &value) { + HandleScope scope; + New(persistentHandle)->Set(index, value); + } + + inline v8::Local GetFromPersistent(const char *key) const { + EscapableHandleScope scope; + return scope.Escape( + New(persistentHandle)->Get(New(key).ToLocalChecked())); + } + + inline v8::Local + GetFromPersistent(const v8::Local &key) const { + EscapableHandleScope scope; + return scope.Escape(New(persistentHandle)->Get(key)); + } + + inline v8::Local GetFromPersistent(uint32_t index) const { + EscapableHandleScope scope; + return scope.Escape(New(persistentHandle)->Get(index)); + } + + virtual void Execute() = 0; + + uv_work_t request; + + virtual void Destroy() { + delete this; + } + + protected: + Persistent persistentHandle; + Callback *callback; + + virtual void HandleOKCallback() { + callback->Call(0, NULL); + } + + virtual void HandleErrorCallback() { + HandleScope scope; + + v8::Local argv[] = { + v8::Exception::Error(New(ErrorMessage()).ToLocalChecked()) + }; + callback->Call(1, argv); + } + + void SetErrorMessage(const char *msg) { + delete[] errmsg_; + + size_t size = strlen(msg) + 1; + errmsg_ = new char[size]; + memcpy(errmsg_, msg, size); + } + + const char* ErrorMessage() const { + return errmsg_; + } + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(AsyncWorker) + char *errmsg_; +}; + + +template +/* abstract */ class AsyncProgressWorkerBase : public AsyncWorker { + public: + explicit AsyncProgressWorkerBase(Callback *callback_) + : AsyncWorker(callback_), asyncdata_(NULL), asyncsize_(0) { + async = new uv_async_t; + uv_async_init( + uv_default_loop() + , async + , AsyncProgress_ + ); + async->data = this; + + uv_mutex_init(&async_lock); + } + + virtual ~AsyncProgressWorkerBase() { + uv_mutex_destroy(&async_lock); + + delete[] asyncdata_; + } + + void WorkProgress() { + uv_mutex_lock(&async_lock); + T *data = asyncdata_; + size_t size = asyncsize_; + asyncdata_ = NULL; + uv_mutex_unlock(&async_lock); + + // Don't send progress events after we've already completed. + if (callback) { + HandleProgressCallback(data, size); + } + delete[] data; + } + + class ExecutionProgress { + friend class AsyncProgressWorkerBase; + public: + void Signal() const { + uv_async_send(that_->async); + } + + void Send(const T* data, size_t size) const { + that_->SendProgress_(data, size); + } + + private: + explicit ExecutionProgress(AsyncProgressWorkerBase *that) : that_(that) {} + NAN_DISALLOW_ASSIGN_COPY_MOVE(ExecutionProgress) + AsyncProgressWorkerBase* const that_; + }; + + virtual void Execute(const ExecutionProgress& progress) = 0; + virtual void HandleProgressCallback(const T *data, size_t size) = 0; + + virtual void Destroy() { + uv_close(reinterpret_cast(async), AsyncClose_); + } + + private: + void Execute() /*final override*/ { + ExecutionProgress progress(this); + Execute(progress); + } + + void SendProgress_(const T *data, size_t size) { + T *new_data = new T[size]; + { + T *it = new_data; + std::copy(data, data + size, it); + } + + uv_mutex_lock(&async_lock); + T *old_data = asyncdata_; + asyncdata_ = new_data; + asyncsize_ = size; + uv_mutex_unlock(&async_lock); + + delete[] old_data; + uv_async_send(async); + } + + inline static NAUV_WORK_CB(AsyncProgress_) { + AsyncProgressWorkerBase *worker = + static_cast(async->data); + worker->WorkProgress(); + } + + inline static void AsyncClose_(uv_handle_t* handle) { + AsyncProgressWorkerBase *worker = + static_cast(handle->data); + delete reinterpret_cast(handle); + delete worker; + } + + uv_async_t *async; + uv_mutex_t async_lock; + T *asyncdata_; + size_t asyncsize_; +}; + +// This ensures compatibility to the previous un-templated AsyncProgressWorker +// class definition. +typedef AsyncProgressWorkerBase AsyncProgressWorker; + +inline void AsyncExecute (uv_work_t* req) { + AsyncWorker *worker = static_cast(req->data); + worker->Execute(); +} + +inline void AsyncExecuteComplete (uv_work_t* req) { + AsyncWorker* worker = static_cast(req->data); + worker->WorkComplete(); + worker->Destroy(); +} + +inline void AsyncQueueWorker (AsyncWorker* worker) { + uv_queue_work( + uv_default_loop() + , &worker->request + , AsyncExecute + , reinterpret_cast(AsyncExecuteComplete) + ); +} + +namespace imp { + +inline +ExternalOneByteStringResource const* +GetExternalResource(v8::Local str) { +#if NODE_MODULE_VERSION < ATOM_0_21_MODULE_VERSION + return str->GetExternalAsciiStringResource(); +#else + return str->GetExternalOneByteStringResource(); +#endif +} + +inline +bool +IsExternal(v8::Local str) { +#if NODE_MODULE_VERSION < ATOM_0_21_MODULE_VERSION + return str->IsExternalAscii(); +#else + return str->IsExternalOneByte(); +#endif +} + +} // end of namespace imp + +enum Encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER}; + +#if NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION +# include "nan_string_bytes.h" // NOLINT(build/include) +#endif + +inline v8::Local Encode( + const void *buf, size_t len, enum Encoding encoding = BINARY) { +#if (NODE_MODULE_VERSION >= ATOM_0_21_MODULE_VERSION) + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + node::encoding node_enc = static_cast(encoding); + + if (encoding == UCS2) { + return node::Encode( + isolate + , reinterpret_cast(buf) + , len / 2); + } else { + return node::Encode( + isolate + , reinterpret_cast(buf) + , len + , node_enc); + } +#elif (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + return node::Encode( + v8::Isolate::GetCurrent() + , buf, len + , static_cast(encoding)); +#else +# if NODE_MODULE_VERSION >= NODE_0_10_MODULE_VERSION + return node::Encode(buf, len, static_cast(encoding)); +# else + return imp::Encode(reinterpret_cast(buf), len, encoding); +# endif +#endif +} + +inline ssize_t DecodeBytes( + v8::Local val, enum Encoding encoding = BINARY) { +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + return node::DecodeBytes( + v8::Isolate::GetCurrent() + , val + , static_cast(encoding)); +#else +# if (NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION) + if (encoding == BUFFER) { + return node::DecodeBytes(val, node::BINARY); + } +# endif + return node::DecodeBytes(val, static_cast(encoding)); +#endif +} + +inline ssize_t DecodeWrite( + char *buf + , size_t len + , v8::Local val + , enum Encoding encoding = BINARY) { +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + return node::DecodeWrite( + v8::Isolate::GetCurrent() + , buf + , len + , val + , static_cast(encoding)); +#else +# if (NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION) + if (encoding == BUFFER) { + return node::DecodeWrite(buf, len, val, node::BINARY); + } +# endif + return node::DecodeWrite( + buf + , len + , val + , static_cast(encoding)); +#endif +} + +inline void SetPrototypeTemplate( + v8::Local templ + , const char *name + , v8::Local value +) { + SetTemplate(templ->PrototypeTemplate(), name, value); +} + +inline void SetPrototypeTemplate( + v8::Local templ + , v8::Local name + , v8::Local value + , v8::PropertyAttribute attributes +) { + SetTemplate(templ->PrototypeTemplate(), name, value, attributes); +} + +inline void SetInstanceTemplate( + v8::Local templ + , const char *name + , v8::Local value +) { + SetTemplate(templ->InstanceTemplate(), name, value); +} + +inline void SetInstanceTemplate( + v8::Local templ + , v8::Local name + , v8::Local value + , v8::PropertyAttribute attributes +) { + SetTemplate(templ->InstanceTemplate(), name, value, attributes); +} + +namespace imp { + +// Note(@agnat): Helper to distinguish different receiver types. The first +// version deals with receivers derived from v8::Template. The second version +// handles everything else. The final argument only serves as discriminator and +// is unused. +template +inline +void +SetMethodAux(T recv, + v8::Local name, + v8::Local tpl, + v8::Template *) { + recv->Set(name, tpl); +} + +template +inline +void +SetMethodAux(T recv, + v8::Local name, + v8::Local tpl, + ...) { + recv->Set(name, GetFunction(tpl).ToLocalChecked()); +} + +} // end of namespace imp + +template class HandleType> +inline void SetMethod( + HandleType recv + , const char *name + , FunctionCallback callback) { + HandleScope scope; + v8::Local t = New(callback); + v8::Local fn_name = New(name).ToLocalChecked(); + t->SetClassName(fn_name); + // Note(@agnat): Pass an empty T* as discriminator. See note on + // SetMethodAux(...) above + imp::SetMethodAux(recv, fn_name, t, static_cast(0)); +} + +inline void SetPrototypeMethod( + v8::Local recv + , const char* name, FunctionCallback callback) { + HandleScope scope; + v8::Local t = New( + callback + , v8::Local() + , New(recv)); + v8::Local fn_name = New(name).ToLocalChecked(); + recv->PrototypeTemplate()->Set(fn_name, t); + t->SetClassName(fn_name); +} + +//=== Accessors and Such ======================================================= + +inline void SetAccessor( + v8::Local tpl + , v8::Local name + , GetterCallback getter + , SetterCallback setter = 0 + , v8::Local data = v8::Local() + , v8::AccessControl settings = v8::DEFAULT + , v8::PropertyAttribute attribute = v8::None + , imp::Sig signature = imp::Sig()) { + HandleScope scope; + + imp::NativeGetter getter_ = + imp::GetterCallbackWrapper; + imp::NativeSetter setter_ = + setter ? imp::SetterCallbackWrapper : 0; + + v8::Local otpl = New(); + otpl->SetInternalFieldCount(imp::kAccessorFieldCount); + v8::Local obj = NewInstance(otpl).ToLocalChecked(); + + obj->SetInternalField( + imp::kGetterIndex + , New(reinterpret_cast(getter))); + + if (setter != 0) { + obj->SetInternalField( + imp::kSetterIndex + , New(reinterpret_cast(setter))); + } + + if (!data.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, data); + } + + tpl->SetAccessor( + name + , getter_ + , setter_ + , obj + , settings + , attribute + , signature); +} + +inline bool SetAccessor( + v8::Local obj + , v8::Local name + , GetterCallback getter + , SetterCallback setter = 0 + , v8::Local data = v8::Local() + , v8::AccessControl settings = v8::DEFAULT + , v8::PropertyAttribute attribute = v8::None) { + EscapableHandleScope scope; + + imp::NativeGetter getter_ = + imp::GetterCallbackWrapper; + imp::NativeSetter setter_ = + setter ? imp::SetterCallbackWrapper : 0; + + v8::Local otpl = New(); + otpl->SetInternalFieldCount(imp::kAccessorFieldCount); + v8::Local dataobj = NewInstance(otpl).ToLocalChecked(); + + dataobj->SetInternalField( + imp::kGetterIndex + , New(reinterpret_cast(getter))); + + if (!data.IsEmpty()) { + dataobj->SetInternalField(imp::kDataIndex, data); + } + + if (setter) { + dataobj->SetInternalField( + imp::kSetterIndex + , New(reinterpret_cast(setter))); + } + +#if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) + return obj->SetAccessor( + GetCurrentContext() + , name + , getter_ + , setter_ + , dataobj + , settings + , attribute).FromMaybe(false); +#else + return obj->SetAccessor( + name + , getter_ + , setter_ + , dataobj + , settings + , attribute); +#endif +} + +inline void SetNamedPropertyHandler( + v8::Local tpl + , PropertyGetterCallback getter + , PropertySetterCallback setter = 0 + , PropertyQueryCallback query = 0 + , PropertyDeleterCallback deleter = 0 + , PropertyEnumeratorCallback enumerator = 0 + , v8::Local data = v8::Local()) { + HandleScope scope; + + imp::NativePropertyGetter getter_ = + imp::PropertyGetterCallbackWrapper; + imp::NativePropertySetter setter_ = + setter ? imp::PropertySetterCallbackWrapper : 0; + imp::NativePropertyQuery query_ = + query ? imp::PropertyQueryCallbackWrapper : 0; + imp::NativePropertyDeleter *deleter_ = + deleter ? imp::PropertyDeleterCallbackWrapper : 0; + imp::NativePropertyEnumerator enumerator_ = + enumerator ? imp::PropertyEnumeratorCallbackWrapper : 0; + + v8::Local otpl = New(); + otpl->SetInternalFieldCount(imp::kPropertyFieldCount); + v8::Local obj = NewInstance(otpl).ToLocalChecked(); + obj->SetInternalField( + imp::kPropertyGetterIndex + , New(reinterpret_cast(getter))); + + if (setter) { + obj->SetInternalField( + imp::kPropertySetterIndex + , New(reinterpret_cast(setter))); + } + + if (query) { + obj->SetInternalField( + imp::kPropertyQueryIndex + , New(reinterpret_cast(query))); + } + + if (deleter) { + obj->SetInternalField( + imp::kPropertyDeleterIndex + , New(reinterpret_cast(deleter))); + } + + if (enumerator) { + obj->SetInternalField( + imp::kPropertyEnumeratorIndex + , New(reinterpret_cast(enumerator))); + } + + if (!data.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, data); + } + +#if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION + tpl->SetHandler(v8::NamedPropertyHandlerConfiguration( + getter_, setter_, query_, deleter_, enumerator_, obj)); +#else + tpl->SetNamedPropertyHandler( + getter_ + , setter_ + , query_ + , deleter_ + , enumerator_ + , obj); +#endif +} + +inline void SetIndexedPropertyHandler( + v8::Local tpl + , IndexGetterCallback getter + , IndexSetterCallback setter = 0 + , IndexQueryCallback query = 0 + , IndexDeleterCallback deleter = 0 + , IndexEnumeratorCallback enumerator = 0 + , v8::Local data = v8::Local()) { + HandleScope scope; + + imp::NativeIndexGetter getter_ = + imp::IndexGetterCallbackWrapper; + imp::NativeIndexSetter setter_ = + setter ? imp::IndexSetterCallbackWrapper : 0; + imp::NativeIndexQuery query_ = + query ? imp::IndexQueryCallbackWrapper : 0; + imp::NativeIndexDeleter deleter_ = + deleter ? imp::IndexDeleterCallbackWrapper : 0; + imp::NativeIndexEnumerator enumerator_ = + enumerator ? imp::IndexEnumeratorCallbackWrapper : 0; + + v8::Local otpl = New(); + otpl->SetInternalFieldCount(imp::kIndexPropertyFieldCount); + v8::Local obj = NewInstance(otpl).ToLocalChecked(); + obj->SetInternalField( + imp::kIndexPropertyGetterIndex + , New(reinterpret_cast(getter))); + + if (setter) { + obj->SetInternalField( + imp::kIndexPropertySetterIndex + , New(reinterpret_cast(setter))); + } + + if (query) { + obj->SetInternalField( + imp::kIndexPropertyQueryIndex + , New(reinterpret_cast(query))); + } + + if (deleter) { + obj->SetInternalField( + imp::kIndexPropertyDeleterIndex + , New(reinterpret_cast(deleter))); + } + + if (enumerator) { + obj->SetInternalField( + imp::kIndexPropertyEnumeratorIndex + , New(reinterpret_cast(enumerator))); + } + + if (!data.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, data); + } + +#if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION + tpl->SetHandler(v8::IndexedPropertyHandlerConfiguration( + getter_, setter_, query_, deleter_, enumerator_, obj)); +#else + tpl->SetIndexedPropertyHandler( + getter_ + , setter_ + , query_ + , deleter_ + , enumerator_ + , obj); +#endif +} + +inline void SetCallHandler( + v8::Local tpl + , FunctionCallback callback + , v8::Local data = v8::Local()) { + HandleScope scope; + + v8::Local otpl = New(); + otpl->SetInternalFieldCount(imp::kFunctionFieldCount); + v8::Local obj = NewInstance(otpl).ToLocalChecked(); + + obj->SetInternalField( + imp::kFunctionIndex + , New(reinterpret_cast(callback))); + + if (!data.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, data); + } + + tpl->SetCallHandler(imp::FunctionCallbackWrapper, obj); +} + + +inline void SetCallAsFunctionHandler( + v8::Local tpl, + FunctionCallback callback, + v8::Local data = v8::Local()) { + HandleScope scope; + + v8::Local otpl = New(); + otpl->SetInternalFieldCount(imp::kFunctionFieldCount); + v8::Local obj = NewInstance(otpl).ToLocalChecked(); + + obj->SetInternalField( + imp::kFunctionIndex + , New(reinterpret_cast(callback))); + + if (!data.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, data); + } + + tpl->SetCallAsFunctionHandler(imp::FunctionCallbackWrapper, obj); +} + +//=== Weak Persistent Handling ================================================= + +#include "nan_weak.h" // NOLINT(build/include) + +//=== ObjectWrap =============================================================== + +#include "nan_object_wrap.h" // NOLINT(build/include) + +//=== Export ================================================================== + +inline +void +Export(ADDON_REGISTER_FUNCTION_ARGS_TYPE target, const char *name, + FunctionCallback f) { + Set(target, New(name).ToLocalChecked(), + GetFunction(New(f)).ToLocalChecked()); +} + +//=== Tap Reverse Binding ===================================================== + +struct Tap { + explicit Tap(v8::Local t) : t_() { + t_.Reset(To(t).ToLocalChecked()); + } + + ~Tap() { t_.Reset(); } // not sure if neccessary + + inline void plan(int i) { + v8::Local arg = New(i); + MakeCallback(New(t_), "plan", 1, &arg); + } + + inline void ok(bool isOk, const char *msg = NULL) { + v8::Local args[2]; + args[0] = New(isOk); + if (msg) args[1] = New(msg).ToLocalChecked(); + MakeCallback(New(t_), "ok", msg ? 2 : 1, args); + } + + inline void pass(const char * msg = NULL) { + v8::Local hmsg; + if (msg) hmsg = New(msg).ToLocalChecked(); + MakeCallback(New(t_), "pass", msg ? 1 : 0, &hmsg); + } + + private: + Persistent t_; +}; + +#define NAN_STRINGIZE2(x) #x +#define NAN_STRINGIZE(x) NAN_STRINGIZE2(x) +#define NAN_TEST_EXPRESSION(expression) \ + ( expression ), __FILE__ ":" NAN_STRINGIZE(__LINE__) ": " #expression + +#define NAN_EXPORT(target, function) Export(target, #function, function) + +#undef TYPE_CHECK + +//=== Generic Maybefication =================================================== + +namespace imp { + +template struct Maybefier; + +template struct Maybefier > { + static MaybeLocal convert(v8::Local v) { + return MaybeLocal(v); + } +}; + +template struct Maybefier > { + static MaybeLocal convert(MaybeLocal v) { + return v; + } +}; + +} // end of namespace imp + +template class MaybeMaybe> +MaybeLocal +MakeMaybe(MaybeMaybe v) { + return imp::Maybefier >::convert(v); +} + +//=== TypedArrayContents ======================================================= + +#include "nan_typedarray_contents.h" // NOLINT(build/include) + +} // end of namespace Nan + +#endif // NAN_H_ diff --git a/node/node_modules/nan/nan_callbacks.h b/node/node_modules/nan/nan_callbacks.h new file mode 100644 index 0000000..851509f --- /dev/null +++ b/node/node_modules/nan/nan_callbacks.h @@ -0,0 +1,88 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CALLBACKS_H_ +#define NAN_CALLBACKS_H_ + +template class FunctionCallbackInfo; +template class PropertyCallbackInfo; +template class Global; + +typedef void(*FunctionCallback)(const FunctionCallbackInfo&); +typedef void(*GetterCallback) + (v8::Local, const PropertyCallbackInfo&); +typedef void(*SetterCallback)( + v8::Local, + v8::Local, + const PropertyCallbackInfo&); +typedef void(*PropertyGetterCallback)( + v8::Local, + const PropertyCallbackInfo&); +typedef void(*PropertySetterCallback)( + v8::Local, + v8::Local, + const PropertyCallbackInfo&); +typedef void(*PropertyEnumeratorCallback) + (const PropertyCallbackInfo&); +typedef void(*PropertyDeleterCallback)( + v8::Local, + const PropertyCallbackInfo&); +typedef void(*PropertyQueryCallback)( + v8::Local, + const PropertyCallbackInfo&); +typedef void(*IndexGetterCallback)( + uint32_t, + const PropertyCallbackInfo&); +typedef void(*IndexSetterCallback)( + uint32_t, + v8::Local, + const PropertyCallbackInfo&); +typedef void(*IndexEnumeratorCallback) + (const PropertyCallbackInfo&); +typedef void(*IndexDeleterCallback)( + uint32_t, + const PropertyCallbackInfo&); +typedef void(*IndexQueryCallback)( + uint32_t, + const PropertyCallbackInfo&); + +namespace imp { +typedef v8::Local Sig; + +static const int kDataIndex = 0; + +static const int kFunctionIndex = 1; +static const int kFunctionFieldCount = 2; + +static const int kGetterIndex = 1; +static const int kSetterIndex = 2; +static const int kAccessorFieldCount = 3; + +static const int kPropertyGetterIndex = 1; +static const int kPropertySetterIndex = 2; +static const int kPropertyEnumeratorIndex = 3; +static const int kPropertyDeleterIndex = 4; +static const int kPropertyQueryIndex = 5; +static const int kPropertyFieldCount = 6; + +static const int kIndexPropertyGetterIndex = 1; +static const int kIndexPropertySetterIndex = 2; +static const int kIndexPropertyEnumeratorIndex = 3; +static const int kIndexPropertyDeleterIndex = 4; +static const int kIndexPropertyQueryIndex = 5; +static const int kIndexPropertyFieldCount = 6; + +} // end of namespace imp + +#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +# include "nan_callbacks_12_inl.h" // NOLINT(build/include) +#else +# include "nan_callbacks_pre_12_inl.h" // NOLINT(build/include) +#endif + +#endif // NAN_CALLBACKS_H_ diff --git a/node/node_modules/nan/nan_callbacks_12_inl.h b/node/node_modules/nan/nan_callbacks_12_inl.h new file mode 100644 index 0000000..bea12c7 --- /dev/null +++ b/node/node_modules/nan/nan_callbacks_12_inl.h @@ -0,0 +1,512 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CALLBACKS_12_INL_H_ +#define NAN_CALLBACKS_12_INL_H_ + +template +class ReturnValue { + v8::ReturnValue value_; + + public: + template + explicit inline ReturnValue(const v8::ReturnValue &value) : + value_(value) {} + template + explicit inline ReturnValue(const ReturnValue& that) + : value_(that.value_) { + TYPE_CHECK(T, S); + } + + // Handle setters + template inline void Set(const v8::Local &handle) { + TYPE_CHECK(T, S); + value_.Set(handle); + } + + template inline void Set(const Global &handle) { + TYPE_CHECK(T, S); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 5 || (V8_MINOR_VERSION == 5 && \ + defined(V8_BUILD_NUMBER) && V8_BUILD_NUMBER >= 8)))) + value_.Set(handle); +#else + value_.Set(*reinterpret_cast*>(&handle)); + const_cast &>(handle).Reset(); +#endif + } + + // Fast primitive setters + inline void Set(bool value) { + TYPE_CHECK(T, v8::Boolean); + value_.Set(value); + } + + inline void Set(double i) { + TYPE_CHECK(T, v8::Number); + value_.Set(i); + } + + inline void Set(int32_t i) { + TYPE_CHECK(T, v8::Integer); + value_.Set(i); + } + + inline void Set(uint32_t i) { + TYPE_CHECK(T, v8::Integer); + value_.Set(i); + } + + // Fast JS primitive setters + inline void SetNull() { + TYPE_CHECK(T, v8::Primitive); + value_.SetNull(); + } + + inline void SetUndefined() { + TYPE_CHECK(T, v8::Primitive); + value_.SetUndefined(); + } + + inline void SetEmptyString() { + TYPE_CHECK(T, v8::String); + value_.SetEmptyString(); + } + + // Convenience getter for isolate + inline v8::Isolate *GetIsolate() const { + return value_.GetIsolate(); + } + + // Pointer setter: Uncompilable to prevent inadvertent misuse. + template + inline void Set(S *whatever) { TYPE_CHECK(S*, v8::Primitive); } +}; + +template +class FunctionCallbackInfo { + const v8::FunctionCallbackInfo &info_; + const v8::Local data_; + + public: + explicit inline FunctionCallbackInfo( + const v8::FunctionCallbackInfo &info + , v8::Local data) : + info_(info) + , data_(data) {} + + inline ReturnValue GetReturnValue() const { + return ReturnValue(info_.GetReturnValue()); + } + + inline v8::Local Callee() const { return info_.Callee(); } + inline v8::Local Data() const { return data_; } + inline v8::Local Holder() const { return info_.Holder(); } + inline bool IsConstructCall() const { return info_.IsConstructCall(); } + inline int Length() const { return info_.Length(); } + inline v8::Local operator[](int i) const { return info_[i]; } + inline v8::Local This() const { return info_.This(); } + inline v8::Isolate *GetIsolate() const { return info_.GetIsolate(); } + + + protected: + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kCalleeIndex = 5; + static const int kContextSaveIndex = 6; + static const int kArgsLength = 7; + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(FunctionCallbackInfo) +}; + +template +class PropertyCallbackInfo { + const v8::PropertyCallbackInfo &info_; + const v8::Local data_; + + public: + explicit inline PropertyCallbackInfo( + const v8::PropertyCallbackInfo &info + , const v8::Local data) : + info_(info) + , data_(data) {} + + inline v8::Isolate* GetIsolate() const { return info_.GetIsolate(); } + inline v8::Local Data() const { return data_; } + inline v8::Local This() const { return info_.This(); } + inline v8::Local Holder() const { return info_.Holder(); } + inline ReturnValue GetReturnValue() const { + return ReturnValue(info_.GetReturnValue()); + } + + protected: + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kThisIndex = 5; + static const int kArgsLength = 6; + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(PropertyCallbackInfo) +}; + +namespace imp { +static +void FunctionCallbackWrapper(const v8::FunctionCallbackInfo &info) { + v8::Local obj = info.Data().As(); + FunctionCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kFunctionIndex).As()->Value())); + FunctionCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + callback(cbinfo); +} + +typedef void (*NativeFunction)(const v8::FunctionCallbackInfo &); + +#if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION +static +void GetterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + GetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kGetterIndex).As()->Value())); + callback(property.As(), cbinfo); +} + +typedef void (*NativeGetter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +void SetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + SetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kSetterIndex).As()->Value())); + callback(property.As(), value, cbinfo); +} + +typedef void (*NativeSetter)( + v8::Local + , v8::Local + , const v8::PropertyCallbackInfo &); +#else +static +void GetterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + GetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kGetterIndex).As()->Value())); + callback(property, cbinfo); +} + +typedef void (*NativeGetter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +void SetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + SetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kSetterIndex).As()->Value())); + callback(property, value, cbinfo); +} + +typedef void (*NativeSetter)( + v8::Local + , v8::Local + , const v8::PropertyCallbackInfo &); +#endif + +#if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION +static +void PropertyGetterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyGetterIndex) + .As()->Value())); + callback(property.As(), cbinfo); +} + +typedef void (*NativePropertyGetter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +void PropertySetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertySetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertySetterIndex) + .As()->Value())); + callback(property.As(), value, cbinfo); +} + +typedef void (*NativePropertySetter)( + v8::Local + , v8::Local + , const v8::PropertyCallbackInfo &); + +static +void PropertyEnumeratorCallbackWrapper( + const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyEnumeratorCallback callback = + reinterpret_cast(reinterpret_cast( + obj->GetInternalField(kPropertyEnumeratorIndex) + .As()->Value())); + callback(cbinfo); +} + +typedef void (*NativePropertyEnumerator) + (const v8::PropertyCallbackInfo &); + +static +void PropertyDeleterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyDeleterIndex) + .As()->Value())); + callback(property.As(), cbinfo); +} + +typedef void (NativePropertyDeleter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +void PropertyQueryCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyQueryIndex) + .As()->Value())); + callback(property.As(), cbinfo); +} + +typedef void (*NativePropertyQuery) + (v8::Local, const v8::PropertyCallbackInfo &); +#else +static +void PropertyGetterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyGetterIndex) + .As()->Value())); + callback(property, cbinfo); +} + +typedef void (*NativePropertyGetter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +void PropertySetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertySetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertySetterIndex) + .As()->Value())); + callback(property, value, cbinfo); +} + +typedef void (*NativePropertySetter)( + v8::Local + , v8::Local + , const v8::PropertyCallbackInfo &); + +static +void PropertyEnumeratorCallbackWrapper( + const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyEnumeratorCallback callback = + reinterpret_cast(reinterpret_cast( + obj->GetInternalField(kPropertyEnumeratorIndex) + .As()->Value())); + callback(cbinfo); +} + +typedef void (*NativePropertyEnumerator) + (const v8::PropertyCallbackInfo &); + +static +void PropertyDeleterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyDeleterIndex) + .As()->Value())); + callback(property, cbinfo); +} + +typedef void (NativePropertyDeleter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +void PropertyQueryCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyQueryIndex) + .As()->Value())); + callback(property, cbinfo); +} + +typedef void (*NativePropertyQuery) + (v8::Local, const v8::PropertyCallbackInfo &); +#endif + +static +void IndexGetterCallbackWrapper( + uint32_t index, const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyGetterIndex) + .As()->Value())); + callback(index, cbinfo); +} + +typedef void (*NativeIndexGetter) + (uint32_t, const v8::PropertyCallbackInfo &); + +static +void IndexSetterCallbackWrapper( + uint32_t index + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexSetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertySetterIndex) + .As()->Value())); + callback(index, value, cbinfo); +} + +typedef void (*NativeIndexSetter)( + uint32_t + , v8::Local + , const v8::PropertyCallbackInfo &); + +static +void IndexEnumeratorCallbackWrapper( + const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexEnumeratorCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField( + kIndexPropertyEnumeratorIndex).As()->Value())); + callback(cbinfo); +} + +typedef void (*NativeIndexEnumerator) + (const v8::PropertyCallbackInfo &); + +static +void IndexDeleterCallbackWrapper( + uint32_t index, const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyDeleterIndex) + .As()->Value())); + callback(index, cbinfo); +} + +typedef void (*NativeIndexDeleter) + (uint32_t, const v8::PropertyCallbackInfo &); + +static +void IndexQueryCallbackWrapper( + uint32_t index, const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyQueryIndex) + .As()->Value())); + callback(index, cbinfo); +} + +typedef void (*NativeIndexQuery) + (uint32_t, const v8::PropertyCallbackInfo &); +} // end of namespace imp + +#endif // NAN_CALLBACKS_12_INL_H_ diff --git a/node/node_modules/nan/nan_callbacks_pre_12_inl.h b/node/node_modules/nan/nan_callbacks_pre_12_inl.h new file mode 100644 index 0000000..5e2b8e2 --- /dev/null +++ b/node/node_modules/nan/nan_callbacks_pre_12_inl.h @@ -0,0 +1,506 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CALLBACKS_PRE_12_INL_H_ +#define NAN_CALLBACKS_PRE_12_INL_H_ + +namespace imp { +template class ReturnValueImp; +} // end of namespace imp + +template +class ReturnValue { + v8::Isolate *isolate_; + v8::Persistent *value_; + friend class imp::ReturnValueImp; + + public: + template + explicit inline ReturnValue(v8::Isolate *isolate, v8::Persistent *p) : + isolate_(isolate), value_(p) {} + template + explicit inline ReturnValue(const ReturnValue& that) + : isolate_(that.isolate_), value_(that.value_) { + TYPE_CHECK(T, S); + } + + // Handle setters + template inline void Set(const v8::Local &handle) { + TYPE_CHECK(T, S); + value_->Dispose(); + *value_ = v8::Persistent::New(handle); + } + + template inline void Set(const Global &handle) { + TYPE_CHECK(T, S); + value_->Dispose(); + *value_ = v8::Persistent::New(handle.persistent); + const_cast &>(handle).Reset(); + } + + // Fast primitive setters + inline void Set(bool value) { + TYPE_CHECK(T, v8::Boolean); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::Boolean::New(value)); + } + + inline void Set(double i) { + TYPE_CHECK(T, v8::Number); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::Number::New(i)); + } + + inline void Set(int32_t i) { + TYPE_CHECK(T, v8::Integer); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::Int32::New(i)); + } + + inline void Set(uint32_t i) { + TYPE_CHECK(T, v8::Integer); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::Uint32::NewFromUnsigned(i)); + } + + // Fast JS primitive setters + inline void SetNull() { + TYPE_CHECK(T, v8::Primitive); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::Null()); + } + + inline void SetUndefined() { + TYPE_CHECK(T, v8::Primitive); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::Undefined()); + } + + inline void SetEmptyString() { + TYPE_CHECK(T, v8::String); + value_->Dispose(); + *value_ = v8::Persistent::New(v8::String::Empty()); + } + + // Convenience getter for isolate + inline v8::Isolate *GetIsolate() const { + return isolate_; + } + + // Pointer setter: Uncompilable to prevent inadvertent misuse. + template + inline void Set(S *whatever) { TYPE_CHECK(S*, v8::Primitive); } +}; + +template +class FunctionCallbackInfo { + const v8::Arguments &args_; + v8::Local data_; + ReturnValue return_value_; + v8::Persistent retval_; + + public: + explicit inline FunctionCallbackInfo( + const v8::Arguments &args + , v8::Local data) : + args_(args) + , data_(data) + , return_value_(args.GetIsolate(), &retval_) + , retval_(v8::Persistent::New(v8::Undefined())) {} + + inline ~FunctionCallbackInfo() { + retval_.Dispose(); + retval_.Clear(); + } + + inline ReturnValue GetReturnValue() const { + return ReturnValue(return_value_); + } + + inline v8::Local Callee() const { return args_.Callee(); } + inline v8::Local Data() const { return data_; } + inline v8::Local Holder() const { return args_.Holder(); } + inline bool IsConstructCall() const { return args_.IsConstructCall(); } + inline int Length() const { return args_.Length(); } + inline v8::Local operator[](int i) const { return args_[i]; } + inline v8::Local This() const { return args_.This(); } + inline v8::Isolate *GetIsolate() const { return args_.GetIsolate(); } + + + protected: + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kCalleeIndex = 5; + static const int kContextSaveIndex = 6; + static const int kArgsLength = 7; + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(FunctionCallbackInfo) +}; + +template +class PropertyCallbackInfoBase { + const v8::AccessorInfo &info_; + const v8::Local data_; + + public: + explicit inline PropertyCallbackInfoBase( + const v8::AccessorInfo &info + , const v8::Local data) : + info_(info) + , data_(data) {} + + inline v8::Isolate* GetIsolate() const { return info_.GetIsolate(); } + inline v8::Local Data() const { return data_; } + inline v8::Local This() const { return info_.This(); } + inline v8::Local Holder() const { return info_.Holder(); } + + protected: + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kThisIndex = 5; + static const int kArgsLength = 6; + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(PropertyCallbackInfoBase) +}; + +template +class PropertyCallbackInfo : public PropertyCallbackInfoBase { + ReturnValue return_value_; + v8::Persistent retval_; + + public: + explicit inline PropertyCallbackInfo( + const v8::AccessorInfo &info + , const v8::Local data) : + PropertyCallbackInfoBase(info, data) + , return_value_(info.GetIsolate(), &retval_) + , retval_(v8::Persistent::New(v8::Undefined())) {} + + inline ~PropertyCallbackInfo() { + retval_.Dispose(); + retval_.Clear(); + } + + inline ReturnValue GetReturnValue() const { return return_value_; } +}; + +template<> +class PropertyCallbackInfo : + public PropertyCallbackInfoBase { + ReturnValue return_value_; + v8::Persistent retval_; + + public: + explicit inline PropertyCallbackInfo( + const v8::AccessorInfo &info + , const v8::Local data) : + PropertyCallbackInfoBase(info, data) + , return_value_(info.GetIsolate(), &retval_) + , retval_(v8::Persistent::New(v8::Local())) {} + + inline ~PropertyCallbackInfo() { + retval_.Dispose(); + retval_.Clear(); + } + + inline ReturnValue GetReturnValue() const { + return return_value_; + } +}; + +template<> +class PropertyCallbackInfo : + public PropertyCallbackInfoBase { + ReturnValue return_value_; + v8::Persistent retval_; + + public: + explicit inline PropertyCallbackInfo( + const v8::AccessorInfo &info + , const v8::Local data) : + PropertyCallbackInfoBase(info, data) + , return_value_(info.GetIsolate(), &retval_) + , retval_(v8::Persistent::New(v8::Local())) {} + + inline ~PropertyCallbackInfo() { + retval_.Dispose(); + retval_.Clear(); + } + + inline ReturnValue GetReturnValue() const { + return return_value_; + } +}; + +template<> +class PropertyCallbackInfo : + public PropertyCallbackInfoBase { + ReturnValue return_value_; + v8::Persistent retval_; + + public: + explicit inline PropertyCallbackInfo( + const v8::AccessorInfo &info + , const v8::Local data) : + PropertyCallbackInfoBase(info, data) + , return_value_(info.GetIsolate(), &retval_) + , retval_(v8::Persistent::New(v8::Local())) {} + + inline ~PropertyCallbackInfo() { + retval_.Dispose(); + retval_.Clear(); + } + + inline ReturnValue GetReturnValue() const { + return return_value_; + } +}; + +namespace imp { +template +class ReturnValueImp : public ReturnValue { + public: + explicit ReturnValueImp(ReturnValue that) : + ReturnValue(that) {} + inline v8::Handle Value() { + return *ReturnValue::value_; + } +}; + +static +v8::Handle FunctionCallbackWrapper(const v8::Arguments &args) { + v8::Local obj = args.Data().As(); + FunctionCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kFunctionIndex).As()->Value())); + FunctionCallbackInfo + cbinfo(args, obj->GetInternalField(kDataIndex)); + callback(cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeFunction)(const v8::Arguments &); + +static +v8::Handle GetterCallbackWrapper( + v8::Local property, const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + GetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kGetterIndex).As()->Value())); + callback(property, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeGetter) + (v8::Local, const v8::AccessorInfo &); + +static +void SetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + SetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kSetterIndex).As()->Value())); + callback(property, value, cbinfo); +} + +typedef void (*NativeSetter) + (v8::Local, v8::Local, const v8::AccessorInfo &); + +static +v8::Handle PropertyGetterCallbackWrapper( + v8::Local property, const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyGetterIndex) + .As()->Value())); + callback(property, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativePropertyGetter) + (v8::Local, const v8::AccessorInfo &); + +static +v8::Handle PropertySetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertySetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertySetterIndex) + .As()->Value())); + callback(property, value, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativePropertySetter) + (v8::Local, v8::Local, const v8::AccessorInfo &); + +static +v8::Handle PropertyEnumeratorCallbackWrapper( + const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyEnumeratorCallback callback = + reinterpret_cast(reinterpret_cast( + obj->GetInternalField(kPropertyEnumeratorIndex) + .As()->Value())); + callback(cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativePropertyEnumerator) + (const v8::AccessorInfo &); + +static +v8::Handle PropertyDeleterCallbackWrapper( + v8::Local property + , const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyDeleterIndex) + .As()->Value())); + callback(property, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (NativePropertyDeleter) + (v8::Local, const v8::AccessorInfo &); + +static +v8::Handle PropertyQueryCallbackWrapper( + v8::Local property, const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyQueryIndex) + .As()->Value())); + callback(property, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativePropertyQuery) + (v8::Local, const v8::AccessorInfo &); + +static +v8::Handle IndexGetterCallbackWrapper( + uint32_t index, const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyGetterIndex) + .As()->Value())); + callback(index, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeIndexGetter) + (uint32_t, const v8::AccessorInfo &); + +static +v8::Handle IndexSetterCallbackWrapper( + uint32_t index + , v8::Local value + , const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexSetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertySetterIndex) + .As()->Value())); + callback(index, value, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeIndexSetter) + (uint32_t, v8::Local, const v8::AccessorInfo &); + +static +v8::Handle IndexEnumeratorCallbackWrapper( + const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexEnumeratorCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyEnumeratorIndex) + .As()->Value())); + callback(cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeIndexEnumerator) + (const v8::AccessorInfo &); + +static +v8::Handle IndexDeleterCallbackWrapper( + uint32_t index, const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyDeleterIndex) + .As()->Value())); + callback(index, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeIndexDeleter) + (uint32_t, const v8::AccessorInfo &); + +static +v8::Handle IndexQueryCallbackWrapper( + uint32_t index, const v8::AccessorInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex)); + IndexQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyQueryIndex) + .As()->Value())); + callback(index, cbinfo); + return ReturnValueImp(cbinfo.GetReturnValue()).Value(); +} + +typedef v8::Handle (*NativeIndexQuery) + (uint32_t, const v8::AccessorInfo &); +} // end of namespace imp + +#endif // NAN_CALLBACKS_PRE_12_INL_H_ diff --git a/node/node_modules/nan/nan_converters.h b/node/node_modules/nan/nan_converters.h new file mode 100644 index 0000000..7386c3b --- /dev/null +++ b/node/node_modules/nan/nan_converters.h @@ -0,0 +1,64 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CONVERTERS_H_ +#define NAN_CONVERTERS_H_ + +namespace imp { +template struct ToFactoryBase { + typedef MaybeLocal return_t; +}; +template struct ValueFactoryBase { typedef Maybe return_t; }; + +template struct ToFactory; + +#define X(TYPE) \ + template<> \ + struct ToFactory : ToFactoryBase { \ + static inline return_t convert(v8::Local val); \ + }; + +X(Boolean) +X(Number) +X(String) +X(Object) +X(Integer) +X(Uint32) +X(Int32) + +#undef X + +#define X(TYPE) \ + template<> \ + struct ToFactory : ValueFactoryBase { \ + static inline return_t convert(v8::Local val); \ + }; + +X(bool) +X(double) +X(int64_t) +X(uint32_t) +X(int32_t) + +#undef X +} // end of namespace imp + +template +inline +typename imp::ToFactory::return_t To(v8::Local val) { + return imp::ToFactory::convert(val); +} + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +# include "nan_converters_43_inl.h" +#else +# include "nan_converters_pre_43_inl.h" +#endif + +#endif // NAN_CONVERTERS_H_ diff --git a/node/node_modules/nan/nan_converters_43_inl.h b/node/node_modules/nan/nan_converters_43_inl.h new file mode 100644 index 0000000..e2eb032 --- /dev/null +++ b/node/node_modules/nan/nan_converters_43_inl.h @@ -0,0 +1,42 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CONVERTERS_43_INL_H_ +#define NAN_CONVERTERS_43_INL_H_ + +#define X(TYPE) \ +imp::ToFactory::return_t \ +imp::ToFactory::convert(v8::Local val) { \ + return val->To ## TYPE(GetCurrentContext()); \ +} + +X(Boolean) +X(Number) +X(String) +X(Object) +X(Integer) +X(Uint32) +X(Int32) + +#undef X + +#define X(TYPE, NAME) \ +imp::ToFactory::return_t \ +imp::ToFactory::convert(v8::Local val) { \ + return val->NAME ## Value(GetCurrentContext()); \ +} + +X(bool, Boolean) +X(double, Number) +X(int64_t, Integer) +X(uint32_t, Uint32) +X(int32_t, Int32) + +#undef X + +#endif // NAN_CONVERTERS_43_INL_H_ diff --git a/node/node_modules/nan/nan_converters_pre_43_inl.h b/node/node_modules/nan/nan_converters_pre_43_inl.h new file mode 100644 index 0000000..177a74a --- /dev/null +++ b/node/node_modules/nan/nan_converters_pre_43_inl.h @@ -0,0 +1,42 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CONVERTERS_PRE_43_INL_H_ +#define NAN_CONVERTERS_PRE_43_INL_H_ + +#define X(TYPE) \ +imp::ToFactory::return_t \ +imp::ToFactory::convert(v8::Local val) { \ + return MaybeLocal(val->To ## TYPE()); \ +} + +X(Boolean) +X(Number) +X(String) +X(Object) +X(Integer) +X(Uint32) +X(Int32) + +#undef X + +#define X(TYPE, NAME) \ +imp::ToFactory::return_t \ +imp::ToFactory::convert(v8::Local val) { \ + return Just(val->NAME ##Value()); \ +} + +X(bool, Boolean) +X(double, Number) +X(int64_t, Integer) +X(uint32_t, Uint32) +X(int32_t, Int32) + +#undef X + +#endif // NAN_CONVERTERS_PRE_43_INL_H_ diff --git a/node/node_modules/nan/nan_implementation_12_inl.h b/node/node_modules/nan/nan_implementation_12_inl.h new file mode 100644 index 0000000..be50fc6 --- /dev/null +++ b/node/node_modules/nan/nan_implementation_12_inl.h @@ -0,0 +1,409 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_IMPLEMENTATION_12_INL_H_ +#define NAN_IMPLEMENTATION_12_INL_H_ +//============================================================================== +// node v0.11 implementation +//============================================================================== + +namespace imp { + +//=== Array ==================================================================== + +Factory::return_t +Factory::New() { + return v8::Array::New(v8::Isolate::GetCurrent()); +} + +Factory::return_t +Factory::New(int length) { + return v8::Array::New(v8::Isolate::GetCurrent(), length); +} + +//=== Boolean ================================================================== + +Factory::return_t +Factory::New(bool value) { + return v8::Boolean::New(v8::Isolate::GetCurrent(), value); +} + +//=== Boolean Object =========================================================== + +Factory::return_t +Factory::New(bool value) { +#if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) + return v8::BooleanObject::New( + v8::Isolate::GetCurrent(), value).As(); +#else + return v8::BooleanObject::New(value).As(); +#endif +} + +//=== Context ================================================================== + +Factory::return_t +Factory::New( v8::ExtensionConfiguration* extensions + , v8::Local tmpl + , v8::Local obj) { + return v8::Context::New(v8::Isolate::GetCurrent(), extensions, tmpl, obj); +} + +//=== Date ===================================================================== + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New(double value) { + v8::Local ret; + if (v8::Date::New(GetCurrentContext(), value). + ToLocal(reinterpret_cast*>(&ret))) { + return v8::MaybeLocal(ret); + } else { + return v8::MaybeLocal(ret); + } +} +#else +Factory::return_t +Factory::New(double value) { + return Factory::return_t( + v8::Date::New(v8::Isolate::GetCurrent(), value).As()); +} +#endif + +//=== External ================================================================= + +Factory::return_t +Factory::New(void * value) { + return v8::External::New(v8::Isolate::GetCurrent(), value); +} + +//=== Function ================================================================= + +Factory::return_t +Factory::New( FunctionCallback callback + , v8::Local data) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::EscapableHandleScope scope(isolate); + v8::Local tpl = v8::ObjectTemplate::New(isolate); + tpl->SetInternalFieldCount(imp::kFunctionFieldCount); + v8::Local obj = NewInstance(tpl).ToLocalChecked(); + + obj->SetInternalField( + imp::kFunctionIndex + , v8::External::New(isolate, reinterpret_cast(callback))); + + v8::Local val = v8::Local::New(isolate, data); + + if (!val.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, val); + } + + return scope.Escape(v8::Function::New( isolate + , imp::FunctionCallbackWrapper + , obj)); +} + +//=== Function Template ======================================================== + +Factory::return_t +Factory::New( FunctionCallback callback + , v8::Local data + , v8::Local signature) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + if (callback) { + v8::EscapableHandleScope scope(isolate); + v8::Local tpl = v8::ObjectTemplate::New(isolate); + tpl->SetInternalFieldCount(imp::kFunctionFieldCount); + v8::Local obj = NewInstance(tpl).ToLocalChecked(); + + obj->SetInternalField( + imp::kFunctionIndex + , v8::External::New(isolate, reinterpret_cast(callback))); + v8::Local val = v8::Local::New(isolate, data); + + if (!val.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, val); + } + + return scope.Escape(v8::FunctionTemplate::New( isolate + , imp::FunctionCallbackWrapper + , obj + , signature)); + } else { + return v8::FunctionTemplate::New(isolate, 0, data, signature); + } +} + +//=== Number =================================================================== + +Factory::return_t +Factory::New(double value) { + return v8::Number::New(v8::Isolate::GetCurrent(), value); +} + +//=== Number Object ============================================================ + +Factory::return_t +Factory::New(double value) { + return v8::NumberObject::New( v8::Isolate::GetCurrent() + , value).As(); +} + +//=== Integer, Int32 and Uint32 ================================================ + +template +typename IntegerFactory::return_t +IntegerFactory::New(int32_t value) { + return To(T::New(v8::Isolate::GetCurrent(), value)); +} + +template +typename IntegerFactory::return_t +IntegerFactory::New(uint32_t value) { + return To(T::NewFromUnsigned(v8::Isolate::GetCurrent(), value)); +} + +Factory::return_t +Factory::New(int32_t value) { + return To( + v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value)); +} + +Factory::return_t +Factory::New(uint32_t value) { + return To( + v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value)); +} + +//=== Object =================================================================== + +Factory::return_t +Factory::New() { + return v8::Object::New(v8::Isolate::GetCurrent()); +} + +//=== Object Template ========================================================== + +Factory::return_t +Factory::New() { + return v8::ObjectTemplate::New(v8::Isolate::GetCurrent()); +} + +//=== RegExp =================================================================== + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New( + v8::Local pattern + , v8::RegExp::Flags flags) { + return v8::RegExp::New(GetCurrentContext(), pattern, flags); +} +#else +Factory::return_t +Factory::New( + v8::Local pattern + , v8::RegExp::Flags flags) { + return Factory::return_t(v8::RegExp::New(pattern, flags)); +} +#endif + +//=== Script =================================================================== + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New( v8::Local source) { + v8::ScriptCompiler::Source src(source); + return v8::ScriptCompiler::Compile(GetCurrentContext(), &src); +} + +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + v8::ScriptCompiler::Source src(source, origin); + return v8::ScriptCompiler::Compile(GetCurrentContext(), &src); +} +#else +Factory::return_t +Factory::New( v8::Local source) { + v8::ScriptCompiler::Source src(source); + return Factory::return_t( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src)); +} + +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + v8::ScriptCompiler::Source src(source, origin); + return Factory::return_t( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src)); +} +#endif + +//=== Signature ================================================================ + +Factory::return_t +Factory::New(Factory::FTH receiver) { + return v8::Signature::New(v8::Isolate::GetCurrent(), receiver); +} + +//=== String =================================================================== + +Factory::return_t +Factory::New() { + return Factory::return_t( + v8::String::Empty(v8::Isolate::GetCurrent())); +} + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New(const char * value, int length) { + return v8::String::NewFromUtf8( + v8::Isolate::GetCurrent(), value, v8::NewStringType::kNormal, length); +} + +Factory::return_t +Factory::New(std::string const& value) { + assert(value.size() <= INT_MAX && "string too long"); + return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), + value.data(), v8::NewStringType::kNormal, static_cast(value.size())); +} + +Factory::return_t +Factory::New(const uint16_t * value, int length) { + return v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), value, + v8::NewStringType::kNormal, length); +} + +Factory::return_t +Factory::New(v8::String::ExternalStringResource * value) { + return v8::String::NewExternalTwoByte(v8::Isolate::GetCurrent(), value); +} + +Factory::return_t +Factory::New(ExternalOneByteStringResource * value) { + return v8::String::NewExternalOneByte(v8::Isolate::GetCurrent(), value); +} +#else +Factory::return_t +Factory::New(const char * value, int length) { + return Factory::return_t( + v8::String::NewFromUtf8( + v8::Isolate::GetCurrent() + , value + , v8::String::kNormalString + , length)); +} + +Factory::return_t +Factory::New( + std::string const& value) /* NOLINT(build/include_what_you_use) */ { + assert(value.size() <= INT_MAX && "string too long"); + return Factory::return_t( + v8::String::NewFromUtf8( + v8::Isolate::GetCurrent() + , value.data() + , v8::String::kNormalString + , static_cast(value.size()))); +} + +Factory::return_t +Factory::New(const uint16_t * value, int length) { + return Factory::return_t( + v8::String::NewFromTwoByte( + v8::Isolate::GetCurrent() + , value + , v8::String::kNormalString + , length)); +} + +Factory::return_t +Factory::New(v8::String::ExternalStringResource * value) { + return Factory::return_t( + v8::String::NewExternal(v8::Isolate::GetCurrent(), value)); +} + +Factory::return_t +Factory::New(ExternalOneByteStringResource * value) { + return Factory::return_t( + v8::String::NewExternal(v8::Isolate::GetCurrent(), value)); +} +#endif + +//=== String Object ============================================================ + +Factory::return_t +Factory::New(v8::Local value) { + return v8::StringObject::New(value).As(); +} + +//=== Unbound Script =========================================================== + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New(v8::Local source) { + v8::ScriptCompiler::Source src(source); + return v8::ScriptCompiler::CompileUnboundScript( + v8::Isolate::GetCurrent(), &src); +} + +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + v8::ScriptCompiler::Source src(source, origin); + return v8::ScriptCompiler::CompileUnboundScript( + v8::Isolate::GetCurrent(), &src); +} +#else +Factory::return_t +Factory::New(v8::Local source) { + v8::ScriptCompiler::Source src(source); + return Factory::return_t( + v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src)); +} + +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + v8::ScriptCompiler::Source src(source, origin); + return Factory::return_t( + v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src)); +} +#endif + +} // end of namespace imp + +//=== Presistents and Handles ================================================== + +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION +template +inline v8::Local New(v8::Handle h) { + return v8::Local::New(v8::Isolate::GetCurrent(), h); +} +#endif + +template +inline v8::Local New(v8::Persistent const& p) { + return v8::Local::New(v8::Isolate::GetCurrent(), p); +} + +template +inline v8::Local New(Persistent const& p) { + return v8::Local::New(v8::Isolate::GetCurrent(), p); +} + +template +inline v8::Local New(Global const& p) { + return v8::Local::New(v8::Isolate::GetCurrent(), p); +} + +#endif // NAN_IMPLEMENTATION_12_INL_H_ diff --git a/node/node_modules/nan/nan_implementation_pre_12_inl.h b/node/node_modules/nan/nan_implementation_pre_12_inl.h new file mode 100644 index 0000000..f6642ee --- /dev/null +++ b/node/node_modules/nan/nan_implementation_pre_12_inl.h @@ -0,0 +1,264 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_IMPLEMENTATION_PRE_12_INL_H_ +#define NAN_IMPLEMENTATION_PRE_12_INL_H_ + +//============================================================================== +// node v0.10 implementation +//============================================================================== + +namespace imp { + +//=== Array ==================================================================== + +Factory::return_t +Factory::New() { + return v8::Array::New(); +} + +Factory::return_t +Factory::New(int length) { + return v8::Array::New(length); +} + +//=== Boolean ================================================================== + +Factory::return_t +Factory::New(bool value) { + return v8::Boolean::New(value)->ToBoolean(); +} + +//=== Boolean Object =========================================================== + +Factory::return_t +Factory::New(bool value) { + return v8::BooleanObject::New(value).As(); +} + +//=== Context ================================================================== + +Factory::return_t +Factory::New( v8::ExtensionConfiguration* extensions + , v8::Local tmpl + , v8::Local obj) { + v8::Persistent ctx = v8::Context::New(extensions, tmpl, obj); + v8::Local lctx = v8::Local::New(ctx); + ctx.Dispose(); + return lctx; +} + +//=== Date ===================================================================== + +Factory::return_t +Factory::New(double value) { + return Factory::return_t(v8::Date::New(value).As()); +} + +//=== External ================================================================= + +Factory::return_t +Factory::New(void * value) { + return v8::External::New(value); +} + +//=== Function ================================================================= + +Factory::return_t +Factory::New( FunctionCallback callback + , v8::Local data) { + return Factory::New( callback + , data + , v8::Local() + )->GetFunction(); +} + + +//=== FunctionTemplate ========================================================= + +Factory::return_t +Factory::New( FunctionCallback callback + , v8::Local data + , v8::Local signature) { + if (callback) { + v8::HandleScope scope; + + v8::Local tpl = v8::ObjectTemplate::New(); + tpl->SetInternalFieldCount(imp::kFunctionFieldCount); + v8::Local obj = tpl->NewInstance(); + + obj->SetInternalField( + imp::kFunctionIndex + , v8::External::New(reinterpret_cast(callback))); + + v8::Local val = v8::Local::New(data); + + if (!val.IsEmpty()) { + obj->SetInternalField(imp::kDataIndex, val); + } + + // Note(agnat): Emulate length argument here. Unfortunately, I couldn't find + // a way. Have at it though... + return scope.Close( + v8::FunctionTemplate::New(imp::FunctionCallbackWrapper + , obj + , signature)); + } else { + return v8::FunctionTemplate::New(0, data, signature); + } +} + +//=== Number =================================================================== + +Factory::return_t +Factory::New(double value) { + return v8::Number::New(value); +} + +//=== Number Object ============================================================ + +Factory::return_t +Factory::New(double value) { + return v8::NumberObject::New(value).As(); +} + +//=== Integer, Int32 and Uint32 ================================================ + +template +typename IntegerFactory::return_t +IntegerFactory::New(int32_t value) { + return To(T::New(value)); +} + +template +typename IntegerFactory::return_t +IntegerFactory::New(uint32_t value) { + return To(T::NewFromUnsigned(value)); +} + +Factory::return_t +Factory::New(int32_t value) { + return To(v8::Uint32::NewFromUnsigned(value)); +} + +Factory::return_t +Factory::New(uint32_t value) { + return To(v8::Uint32::NewFromUnsigned(value)); +} + + +//=== Object =================================================================== + +Factory::return_t +Factory::New() { + return v8::Object::New(); +} + +//=== Object Template ========================================================== + +Factory::return_t +Factory::New() { + return v8::ObjectTemplate::New(); +} + +//=== RegExp =================================================================== + +Factory::return_t +Factory::New( + v8::Local pattern + , v8::RegExp::Flags flags) { + return Factory::return_t(v8::RegExp::New(pattern, flags)); +} + +//=== Script =================================================================== + +Factory::return_t +Factory::New( v8::Local source) { + return Factory::return_t(v8::Script::New(source)); +} +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + return Factory::return_t( + v8::Script::New(source, const_cast(&origin))); +} + +//=== Signature ================================================================ + +Factory::return_t +Factory::New(Factory::FTH receiver) { + return v8::Signature::New(receiver); +} + +//=== String =================================================================== + +Factory::return_t +Factory::New() { + return Factory::return_t(v8::String::Empty()); +} + +Factory::return_t +Factory::New(const char * value, int length) { + return Factory::return_t(v8::String::New(value, length)); +} + +Factory::return_t +Factory::New( + std::string const& value) /* NOLINT(build/include_what_you_use) */ { + assert(value.size() <= INT_MAX && "string too long"); + return Factory::return_t( + v8::String::New( value.data(), static_cast(value.size()))); +} + +Factory::return_t +Factory::New(const uint16_t * value, int length) { + return Factory::return_t(v8::String::New(value, length)); +} + +Factory::return_t +Factory::New(v8::String::ExternalStringResource * value) { + return Factory::return_t(v8::String::NewExternal(value)); +} + +Factory::return_t +Factory::New(v8::String::ExternalAsciiStringResource * value) { + return Factory::return_t(v8::String::NewExternal(value)); +} + +//=== String Object ============================================================ + +Factory::return_t +Factory::New(v8::Local value) { + return v8::StringObject::New(value).As(); +} + +} // end of namespace imp + +//=== Presistents and Handles ================================================== + +template +inline v8::Local New(v8::Handle h) { + return v8::Local::New(h); +} + +template +inline v8::Local New(v8::Persistent const& p) { + return v8::Local::New(p); +} + +template +inline v8::Local New(Persistent const& p) { + return v8::Local::New(p.persistent); +} + +template +inline v8::Local New(Global const& p) { + return v8::Local::New(p.persistent); +} + +#endif // NAN_IMPLEMENTATION_PRE_12_INL_H_ diff --git a/node/node_modules/nan/nan_maybe_43_inl.h b/node/node_modules/nan/nan_maybe_43_inl.h new file mode 100644 index 0000000..a8b432d --- /dev/null +++ b/node/node_modules/nan/nan_maybe_43_inl.h @@ -0,0 +1,245 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_MAYBE_43_INL_H_ +#define NAN_MAYBE_43_INL_H_ + +template +using MaybeLocal = v8::MaybeLocal; + +template +using Maybe = v8::Maybe; + +template +inline Maybe Nothing() { + return v8::Nothing(); +} + +template +inline Maybe Just(const T& t) { + return v8::Just(t); +} + +v8::Local GetCurrentContext(); + +inline +MaybeLocal ToDetailString(v8::Local val) { + return val->ToDetailString(GetCurrentContext()); +} + +inline +MaybeLocal ToArrayIndex(v8::Local val) { + return val->ToArrayIndex(GetCurrentContext()); +} + +inline +Maybe Equals(v8::Local a, v8::Local(b)) { + return a->Equals(GetCurrentContext(), b); +} + +inline +MaybeLocal NewInstance(v8::Local h) { + return h->NewInstance(GetCurrentContext()); +} + +inline +MaybeLocal NewInstance( + v8::Local h + , int argc + , v8::Local argv[]) { + return h->NewInstance(GetCurrentContext(), argc, argv); +} + +inline +MaybeLocal NewInstance(v8::Local h) { + return h->NewInstance(GetCurrentContext()); +} + + +inline MaybeLocal GetFunction( + v8::Local t) { + return t->GetFunction(GetCurrentContext()); +} + +inline Maybe Set( + v8::Local obj + , v8::Local key + , v8::Local value) { + return obj->Set(GetCurrentContext(), key, value); +} + +inline Maybe Set( + v8::Local obj + , uint32_t index + , v8::Local value) { + return obj->Set(GetCurrentContext(), index, value); +} + +inline Maybe ForceSet( + v8::Local obj + , v8::Local key + , v8::Local value + , v8::PropertyAttribute attribs = v8::None) { + return obj->ForceSet(GetCurrentContext(), key, value, attribs); +} + +inline MaybeLocal Get( + v8::Local obj + , v8::Local key) { + return obj->Get(GetCurrentContext(), key); +} + +inline +MaybeLocal Get(v8::Local obj, uint32_t index) { + return obj->Get(GetCurrentContext(), index); +} + +inline v8::PropertyAttribute GetPropertyAttributes( + v8::Local obj + , v8::Local key) { + return obj->GetPropertyAttributes(GetCurrentContext(), key).FromJust(); +} + +inline Maybe Has( + v8::Local obj + , v8::Local key) { + return obj->Has(GetCurrentContext(), key); +} + +inline Maybe Has(v8::Local obj, uint32_t index) { + return obj->Has(GetCurrentContext(), index); +} + +inline Maybe Delete( + v8::Local obj + , v8::Local key) { + return obj->Delete(GetCurrentContext(), key); +} + +inline +Maybe Delete(v8::Local obj, uint32_t index) { + return obj->Delete(GetCurrentContext(), index); +} + +inline +MaybeLocal GetPropertyNames(v8::Local obj) { + return obj->GetPropertyNames(GetCurrentContext()); +} + +inline +MaybeLocal GetOwnPropertyNames(v8::Local obj) { + return obj->GetOwnPropertyNames(GetCurrentContext()); +} + +inline Maybe SetPrototype( + v8::Local obj + , v8::Local prototype) { + return obj->SetPrototype(GetCurrentContext(), prototype); +} + +inline MaybeLocal ObjectProtoToString( + v8::Local obj) { + return obj->ObjectProtoToString(GetCurrentContext()); +} + +inline Maybe HasOwnProperty( + v8::Local obj + , v8::Local key) { + return obj->HasOwnProperty(GetCurrentContext(), key); +} + +inline Maybe HasRealNamedProperty( + v8::Local obj + , v8::Local key) { + return obj->HasRealNamedProperty(GetCurrentContext(), key); +} + +inline Maybe HasRealIndexedProperty( + v8::Local obj + , uint32_t index) { + return obj->HasRealIndexedProperty(GetCurrentContext(), index); +} + +inline Maybe HasRealNamedCallbackProperty( + v8::Local obj + , v8::Local key) { + return obj->HasRealNamedCallbackProperty(GetCurrentContext(), key); +} + +inline MaybeLocal GetRealNamedPropertyInPrototypeChain( + v8::Local obj + , v8::Local key) { + return obj->GetRealNamedPropertyInPrototypeChain(GetCurrentContext(), key); +} + +inline MaybeLocal GetRealNamedProperty( + v8::Local obj + , v8::Local key) { + return obj->GetRealNamedProperty(GetCurrentContext(), key); +} + +inline MaybeLocal CallAsFunction( + v8::Local obj + , v8::Local recv + , int argc + , v8::Local argv[]) { + return obj->CallAsFunction(GetCurrentContext(), recv, argc, argv); +} + +inline MaybeLocal CallAsConstructor( + v8::Local obj + , int argc, v8::Local argv[]) { + return obj->CallAsConstructor(GetCurrentContext(), argc, argv); +} + +inline +MaybeLocal GetSourceLine(v8::Local msg) { + return msg->GetSourceLine(GetCurrentContext()); +} + +inline Maybe GetLineNumber(v8::Local msg) { + return msg->GetLineNumber(GetCurrentContext()); +} + +inline Maybe GetStartColumn(v8::Local msg) { + return msg->GetStartColumn(GetCurrentContext()); +} + +inline Maybe GetEndColumn(v8::Local msg) { + return msg->GetEndColumn(GetCurrentContext()); +} + +inline MaybeLocal CloneElementAt( + v8::Local array + , uint32_t index) { +#if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) + v8::EscapableHandleScope handle_scope(v8::Isolate::GetCurrent()); + v8::Local context = GetCurrentContext(); + v8::Local elem; + if (!array->Get(context, index).ToLocal(&elem)) { + return MaybeLocal(); + } + v8::Local obj; + if (!elem->ToObject(context).ToLocal(&obj)) { + return MaybeLocal(); + } + return MaybeLocal(handle_scope.Escape(obj->Clone())); +#else + return array->CloneElementAt(GetCurrentContext(), index); +#endif +} + +inline MaybeLocal Call( + v8::Local fun + , v8::Local recv + , int argc + , v8::Local argv[]) { + return fun->Call(GetCurrentContext(), recv, argc, argv); +} + +#endif // NAN_MAYBE_43_INL_H_ diff --git a/node/node_modules/nan/nan_maybe_pre_43_inl.h b/node/node_modules/nan/nan_maybe_pre_43_inl.h new file mode 100644 index 0000000..c538687 --- /dev/null +++ b/node/node_modules/nan/nan_maybe_pre_43_inl.h @@ -0,0 +1,303 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_MAYBE_PRE_43_INL_H_ +#define NAN_MAYBE_PRE_43_INL_H_ + +template +class MaybeLocal { + public: + inline MaybeLocal() : val_(v8::Local()) {} + + template +# if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION + inline MaybeLocal(v8::Local that) : val_(that) {} +# else + inline MaybeLocal(v8::Local that) : + val_(*reinterpret_cast*>(&that)) {} +# endif + + inline bool IsEmpty() const { return val_.IsEmpty(); } + + template + inline bool ToLocal(v8::Local *out) const { + *out = val_; + return !IsEmpty(); + } + + inline v8::Local ToLocalChecked() const { +#if defined(V8_ENABLE_CHECKS) + assert(!IsEmpty() && "ToLocalChecked is Empty"); +#endif // V8_ENABLE_CHECKS + return val_; + } + + template + inline v8::Local FromMaybe(v8::Local default_value) const { + return IsEmpty() ? default_value : val_; + } + + private: + v8::Local val_; +}; + +template +class Maybe { + public: + inline bool IsNothing() const { return !has_value_; } + inline bool IsJust() const { return has_value_; } + + inline T FromJust() const { +#if defined(V8_ENABLE_CHECKS) + assert(IsJust() && "FromJust is Nothing"); +#endif // V8_ENABLE_CHECKS + return value_; + } + + inline T FromMaybe(const T& default_value) const { + return has_value_ ? value_ : default_value; + } + + inline bool operator==(const Maybe &other) const { + return (IsJust() == other.IsJust()) && + (!IsJust() || FromJust() == other.FromJust()); + } + + inline bool operator!=(const Maybe &other) const { + return !operator==(other); + } + + private: + Maybe() : has_value_(false) {} + explicit Maybe(const T& t) : has_value_(true), value_(t) {} + bool has_value_; + T value_; + + template + friend Maybe Nothing(); + template + friend Maybe Just(const U& u); +}; + +template +inline Maybe Nothing() { + return Maybe(); +} + +template +inline Maybe Just(const T& t) { + return Maybe(t); +} + +inline +MaybeLocal ToDetailString(v8::Handle val) { + return MaybeLocal(val->ToDetailString()); +} + +inline +MaybeLocal ToArrayIndex(v8::Handle val) { + return MaybeLocal(val->ToArrayIndex()); +} + +inline +Maybe Equals(v8::Handle a, v8::Handle(b)) { + return Just(a->Equals(b)); +} + +inline +MaybeLocal NewInstance(v8::Handle h) { + return MaybeLocal(h->NewInstance()); +} + +inline +MaybeLocal NewInstance( + v8::Local h + , int argc + , v8::Local argv[]) { + return MaybeLocal(h->NewInstance(argc, argv)); +} + +inline +MaybeLocal NewInstance(v8::Handle h) { + return MaybeLocal(h->NewInstance()); +} + +inline +MaybeLocal GetFunction(v8::Handle t) { + return MaybeLocal(t->GetFunction()); +} + +inline Maybe Set( + v8::Handle obj + , v8::Handle key + , v8::Handle value) { + return Just(obj->Set(key, value)); +} + +inline Maybe Set( + v8::Handle obj + , uint32_t index + , v8::Handle value) { + return Just(obj->Set(index, value)); +} + +inline Maybe ForceSet( + v8::Handle obj + , v8::Handle key + , v8::Handle value + , v8::PropertyAttribute attribs = v8::None) { + return Just(obj->ForceSet(key, value, attribs)); +} + +inline MaybeLocal Get( + v8::Handle obj + , v8::Handle key) { + return MaybeLocal(obj->Get(key)); +} + +inline MaybeLocal Get( + v8::Handle obj + , uint32_t index) { + return MaybeLocal(obj->Get(index)); +} + +inline Maybe GetPropertyAttributes( + v8::Handle obj + , v8::Handle key) { + return Just(obj->GetPropertyAttributes(key)); +} + +inline Maybe Has( + v8::Handle obj + , v8::Handle key) { + return Just(obj->Has(key)); +} + +inline Maybe Has( + v8::Handle obj + , uint32_t index) { + return Just(obj->Has(index)); +} + +inline Maybe Delete( + v8::Handle obj + , v8::Handle key) { + return Just(obj->Delete(key)); +} + +inline Maybe Delete( + v8::Handle obj + , uint32_t index) { + return Just(obj->Delete(index)); +} + +inline +MaybeLocal GetPropertyNames(v8::Handle obj) { + return MaybeLocal(obj->GetPropertyNames()); +} + +inline +MaybeLocal GetOwnPropertyNames(v8::Handle obj) { + return MaybeLocal(obj->GetOwnPropertyNames()); +} + +inline Maybe SetPrototype( + v8::Handle obj + , v8::Handle prototype) { + return Just(obj->SetPrototype(prototype)); +} + +inline MaybeLocal ObjectProtoToString( + v8::Handle obj) { + return MaybeLocal(obj->ObjectProtoToString()); +} + +inline Maybe HasOwnProperty( + v8::Handle obj + , v8::Handle key) { + return Just(obj->HasOwnProperty(key)); +} + +inline Maybe HasRealNamedProperty( + v8::Handle obj + , v8::Handle key) { + return Just(obj->HasRealNamedProperty(key)); +} + +inline Maybe HasRealIndexedProperty( + v8::Handle obj + , uint32_t index) { + return Just(obj->HasRealIndexedProperty(index)); +} + +inline Maybe HasRealNamedCallbackProperty( + v8::Handle obj + , v8::Handle key) { + return Just(obj->HasRealNamedCallbackProperty(key)); +} + +inline MaybeLocal GetRealNamedPropertyInPrototypeChain( + v8::Handle obj + , v8::Handle key) { + return MaybeLocal( + obj->GetRealNamedPropertyInPrototypeChain(key)); +} + +inline MaybeLocal GetRealNamedProperty( + v8::Handle obj + , v8::Handle key) { + return MaybeLocal(obj->GetRealNamedProperty(key)); +} + +inline MaybeLocal CallAsFunction( + v8::Handle obj + , v8::Handle recv + , int argc + , v8::Handle argv[]) { + return MaybeLocal(obj->CallAsFunction(recv, argc, argv)); +} + +inline MaybeLocal CallAsConstructor( + v8::Handle obj + , int argc + , v8::Local argv[]) { + return MaybeLocal(obj->CallAsConstructor(argc, argv)); +} + +inline +MaybeLocal GetSourceLine(v8::Handle msg) { + return MaybeLocal(msg->GetSourceLine()); +} + +inline Maybe GetLineNumber(v8::Handle msg) { + return Just(msg->GetLineNumber()); +} + +inline Maybe GetStartColumn(v8::Handle msg) { + return Just(msg->GetStartColumn()); +} + +inline Maybe GetEndColumn(v8::Handle msg) { + return Just(msg->GetEndColumn()); +} + +inline MaybeLocal CloneElementAt( + v8::Handle array + , uint32_t index) { + return MaybeLocal(array->CloneElementAt(index)); +} + +inline MaybeLocal Call( + v8::Local fun + , v8::Local recv + , int argc + , v8::Local argv[]) { + return MaybeLocal(fun->Call(recv, argc, argv)); +} + +#endif // NAN_MAYBE_PRE_43_INL_H_ diff --git a/node/node_modules/nan/nan_new.h b/node/node_modules/nan/nan_new.h new file mode 100644 index 0000000..6c7d19f --- /dev/null +++ b/node/node_modules/nan/nan_new.h @@ -0,0 +1,340 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_NEW_H_ +#define NAN_NEW_H_ + +namespace imp { // scnr + +// TODO(agnat): Generalize +template v8::Local To(v8::Local i); + +template <> +inline +v8::Local +To(v8::Local i) { + return Nan::To(i).ToLocalChecked(); +} + +template <> +inline +v8::Local +To(v8::Local i) { + return Nan::To(i).ToLocalChecked(); +} + +template <> +inline +v8::Local +To(v8::Local i) { + return Nan::To(i).ToLocalChecked(); +} + +template struct FactoryBase { + typedef v8::Local return_t; +}; + +template struct MaybeFactoryBase { + typedef MaybeLocal return_t; +}; + +template struct Factory; + +template <> +struct Factory : FactoryBase { + static inline return_t New(); + static inline return_t New(int length); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(bool value); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(bool value); +}; + +template <> +struct Factory : FactoryBase { + static inline + return_t + New( v8::ExtensionConfiguration* extensions = NULL + , v8::Local tmpl = v8::Local() + , v8::Local obj = v8::Local()); +}; + +template <> +struct Factory : MaybeFactoryBase { + static inline return_t New(double value); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(void *value); +}; + +template <> +struct Factory : FactoryBase { + static inline + return_t + New( FunctionCallback callback + , v8::Local data = v8::Local()); +}; + +template <> +struct Factory : FactoryBase { + static inline + return_t + New( FunctionCallback callback = NULL + , v8::Local data = v8::Local() + , v8::Local signature = v8::Local()); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(double value); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(double value); +}; + +template +struct IntegerFactory : FactoryBase { + typedef typename FactoryBase::return_t return_t; + static inline return_t New(int32_t value); + static inline return_t New(uint32_t value); +}; + +template <> +struct Factory : IntegerFactory {}; + +template <> +struct Factory : IntegerFactory {}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(int32_t value); + static inline return_t New(uint32_t value); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(); +}; + +template <> +struct Factory : MaybeFactoryBase { + static inline return_t New( + v8::Local pattern, v8::RegExp::Flags flags); +}; + +template <> +struct Factory : MaybeFactoryBase { + static inline return_t New( v8::Local source); + static inline return_t New( v8::Local source + , v8::ScriptOrigin const& origin); +}; + +template <> +struct Factory : FactoryBase { + typedef v8::Local FTH; + static inline return_t New(FTH receiver = FTH()); +}; + +template <> +struct Factory : MaybeFactoryBase { + static inline return_t New(); + static inline return_t New(const char *value, int length = -1); + static inline return_t New(const uint16_t *value, int length = -1); + static inline return_t New(std::string const& value); + + static inline return_t New(v8::String::ExternalStringResource * value); + static inline return_t New(ExternalOneByteStringResource * value); +}; + +template <> +struct Factory : FactoryBase { + static inline return_t New(v8::Local value); +}; + +} // end of namespace imp + +#if (NODE_MODULE_VERSION >= 12) + +namespace imp { + +template <> +struct Factory : MaybeFactoryBase { + static inline return_t New( v8::Local source); + static inline return_t New( v8::Local source + , v8::ScriptOrigin const& origin); +}; + +} // end of namespace imp + +# include "nan_implementation_12_inl.h" + +#else // NODE_MODULE_VERSION >= 12 + +# include "nan_implementation_pre_12_inl.h" + +#endif + +//=== API ====================================================================== + +template +typename imp::Factory::return_t +New() { + return imp::Factory::New(); +} + +template +typename imp::Factory::return_t +New(A0 arg0) { + return imp::Factory::New(arg0); +} + +template +typename imp::Factory::return_t +New(A0 arg0, A1 arg1) { + return imp::Factory::New(arg0, arg1); +} + +template +typename imp::Factory::return_t +New(A0 arg0, A1 arg1, A2 arg2) { + return imp::Factory::New(arg0, arg1, arg2); +} + +template +typename imp::Factory::return_t +New(A0 arg0, A1 arg1, A2 arg2, A3 arg3) { + return imp::Factory::New(arg0, arg1, arg2, arg3); +} + +// Note(agnat): When passing overloaded function pointers to template functions +// as generic arguments the compiler needs help in picking the right overload. +// These two functions handle New and New with +// all argument variations. + +// v8::Function and v8::FunctionTemplate with one or two arguments +template +typename imp::Factory::return_t +New( FunctionCallback callback + , v8::Local data = v8::Local()) { + return imp::Factory::New(callback, data); +} + +// v8::Function and v8::FunctionTemplate with three arguments +template +typename imp::Factory::return_t +New( FunctionCallback callback + , v8::Local data = v8::Local() + , A2 a2 = A2()) { + return imp::Factory::New(callback, data, a2); +} + +// Convenience + +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION +template inline v8::Local New(v8::Handle h); +#endif + +#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +template + inline v8::Local New(v8::Persistent const& p); +#else +template inline v8::Local New(v8::Persistent const& p); +#endif +template +inline v8::Local New(Persistent const& p); +template +inline v8::Local New(Global const& p); + +inline +imp::Factory::return_t +New(bool value) { + return New(value); +} + +inline +imp::Factory::return_t +New(int32_t value) { + return New(value); +} + +inline +imp::Factory::return_t +New(uint32_t value) { + return New(value); +} + +inline +imp::Factory::return_t +New(double value) { + return New(value); +} + +inline +imp::Factory::return_t +New(std::string const& value) { // NOLINT(build/include_what_you_use) + return New(value); +} + +inline +imp::Factory::return_t +New(const char * value, int length) { + return New(value, length); +} + +inline +imp::Factory::return_t +New(const uint16_t * value, int length) { + return New(value, length); +} + +inline +imp::Factory::return_t +New(const char * value) { + return New(value); +} + +inline +imp::Factory::return_t +New(const uint16_t * value) { + return New(value); +} + +inline +imp::Factory::return_t +New(v8::String::ExternalStringResource * value) { + return New(value); +} + +inline +imp::Factory::return_t +New(ExternalOneByteStringResource * value) { + return New(value); +} + +inline +imp::Factory::return_t +New(v8::Local pattern, v8::RegExp::Flags flags) { + return New(pattern, flags); +} + +#endif // NAN_NEW_H_ diff --git a/node/node_modules/nan/nan_object_wrap.h b/node/node_modules/nan/nan_object_wrap.h new file mode 100644 index 0000000..f1cc156 --- /dev/null +++ b/node/node_modules/nan/nan_object_wrap.h @@ -0,0 +1,155 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_OBJECT_WRAP_H_ +#define NAN_OBJECT_WRAP_H_ + +class ObjectWrap { + public: + ObjectWrap() { + refs_ = 0; + } + + + virtual ~ObjectWrap() { + if (persistent().IsEmpty()) { + return; + } + + assert(persistent().IsNearDeath()); + persistent().ClearWeak(); + persistent().Reset(); + } + + + template + static inline T* Unwrap(v8::Local object) { + assert(!object.IsEmpty()); + assert(object->InternalFieldCount() > 0); + // Cast to ObjectWrap before casting to T. A direct cast from void + // to T won't work right when T has more than one base class. + void* ptr = GetInternalFieldPointer(object, 0); + ObjectWrap* wrap = static_cast(ptr); + return static_cast(wrap); + } + + + inline v8::Local handle() const { + return New(handle_); + } + + + inline Persistent& persistent() { + return handle_; + } + + + protected: + inline void Wrap(v8::Local object) { + assert(persistent().IsEmpty()); + assert(object->InternalFieldCount() > 0); + SetInternalFieldPointer(object, 0, this); + persistent().Reset(object); + MakeWeak(); + } + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + + inline void MakeWeak() { + persistent().v8::PersistentBase::SetWeak( + this, WeakCallback, v8::WeakCallbackType::kParameter); + persistent().MarkIndependent(); + } + +#elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + + inline void MakeWeak() { + persistent().v8::PersistentBase::SetWeak(this, WeakCallback); + persistent().MarkIndependent(); + } + +#else + + inline void MakeWeak() { + persistent().persistent.MakeWeak(this, WeakCallback); + persistent().MarkIndependent(); + } + +#endif + + /* Ref() marks the object as being attached to an event loop. + * Refed objects will not be garbage collected, even if + * all references are lost. + */ + virtual void Ref() { + assert(!persistent().IsEmpty()); + persistent().ClearWeak(); + refs_++; + } + + /* Unref() marks an object as detached from the event loop. This is its + * default state. When an object with a "weak" reference changes from + * attached to detached state it will be freed. Be careful not to access + * the object after making this call as it might be gone! + * (A "weak reference" means an object that only has a + * persistant handle.) + * + * DO NOT CALL THIS FROM DESTRUCTOR + */ + virtual void Unref() { + assert(!persistent().IsEmpty()); + assert(!persistent().IsWeak()); + assert(refs_ > 0); + if (--refs_ == 0) + MakeWeak(); + } + + int refs_; // ro + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(ObjectWrap) +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + + static void + WeakCallback(v8::WeakCallbackInfo const& info) { + ObjectWrap* wrap = info.GetParameter(); + assert(wrap->refs_ == 0); + assert(wrap->handle_.IsNearDeath()); + wrap->handle_.Reset(); + delete wrap; + } + +#elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + + static void + WeakCallback(v8::WeakCallbackData const& data) { + ObjectWrap* wrap = data.GetParameter(); + assert(wrap->refs_ == 0); + assert(wrap->handle_.IsNearDeath()); + wrap->handle_.Reset(); + delete wrap; + } + +#else + + static void WeakCallback(v8::Persistent value, void *data) { + ObjectWrap *wrap = static_cast(data); + assert(wrap->refs_ == 0); + assert(wrap->handle_.IsNearDeath()); + wrap->handle_.Reset(); + delete wrap; + } + +#endif + Persistent handle_; +}; + + +#endif // NAN_OBJECT_WRAP_H_ diff --git a/node/node_modules/nan/nan_persistent_12_inl.h b/node/node_modules/nan/nan_persistent_12_inl.h new file mode 100644 index 0000000..eb4ff10 --- /dev/null +++ b/node/node_modules/nan/nan_persistent_12_inl.h @@ -0,0 +1,129 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_PERSISTENT_12_INL_H_ +#define NAN_PERSISTENT_12_INL_H_ + +template class Persistent : + public v8::Persistent { + public: + inline Persistent() : v8::Persistent() {} + + template inline Persistent(v8::Local that) : + v8::Persistent(v8::Isolate::GetCurrent(), that) {} + + template + inline Persistent(const v8::Persistent &that) : + v8::Persistent(v8::Isolate::GetCurrent(), that) {} + + inline void Reset() { v8::PersistentBase::Reset(); } + + template + inline void Reset(const v8::Local &other) { + v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); + } + + template + inline void Reset(const v8::PersistentBase &other) { + v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); + } + + template + inline void SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type); + + private: + inline T *operator*() const { return *PersistentBase::persistent; } + + template + inline void Copy(const Persistent &that) { + TYPE_CHECK(T, S); + + this->Reset(); + + if (!that.IsEmpty()) { + this->Reset(that); + M::Copy(that, this); + } + } +}; + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +template +class Global : public v8::Global { + public: + inline Global() : v8::Global() {} + + template inline Global(v8::Local that) : + v8::Global(v8::Isolate::GetCurrent(), that) {} + + template + inline Global(const v8::PersistentBase &that) : + v8::Global(v8::Isolate::GetCurrent(), that) {} + + inline void Reset() { v8::PersistentBase::Reset(); } + + template + inline void Reset(const v8::Local &other) { + v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); + } + + template + inline void Reset(const v8::PersistentBase &other) { + v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); + } + + template + inline void SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + reinterpret_cast*>(this)->SetWeak( + parameter, callback, type); + } +}; +#else +template +class Global : public v8::UniquePersistent { + public: + inline Global() : v8::UniquePersistent() {} + + template inline Global(v8::Local that) : + v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} + + template + inline Global(const v8::PersistentBase &that) : + v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} + + inline void Reset() { v8::PersistentBase::Reset(); } + + template + inline void Reset(const v8::Local &other) { + v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); + } + + template + inline void Reset(const v8::PersistentBase &other) { + v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); + } + + template + inline void SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + reinterpret_cast*>(this)->SetWeak( + parameter, callback, type); + } +}; +#endif + +#endif // NAN_PERSISTENT_12_INL_H_ diff --git a/node/node_modules/nan/nan_persistent_pre_12_inl.h b/node/node_modules/nan/nan_persistent_pre_12_inl.h new file mode 100644 index 0000000..0d427ed --- /dev/null +++ b/node/node_modules/nan/nan_persistent_pre_12_inl.h @@ -0,0 +1,242 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_PERSISTENT_PRE_12_INL_H_ +#define NAN_PERSISTENT_PRE_12_INL_H_ + +template +class PersistentBase { + v8::Persistent persistent; + template + friend v8::Local New(const PersistentBase &p); + template + friend v8::Local New(const Persistent &p); + template + friend v8::Local New(const Global &p); + template friend class ReturnValue; + + public: + inline PersistentBase() : + persistent() {} + + inline void Reset() { + persistent.Dispose(); + persistent.Clear(); + } + + template + inline void Reset(const v8::Local &other) { + TYPE_CHECK(T, S); + + if (!persistent.IsEmpty()) { + persistent.Dispose(); + } + + if (other.IsEmpty()) { + persistent.Clear(); + } else { + persistent = v8::Persistent::New(other); + } + } + + template + inline void Reset(const PersistentBase &other) { + TYPE_CHECK(T, S); + + if (!persistent.IsEmpty()) { + persistent.Dispose(); + } + + if (other.IsEmpty()) { + persistent.Clear(); + } else { + persistent = v8::Persistent::New(other.persistent); + } + } + + inline bool IsEmpty() const { return persistent.IsEmpty(); } + + inline void Empty() { persistent.Clear(); } + + template + inline bool operator==(const PersistentBase &that) const { + return this->persistent == that.persistent; + } + + template + inline bool operator==(const v8::Local &that) const { + return this->persistent == that; + } + + template + inline bool operator!=(const PersistentBase &that) const { + return !operator==(that); + } + + template + inline bool operator!=(const v8::Local &that) const { + return !operator==(that); + } + + template + inline void SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type); + + inline void ClearWeak() { persistent.ClearWeak(); } + + inline void MarkIndependent() { persistent.MarkIndependent(); } + + inline bool IsIndependent() const { return persistent.IsIndependent(); } + + inline bool IsNearDeath() const { return persistent.IsNearDeath(); } + + inline bool IsWeak() const { return persistent.IsWeak(); } + + private: + inline explicit PersistentBase(v8::Persistent that) : + persistent(that) { } + inline explicit PersistentBase(T *val) : persistent(val) {} + template friend class Persistent; + template friend class Global; + friend class ObjectWrap; +}; + +template +class NonCopyablePersistentTraits { + public: + typedef Persistent > + NonCopyablePersistent; + static const bool kResetInDestructor = false; + template + inline static void Copy(const Persistent &source, + NonCopyablePersistent *dest) { + Uncompilable(); + } + + template inline static void Uncompilable() { + TYPE_CHECK(O, v8::Primitive); + } +}; + +template +struct CopyablePersistentTraits { + typedef Persistent > CopyablePersistent; + static const bool kResetInDestructor = true; + template + static inline void Copy(const Persistent &source, + CopyablePersistent *dest) {} +}; + +template class Persistent : + public PersistentBase { + public: + inline Persistent() {} + + template inline Persistent(v8::Handle that) + : PersistentBase(v8::Persistent::New(that)) { + TYPE_CHECK(T, S); + } + + inline Persistent(const Persistent &that) : PersistentBase() { + Copy(that); + } + + template + inline Persistent(const Persistent &that) : + PersistentBase() { + Copy(that); + } + + inline Persistent &operator=(const Persistent &that) { + Copy(that); + return *this; + } + + template + inline Persistent &operator=(const Persistent &that) { + Copy(that); + return *this; + } + + inline ~Persistent() { + if (M::kResetInDestructor) this->Reset(); + } + + private: + inline T *operator*() const { return *PersistentBase::persistent; } + + template + inline void Copy(const Persistent &that) { + TYPE_CHECK(T, S); + + this->Reset(); + + if (!that.IsEmpty()) { + this->persistent = v8::Persistent::New(that.persistent); + M::Copy(that, this); + } + } +}; + +template +class Global : public PersistentBase { + struct RValue { + inline explicit RValue(Global* obj) : object(obj) {} + Global* object; + }; + + public: + inline Global() : PersistentBase(0) { } + + template + inline Global(v8::Local that) + : PersistentBase(v8::Persistent::New(that)) { + TYPE_CHECK(T, S); + } + + template + inline Global(const PersistentBase &that) + : PersistentBase(that) { + TYPE_CHECK(T, S); + } + /** + * Move constructor. + */ + inline Global(RValue rvalue) + : PersistentBase(rvalue.object->persistent) { + rvalue.object->Reset(); + } + inline ~Global() { this->Reset(); } + /** + * Move via assignment. + */ + template + inline Global &operator=(Global rhs) { + TYPE_CHECK(T, S); + this->Reset(rhs.persistent); + rhs.Reset(); + return *this; + } + /** + * Cast operator for moves. + */ + inline operator RValue() { return RValue(this); } + /** + * Pass allows returning uniques from functions, etc. + */ + Global Pass() { return Global(RValue(this)); } + + private: + Global(Global &); + void operator=(Global &); + template friend class ReturnValue; +}; + +#endif // NAN_PERSISTENT_PRE_12_INL_H_ diff --git a/node/node_modules/nan/nan_string_bytes.h b/node/node_modules/nan/nan_string_bytes.h new file mode 100644 index 0000000..a2e6437 --- /dev/null +++ b/node/node_modules/nan/nan_string_bytes.h @@ -0,0 +1,305 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +#ifndef NAN_STRING_BYTES_H_ +#define NAN_STRING_BYTES_H_ + +// Decodes a v8::Local or Buffer to a raw char* + +namespace imp { + +using v8::Local; +using v8::Object; +using v8::String; +using v8::Value; + + +//// Base 64 //// + +#define base64_encoded_size(size) ((size + 2 - ((size + 2) % 3)) / 3 * 4) + + + +//// HEX //// + +static bool contains_non_ascii_slow(const char* buf, size_t len) { + for (size_t i = 0; i < len; ++i) { + if (buf[i] & 0x80) return true; + } + return false; +} + + +static bool contains_non_ascii(const char* src, size_t len) { + if (len < 16) { + return contains_non_ascii_slow(src, len); + } + + const unsigned bytes_per_word = sizeof(void*); + const unsigned align_mask = bytes_per_word - 1; + const unsigned unaligned = reinterpret_cast(src) & align_mask; + + if (unaligned > 0) { + const unsigned n = bytes_per_word - unaligned; + if (contains_non_ascii_slow(src, n)) return true; + src += n; + len -= n; + } + + +#if defined(__x86_64__) || defined(_WIN64) + const uintptr_t mask = 0x8080808080808080ll; +#else + const uintptr_t mask = 0x80808080l; +#endif + + const uintptr_t* srcw = reinterpret_cast(src); + + for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { + if (srcw[i] & mask) return true; + } + + const unsigned remainder = len & align_mask; + if (remainder > 0) { + const size_t offset = len - remainder; + if (contains_non_ascii_slow(src + offset, remainder)) return true; + } + + return false; +} + + +static void force_ascii_slow(const char* src, char* dst, size_t len) { + for (size_t i = 0; i < len; ++i) { + dst[i] = src[i] & 0x7f; + } +} + + +static void force_ascii(const char* src, char* dst, size_t len) { + if (len < 16) { + force_ascii_slow(src, dst, len); + return; + } + + const unsigned bytes_per_word = sizeof(void*); + const unsigned align_mask = bytes_per_word - 1; + const unsigned src_unalign = reinterpret_cast(src) & align_mask; + const unsigned dst_unalign = reinterpret_cast(dst) & align_mask; + + if (src_unalign > 0) { + if (src_unalign == dst_unalign) { + const unsigned unalign = bytes_per_word - src_unalign; + force_ascii_slow(src, dst, unalign); + src += unalign; + dst += unalign; + len -= src_unalign; + } else { + force_ascii_slow(src, dst, len); + return; + } + } + +#if defined(__x86_64__) || defined(_WIN64) + const uintptr_t mask = ~0x8080808080808080ll; +#else + const uintptr_t mask = ~0x80808080l; +#endif + + const uintptr_t* srcw = reinterpret_cast(src); + uintptr_t* dstw = reinterpret_cast(dst); + + for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { + dstw[i] = srcw[i] & mask; + } + + const unsigned remainder = len & align_mask; + if (remainder > 0) { + const size_t offset = len - remainder; + force_ascii_slow(src + offset, dst + offset, remainder); + } +} + + +static size_t base64_encode(const char* src, + size_t slen, + char* dst, + size_t dlen) { + // We know how much we'll write, just make sure that there's space. + assert(dlen >= base64_encoded_size(slen) && + "not enough space provided for base64 encode"); + + dlen = base64_encoded_size(slen); + + unsigned a; + unsigned b; + unsigned c; + unsigned i; + unsigned k; + unsigned n; + + static const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + + i = 0; + k = 0; + n = slen / 3 * 3; + + while (i < n) { + a = src[i + 0] & 0xff; + b = src[i + 1] & 0xff; + c = src[i + 2] & 0xff; + + dst[k + 0] = table[a >> 2]; + dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; + dst[k + 2] = table[((b & 0x0f) << 2) | (c >> 6)]; + dst[k + 3] = table[c & 0x3f]; + + i += 3; + k += 4; + } + + if (n != slen) { + switch (slen - n) { + case 1: + a = src[i + 0] & 0xff; + dst[k + 0] = table[a >> 2]; + dst[k + 1] = table[(a & 3) << 4]; + dst[k + 2] = '='; + dst[k + 3] = '='; + break; + + case 2: + a = src[i + 0] & 0xff; + b = src[i + 1] & 0xff; + dst[k + 0] = table[a >> 2]; + dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; + dst[k + 2] = table[(b & 0x0f) << 2]; + dst[k + 3] = '='; + break; + } + } + + return dlen; +} + + +static size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) { + // We know how much we'll write, just make sure that there's space. + assert(dlen >= slen * 2 && + "not enough space provided for hex encode"); + + dlen = slen * 2; + for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) { + static const char hex[] = "0123456789abcdef"; + uint8_t val = static_cast(src[i]); + dst[k + 0] = hex[val >> 4]; + dst[k + 1] = hex[val & 15]; + } + + return dlen; +} + + + +static Local Encode(const char* buf, + size_t buflen, + enum Encoding encoding) { + assert(buflen <= node::Buffer::kMaxLength); + if (!buflen && encoding != BUFFER) + return New("").ToLocalChecked(); + + Local val; + switch (encoding) { + case BUFFER: + return CopyBuffer(buf, buflen).ToLocalChecked(); + + case ASCII: + if (contains_non_ascii(buf, buflen)) { + char* out = new char[buflen]; + force_ascii(buf, out, buflen); + val = New(out, buflen).ToLocalChecked(); + delete[] out; + } else { + val = New(buf, buflen).ToLocalChecked(); + } + break; + + case UTF8: + val = New(buf, buflen).ToLocalChecked(); + break; + + case BINARY: { + // TODO(isaacs) use ExternalTwoByteString? + const unsigned char *cbuf = reinterpret_cast(buf); + uint16_t * twobytebuf = new uint16_t[buflen]; + for (size_t i = 0; i < buflen; i++) { + // XXX is the following line platform independent? + twobytebuf[i] = cbuf[i]; + } + val = New(twobytebuf, buflen).ToLocalChecked(); + delete[] twobytebuf; + break; + } + + case BASE64: { + size_t dlen = base64_encoded_size(buflen); + char* dst = new char[dlen]; + + size_t written = base64_encode(buf, buflen, dst, dlen); + assert(written == dlen); + + val = New(dst, dlen).ToLocalChecked(); + delete[] dst; + break; + } + + case UCS2: { + const uint16_t* data = reinterpret_cast(buf); + val = New(data, buflen / 2).ToLocalChecked(); + break; + } + + case HEX: { + size_t dlen = buflen * 2; + char* dst = new char[dlen]; + size_t written = hex_encode(buf, buflen, dst, dlen); + assert(written == dlen); + + val = New(dst, dlen).ToLocalChecked(); + delete[] dst; + break; + } + + default: + assert(0 && "unknown encoding"); + break; + } + + return val; +} + +#undef base64_encoded_size + +} // end of namespace imp + +#endif // NAN_STRING_BYTES_H_ diff --git a/node/node_modules/nan/nan_typedarray_contents.h b/node/node_modules/nan/nan_typedarray_contents.h new file mode 100644 index 0000000..b715961 --- /dev/null +++ b/node/node_modules/nan/nan_typedarray_contents.h @@ -0,0 +1,87 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_TYPEDARRAY_CONTENTS_H_ +#define NAN_TYPEDARRAY_CONTENTS_H_ + +template +class TypedArrayContents { + public: + inline explicit TypedArrayContents(v8::Local from) : + length_(0), data_(NULL) { + + size_t length = 0; + void* data = NULL; + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + + if (from->IsArrayBufferView()) { + v8::Local array = + v8::Local::Cast(from); + + const size_t byte_length = array->ByteLength(); + const ptrdiff_t byte_offset = array->ByteOffset(); + v8::Local buffer = array->Buffer(); + + length = byte_length / sizeof(T); + data = static_cast(buffer->GetContents().Data()) + byte_offset; + } + +#else + + if (from->IsObject() && !from->IsNull()) { + v8::Local array = v8::Local::Cast(from); + + MaybeLocal buffer = Get(array, + New("buffer").ToLocalChecked()); + MaybeLocal byte_length = Get(array, + New("byteLength").ToLocalChecked()); + MaybeLocal byte_offset = Get(array, + New("byteOffset").ToLocalChecked()); + + if (!buffer.IsEmpty() && + !byte_length.IsEmpty() && byte_length.ToLocalChecked()->IsUint32() && + !byte_offset.IsEmpty() && byte_offset.ToLocalChecked()->IsUint32()) { + data = array->GetIndexedPropertiesExternalArrayData(); + if(data) { + length = byte_length.ToLocalChecked()->Uint32Value() / sizeof(T); + } + } + } + +#endif + +#if defined(_MSC_VER) && _MSC_VER >= 1900 || __cplusplus >= 201103L + assert(reinterpret_cast(data) % alignof (T) == 0); +#elif defined(_MSC_VER) && _MSC_VER >= 1600 || defined(__GNUC__) + assert(reinterpret_cast(data) % __alignof(T) == 0); +#else + assert(reinterpret_cast(data) % sizeof (T) == 0); +#endif + + length_ = length; + data_ = static_cast(data); + } + + inline size_t length() const { return length_; } + inline T* operator*() { return data_; } + inline const T* operator*() const { return data_; } + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(TypedArrayContents) + + //Disable heap allocation + void *operator new(size_t size); + void operator delete(void *, size_t); + + size_t length_; + T* data_; +}; + +#endif // NAN_TYPEDARRAY_CONTENTS_H_ diff --git a/node/node_modules/nan/nan_weak.h b/node/node_modules/nan/nan_weak.h new file mode 100644 index 0000000..93f6fe8 --- /dev/null +++ b/node/node_modules/nan/nan_weak.h @@ -0,0 +1,432 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_WEAK_H_ +#define NAN_WEAK_H_ + +static const int kInternalFieldsInWeakCallback = 2; +static const int kNoInternalFieldIndex = -1; + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +# define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ + v8::WeakCallbackInfo > const& +# define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +# define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +# define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#elif NODE_MODULE_VERSION > IOJS_1_1_MODULE_VERSION +# define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ + v8::PhantomCallbackData > const& +# define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +# define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +# define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION +# define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ + v8::PhantomCallbackData > const& +# define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ + v8::InternalFieldsCallbackData, void> const& +# define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +# define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +# define NAN_WEAK_CALLBACK_DATA_TYPE_ \ + v8::WeakCallbackData > const& +# define NAN_WEAK_CALLBACK_SIG_ NAN_WEAK_CALLBACK_DATA_TYPE_ +#else +# define NAN_WEAK_CALLBACK_DATA_TYPE_ void * +# define NAN_WEAK_CALLBACK_SIG_ \ + v8::Persistent, NAN_WEAK_CALLBACK_DATA_TYPE_ +#endif + +template +class WeakCallbackInfo { + public: + typedef void (*Callback)(const WeakCallbackInfo& data); + WeakCallbackInfo( + Persistent *persistent + , Callback callback + , void *parameter + , void *field1 = 0 + , void *field2 = 0) : + callback_(callback), isolate_(0), parameter_(parameter) { + std::memcpy(&persistent_, persistent, sizeof (v8::Persistent)); + internal_fields_[0] = field1; + internal_fields_[1] = field2; + } + inline v8::Isolate *GetIsolate() const { return isolate_; } + inline T *GetParameter() const { return static_cast(parameter_); } + inline void *GetInternalField(int index) const { + assert((index == 0 || index == 1) && "internal field index out of bounds"); + if (index == 0) { + return internal_fields_[0]; + } else { + return internal_fields_[1]; + } + } + + private: + NAN_DISALLOW_ASSIGN_COPY_MOVE(WeakCallbackInfo) + Callback callback_; + v8::Isolate *isolate_; + void *parameter_; + void *internal_fields_[kInternalFieldsInWeakCallback]; + v8::Persistent persistent_; + template friend class Persistent; + template friend class PersistentBase; +#if NODE_MODULE_VERSION <= NODE_0_12_MODULE_VERSION +# if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + template + static void invoke(NAN_WEAK_CALLBACK_SIG_ data); + template + static WeakCallbackInfo *unwrap(NAN_WEAK_CALLBACK_DATA_TYPE_ data); +# else + static void invoke(NAN_WEAK_CALLBACK_SIG_ data); + static WeakCallbackInfo *unwrap(NAN_WEAK_CALLBACK_DATA_TYPE_ data); +# endif +#else +# if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + template + static void invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data); + template + static void invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data); +# else + static void invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data); + static void invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data); +# endif + static WeakCallbackInfo *unwrapparameter( + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data); + static WeakCallbackInfo *unwraptwofield( + NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data); +#endif +}; + + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + +template +template +void +WeakCallbackInfo::invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { + WeakCallbackInfo *cbinfo = unwrapparameter(data); + if (isFirstPass) { + cbinfo->persistent_.Reset(); + data.SetSecondPassCallback(invokeparameter); + } else { + cbinfo->callback_(*cbinfo); + delete cbinfo; + } +} + +template +template +void +WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { + WeakCallbackInfo *cbinfo = unwraptwofield(data); + if (isFirstPass) { + cbinfo->persistent_.Reset(); + data.SetSecondPassCallback(invoketwofield); + } else { + cbinfo->callback_(*cbinfo); + delete cbinfo; + } +} + +template +WeakCallbackInfo *WeakCallbackInfo::unwrapparameter( + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data) { + WeakCallbackInfo *cbinfo = + static_cast*>(data.GetParameter()); + cbinfo->isolate_ = data.GetIsolate(); + return cbinfo; +} + +template +WeakCallbackInfo *WeakCallbackInfo::unwraptwofield( + NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data) { + WeakCallbackInfo *cbinfo = + static_cast*>(data.GetInternalField(0)); + cbinfo->isolate_ = data.GetIsolate(); + return cbinfo; +} + +#undef NAN_WEAK_PARAMETER_CALLBACK_SIG_ +#undef NAN_WEAK_TWOFIELD_CALLBACK_SIG_ +#undef NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#undef NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +# elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION + +template +void +WeakCallbackInfo::invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { + WeakCallbackInfo *cbinfo = unwrapparameter(data); + cbinfo->persistent_.Reset(); + cbinfo->callback_(*cbinfo); + delete cbinfo; +} + +template +void +WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { + WeakCallbackInfo *cbinfo = unwraptwofield(data); + cbinfo->persistent_.Reset(); + cbinfo->callback_(*cbinfo); + delete cbinfo; +} + +template +WeakCallbackInfo *WeakCallbackInfo::unwrapparameter( + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data) { + WeakCallbackInfo *cbinfo = + static_cast*>(data.GetParameter()); + cbinfo->isolate_ = data.GetIsolate(); + return cbinfo; +} + +template +WeakCallbackInfo *WeakCallbackInfo::unwraptwofield( + NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data) { + WeakCallbackInfo *cbinfo = + static_cast*>(data.GetInternalField1()); + cbinfo->isolate_ = data.GetIsolate(); + return cbinfo; +} + +#undef NAN_WEAK_PARAMETER_CALLBACK_SIG_ +#undef NAN_WEAK_TWOFIELD_CALLBACK_SIG_ +#undef NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#undef NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + +template +template +void WeakCallbackInfo::invoke(NAN_WEAK_CALLBACK_SIG_ data) { + WeakCallbackInfo *cbinfo = unwrap(data); + cbinfo->persistent_.Reset(); + cbinfo->callback_(*cbinfo); + delete cbinfo; +} + +template +template +WeakCallbackInfo *WeakCallbackInfo::unwrap( + NAN_WEAK_CALLBACK_DATA_TYPE_ data) { + void *parameter = data.GetParameter(); + WeakCallbackInfo *cbinfo = + static_cast*>(parameter); + cbinfo->isolate_ = data.GetIsolate(); + return cbinfo; +} + +#undef NAN_WEAK_CALLBACK_SIG_ +#undef NAN_WEAK_CALLBACK_DATA_TYPE_ +#else + +template +void WeakCallbackInfo::invoke(NAN_WEAK_CALLBACK_SIG_ data) { + WeakCallbackInfo *cbinfo = unwrap(data); + cbinfo->persistent_.Dispose(); + cbinfo->persistent_.Clear(); + cbinfo->callback_(*cbinfo); + delete cbinfo; +} + +template +WeakCallbackInfo *WeakCallbackInfo::unwrap( + NAN_WEAK_CALLBACK_DATA_TYPE_ data) { + WeakCallbackInfo *cbinfo = + static_cast*>(data); + cbinfo->isolate_ = v8::Isolate::GetCurrent(); + return cbinfo; +} + +#undef NAN_WEAK_CALLBACK_SIG_ +#undef NAN_WEAK_CALLBACK_DATA_TYPE_ +#endif + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +template +template +inline void Persistent::SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + WeakCallbackInfo

*wcbd; + if (type == WeakCallbackType::kParameter) { + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , parameter); + v8::PersistentBase::SetWeak( + wcbd + , WeakCallbackInfo

::template invokeparameter + , type); + } else { + v8::Local* self = reinterpret_cast*>(this); + assert((*self)->IsObject()); + int count = (*self)->InternalFieldCount(); + void *internal_fields[kInternalFieldsInWeakCallback] = {0, 0}; + for (int i = 0; i < count && i < kInternalFieldsInWeakCallback; i++) { + internal_fields[i] = (*self)->GetAlignedPointerFromInternalField(i); + } + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , 0 + , internal_fields[0] + , internal_fields[1]); + (*self)->SetAlignedPointerInInternalField(0, wcbd); + v8::PersistentBase::SetWeak( + static_cast*>(0) + , WeakCallbackInfo

::template invoketwofield + , type); + } +} +#elif NODE_MODULE_VERSION > IOJS_1_1_MODULE_VERSION +template +template +inline void Persistent::SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + WeakCallbackInfo

*wcbd; + if (type == WeakCallbackType::kParameter) { + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , parameter); + v8::PersistentBase::SetPhantom( + wcbd + , WeakCallbackInfo

::invokeparameter); + } else { + v8::Local* self = reinterpret_cast*>(this); + assert((*self)->IsObject()); + int count = (*self)->InternalFieldCount(); + void *internal_fields[kInternalFieldsInWeakCallback] = {0, 0}; + for (int i = 0; i < count && i < kInternalFieldsInWeakCallback; i++) { + internal_fields[i] = (*self)->GetAlignedPointerFromInternalField(i); + } + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , 0 + , internal_fields[0] + , internal_fields[1]); + (*self)->SetAlignedPointerInInternalField(0, wcbd); + v8::PersistentBase::SetPhantom( + static_cast*>(0) + , WeakCallbackInfo

::invoketwofield + , 0 + , count > 1 ? 1 : kNoInternalFieldIndex); + } +} +#elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION +template +template +inline void Persistent::SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + WeakCallbackInfo

*wcbd; + if (type == WeakCallbackType::kParameter) { + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , parameter); + v8::PersistentBase::SetPhantom( + wcbd + , WeakCallbackInfo

::invokeparameter); + } else { + v8::Local* self = reinterpret_cast*>(this); + assert((*self)->IsObject()); + int count = (*self)->InternalFieldCount(); + void *internal_fields[kInternalFieldsInWeakCallback] = {0, 0}; + for (int i = 0; i < count && i < kInternalFieldsInWeakCallback; i++) { + internal_fields[i] = (*self)->GetAlignedPointerFromInternalField(i); + } + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , 0 + , internal_fields[0] + , internal_fields[1]); + (*self)->SetAlignedPointerInInternalField(0, wcbd); + v8::PersistentBase::SetPhantom( + WeakCallbackInfo

::invoketwofield + , 0 + , count > 1 ? 1 : kNoInternalFieldIndex); + } +} +#elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +template +template +inline void Persistent::SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + WeakCallbackInfo

*wcbd; + if (type == WeakCallbackType::kParameter) { + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , parameter); + v8::PersistentBase::SetWeak(wcbd, WeakCallbackInfo

::invoke); + } else { + v8::Local* self = reinterpret_cast*>(this); + assert((*self)->IsObject()); + int count = (*self)->InternalFieldCount(); + void *internal_fields[kInternalFieldsInWeakCallback] = {0, 0}; + for (int i = 0; i < count && i < kInternalFieldsInWeakCallback; i++) { + internal_fields[i] = (*self)->GetAlignedPointerFromInternalField(i); + } + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , 0 + , internal_fields[0] + , internal_fields[1]); + v8::PersistentBase::SetWeak(wcbd, WeakCallbackInfo

::invoke); + } +} +#else +template +template +inline void PersistentBase::SetWeak( + P *parameter + , typename WeakCallbackInfo

::Callback callback + , WeakCallbackType type) { + WeakCallbackInfo

*wcbd; + if (type == WeakCallbackType::kParameter) { + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , parameter); + persistent.MakeWeak(wcbd, WeakCallbackInfo

::invoke); + } else { + v8::Local* self = reinterpret_cast*>(this); + assert((*self)->IsObject()); + int count = (*self)->InternalFieldCount(); + void *internal_fields[kInternalFieldsInWeakCallback] = {0, 0}; + for (int i = 0; i < count && i < kInternalFieldsInWeakCallback; i++) { + internal_fields[i] = (*self)->GetPointerFromInternalField(i); + } + wcbd = new WeakCallbackInfo

( + reinterpret_cast*>(this) + , callback + , 0 + , internal_fields[0] + , internal_fields[1]); + persistent.MakeWeak(wcbd, WeakCallbackInfo

::invoke); + } +} +#endif + +#endif // NAN_WEAK_H_ diff --git a/node/node_modules/nan/package.json b/node/node_modules/nan/package.json new file mode 100644 index 0000000..eafd669 --- /dev/null +++ b/node/node_modules/nan/package.json @@ -0,0 +1,91 @@ +{ + "_from": "nan@2.4", + "_id": "nan@2.4.0", + "_inBundle": false, + "_integrity": "sha1-+zxZ1F/k7/4hXwuJD4rfbrMtIjI=", + "_location": "/nan", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "nan@2.4", + "name": "nan", + "escapedName": "nan", + "rawSpec": "2.4", + "saveSpec": null, + "fetchSpec": "2.4" + }, + "_requiredBy": [ + "/nanomsg" + ], + "_resolved": "https://registry.npmjs.org/nan/-/nan-2.4.0.tgz", + "_shasum": "fb3c59d45fe4effe215f0b890f8adf6eb32d2232", + "_spec": "nan@2.4", + "_where": "/Users/hwwu/Git/ats-sessions/node/node_modules/nanomsg", + "bugs": { + "url": "https://github.com/nodejs/nan/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Rod Vagg", + "email": "r@va.gg", + "url": "https://github.com/rvagg" + }, + { + "name": "Benjamin Byholm", + "email": "bbyholm@abo.fi", + "url": "https://github.com/kkoopa/" + }, + { + "name": "Trevor Norris", + "email": "trev.norris@gmail.com", + "url": "https://github.com/trevnorris" + }, + { + "name": "Nathan Rajlich", + "email": "nathan@tootallnate.net", + "url": "https://github.com/TooTallNate" + }, + { + "name": "Brett Lawson", + "email": "brett19@gmail.com", + "url": "https://github.com/brett19" + }, + { + "name": "Ben Noordhuis", + "email": "info@bnoordhuis.nl", + "url": "https://github.com/bnoordhuis" + }, + { + "name": "David Siegel", + "email": "david@artcom.de", + "url": "https://github.com/agnat" + } + ], + "deprecated": false, + "description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 6 compatibility", + "devDependencies": { + "bindings": "~1.2.1", + "commander": "^2.8.1", + "glob": "^5.0.14", + "node-gyp": "~3.0.1", + "readable-stream": "^2.1.4", + "tap": "~0.7.1", + "xtend": "~4.0.0" + }, + "homepage": "https://github.com/nodejs/nan#readme", + "license": "MIT", + "main": "include_dirs.js", + "name": "nan", + "repository": { + "type": "git", + "url": "git://github.com/nodejs/nan.git" + }, + "scripts": { + "docs": "doc/.build.sh", + "rebuild-tests": "node-gyp rebuild --msvs_version=2013 --directory test", + "test": "tap --gc --stderr test/js/*-test.js" + }, + "version": "2.4.0" +} diff --git a/node/node_modules/nan/tools/1to2.js b/node/node_modules/nan/tools/1to2.js new file mode 100755 index 0000000..b7498e4 --- /dev/null +++ b/node/node_modules/nan/tools/1to2.js @@ -0,0 +1,412 @@ +#!/usr/bin/env node +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2016 NAN contributors + * + * MIT License + ********************************************************************/ + +var commander = require('commander'), + fs = require('fs'), + glob = require('glob'), + groups = [], + total = 0, + warning1 = '/* ERROR: Rewrite using Buffer */\n', + warning2 = '\\/\\* ERROR\\: Rewrite using Buffer \\*\\/\\n', + length, + i; + +fs.readFile(__dirname + '/package.json', 'utf8', function (err, data) { + if (err) { + throw err; + } + + commander + .version(JSON.parse(data).version) + .usage('[options] ') + .parse(process.argv); + + if (!process.argv.slice(2).length) { + commander.outputHelp(); + } +}); + +/* construct strings representing regular expressions + each expression contains a unique group allowing for identification of the match + the index of this key group, relative to the regular expression in question, + is indicated by the first array member */ + +/* simple substistutions, key group is the entire match, 0 */ +groups.push([0, [ + '_NAN_', + 'NODE_SET_METHOD', + 'NODE_SET_PROTOTYPE_METHOD', + 'NanAsciiString', + 'NanEscapeScope', + 'NanReturnValue', + 'NanUcs2String'].join('|')]); + +/* substitutions of parameterless macros, key group is 1 */ +groups.push([1, ['(', [ + 'NanEscapableScope', + 'NanReturnNull', + 'NanReturnUndefined', + 'NanScope'].join('|'), ')\\(\\)'].join('')]); + +/* replace TryCatch with NanTryCatch once, gobbling possible namespace, key group 2 */ +groups.push([2, '(?:(?:v8\\:\\:)?|(Nan)?)(TryCatch)']); + +/* NanNew("string") will likely not fail a ToLocalChecked(), key group 1 */ +groups.push([1, ['(NanNew)', '(\\("[^\\"]*"[^\\)]*\\))(?!\\.ToLocalChecked\\(\\))'].join('')]); + +/* Removed v8 APIs, warn that the code needs rewriting using node::Buffer, key group 2 */ +groups.push([2, ['(', warning2, ')?', '^.*?(', [ + 'GetIndexedPropertiesExternalArrayDataLength', + 'GetIndexedPropertiesExternalArrayData', + 'GetIndexedPropertiesExternalArrayDataType', + 'GetIndexedPropertiesPixelData', + 'GetIndexedPropertiesPixelDataLength', + 'HasIndexedPropertiesInExternalArrayData', + 'HasIndexedPropertiesInPixelData', + 'SetIndexedPropertiesToExternalArrayData', + 'SetIndexedPropertiesToPixelData'].join('|'), ')'].join('')]); + +/* No need for NanScope in V8-exposed methods, key group 2 */ +groups.push([2, ['((', [ + 'NAN_METHOD', + 'NAN_GETTER', + 'NAN_SETTER', + 'NAN_PROPERTY_GETTER', + 'NAN_PROPERTY_SETTER', + 'NAN_PROPERTY_ENUMERATOR', + 'NAN_PROPERTY_DELETER', + 'NAN_PROPERTY_QUERY', + 'NAN_INDEX_GETTER', + 'NAN_INDEX_SETTER', + 'NAN_INDEX_ENUMERATOR', + 'NAN_INDEX_DELETER', + 'NAN_INDEX_QUERY'].join('|'), ')\\([^\\)]*\\)\\s*\\{)\\s*NanScope\\(\\)\\s*;'].join('')]); + +/* v8::Value::ToXXXXXXX returns v8::MaybeLocal, key group 3 */ +groups.push([3, ['([\\s\\(\\)])([^\\s\\(\\)]+)->(', [ + 'Boolean', + 'Number', + 'String', + 'Object', + 'Integer', + 'Uint32', + 'Int32'].join('|'), ')\\('].join('')]); + +/* v8::Value::XXXXXXXValue returns v8::Maybe, key group 3 */ +groups.push([3, ['([\\s\\(\\)])([^\\s\\(\\)]+)->((?:', [ + 'Boolean', + 'Number', + 'Integer', + 'Uint32', + 'Int32'].join('|'), ')Value)\\('].join('')]); + +/* NAN_WEAK_CALLBACK macro was removed, write out callback definition, key group 1 */ +groups.push([1, '(NAN_WEAK_CALLBACK)\\(([^\\s\\)]+)\\)']); + +/* node::ObjectWrap and v8::Persistent have been replaced with Nan implementations, key group 1 */ +groups.push([1, ['(', [ + 'NanDisposePersistent', + 'NanObjectWrapHandle'].join('|'), ')\\s*\\(\\s*([^\\s\\)]+)'].join('')]); + +/* Since NanPersistent there is no need for NanMakeWeakPersistent, key group 1 */ +groups.push([1, '(NanMakeWeakPersistent)\\s*\\(\\s*([^\\s,]+)\\s*,\\s*']); + +/* Many methods of v8::Object and others now return v8::MaybeLocal, key group 3 */ +groups.push([3, ['([\\s])([^\\s]+)->(', [ + 'GetEndColumn', + 'GetFunction', + 'GetLineNumber', + 'NewInstance', + 'GetPropertyNames', + 'GetOwnPropertyNames', + 'GetSourceLine', + 'GetStartColumn', + 'ObjectProtoToString', + 'ToArrayIndex', + 'ToDetailString', + 'CallAsConstructor', + 'CallAsFunction', + 'CloneElementAt', + 'Delete', + 'ForceSet', + 'Get', + 'GetPropertyAttributes', + 'GetRealNamedProperty', + 'GetRealNamedPropertyInPrototypeChain', + 'Has', + 'HasOwnProperty', + 'HasRealIndexedProperty', + 'HasRealNamedCallbackProperty', + 'HasRealNamedProperty', + 'Set', + 'SetAccessor', + 'SetIndexedPropertyHandler', + 'SetNamedPropertyHandler', + 'SetPrototype'].join('|'), ')\\('].join('')]); + +/* You should get an error if any of these fail anyways, + or handle the error better, it is indicated either way, key group 2 */ +groups.push([2, ['NanNew(<(?:v8\\:\\:)?(', ['Date', 'String', 'RegExp'].join('|'), ')>)(\\([^\\)]*\\))(?!\\.ToLocalChecked\\(\\))'].join('')]); + +/* v8::Value::Equals now returns a v8::Maybe, key group 3 */ +groups.push([3, '([\\s\\(\\)])([^\\s\\(\\)]+)->(Equals)\\(([^\\s\\)]+)']); + +/* NanPersistent makes this unnecessary, key group 1 */ +groups.push([1, '(NanAssignPersistent)(?:]+>)?\\(([^,]+),\\s*']); + +/* args has been renamed to info, key group 2 */ +groups.push([2, '(\\W)(args)(\\W)']) + +/* node::ObjectWrap was replaced with NanObjectWrap, key group 2 */ +groups.push([2, '(\\W)(?:node\\:\\:)?(ObjectWrap)(\\W)']); + +/* v8::Persistent was replaced with NanPersistent, key group 2 */ +groups.push([2, '(\\W)(?:v8\\:\\:)?(Persistent)(\\W)']); + +/* counts the number of capturing groups in a well-formed regular expression, + ignoring non-capturing groups and escaped parentheses */ +function groupcount(s) { + var positive = s.match(/\((?!\?)/g), + negative = s.match(/\\\(/g); + return (positive ? positive.length : 0) - (negative ? negative.length : 0); +} + +/* compute the absolute position of each key group in the joined master RegExp */ +for (i = 1, length = groups.length; i < length; i++) { + total += groupcount(groups[i - 1][1]); + groups[i][0] += total; +} + +/* create the master RegExp, whis is the union of all the groups' expressions */ +master = new RegExp(groups.map(function (a) { return a[1]; }).join('|'), 'gm'); + +/* replacement function for String.replace, receives 21 arguments */ +function replace() { + /* simple expressions */ + switch (arguments[groups[0][0]]) { + case '_NAN_': + return 'NAN_'; + case 'NODE_SET_METHOD': + return 'NanSetMethod'; + case 'NODE_SET_PROTOTYPE_METHOD': + return 'NanSetPrototypeMethod'; + case 'NanAsciiString': + return 'NanUtf8String'; + case 'NanEscapeScope': + return 'scope.Escape'; + case 'NanReturnNull': + return 'info.GetReturnValue().SetNull'; + case 'NanReturnValue': + return 'info.GetReturnValue().Set'; + case 'NanUcs2String': + return 'v8::String::Value'; + default: + } + + /* macros without arguments */ + switch (arguments[groups[1][0]]) { + case 'NanEscapableScope': + return 'NanEscapableScope scope' + case 'NanReturnUndefined': + return 'return'; + case 'NanScope': + return 'NanScope scope'; + default: + } + + /* TryCatch, emulate negative backref */ + if (arguments[groups[2][0]] === 'TryCatch') { + return arguments[groups[2][0] - 1] ? arguments[0] : 'NanTryCatch'; + } + + /* NanNew("foo") --> NanNew("foo").ToLocalChecked() */ + if (arguments[groups[3][0]] === 'NanNew') { + return [arguments[0], '.ToLocalChecked()'].join(''); + } + + /* insert warning for removed functions as comment on new line above */ + switch (arguments[groups[4][0]]) { + case 'GetIndexedPropertiesExternalArrayData': + case 'GetIndexedPropertiesExternalArrayDataLength': + case 'GetIndexedPropertiesExternalArrayDataType': + case 'GetIndexedPropertiesPixelData': + case 'GetIndexedPropertiesPixelDataLength': + case 'HasIndexedPropertiesInExternalArrayData': + case 'HasIndexedPropertiesInPixelData': + case 'SetIndexedPropertiesToExternalArrayData': + case 'SetIndexedPropertiesToPixelData': + return arguments[groups[4][0] - 1] ? arguments[0] : [warning1, arguments[0]].join(''); + default: + } + + /* remove unnecessary NanScope() */ + switch (arguments[groups[5][0]]) { + case 'NAN_GETTER': + case 'NAN_METHOD': + case 'NAN_SETTER': + case 'NAN_INDEX_DELETER': + case 'NAN_INDEX_ENUMERATOR': + case 'NAN_INDEX_GETTER': + case 'NAN_INDEX_QUERY': + case 'NAN_INDEX_SETTER': + case 'NAN_PROPERTY_DELETER': + case 'NAN_PROPERTY_ENUMERATOR': + case 'NAN_PROPERTY_GETTER': + case 'NAN_PROPERTY_QUERY': + case 'NAN_PROPERTY_SETTER': + return arguments[groups[5][0] - 1]; + default: + } + + /* Value converstion */ + switch (arguments[groups[6][0]]) { + case 'Boolean': + case 'Int32': + case 'Integer': + case 'Number': + case 'Object': + case 'String': + case 'Uint32': + return [arguments[groups[6][0] - 2], 'NanTo(', arguments[groups[6][0] - 1]].join(''); + default: + } + + /* other value conversion */ + switch (arguments[groups[7][0]]) { + case 'BooleanValue': + return [arguments[groups[7][0] - 2], 'NanTo(', arguments[groups[7][0] - 1]].join(''); + case 'Int32Value': + return [arguments[groups[7][0] - 2], 'NanTo(', arguments[groups[7][0] - 1]].join(''); + case 'IntegerValue': + return [arguments[groups[7][0] - 2], 'NanTo(', arguments[groups[7][0] - 1]].join(''); + case 'Uint32Value': + return [arguments[groups[7][0] - 2], 'NanTo(', arguments[groups[7][0] - 1]].join(''); + default: + } + + /* NAN_WEAK_CALLBACK */ + if (arguments[groups[8][0]] === 'NAN_WEAK_CALLBACK') { + return ['template\nvoid ', + arguments[groups[8][0] + 1], '(const NanWeakCallbackInfo &data)'].join(''); + } + + /* use methods on NAN classes instead */ + switch (arguments[groups[9][0]]) { + case 'NanDisposePersistent': + return [arguments[groups[9][0] + 1], '.Reset('].join(''); + case 'NanObjectWrapHandle': + return [arguments[groups[9][0] + 1], '->handle('].join(''); + default: + } + + /* use method on NanPersistent instead */ + if (arguments[groups[10][0]] === 'NanMakeWeakPersistent') { + return arguments[groups[10][0] + 1] + '.SetWeak('; + } + + /* These return Maybes, the upper ones take no arguments */ + switch (arguments[groups[11][0]]) { + case 'GetEndColumn': + case 'GetFunction': + case 'GetLineNumber': + case 'GetOwnPropertyNames': + case 'GetPropertyNames': + case 'GetSourceLine': + case 'GetStartColumn': + case 'NewInstance': + case 'ObjectProtoToString': + case 'ToArrayIndex': + case 'ToDetailString': + return [arguments[groups[11][0] - 2], 'Nan', arguments[groups[11][0]], '(', arguments[groups[11][0] - 1]].join(''); + case 'CallAsConstructor': + case 'CallAsFunction': + case 'CloneElementAt': + case 'Delete': + case 'ForceSet': + case 'Get': + case 'GetPropertyAttributes': + case 'GetRealNamedProperty': + case 'GetRealNamedPropertyInPrototypeChain': + case 'Has': + case 'HasOwnProperty': + case 'HasRealIndexedProperty': + case 'HasRealNamedCallbackProperty': + case 'HasRealNamedProperty': + case 'Set': + case 'SetAccessor': + case 'SetIndexedPropertyHandler': + case 'SetNamedPropertyHandler': + case 'SetPrototype': + return [arguments[groups[11][0] - 2], 'Nan', arguments[groups[11][0]], '(', arguments[groups[11][0] - 1], ', '].join(''); + default: + } + + /* Automatic ToLocalChecked(), take it or leave it */ + switch (arguments[groups[12][0]]) { + case 'Date': + case 'String': + case 'RegExp': + return ['NanNew', arguments[groups[12][0] - 1], arguments[groups[12][0] + 1], '.ToLocalChecked()'].join(''); + default: + } + + /* NanEquals is now required for uniformity */ + if (arguments[groups[13][0]] === 'Equals') { + return [arguments[groups[13][0] - 1], 'NanEquals(', arguments[groups[13][0] - 1], ', ', arguments[groups[13][0] + 1]].join(''); + } + + /* use method on replacement class instead */ + if (arguments[groups[14][0]] === 'NanAssignPersistent') { + return [arguments[groups[14][0] + 1], '.Reset('].join(''); + } + + /* args --> info */ + if (arguments[groups[15][0]] === 'args') { + return [arguments[groups[15][0] - 1], 'info', arguments[groups[15][0] + 1]].join(''); + } + + /* ObjectWrap --> NanObjectWrap */ + if (arguments[groups[16][0]] === 'ObjectWrap') { + return [arguments[groups[16][0] - 1], 'NanObjectWrap', arguments[groups[16][0] + 1]].join(''); + } + + /* Persistent --> NanPersistent */ + if (arguments[groups[17][0]] === 'Persistent') { + return [arguments[groups[17][0] - 1], 'NanPersistent', arguments[groups[17][0] + 1]].join(''); + } + + /* This should not happen. A switch is probably missing a case if it does. */ + throw 'Unhandled match: ' + arguments[0]; +} + +/* reads a file, runs replacement and writes it back */ +function processFile(file) { + fs.readFile(file, {encoding: 'utf8'}, function (err, data) { + if (err) { + throw err; + } + + /* run replacement twice, might need more runs */ + fs.writeFile(file, data.replace(master, replace).replace(master, replace), function (err) { + if (err) { + throw err; + } + }); + }); +} + +/* process file names from command line and process the identified files */ +for (i = 2, length = process.argv.length; i < length; i++) { + glob(process.argv[i], function (err, matches) { + if (err) { + throw err; + } + matches.forEach(processFile); + }); +} diff --git a/node/node_modules/nan/tools/README.md b/node/node_modules/nan/tools/README.md new file mode 100644 index 0000000..7f07e4b --- /dev/null +++ b/node/node_modules/nan/tools/README.md @@ -0,0 +1,14 @@ +1to2 naively converts source code files from NAN 1 to NAN 2. There will be erroneous conversions, +false positives and missed opportunities. The input files are rewritten in place. Make sure that +you have backups. You will have to manually review the changes afterwards and do some touchups. + +```sh +$ tools/1to2.js + + Usage: 1to2 [options] + + Options: + + -h, --help output usage information + -V, --version output the version number +``` diff --git a/node/node_modules/nan/tools/package.json b/node/node_modules/nan/tools/package.json new file mode 100644 index 0000000..2dcdd78 --- /dev/null +++ b/node/node_modules/nan/tools/package.json @@ -0,0 +1,19 @@ +{ + "name": "1to2", + "version": "1.0.0", + "description": "NAN 1 -> 2 Migration Script", + "main": "1to2.js", + "repository": { + "type": "git", + "url": "git://github.com/nodejs/nan.git" + }, + "contributors": [ + "Benjamin Byholm (https://github.com/kkoopa/)", + "Mathias Küsel (https://github.com/mathiask88/)" + ], + "dependencies": { + "glob": "~5.0.10", + "commander": "~2.8.1" + }, + "license": "MIT" +} diff --git a/node/node_modules/nanomsg/.esformatter b/node/node_modules/nanomsg/.esformatter new file mode 100644 index 0000000..14c3bf3 --- /dev/null +++ b/node/node_modules/nanomsg/.esformatter @@ -0,0 +1,18 @@ +{ + "preset": "default", + "indent": { + "value": " " + }, + "whiteSpace": { + "before": { + "ArgumentListFunctionExpression": 1 + }, + "after": { + "FunctionReservedWord": 1, + "FunctionName": 1 + } + } +} + + + diff --git a/node/node_modules/nanomsg/.gitmodules b/node/node_modules/nanomsg/.gitmodules new file mode 100644 index 0000000..8396558 --- /dev/null +++ b/node/node_modules/nanomsg/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/nanomsg"] + path = deps/nanomsg + url = https://github.com/nanomsg/nanomsg.git diff --git a/node/node_modules/nanomsg/.npmignore b/node/node_modules/nanomsg/.npmignore new file mode 100644 index 0000000..9cb1f73 --- /dev/null +++ b/node/node_modules/nanomsg/.npmignore @@ -0,0 +1,16 @@ +node_modules +build +*.log +*.o +*.lo +.deps +.dirstamp +*.status +doltcompile +doltlibtool +*.la +*.pc +libtool +nanocat +.libs +v8 diff --git a/node/node_modules/nanomsg/.travis.yml b/node/node_modules/nanomsg/.travis.yml new file mode 100644 index 0000000..ae2e526 --- /dev/null +++ b/node/node_modules/nanomsg/.travis.yml @@ -0,0 +1,26 @@ +sudo: false +language: c +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 +branches: + only: + - master +env: + - NODE_V="0.10" + - NODE_V="0.12" + - NODE_V="4" + - NODE_V="5" + - NODE_V="6" +before_install: + - rm -rf ~/.nvm ~/.npm && git clone https://github.com/creationix/nvm.git ~/.nvm + - source ~/.nvm/nvm.sh && nvm install $NODE_V + - if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CC=gcc-4.8 && export CXX=g++-4.8; fi +install: + - make +script: + - make check diff --git a/node/node_modules/nanomsg/LICENSE b/node/node_modules/nanomsg/LICENSE new file mode 100644 index 0000000..03b2154 --- /dev/null +++ b/node/node_modules/nanomsg/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2014-2015, node-nanomsg contributors (see README). All +rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/node/node_modules/nanomsg/Makefile b/node/node_modules/nanomsg/Makefile new file mode 100644 index 0000000..fa11dfe --- /dev/null +++ b/node/node_modules/nanomsg/Makefile @@ -0,0 +1,31 @@ +.PHONY: clean check test perf bench full + +ALL: + git submodule update --init + npm i + +use_system_libnanomsg: + npm i --use_system_libnanomsg=true + +check: + rm -f some_address /tmp/*.ipc + find test/*.js test/standalone/*.js | xargs -n 1 node | node_modules/tap-difflet/bin/tap-difflet + rm -f some_address /tmp/*.ipc + +test: + find test/*.js test/standalone/*.js | xargs -n 1 node | node_modules/tap-nyan/bin/cmd.js + +clean: + rm -fr build && rm -rf node_modules + +perf: + node perf/local_lat.js tcp://127.0.0.1:5555 1 100000& node perf/remote_lat.js tcp://127.0.0.1:5555 1 100000 && wait + node perf/local_thr.js tcp://127.0.0.1:5556 1 100000& node perf/remote_thr.js tcp://127.0.0.1:5556 1 100000 && wait + +bench: + node perf/local_lat.js tcp://127.0.0.1:5555 10 10000& node perf/remote_lat.js tcp://127.0.0.1:5555 10 10000 && wait + node perf/local_thr.js tcp://127.0.0.1:5556 10 100000& node perf/remote_thr.js tcp://127.0.0.1:5556 10 100000 && wait + +full: clean ALL test + +use_system_libnanomsg-full: clean use_system_libnanomsg test diff --git a/node/node_modules/nanomsg/README.md b/node/node_modules/nanomsg/README.md new file mode 100644 index 0000000..d7612d9 --- /dev/null +++ b/node/node_modules/nanomsg/README.md @@ -0,0 +1,445 @@ +# nanomsg for node + +[![Build Status](https://travis-ci.org/nickdesaulniers/node-nanomsg.svg?branch=master)](https://travis-ci.org/nickdesaulniers/node-nanomsg) [![Build status](https://ci.appveyor.com/api/projects/status/og7qumak4khcne8u?svg=true)](https://ci.appveyor.com/project/reqshark/node-nanomsg) + +### install: + +``` +npm install nanomsg +``` +This is the default way of installing node-nanomsg. Behind the scenes, nanomsg library will be downloaded, built and statically linked, providing the simplest and easiest way to start working. + +Another option, if you have a more complex environment/project, and you may already have nanomsg installed on your system, or you want to target a specific version when using it from node: +``` +npm install nanomsg --use_system_libnanomsg=true +``` +This has the following prerequisites: +* nanomsg must be installed. See https://github.com/nanomsg/nanomsg +* pkg-config must be installed +* only tested on linux, so other platforms are explicitly excluded at the moment (any help testing other OS is welcome) + +### check it out: + +```js +var nano = require('nanomsg'); + +var pub = nano.socket('pub'); +var sub = nano.socket('sub'); + +var addr = 'tcp://127.0.0.1:7789' +pub.bind(addr); +sub.connect(addr); + +sub.on('data', function (buf) { + console.log(String(buf)); + pub.close(); + sub.close(); +}); + +setTimeout(function () { + pub.send("Hello from nanomsg!"); +}, 100); +``` + +# API + +### nano.socket(type, [options,]) + +Starts a new socket. The nanomsg socket can bind or connect to multiple heterogeneous endpoints as well as shutdown any of these established links. + +#### `options` +* `'raw'` *(Boolean, default: `false`)*: determines the domain of the socket. `AF_SP`, the default, creates a standard full-blown SP socket. `AF_SP_RAW` family sockets operate over internal network protocols and interfaces. Raw sockets omit the end-to-end functionality found in `AF_SP` sockets and thus can be used to implement intermediary devices in SP topologies, see [nanomsg docs](http://nanomsg.org/v0.5/nn_socket.3.html) or consult your man page entry `socket(2)` for more info. +```js +//ex. starting raw sockets +nano.socket('bus', { raw: true } ); +``` +* `'tcpnodelay'` *(Boolean, default: `false`)*: see [`socket.tcpnodelay(boolean)`](https://github.com/nickdesaulniers/node-nanomsg#sockettcpnodelayboolean) +* `'linger'` *(Number, default: `1000`)*: see [`socket.linger(duration)`](https://github.com/nickdesaulniers/node-nanomsg#socketlingerduration) +* `'sndbuf'` *(Number, size in bytes, default: `128kB`)*: see [`socket.sndbuf(size)`](https://github.com/nickdesaulniers/node-nanomsg#socketsndbufsize) +* `'rcvbuf'` *(Number, size in bytes, default: `128kB`)*: see [`socket.rcvbuf(size)`](https://github.com/nickdesaulniers/node-nanomsg#socketrcvbufsize) +* `'sndtimeo'` *(Number, default: `-1`)*: see [`socket.sndtimeo(duration)`](https://github.com/nickdesaulniers/node-nanomsg#socketsndtimeoduration) +* `'rcvtimeo'` *(Number, default: `-1`)*: see [`socket.rcvtimeo(duration)`](https://github.com/nickdesaulniers/node-nanomsg#socketrcvtimeoduration) +* `'reconn'` *(Number, default: `100`)*: see [`socket.reconn(duration)`](https://github.com/nickdesaulniers/node-nanomsg#socketreconnduration) +* `'maxreconn'` *(Number, default: `0`)*: see [`socket.maxreconn(duration)`](https://github.com/nickdesaulniers/node-nanomsg#socketmaxreconnduration) +* `'sndprio'` *(Number, default: `0`)*: see [`socket.sndprio(priority)`](https://github.com/nickdesaulniers/node-nanomsg#socketsndpriopriority) +* `'rcvprio'` *(Number, default: `0`)*: see [`socket.rcvprio(priority)`](https://github.com/nickdesaulniers/node-nanomsg#socketrcvpriopriority) +* `'ipv6'` *(Boolean, default: `false`)*: see [`socket.ipv6(boolean)`](https://github.com/nickdesaulniers/node-nanomsg#socketipv6boolean) +* `'rcvmaxsize'` *(Number, default: `false`)*: see [`socket.rcvmaxsize(size)`](https://github.com/nickdesaulniers/node-nanomsg#socketrcvmaxsizesize) +* `'chan'` *(Array, default: `['']`)*: see [`socket.chan(Array)`](https://github.com/nickdesaulniers/node-nanomsg#socketchanarray) +* `'wsopt'` *(String, default: `'binary'`)*: see [`socket.wsopt(str)`](https://github.com/nickdesaulniers/node-nanomsg#socketwsoptstr) +* `'dontwait'` *(boolean, default: `true`)*: see [`socket.dontwait(boolean)`](https://github.com/nickdesaulniers/node-nanomsg#socketdontwaitboolean) + +### socket.shutdown(address) + +*(Function, param: String)*: Removes an endpoint established by calls to `bind()` or `connect()`. The nanomsg library will try to deliver any outstanding outbound messages to the endpoint for the time specified by `linger`. + +```js +socket.shutdown('tcp://127.0.0.1:5555'); +``` + +### socket.bind(address) + +*(Function, param: String)*: Adds a local endpoint to the socket. The endpoint can be then used by other applications to connect. + +`bind()` (or `connect()`) may be called multiple times on the same socket thus allowing the socket to communicate with multiple heterogeneous endpoints. + +```js +socket.bind('tcp://eth0:5555'); +``` + +*recommend checking your machine's `ifconfig` first before using a named interface. `ipconfig` on windows.* + +### socket.connect(address) + +*(Function, param: String)*: Adds a remote endpoint to the socket. The nanomsg library would then try to connect to the specified remote endpoint. + +`connect()` (as well as `bind()`) may be called multiple times on the same socket thus allowing the socket to communicate with multiple heterogeneous endpoints. + +```js +socket.connect('tcp://127.0.0.1:5555'); +``` + +*When connecting over remote TCP allow `100ms` or more depending on round trip time for the operation to complete.* + +### socket.close() + +*(Function, param: Function)*: Closes the socket. Any buffered inbound messages that were not yet received by the application will be discarded. The nanomsg library will try to deliver any outstanding outbound messages for the time specified by `linger`. + +## nanomsg transports and the endpoint address string + +*(String)* + +Endpoint address strings consist of two parts as follows: `transport://address`. The transport specifies the underlying transport protocol to use. The meaning of the address part is specific to the underlying transport protocol. +* *TCP transport mechanism*: `'tcp://127.0.0.1:65000'` When binding a TCP socket, address of the form `tcp://interface:port` should be used. Port is the TCP port number to use. Interface is either: `IPv4` or `IPv6` address of a local network interface, or DNS name of the remote box. +* *WebSocket transport mechanism*: `'ws://127.0.0.1:64999'` Implemented on top of TCP, a WebSocket address of the form `ws://interface:port` should be used. Port is the TCP port number to use. Interface is either: `IPv4` or `IPv6` address of a local network interface, or DNS name of the remote box. When calling either `bind()` or `connect()`, omitting the port defaults to the RFC 6455 default port 80 for HTTP. See [examples/ws](examples/ws) for basic implementation over the browser. +* *in-process transport mechanism*: `'inproc://bar'` The `inproc` transport allows messages between threads or modules inside a process. In-process address is an arbitrary case-sensitive string preceded by `inproc://` protocol specifier. All in-process addresses are visible from any module within the process. They are not visible from outside of the process. The overall buffer size for an inproc connection is determined by `rcvbuf` socket option on the receiving end of the connection. `sndbuf` is ignored. In addition to the buffer, one message of arbitrary size will fit into the buffer. That way, even messages larger than the buffer can be transfered via inproc connection. +* *inter-process transport mechanism*: `'ipc:///tmp/foo.ipc'` The `ipc` transport allows for sending messages between processes within a single box. The nanomsg implementation uses native IPC mechanism provided by the local operating system and the IPC addresses are thus OS-specific. On POSIX-compliant systems, UNIX domain sockets are used and IPC addresses are file references. Note that both relative (`ipc://test.ipc`) and absolute (`ipc:///tmp/test.ipc`) paths may be used. Also note that access rights on the IPC files must be set in such a way that the appropriate applications can actually use them. On Windows, named pipes are used for IPC. The Windows IPC address is an arbitrary case-insensitive string containing any character except for backslash: internally, address `ipc://test` means that named pipe `\\.\pipe\test` will be used. + +## sending and receiving: writable and readable + +### socket.send(msg) +*(Function, param: String or Buffer)*: send a message. + +```js +socket.send('hello from nanømsg!'); +``` + +`send(msg)` is automatically invoked during `Writable` consumption of some other `Readable` stream. In that case a `Writable`'s `pipe()` method can be used to transmit across readable data sources. See [example for more detail](examples/writablepipe.js). The flow of data distributes to endpoint(s) determined by the particular socket type. + +```js +var source = require('fs').createReadStream('filename.ext'); + +source.pipe(socket); //sends each chunk as a msg to socket's particular endpoint +``` + +### socket.on('data', callback) +*(Function, param order: String, Function)*: The `Readable` stream's `on()` function is an event listener that emits `'data'` events. To receive messages, pass the string `'data'` followed a callback containing a single data parameter. + +```js +// the default inbound message is a node buffer +// setEncoding sets the message type, use utf8 to receive strings instead. +socket.setEncoding('utf8'); + +socket.on('data', function (msg) { + console.log(msg); //'hello from nanømsg!' +}); +``` + +The readable stream's `data` event is automatically invoked when piped to a `Writable` or `Transform` consumer stream. See [example for more detail](examples/transforms.js). Here `msgprocessor` is a transform you could pipe to a writable or the next transform: + +```js +var through = require('through'); + +var msgprocessor = through(function(msg){ + var str = msg; //'hello from nanømsg' + this.queue(str + ' and cheers!'); +}); + +socket.pipe(msgprocessor); //msg transformed to: 'hello from nanømsg and cheers!' +``` + +## subscription api + +### socket.chan(Array) + +*(Function, param: Array of Strings, default: `['']`)*: Allows for sub sockets +to filter messages based on a prefix. Not applicable to non sub sockets. + +By default, all sub sockets are subscribed to the `''` channel. Once you opt +in to filtering on a channel, you are unsubscribed from `''`. + +### socket.rmchan(String) + +*(Function, param: String)*: Allows for sub sockets to remove channel filters. +Not applicable to non sub sockets. This function is variadic; you can pass +multiple strings and all will be unfiltered. + +If you unsubscribe from the default channel, `''`, without subscribing to any +new channels, your sub socket will stop receiving messages. + +## sockopt api + +### socket.tcpnodelay(boolean) + +*(Function, param: Boolean, default: false)*: When set, disables Nagle’s algorithm. It also disables delaying of TCP acknowledgments. Using this option improves latency at the expense of throughput. + +Pass no parameter for current tcp nodelay setting. + +```js +//default +console.log(socket.tcpnodelay()); //tcp nodelay: off + +socket.tcpnodelay(true); //disabling Nagle's algorithm + +console.log(socket.tcpnodelay()); //tcp nodelay: on +``` + +### socket.linger(duration) + +*(Function, param: Number, default: `1000`)*: Specifies how long the socket should try to send pending outbound messages after `socket.close()` or `socket.shutdown()` is called, in milliseconds. + +Pass no parameter for the linger duration. + +```js +socket.linger(5000); +console.log(socket.linger()); //5000 +``` + +### socket.sndbuf(size) + +*(Function, param: Number, size in bytes, default: `128kB`)*: Size of the send buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the send buffer. + +Pass no parameter for the socket's send buffer size. + +```js +socket.sndbuf(131072); +console.log(socket.sndbuf()); // 131072 +``` + +### socket.rcvbuf(size) + +*(Function, param: Number, size in bytes, default: `128kB`)*: Size of the receive buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the receive buffer. + +Pass no parameter for the socket's receive buffer size. + +```js +socket.rcvbuf(20480); +console.log(socket.rcvbuf()); // 20480 +``` + +### socket.sndtimeo(duration) + +*(Function, param: Number, default: `-1`)*: The timeout for send operation on the socket, in milliseconds. + +Pass no parameter for the socket's send timeout. + +```js +socket.sndtimeo(200); +console.log(socket.sndtimeo()); // 200 +``` + +### socket.rcvtimeo(duration) + +*(Function, param: Number, default: `-1`)*: The timeout for recv operation on the socket, in milliseconds. + +Pass no parameter for the socket's recv timeout. + +```js +socket.rcvtimeo(50); +console.log(socket.rcvtimeo()); // 50 +``` + +### socket.reconn(duration) + +*(Function, param: Number, default: `100`)*: For connection-based transports such as TCP, this option specifies how long to wait, in milliseconds, when connection is broken before trying to re-establish it. Note that actual reconnect interval may be randomized to some extent to prevent severe reconnection storms. + +Pass no parameter for the socket's `reconnect` interval. + +```js +socket.reconn(600); +console.log(socket.reconn()); // 600 +``` + +### socket.maxreconn(duration) + +*(Function, param: Number, default: `0`)*: Only to be used in addition to `socket.reconn()`. `maxreconn()` specifies maximum reconnection interval. On each reconnect attempt, the previous interval is doubled until `maxreconn` is reached. Value of zero means that no exponential backoff is performed and reconnect interval is based only on `reconn`. If `maxreconn` is less than `reconn`, it is ignored. + +Pass no parameter for the socket's `maxreconn` interval. + +```js +socket.maxreconn(60000); +console.log(socket.maxreconn()); // 60000 +``` + +### socket.sndprio(priority) + +*(Function, param: Number, default: `8`)*: Sets outbound priority for endpoints subsequently added to the socket. + +This option has no effect on socket types that send messages to all the peers. However, if the socket type sends each message to a single peer (or a limited set of peers), peers with high priority take precedence over peers with low priority. + +Highest priority is 1, lowest is 16. Pass no parameter for the socket's current outbound priority. + +```js +socket.sndprio(2); +console.log(socket.sndprio()); // 2 +``` + +### socket.rcvprio(priority) + +*(Function, param: Number, default: `8`)*: Sets inbound priority for endpoints subsequently added to the socket. + +This option has no effect on socket types that are not able to receive messages. + +When receiving a message, messages from peer with higher priority are received before messages from peer with lower priority. + +Highest priority is 1, lowest is 16. Pass no parameter for the socket's current inbound priority. + +```js +socket.rcvprio(10); +console.log(socket.rcvprio()); // 10 +``` + +### socket.ipv6(boolean) + +*(Function, param: Boolean, default: `false`)*: Allows for the use of IPv6 addresses to bind or connect to. + +By default, nanomsg only works with IPv4 addresses, and support for IPv6 addresses must explicitly be enabled. + +If enabled, both IPv4 and IPv6 addresses can be used. + +```js +socket.ipv6(true); +console.log(socket.ipv6()); // true +``` + +### socket.rcvmaxsize(size) + +*(Function, param: Number, size in bytes, default: `1024kB`)*: Maximum message size that can be received, in bytes. Negative value means that the received size is limited only by available addressable memory. + +Pass no parameter for the socket's maximum receive buffer size. + +```js +socket.rcvmaxsize(10000000); +console.log(socket.rcvmaxsize()); // 10000000 +``` + +### socket.wsopt(str) + +*(Function, param: String, Websocket msg frame format, default: `'binary'`)*: This option may be set to type `'text'` or `'binary'`. This string value determines whether data msgs are sent as WebSocket *text frames*, or *binary frames*, per RFC 6455. Text frames should contain only valid UTF-8 text in their payload, or they will be rejected. Binary frames may contain any data. Not all WebSocket implementations support binary frames. The default is to send binary frames. + +Pass no parameter for the socket's frame format. + +```js +socket.wsopt('text'); +console.log(socket.wsopt()); // 'text' +``` + +If you are implementing nanomsg websockets in the browser, please carefully review the spec: https://raw.githubusercontent.com/nanomsg/nanomsg/master/rfc/sp-websocket-mapping-01.txt + +### socket.dontwait(boolean) + +*(Function, param: Boolean, default: `true`, except PUSH sockets)*: Sets the NN_DONTWAIT flag, specifying that the operation should be performed in non-blocking mode, + +* `true` for non-blocking mode +* `false` for blocking mode + +Pass no parameter for the socket's current mode. + +```js +socket.dontwait(false); +console.log(socket.dontwait()); // false + +// or set when socket is started: +require('nanomsg').socket('pub', { dontwait: false }); +``` + +# test + +```bash +$ git clone https://github.com/nickdesaulniers/node-nanomsg.git nano +$ cd nano && git submodule update --init + +# now you can build the project and run the test suite: +$ make && make check + +# or perhaps you'd prefer to use the npm commands instead: +$ npm i +$ npm t + +# let's say you switch to another version of node/iojs, you might want to run: +$ make clean && make && make check + +# for the super deluxe make clean, rebuild, and test suite: +$ make full +``` + +Note: you must `git submodule update --init` to initialize the nanomsg repository. + +# test - when node-nanomsg is being installed the optional way (dynamically linking to libnanomsg) + +```bash +# you can build the project and run the test suite: +$ make use_system_libnanomsg && make check + +# or perhaps you'd prefer to use the npm commands instead: +$ npm i --use_system_libnanomsg=true +$ npm t + +# let's say you switch to another version of node/iojs, you might want to run: +$ make clean && make use_system_libnanomsg && make check + +# for the super deluxe make clean, rebuild, and test suite: +$ make use_system_libnanomsg-full +``` + +# performance + +run benchmarks: +```bash +$ make perf +``` + +for more info how to do that and your own custom comparisons check out: [running benchmarks](https://github.com/JustinTulloss/zeromq.node#running-benchmarks) + +and if you want you can also run: +```bash +$ make bench +``` +:) + +## contributing + +Issues and pull requests welcome! + +## contributors + + + + + + + + + + + + + + +
a0000778GitHub/a0000778-
Ant SkeltonGitHub/blowback-
Adam BiroGitHub/sirudog-
Benjamin ByholmGitHub/kkoopa-
Bent CardanGitHub/reqsharkTwitter/@rekshark
Deepak PrabhakaraGitHub/deepakprabhakaraTwitter/@deepakprab
Flynn JoffrayGitHub/nucleardreamerTwitter/@nucleardreamer
m-ohuchiGitHub/m-ohuchi-
Michele ComignanoGitHub/comick-
Nick DesaulniersGitHub/nickdesaulniersTwitter/@LostOracle
Tim Cameron RyanGitHub/tcrTwitter/@timcameronryan
Trygve LieGitHub/trygve-lieTwitter/@trygve_lie
+ +## formatting + +### C/C++ +Please run `clang-format -style=Mozilla -i ` on all C/C++ code. + +### JS +WIP + +## license + +MIT + +## memory leak hunting +`npm i --asan=true` + diff --git a/node/node_modules/nanomsg/appveyor.yml b/node/node_modules/nanomsg/appveyor.yml new file mode 100644 index 0000000..bcbb1bb --- /dev/null +++ b/node/node_modules/nanomsg/appveyor.yml @@ -0,0 +1,8 @@ +install: + - cinst nodejs.install -x86 + - set PATH=%PATH%;"C:\Program Files (x86)\nodejs\" + +build_script: + - git submodule update --init + - npm -g install npm@latest + - npm install diff --git a/node/node_modules/nanomsg/binding.gyp b/node/node_modules/nanomsg/binding.gyp new file mode 100644 index 0000000..ab513c2 --- /dev/null +++ b/node/node_modules/nanomsg/binding.gyp @@ -0,0 +1,54 @@ +{ + 'variables': { + 'use_system_libnanomsg%': 'false', + 'asan': 'false', + }, + 'targets': [ + { + 'target_name': 'node_nanomsg', + 'sources': [ + 'src/node_nanomsg.cc', + 'src/poll_ctx.cc' + ], + 'include_dirs': [ + "> $(depfile) +# Add extra rules as in (2). +# We remove slashes and replace spaces with new lines; +# remove blank lines; +# delete the first line and append a colon to the remaining lines. +sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\ + grep -v '^$$' |\ + sed -e 1d -e 's|$$|:|' \ + >> $(depfile) +rm $(depfile).raw +endef + +# Command definitions: +# - cmd_foo is the actual command to run; +# - quiet_cmd_foo is the brief-output summary of the command. + +quiet_cmd_cc = CC($(TOOLSET)) $@ +cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_cxx = CXX($(TOOLSET)) $@ +cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_objc = CXX($(TOOLSET)) $@ +cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $< + +quiet_cmd_objcxx = CXX($(TOOLSET)) $@ +cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $< + +# Commands for precompiled header files. +quiet_cmd_pch_c = CXX($(TOOLSET)) $@ +cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< +quiet_cmd_pch_cc = CXX($(TOOLSET)) $@ +cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< +quiet_cmd_pch_m = CXX($(TOOLSET)) $@ +cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $< +quiet_cmd_pch_mm = CXX($(TOOLSET)) $@ +cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $< + +# gyp-mac-tool is written next to the root Makefile by gyp. +# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd +# already. +quiet_cmd_mac_tool = MACTOOL $(4) $< +cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@" + +quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@ +cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4) + +quiet_cmd_infoplist = INFOPLIST $@ +cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@" + +quiet_cmd_touch = TOUCH $@ +cmd_touch = touch $@ + +quiet_cmd_copy = COPY $@ +# send stderr to /dev/null to ignore messages when linking directories. +cmd_copy = rm -rf "$@" && cp -af "$<" "$@" + +quiet_cmd_alink = LIBTOOL-STATIC $@ +cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^) + +quiet_cmd_link = LINK($(TOOLSET)) $@ +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS) + +quiet_cmd_solink = SOLINK($(TOOLSET)) $@ +cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS) + +quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@ +cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS) + + +# Define an escape_quotes function to escape single quotes. +# This allows us to handle quotes properly as long as we always use +# use single quotes and escape_quotes. +escape_quotes = $(subst ','\'',$(1)) +# This comment is here just to include a ' to unconfuse syntax highlighting. +# Define an escape_vars function to escape '$' variable syntax. +# This allows us to read/write command lines with shell variables (e.g. +# $LD_LIBRARY_PATH), without triggering make substitution. +escape_vars = $(subst $$,$$$$,$(1)) +# Helper that expands to a shell command to echo a string exactly as it is in +# make. This uses printf instead of echo because printf's behaviour with respect +# to escape sequences is more portable than echo's across different shells +# (e.g., dash, bash). +exact_echo = printf '%s\n' '$(call escape_quotes,$(1))' + +# Helper to compare the command we're about to run against the command +# we logged the last time we ran the command. Produces an empty +# string (false) when the commands match. +# Tricky point: Make has no string-equality test function. +# The kernel uses the following, but it seems like it would have false +# positives, where one string reordered its arguments. +# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ +# $(filter-out $(cmd_$@), $(cmd_$(1)))) +# We instead substitute each for the empty string into the other, and +# say they're equal if both substitutions produce the empty string. +# .d files contain ? instead of spaces, take that into account. +command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\ + $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1)))) + +# Helper that is non-empty when a prerequisite changes. +# Normally make does this implicitly, but we force rules to always run +# so we can check their command lines. +# $? -- new prerequisites +# $| -- order-only dependencies +prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?)) + +# Helper that executes all postbuilds until one fails. +define do_postbuilds + @E=0;\ + for p in $(POSTBUILDS); do\ + eval $$p;\ + E=$$?;\ + if [ $$E -ne 0 ]; then\ + break;\ + fi;\ + done;\ + if [ $$E -ne 0 ]; then\ + rm -rf "$@";\ + exit $$E;\ + fi +endef + +# do_cmd: run a command via the above cmd_foo names, if necessary. +# Should always run for a given target to handle command-line changes. +# Second argument, if non-zero, makes it do asm/C/C++ dependency munging. +# Third argument, if non-zero, makes it do POSTBUILDS processing. +# Note: We intentionally do NOT call dirx for depfile, since it contains ? for +# spaces already and dirx strips the ? characters. +define do_cmd +$(if $(or $(command_changed),$(prereq_changed)), + @$(call exact_echo, $($(quiet)cmd_$(1))) + @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))" + $(if $(findstring flock,$(word 2,$(cmd_$1))), + @$(cmd_$(1)) + @echo " $(quiet_cmd_$(1)): Finished", + @$(cmd_$(1)) + ) + @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile) + @$(if $(2),$(fixup_dep)) + $(if $(and $(3), $(POSTBUILDS)), + $(call do_postbuilds) + ) +) +endef + +# Declare the "all" target first so it is the default, +# even though we don't have the deps yet. +.PHONY: all +all: + +# make looks for ways to re-generate included makefiles, but in our case, we +# don't have a direct way. Explicitly telling make that it has nothing to do +# for them makes it go faster. +%.d: ; + +# Use FORCE_DO_CMD to force a target to run. Should be coupled with +# do_cmd. +.PHONY: FORCE_DO_CMD +FORCE_DO_CMD: + +TOOLSET := target +# Suffix rules, putting all outputs into $(obj). +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.m FORCE_DO_CMD + @$(call do_cmd,objc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.mm FORCE_DO_CMD + @$(call do_cmd,objcxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.m FORCE_DO_CMD + @$(call do_cmd,objc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.mm FORCE_DO_CMD + @$(call do_cmd,objcxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.m FORCE_DO_CMD + @$(call do_cmd,objc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.mm FORCE_DO_CMD + @$(call do_cmd,objcxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + + +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,deps/nanomsg.target.mk)))),) + include deps/nanomsg.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,node_nanomsg.target.mk)))),) + include node_nanomsg.target.mk +endif + +quiet_cmd_regen_makefile = ACTION Regenerating $@ +cmd_regen_makefile = cd $(srcdir); /usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "--toplevel-dir=." -I/Users/hwwu/Git/ats-sessions/node/node_modules/nanomsg/build/config.gypi -I/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/hwwu/.node-gyp/8.7.0/include/node/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/hwwu/.node-gyp/8.7.0" "-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/hwwu/.node-gyp/8.7.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/hwwu/Git/ats-sessions/node/node_modules/nanomsg" "-Dnode_engine=v8" binding.gyp +Makefile: $(srcdir)/deps/common.gypi $(srcdir)/deps/nanomsg.gyp $(srcdir)/binding.gyp $(srcdir)/deps/macosx.gypi $(srcdir)/../../../../../../../usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/build/config.gypi $(srcdir)/../../../../../.node-gyp/8.7.0/include/node/common.gypi $(srcdir)/deps/linux.gypi $(srcdir)/deps/win.gypi + $(call do_cmd,regen_makefile) + +# "all" is a concatenation of the "all" targets from all the included +# sub-makefiles. This is just here to clarify. +all: + +# Add in dependency-tracking rules. $(all_deps) is the list of every single +# target in our tree. Only consider the ones with .d (dependency) info: +d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d)) +ifneq ($(d_files),) + include $(d_files) +endif diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/nanomsg.a.d b/node/node_modules/nanomsg/build/Release/.deps/Release/nanomsg.a.d new file mode 100644 index 0000000..2cdec4d --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/nanomsg.a.d @@ -0,0 +1 @@ +cmd_Release/nanomsg.a := rm -f Release/nanomsg.a && ./gyp-mac-tool filter-libtool libtool -static -o Release/nanomsg.a Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/node_nanomsg.node.d b/node/node_modules/nanomsg/build/Release/.deps/Release/node_nanomsg.node.d new file mode 100644 index 0000000..64ad7bf --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/node_nanomsg.node.d @@ -0,0 +1 @@ +cmd_Release/node_nanomsg.node := c++ -bundle -undefined dynamic_lookup -Wl,-no_pie -Wl,-search_paths_first -mmacosx-version-min=10.7 -arch x86_64 -L./Release -stdlib=libc++ -o Release/node_nanomsg.node Release/obj.target/node_nanomsg/src/node_nanomsg.o Release/obj.target/node_nanomsg/src/poll_ctx.o Release/nanomsg.a diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o.d new file mode 100644 index 0000000..6d914d0 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o.d @@ -0,0 +1,38 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o ../deps/nanomsg/src/aio/ctx.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o: \ + ../deps/nanomsg/src/aio/ctx.c ../deps/nanomsg/src/aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/cont.h +../deps/nanomsg/src/aio/ctx.c: +../deps/nanomsg/src/aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/aio/../utils/cont.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o.d new file mode 100644 index 0000000..bf3a0ed --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o.d @@ -0,0 +1,37 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o ../deps/nanomsg/src/aio/fsm.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o: \ + ../deps/nanomsg/src/aio/fsm.c ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h ../deps/nanomsg/src/aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/attr.h +../deps/nanomsg/src/aio/fsm.c: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/aio/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o.d new file mode 100644 index 0000000..935aaa1 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o.d @@ -0,0 +1,19 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o ../deps/nanomsg/src/aio/poller.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o: \ + ../deps/nanomsg/src/aio/poller.c ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/aio/poller_kqueue.inc \ + ../deps/nanomsg/src/aio/../utils/attr.h \ + ../deps/nanomsg/src/aio/../utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/aio/../utils/closefd.h +../deps/nanomsg/src/aio/poller.c: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/poller_kqueue.inc: +../deps/nanomsg/src/aio/../utils/attr.h: +../deps/nanomsg/src/aio/../utils/fast.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/aio/../utils/closefd.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o.d new file mode 100644 index 0000000..652972d --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o.d @@ -0,0 +1,30 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o ../deps/nanomsg/src/aio/pool.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o: \ + ../deps/nanomsg/src/aio/pool.c ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h +../deps/nanomsg/src/aio/pool.c: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o.d new file mode 100644 index 0000000..4b024cd --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o.d @@ -0,0 +1,39 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o ../deps/nanomsg/src/aio/timer.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o: \ + ../deps/nanomsg/src/aio/timer.c ../deps/nanomsg/src/aio/timer.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/aio/../utils/cont.h \ + ../deps/nanomsg/src/aio/../utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/aio/../utils/attr.h +../deps/nanomsg/src/aio/timer.c: +../deps/nanomsg/src/aio/timer.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/../utils/cont.h: +../deps/nanomsg/src/aio/../utils/fast.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/aio/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o.d new file mode 100644 index 0000000..7269a3a --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o.d @@ -0,0 +1,17 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o ../deps/nanomsg/src/aio/timerset.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o: \ + ../deps/nanomsg/src/aio/timerset.c ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/../utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/cont.h \ + ../deps/nanomsg/src/aio/../utils/clock.h \ + ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h +../deps/nanomsg/src/aio/timerset.c: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/../utils/fast.h: +../deps/nanomsg/src/aio/../utils/cont.h: +../deps/nanomsg/src/aio/../utils/clock.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o.d new file mode 100644 index 0000000..e343bcd --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o.d @@ -0,0 +1,46 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o ../deps/nanomsg/src/aio/usock.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o: \ + ../deps/nanomsg/src/aio/usock.c ../deps/nanomsg/src/aio/usock.h \ + ../deps/nanomsg/src/aio/../nn.h ../deps/nanomsg/src/aio/usock_posix.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/aio/usock_posix.inc \ + ../deps/nanomsg/src/aio/../utils/alloc.h \ + ../deps/nanomsg/src/aio/../utils/closefd.h \ + ../deps/nanomsg/src/aio/../utils/cont.h \ + ../deps/nanomsg/src/aio/../utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/aio/../utils/attr.h +../deps/nanomsg/src/aio/usock.c: +../deps/nanomsg/src/aio/usock.h: +../deps/nanomsg/src/aio/../nn.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/usock_posix.inc: +../deps/nanomsg/src/aio/../utils/alloc.h: +../deps/nanomsg/src/aio/../utils/closefd.h: +../deps/nanomsg/src/aio/../utils/cont.h: +../deps/nanomsg/src/aio/../utils/fast.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/aio/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o.d new file mode 100644 index 0000000..e335ba2 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o.d @@ -0,0 +1,41 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o ../deps/nanomsg/src/aio/worker.c +Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o: \ + ../deps/nanomsg/src/aio/worker.c ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/aio/worker_posix.inc ../deps/nanomsg/src/aio/ctx.h \ + ../deps/nanomsg/src/aio/pool.h ../deps/nanomsg/src/aio/../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/aio/../utils/cont.h \ + ../deps/nanomsg/src/aio/../utils/attr.h +../deps/nanomsg/src/aio/worker.c: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/worker_posix.inc: +../deps/nanomsg/src/aio/ctx.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/aio/../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/aio/../utils/cont.h: +../deps/nanomsg/src/aio/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o.d new file mode 100644 index 0000000..5f04246 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o.d @@ -0,0 +1,53 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o ../deps/nanomsg/src/core/ep.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o: \ + ../deps/nanomsg/src/core/ep.c ../deps/nanomsg/src/core/../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/core/ep.h ../deps/nanomsg/src/core/sock.h \ + ../deps/nanomsg/src/core/../protocol.h \ + ../deps/nanomsg/src/core/../aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h \ + ../deps/nanomsg/src/core/../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/core/../utils/cont.h \ + ../deps/nanomsg/src/core/../utils/attr.h +../deps/nanomsg/src/core/ep.c: +../deps/nanomsg/src/core/../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/core/ep.h: +../deps/nanomsg/src/core/sock.h: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/core/../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/core/../utils/cont.h: +../deps/nanomsg/src/core/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o.d new file mode 100644 index 0000000..81df16e --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o.d @@ -0,0 +1,47 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o ../deps/nanomsg/src/core/epbase.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o: \ + ../deps/nanomsg/src/core/epbase.c \ + ../deps/nanomsg/src/core/../transport.h ../deps/nanomsg/src/nn.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/core/ep.h ../deps/nanomsg/src/core/sock.h \ + ../deps/nanomsg/src/core/../protocol.h \ + ../deps/nanomsg/src/core/../aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h \ + ../deps/nanomsg/src/core/../utils/attr.h +../deps/nanomsg/src/core/epbase.c: +../deps/nanomsg/src/core/../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/core/ep.h: +../deps/nanomsg/src/core/sock.h: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/core/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o.d new file mode 100644 index 0000000..2500e27 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o.d @@ -0,0 +1,130 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o ../deps/nanomsg/src/core/global.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o: \ + ../deps/nanomsg/src/core/global.c ../deps/nanomsg/src/core/../nn.h \ + ../deps/nanomsg/src/core/../transport.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/core/../protocol.h \ + ../deps/nanomsg/src/core/global.h ../deps/nanomsg/src/core/sock.h \ + ../deps/nanomsg/src/core/../aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h ../deps/nanomsg/src/core/ep.h \ + ../deps/nanomsg/src/core/../aio/timer.h \ + ../deps/nanomsg/src/core/../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/core/../utils/alloc.h \ + ../deps/nanomsg/src/core/../utils/condvar.h \ + ../deps/nanomsg/src/core/../utils/once.h \ + ../deps/nanomsg/src/core/../utils/cont.h \ + ../deps/nanomsg/src/core/../utils/random.h \ + ../deps/nanomsg/src/core/../utils/attr.h \ + ../deps/nanomsg/src/core/../transports/inproc/inproc.h \ + ../deps/nanomsg/src/core/../transports/ipc/ipc.h \ + ../deps/nanomsg/src/core/../transports/tcp/tcp.h \ + ../deps/nanomsg/src/core/../transports/ws/ws.h \ + ../deps/nanomsg/src/core/../protocols/pair/pair.h \ + ../deps/nanomsg/src/core/../protocols/pair/xpair.h \ + ../deps/nanomsg/src/core/../protocols/pubsub/pub.h \ + ../deps/nanomsg/src/core/../protocols/pubsub/sub.h \ + ../deps/nanomsg/src/core/../protocols/pubsub/xpub.h \ + ../deps/nanomsg/src/core/../protocols/pubsub/xsub.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/rep.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/xrep.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/../../utils/hash.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/../utils/fq.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/../utils/priolist.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/req.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/xreq.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/../utils/lb.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/task.h \ + ../deps/nanomsg/src/core/../protocols/reqrep/../../reqrep.h \ + ../deps/nanomsg/src/core/../protocols/pipeline/push.h \ + ../deps/nanomsg/src/core/../protocols/pipeline/pull.h \ + ../deps/nanomsg/src/core/../protocols/pipeline/xpush.h \ + ../deps/nanomsg/src/core/../protocols/pipeline/xpull.h \ + ../deps/nanomsg/src/core/../protocols/survey/respondent.h \ + ../deps/nanomsg/src/core/../protocols/survey/surveyor.h \ + ../deps/nanomsg/src/core/../protocols/survey/xrespondent.h \ + ../deps/nanomsg/src/core/../protocols/survey/xsurveyor.h \ + ../deps/nanomsg/src/core/../protocols/survey/../utils/dist.h \ + ../deps/nanomsg/src/core/../protocols/bus/bus.h \ + ../deps/nanomsg/src/core/../protocols/bus/xbus.h \ + ../deps/nanomsg/src/core/../pubsub.h \ + ../deps/nanomsg/src/core/../pipeline.h +../deps/nanomsg/src/core/global.c: +../deps/nanomsg/src/core/../nn.h: +../deps/nanomsg/src/core/../transport.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/core/global.h: +../deps/nanomsg/src/core/sock.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/core/ep.h: +../deps/nanomsg/src/core/../aio/timer.h: +../deps/nanomsg/src/core/../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/core/../utils/alloc.h: +../deps/nanomsg/src/core/../utils/condvar.h: +../deps/nanomsg/src/core/../utils/once.h: +../deps/nanomsg/src/core/../utils/cont.h: +../deps/nanomsg/src/core/../utils/random.h: +../deps/nanomsg/src/core/../utils/attr.h: +../deps/nanomsg/src/core/../transports/inproc/inproc.h: +../deps/nanomsg/src/core/../transports/ipc/ipc.h: +../deps/nanomsg/src/core/../transports/tcp/tcp.h: +../deps/nanomsg/src/core/../transports/ws/ws.h: +../deps/nanomsg/src/core/../protocols/pair/pair.h: +../deps/nanomsg/src/core/../protocols/pair/xpair.h: +../deps/nanomsg/src/core/../protocols/pubsub/pub.h: +../deps/nanomsg/src/core/../protocols/pubsub/sub.h: +../deps/nanomsg/src/core/../protocols/pubsub/xpub.h: +../deps/nanomsg/src/core/../protocols/pubsub/xsub.h: +../deps/nanomsg/src/core/../protocols/reqrep/rep.h: +../deps/nanomsg/src/core/../protocols/reqrep/xrep.h: +../deps/nanomsg/src/core/../protocols/reqrep/../../utils/hash.h: +../deps/nanomsg/src/core/../protocols/reqrep/../utils/fq.h: +../deps/nanomsg/src/core/../protocols/reqrep/../utils/priolist.h: +../deps/nanomsg/src/core/../protocols/reqrep/req.h: +../deps/nanomsg/src/core/../protocols/reqrep/xreq.h: +../deps/nanomsg/src/core/../protocols/reqrep/../utils/lb.h: +../deps/nanomsg/src/core/../protocols/reqrep/task.h: +../deps/nanomsg/src/core/../protocols/reqrep/../../reqrep.h: +../deps/nanomsg/src/core/../protocols/pipeline/push.h: +../deps/nanomsg/src/core/../protocols/pipeline/pull.h: +../deps/nanomsg/src/core/../protocols/pipeline/xpush.h: +../deps/nanomsg/src/core/../protocols/pipeline/xpull.h: +../deps/nanomsg/src/core/../protocols/survey/respondent.h: +../deps/nanomsg/src/core/../protocols/survey/surveyor.h: +../deps/nanomsg/src/core/../protocols/survey/xrespondent.h: +../deps/nanomsg/src/core/../protocols/survey/xsurveyor.h: +../deps/nanomsg/src/core/../protocols/survey/../utils/dist.h: +../deps/nanomsg/src/core/../protocols/bus/bus.h: +../deps/nanomsg/src/core/../protocols/bus/xbus.h: +../deps/nanomsg/src/core/../pubsub.h: +../deps/nanomsg/src/core/../pipeline.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o.d new file mode 100644 index 0000000..bf47c8f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o.d @@ -0,0 +1,48 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o ../deps/nanomsg/src/core/pipe.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o: \ + ../deps/nanomsg/src/core/pipe.c \ + ../deps/nanomsg/src/core/../transport.h ../deps/nanomsg/src/nn.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/core/../protocol.h ../deps/nanomsg/src/core/sock.h \ + ../deps/nanomsg/src/core/../aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h ../deps/nanomsg/src/core/ep.h \ + ../deps/nanomsg/src/core/../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/core/pipe.c: +../deps/nanomsg/src/core/../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/core/sock.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/core/ep.h: +../deps/nanomsg/src/core/../utils/err.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o.d new file mode 100644 index 0000000..0fcbd78 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o ../deps/nanomsg/src/core/poll.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o: \ + ../deps/nanomsg/src/core/poll.c ../deps/nanomsg/src/core/../nn.h \ + ../deps/nanomsg/src/core/../utils/alloc.h \ + ../deps/nanomsg/src/core/../utils/fast.h \ + ../deps/nanomsg/src/core/../utils/err.h +../deps/nanomsg/src/core/poll.c: +../deps/nanomsg/src/core/../nn.h: +../deps/nanomsg/src/core/../utils/alloc.h: +../deps/nanomsg/src/core/../utils/fast.h: +../deps/nanomsg/src/core/../utils/err.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o.d new file mode 100644 index 0000000..97bdc77 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o.d @@ -0,0 +1,55 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o ../deps/nanomsg/src/core/sock.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o: \ + ../deps/nanomsg/src/core/sock.c ../deps/nanomsg/src/core/../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/core/../transport.h ../deps/nanomsg/src/nn.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/core/sock.h ../deps/nanomsg/src/core/../aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h \ + ../deps/nanomsg/src/core/global.h ../deps/nanomsg/src/core/ep.h \ + ../deps/nanomsg/src/core/../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/core/../utils/cont.h \ + ../deps/nanomsg/src/core/../utils/clock.h \ + ../deps/nanomsg/src/core/../utils/alloc.h +../deps/nanomsg/src/core/sock.c: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/core/../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/core/sock.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/core/global.h: +../deps/nanomsg/src/core/ep.h: +../deps/nanomsg/src/core/../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/core/../utils/cont.h: +../deps/nanomsg/src/core/../utils/clock.h: +../deps/nanomsg/src/core/../utils/alloc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o.d new file mode 100644 index 0000000..2e14e8d --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o.d @@ -0,0 +1,49 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o ../deps/nanomsg/src/core/sockbase.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o: \ + ../deps/nanomsg/src/core/sockbase.c \ + ../deps/nanomsg/src/core/../protocol.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/core/sock.h \ + ../deps/nanomsg/src/core/../transport.h ../deps/nanomsg/src/nn.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/core/../aio/ctx.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h \ + ../deps/nanomsg/src/core/../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/core/../utils/attr.h +../deps/nanomsg/src/core/sockbase.c: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/core/sock.h: +../deps/nanomsg/src/core/../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/core/../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/core/../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o.d new file mode 100644 index 0000000..bdca20f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o.d @@ -0,0 +1,22 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o ../deps/nanomsg/src/core/symbol.c +Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o: \ + ../deps/nanomsg/src/core/symbol.c ../deps/nanomsg/src/core/../nn.h \ + ../deps/nanomsg/src/core/../inproc.h ../deps/nanomsg/src/core/../ipc.h \ + ../deps/nanomsg/src/core/../tcp.h ../deps/nanomsg/src/core/../pair.h \ + ../deps/nanomsg/src/core/../pubsub.h \ + ../deps/nanomsg/src/core/../reqrep.h \ + ../deps/nanomsg/src/core/../pipeline.h \ + ../deps/nanomsg/src/core/../survey.h ../deps/nanomsg/src/core/../bus.h \ + ../deps/nanomsg/src/core/../ws.h +../deps/nanomsg/src/core/symbol.c: +../deps/nanomsg/src/core/../nn.h: +../deps/nanomsg/src/core/../inproc.h: +../deps/nanomsg/src/core/../ipc.h: +../deps/nanomsg/src/core/../tcp.h: +../deps/nanomsg/src/core/../pair.h: +../deps/nanomsg/src/core/../pubsub.h: +../deps/nanomsg/src/core/../reqrep.h: +../deps/nanomsg/src/core/../pipeline.h: +../deps/nanomsg/src/core/../survey.h: +../deps/nanomsg/src/core/../bus.h: +../deps/nanomsg/src/core/../ws.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o.d new file mode 100644 index 0000000..f554c5f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o.d @@ -0,0 +1,20 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o ../deps/nanomsg/src/devices/device.c +Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o: \ + ../deps/nanomsg/src/devices/device.c \ + ../deps/nanomsg/src/devices/../nn.h \ + ../deps/nanomsg/src/devices/../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/devices/../utils/fd.h \ + ../deps/nanomsg/src/devices/../utils/attr.h \ + ../deps/nanomsg/src/devices/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/devices/device.h +../deps/nanomsg/src/devices/device.c: +../deps/nanomsg/src/devices/../nn.h: +../deps/nanomsg/src/devices/../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/devices/../utils/fd.h: +../deps/nanomsg/src/devices/../utils/attr.h: +../deps/nanomsg/src/devices/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/devices/device.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o.d new file mode 100644 index 0000000..c4cb3a2 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o.d @@ -0,0 +1,34 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o ../deps/nanomsg/src/protocols/bus/bus.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o: \ + ../deps/nanomsg/src/protocols/bus/bus.c \ + ../deps/nanomsg/src/protocols/bus/bus.h \ + ../deps/nanomsg/src/protocols/bus/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/bus/xbus.h \ + ../deps/nanomsg/src/protocols/bus/../utils/dist.h \ + ../deps/nanomsg/src/protocols/bus/../utils/fq.h \ + ../deps/nanomsg/src/protocols/bus/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/bus/../../nn.h \ + ../deps/nanomsg/src/protocols/bus/../../bus.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/protocols/bus/bus.c: +../deps/nanomsg/src/protocols/bus/bus.h: +../deps/nanomsg/src/protocols/bus/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/bus/xbus.h: +../deps/nanomsg/src/protocols/bus/../utils/dist.h: +../deps/nanomsg/src/protocols/bus/../utils/fq.h: +../deps/nanomsg/src/protocols/bus/../utils/priolist.h: +../deps/nanomsg/src/protocols/bus/../../nn.h: +../deps/nanomsg/src/protocols/bus/../../bus.h: +../deps/nanomsg/src/protocols/bus/../../utils/cont.h: +../deps/nanomsg/src/protocols/bus/../../utils/alloc.h: +../deps/nanomsg/src/protocols/bus/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o.d new file mode 100644 index 0000000..ea23b7e --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o.d @@ -0,0 +1,34 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o ../deps/nanomsg/src/protocols/bus/xbus.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o: \ + ../deps/nanomsg/src/protocols/bus/xbus.c \ + ../deps/nanomsg/src/protocols/bus/xbus.h \ + ../deps/nanomsg/src/protocols/bus/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/bus/../utils/dist.h \ + ../deps/nanomsg/src/protocols/bus/../utils/fq.h \ + ../deps/nanomsg/src/protocols/bus/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/bus/../../nn.h \ + ../deps/nanomsg/src/protocols/bus/../../bus.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/bus/../../utils/attr.h +../deps/nanomsg/src/protocols/bus/xbus.c: +../deps/nanomsg/src/protocols/bus/xbus.h: +../deps/nanomsg/src/protocols/bus/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/bus/../utils/dist.h: +../deps/nanomsg/src/protocols/bus/../utils/fq.h: +../deps/nanomsg/src/protocols/bus/../utils/priolist.h: +../deps/nanomsg/src/protocols/bus/../../nn.h: +../deps/nanomsg/src/protocols/bus/../../bus.h: +../deps/nanomsg/src/protocols/bus/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/bus/../../utils/cont.h: +../deps/nanomsg/src/protocols/bus/../../utils/alloc.h: +../deps/nanomsg/src/protocols/bus/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o.d new file mode 100644 index 0000000..bcfb828 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o.d @@ -0,0 +1,20 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o ../deps/nanomsg/src/protocols/pair/pair.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o: \ + ../deps/nanomsg/src/protocols/pair/pair.c \ + ../deps/nanomsg/src/protocols/pair/pair.h \ + ../deps/nanomsg/src/protocols/pair/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pair/xpair.h \ + ../deps/nanomsg/src/protocols/pair/../../nn.h \ + ../deps/nanomsg/src/protocols/pair/../../pair.h +../deps/nanomsg/src/protocols/pair/pair.c: +../deps/nanomsg/src/protocols/pair/pair.h: +../deps/nanomsg/src/protocols/pair/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pair/xpair.h: +../deps/nanomsg/src/protocols/pair/../../nn.h: +../deps/nanomsg/src/protocols/pair/../../pair.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o.d new file mode 100644 index 0000000..beba1db --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o.d @@ -0,0 +1,30 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o ../deps/nanomsg/src/protocols/pair/xpair.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o: \ + ../deps/nanomsg/src/protocols/pair/xpair.c \ + ../deps/nanomsg/src/protocols/pair/xpair.h \ + ../deps/nanomsg/src/protocols/pair/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pair/../../nn.h \ + ../deps/nanomsg/src/protocols/pair/../../pair.h \ + ../deps/nanomsg/src/protocols/pair/../utils/excl.h \ + ../deps/nanomsg/src/protocols/pair/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/pair/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/pair/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/pair/../../utils/attr.h +../deps/nanomsg/src/protocols/pair/xpair.c: +../deps/nanomsg/src/protocols/pair/xpair.h: +../deps/nanomsg/src/protocols/pair/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pair/../../nn.h: +../deps/nanomsg/src/protocols/pair/../../pair.h: +../deps/nanomsg/src/protocols/pair/../utils/excl.h: +../deps/nanomsg/src/protocols/pair/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/pair/../../utils/cont.h: +../deps/nanomsg/src/protocols/pair/../../utils/alloc.h: +../deps/nanomsg/src/protocols/pair/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o.d new file mode 100644 index 0000000..c40ccbd --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o.d @@ -0,0 +1,20 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o ../deps/nanomsg/src/protocols/pipeline/pull.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o: \ + ../deps/nanomsg/src/protocols/pipeline/pull.c \ + ../deps/nanomsg/src/protocols/pipeline/pull.h \ + ../deps/nanomsg/src/protocols/pipeline/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pipeline/xpull.h \ + ../deps/nanomsg/src/protocols/pipeline/../../nn.h \ + ../deps/nanomsg/src/protocols/pipeline/../../pipeline.h +../deps/nanomsg/src/protocols/pipeline/pull.c: +../deps/nanomsg/src/protocols/pipeline/pull.h: +../deps/nanomsg/src/protocols/pipeline/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pipeline/xpull.h: +../deps/nanomsg/src/protocols/pipeline/../../nn.h: +../deps/nanomsg/src/protocols/pipeline/../../pipeline.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o.d new file mode 100644 index 0000000..3507096 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o.d @@ -0,0 +1,20 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o ../deps/nanomsg/src/protocols/pipeline/push.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o: \ + ../deps/nanomsg/src/protocols/pipeline/push.c \ + ../deps/nanomsg/src/protocols/pipeline/push.h \ + ../deps/nanomsg/src/protocols/pipeline/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pipeline/xpush.h \ + ../deps/nanomsg/src/protocols/pipeline/../../nn.h \ + ../deps/nanomsg/src/protocols/pipeline/../../pipeline.h +../deps/nanomsg/src/protocols/pipeline/push.c: +../deps/nanomsg/src/protocols/pipeline/push.h: +../deps/nanomsg/src/protocols/pipeline/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pipeline/xpush.h: +../deps/nanomsg/src/protocols/pipeline/../../nn.h: +../deps/nanomsg/src/protocols/pipeline/../../pipeline.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o.d new file mode 100644 index 0000000..7c66e78 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o.d @@ -0,0 +1,32 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o ../deps/nanomsg/src/protocols/pipeline/xpull.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o: \ + ../deps/nanomsg/src/protocols/pipeline/xpull.c \ + ../deps/nanomsg/src/protocols/pipeline/xpull.h \ + ../deps/nanomsg/src/protocols/pipeline/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pipeline/../../nn.h \ + ../deps/nanomsg/src/protocols/pipeline/../../pipeline.h \ + ../deps/nanomsg/src/protocols/pipeline/../utils/fq.h \ + ../deps/nanomsg/src/protocols/pipeline/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/attr.h +../deps/nanomsg/src/protocols/pipeline/xpull.c: +../deps/nanomsg/src/protocols/pipeline/xpull.h: +../deps/nanomsg/src/protocols/pipeline/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pipeline/../../nn.h: +../deps/nanomsg/src/protocols/pipeline/../../pipeline.h: +../deps/nanomsg/src/protocols/pipeline/../utils/fq.h: +../deps/nanomsg/src/protocols/pipeline/../utils/priolist.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/cont.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/alloc.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o.d new file mode 100644 index 0000000..c08c964 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o.d @@ -0,0 +1,32 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o ../deps/nanomsg/src/protocols/pipeline/xpush.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o: \ + ../deps/nanomsg/src/protocols/pipeline/xpush.c \ + ../deps/nanomsg/src/protocols/pipeline/xpush.h \ + ../deps/nanomsg/src/protocols/pipeline/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pipeline/../../nn.h \ + ../deps/nanomsg/src/protocols/pipeline/../../pipeline.h \ + ../deps/nanomsg/src/protocols/pipeline/../utils/lb.h \ + ../deps/nanomsg/src/protocols/pipeline/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/pipeline/../../utils/attr.h +../deps/nanomsg/src/protocols/pipeline/xpush.c: +../deps/nanomsg/src/protocols/pipeline/xpush.h: +../deps/nanomsg/src/protocols/pipeline/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pipeline/../../nn.h: +../deps/nanomsg/src/protocols/pipeline/../../pipeline.h: +../deps/nanomsg/src/protocols/pipeline/../utils/lb.h: +../deps/nanomsg/src/protocols/pipeline/../utils/priolist.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/cont.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/alloc.h: +../deps/nanomsg/src/protocols/pipeline/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o.d new file mode 100644 index 0000000..dca3237 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o.d @@ -0,0 +1,20 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o ../deps/nanomsg/src/protocols/pubsub/pub.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o: \ + ../deps/nanomsg/src/protocols/pubsub/pub.c \ + ../deps/nanomsg/src/protocols/pubsub/pub.h \ + ../deps/nanomsg/src/protocols/pubsub/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pubsub/xpub.h \ + ../deps/nanomsg/src/protocols/pubsub/../../nn.h \ + ../deps/nanomsg/src/protocols/pubsub/../../pubsub.h +../deps/nanomsg/src/protocols/pubsub/pub.c: +../deps/nanomsg/src/protocols/pubsub/pub.h: +../deps/nanomsg/src/protocols/pubsub/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pubsub/xpub.h: +../deps/nanomsg/src/protocols/pubsub/../../nn.h: +../deps/nanomsg/src/protocols/pubsub/../../pubsub.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o.d new file mode 100644 index 0000000..d3d5ddc --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o.d @@ -0,0 +1,20 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o ../deps/nanomsg/src/protocols/pubsub/sub.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o: \ + ../deps/nanomsg/src/protocols/pubsub/sub.c \ + ../deps/nanomsg/src/protocols/pubsub/sub.h \ + ../deps/nanomsg/src/protocols/pubsub/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pubsub/xsub.h \ + ../deps/nanomsg/src/protocols/pubsub/../../nn.h \ + ../deps/nanomsg/src/protocols/pubsub/../../pubsub.h +../deps/nanomsg/src/protocols/pubsub/sub.c: +../deps/nanomsg/src/protocols/pubsub/sub.h: +../deps/nanomsg/src/protocols/pubsub/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pubsub/xsub.h: +../deps/nanomsg/src/protocols/pubsub/../../nn.h: +../deps/nanomsg/src/protocols/pubsub/../../pubsub.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o.d new file mode 100644 index 0000000..388e265 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o.d @@ -0,0 +1,14 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o ../deps/nanomsg/src/protocols/pubsub/trie.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o: \ + ../deps/nanomsg/src/protocols/pubsub/trie.c \ + ../deps/nanomsg/src/protocols/pubsub/trie.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/fast.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h +../deps/nanomsg/src/protocols/pubsub/trie.c: +../deps/nanomsg/src/protocols/pubsub/trie.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/alloc.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/fast.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o.d new file mode 100644 index 0000000..4790790 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o.d @@ -0,0 +1,30 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o ../deps/nanomsg/src/protocols/pubsub/xpub.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o: \ + ../deps/nanomsg/src/protocols/pubsub/xpub.c \ + ../deps/nanomsg/src/protocols/pubsub/xpub.h \ + ../deps/nanomsg/src/protocols/pubsub/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pubsub/../../nn.h \ + ../deps/nanomsg/src/protocols/pubsub/../../pubsub.h \ + ../deps/nanomsg/src/protocols/pubsub/../utils/dist.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/attr.h +../deps/nanomsg/src/protocols/pubsub/xpub.c: +../deps/nanomsg/src/protocols/pubsub/xpub.h: +../deps/nanomsg/src/protocols/pubsub/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pubsub/../../nn.h: +../deps/nanomsg/src/protocols/pubsub/../../pubsub.h: +../deps/nanomsg/src/protocols/pubsub/../utils/dist.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/cont.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/alloc.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o.d new file mode 100644 index 0000000..a765630 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o.d @@ -0,0 +1,34 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o ../deps/nanomsg/src/protocols/pubsub/xsub.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o: \ + ../deps/nanomsg/src/protocols/pubsub/xsub.c \ + ../deps/nanomsg/src/protocols/pubsub/xsub.h \ + ../deps/nanomsg/src/protocols/pubsub/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/pubsub/trie.h \ + ../deps/nanomsg/src/protocols/pubsub/../../nn.h \ + ../deps/nanomsg/src/protocols/pubsub/../../pubsub.h \ + ../deps/nanomsg/src/protocols/pubsub/../utils/fq.h \ + ../deps/nanomsg/src/protocols/pubsub/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/pubsub/../../utils/attr.h +../deps/nanomsg/src/protocols/pubsub/xsub.c: +../deps/nanomsg/src/protocols/pubsub/xsub.h: +../deps/nanomsg/src/protocols/pubsub/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/pubsub/trie.h: +../deps/nanomsg/src/protocols/pubsub/../../nn.h: +../deps/nanomsg/src/protocols/pubsub/../../pubsub.h: +../deps/nanomsg/src/protocols/pubsub/../utils/fq.h: +../deps/nanomsg/src/protocols/pubsub/../utils/priolist.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/cont.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/alloc.h: +../deps/nanomsg/src/protocols/pubsub/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o.d new file mode 100644 index 0000000..fee5e31 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o.d @@ -0,0 +1,36 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o ../deps/nanomsg/src/protocols/reqrep/rep.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o: \ + ../deps/nanomsg/src/protocols/reqrep/rep.c \ + ../deps/nanomsg/src/protocols/reqrep/rep.h \ + ../deps/nanomsg/src/protocols/reqrep/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/reqrep/xrep.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/hash.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/fq.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/reqrep/../../nn.h \ + ../deps/nanomsg/src/protocols/reqrep/../../reqrep.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/wire.h +../deps/nanomsg/src/protocols/reqrep/rep.c: +../deps/nanomsg/src/protocols/reqrep/rep.h: +../deps/nanomsg/src/protocols/reqrep/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/reqrep/xrep.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/hash.h: +../deps/nanomsg/src/protocols/reqrep/../utils/fq.h: +../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h: +../deps/nanomsg/src/protocols/reqrep/../../nn.h: +../deps/nanomsg/src/protocols/reqrep/../../reqrep.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/wire.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o.d new file mode 100644 index 0000000..ac6a15f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o.d @@ -0,0 +1,67 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o ../deps/nanomsg/src/protocols/reqrep/req.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o: \ + ../deps/nanomsg/src/protocols/reqrep/req.c \ + ../deps/nanomsg/src/protocols/reqrep/req.h \ + ../deps/nanomsg/src/protocols/reqrep/xreq.h \ + ../deps/nanomsg/src/protocols/reqrep/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/lb.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/fq.h \ + ../deps/nanomsg/src/protocols/reqrep/task.h \ + ../deps/nanomsg/src/protocols/reqrep/../../reqrep.h \ + ../deps/nanomsg/src/nn.h \ + ../deps/nanomsg/src/protocols/reqrep/../../aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/protocols/reqrep/../../aio/timer.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/random.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/wire.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h +../deps/nanomsg/src/protocols/reqrep/req.c: +../deps/nanomsg/src/protocols/reqrep/req.h: +../deps/nanomsg/src/protocols/reqrep/xreq.h: +../deps/nanomsg/src/protocols/reqrep/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/reqrep/../utils/lb.h: +../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h: +../deps/nanomsg/src/protocols/reqrep/../utils/fq.h: +../deps/nanomsg/src/protocols/reqrep/task.h: +../deps/nanomsg/src/protocols/reqrep/../../reqrep.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/protocols/reqrep/../../aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/protocols/reqrep/../../aio/timer.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/random.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/wire.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o.d new file mode 100644 index 0000000..790cff9 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o.d @@ -0,0 +1,44 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o ../deps/nanomsg/src/protocols/reqrep/task.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o: \ + ../deps/nanomsg/src/protocols/reqrep/task.c \ + ../deps/nanomsg/src/protocols/reqrep/task.h \ + ../deps/nanomsg/src/protocols/reqrep/../../reqrep.h \ + ../deps/nanomsg/src/nn.h \ + ../deps/nanomsg/src/protocols/reqrep/../../aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/protocols/reqrep/../../aio/timer.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h +../deps/nanomsg/src/protocols/reqrep/task.c: +../deps/nanomsg/src/protocols/reqrep/task.h: +../deps/nanomsg/src/protocols/reqrep/../../reqrep.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/protocols/reqrep/../../aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/protocols/reqrep/../../aio/timer.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o.d new file mode 100644 index 0000000..ee5cb68 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o.d @@ -0,0 +1,38 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o ../deps/nanomsg/src/protocols/reqrep/xrep.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o: \ + ../deps/nanomsg/src/protocols/reqrep/xrep.c \ + ../deps/nanomsg/src/protocols/reqrep/xrep.h \ + ../deps/nanomsg/src/protocols/reqrep/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/hash.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/fq.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/reqrep/../../nn.h \ + ../deps/nanomsg/src/protocols/reqrep/../../reqrep.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/random.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/wire.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h +../deps/nanomsg/src/protocols/reqrep/xrep.c: +../deps/nanomsg/src/protocols/reqrep/xrep.h: +../deps/nanomsg/src/protocols/reqrep/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/hash.h: +../deps/nanomsg/src/protocols/reqrep/../utils/fq.h: +../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h: +../deps/nanomsg/src/protocols/reqrep/../../nn.h: +../deps/nanomsg/src/protocols/reqrep/../../reqrep.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/random.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/wire.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o.d new file mode 100644 index 0000000..6b79b46 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o.d @@ -0,0 +1,34 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o ../deps/nanomsg/src/protocols/reqrep/xreq.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o: \ + ../deps/nanomsg/src/protocols/reqrep/xreq.c \ + ../deps/nanomsg/src/protocols/reqrep/xreq.h \ + ../deps/nanomsg/src/protocols/reqrep/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/lb.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/reqrep/../utils/fq.h \ + ../deps/nanomsg/src/protocols/reqrep/../../nn.h \ + ../deps/nanomsg/src/protocols/reqrep/../../reqrep.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h +../deps/nanomsg/src/protocols/reqrep/xreq.c: +../deps/nanomsg/src/protocols/reqrep/xreq.h: +../deps/nanomsg/src/protocols/reqrep/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/reqrep/../utils/lb.h: +../deps/nanomsg/src/protocols/reqrep/../utils/priolist.h: +../deps/nanomsg/src/protocols/reqrep/../utils/fq.h: +../deps/nanomsg/src/protocols/reqrep/../../nn.h: +../deps/nanomsg/src/protocols/reqrep/../../reqrep.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/cont.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/alloc.h: +../deps/nanomsg/src/protocols/reqrep/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o.d new file mode 100644 index 0000000..79d9716 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o.d @@ -0,0 +1,36 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o ../deps/nanomsg/src/protocols/survey/respondent.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o: \ + ../deps/nanomsg/src/protocols/survey/respondent.c \ + ../deps/nanomsg/src/protocols/survey/respondent.h \ + ../deps/nanomsg/src/protocols/survey/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/survey/xrespondent.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/hash.h \ + ../deps/nanomsg/src/protocols/survey/../utils/fq.h \ + ../deps/nanomsg/src/protocols/survey/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/survey/../../nn.h \ + ../deps/nanomsg/src/protocols/survey/../../survey.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/wire.h +../deps/nanomsg/src/protocols/survey/respondent.c: +../deps/nanomsg/src/protocols/survey/respondent.h: +../deps/nanomsg/src/protocols/survey/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/survey/xrespondent.h: +../deps/nanomsg/src/protocols/survey/../../utils/hash.h: +../deps/nanomsg/src/protocols/survey/../utils/fq.h: +../deps/nanomsg/src/protocols/survey/../utils/priolist.h: +../deps/nanomsg/src/protocols/survey/../../nn.h: +../deps/nanomsg/src/protocols/survey/../../survey.h: +../deps/nanomsg/src/protocols/survey/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/survey/../../utils/cont.h: +../deps/nanomsg/src/protocols/survey/../../utils/alloc.h: +../deps/nanomsg/src/protocols/survey/../../utils/wire.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o.d new file mode 100644 index 0000000..c94a48d --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o.d @@ -0,0 +1,65 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o ../deps/nanomsg/src/protocols/survey/surveyor.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o: \ + ../deps/nanomsg/src/protocols/survey/surveyor.c \ + ../deps/nanomsg/src/protocols/survey/surveyor.h \ + ../deps/nanomsg/src/protocols/survey/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/survey/xsurveyor.h \ + ../deps/nanomsg/src/protocols/survey/../utils/dist.h \ + ../deps/nanomsg/src/protocols/survey/../utils/fq.h \ + ../deps/nanomsg/src/protocols/survey/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/survey/../../nn.h \ + ../deps/nanomsg/src/protocols/survey/../../survey.h \ + ../deps/nanomsg/src/protocols/survey/../../aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/protocols/survey/../../aio/timer.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/wire.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/random.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/attr.h +../deps/nanomsg/src/protocols/survey/surveyor.c: +../deps/nanomsg/src/protocols/survey/surveyor.h: +../deps/nanomsg/src/protocols/survey/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/survey/xsurveyor.h: +../deps/nanomsg/src/protocols/survey/../utils/dist.h: +../deps/nanomsg/src/protocols/survey/../utils/fq.h: +../deps/nanomsg/src/protocols/survey/../utils/priolist.h: +../deps/nanomsg/src/protocols/survey/../../nn.h: +../deps/nanomsg/src/protocols/survey/../../survey.h: +../deps/nanomsg/src/protocols/survey/../../aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/protocols/survey/../../aio/timer.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/protocols/survey/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/survey/../../utils/cont.h: +../deps/nanomsg/src/protocols/survey/../../utils/wire.h: +../deps/nanomsg/src/protocols/survey/../../utils/alloc.h: +../deps/nanomsg/src/protocols/survey/../../utils/random.h: +../deps/nanomsg/src/protocols/survey/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o.d new file mode 100644 index 0000000..b9b5761 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o.d @@ -0,0 +1,38 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o ../deps/nanomsg/src/protocols/survey/xrespondent.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o: \ + ../deps/nanomsg/src/protocols/survey/xrespondent.c \ + ../deps/nanomsg/src/protocols/survey/xrespondent.h \ + ../deps/nanomsg/src/protocols/survey/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/hash.h \ + ../deps/nanomsg/src/protocols/survey/../utils/fq.h \ + ../deps/nanomsg/src/protocols/survey/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/survey/../../nn.h \ + ../deps/nanomsg/src/protocols/survey/../../survey.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/random.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/wire.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/attr.h +../deps/nanomsg/src/protocols/survey/xrespondent.c: +../deps/nanomsg/src/protocols/survey/xrespondent.h: +../deps/nanomsg/src/protocols/survey/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/survey/../../utils/hash.h: +../deps/nanomsg/src/protocols/survey/../utils/fq.h: +../deps/nanomsg/src/protocols/survey/../utils/priolist.h: +../deps/nanomsg/src/protocols/survey/../../nn.h: +../deps/nanomsg/src/protocols/survey/../../survey.h: +../deps/nanomsg/src/protocols/survey/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/survey/../../utils/cont.h: +../deps/nanomsg/src/protocols/survey/../../utils/alloc.h: +../deps/nanomsg/src/protocols/survey/../../utils/random.h: +../deps/nanomsg/src/protocols/survey/../../utils/wire.h: +../deps/nanomsg/src/protocols/survey/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o.d new file mode 100644 index 0000000..bc6703c --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o.d @@ -0,0 +1,34 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o ../deps/nanomsg/src/protocols/survey/xsurveyor.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o: \ + ../deps/nanomsg/src/protocols/survey/xsurveyor.c \ + ../deps/nanomsg/src/protocols/survey/xsurveyor.h \ + ../deps/nanomsg/src/protocols/survey/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/survey/../utils/dist.h \ + ../deps/nanomsg/src/protocols/survey/../utils/fq.h \ + ../deps/nanomsg/src/protocols/survey/../utils/priolist.h \ + ../deps/nanomsg/src/protocols/survey/../../nn.h \ + ../deps/nanomsg/src/protocols/survey/../../survey.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/alloc.h \ + ../deps/nanomsg/src/protocols/survey/../../utils/attr.h +../deps/nanomsg/src/protocols/survey/xsurveyor.c: +../deps/nanomsg/src/protocols/survey/xsurveyor.h: +../deps/nanomsg/src/protocols/survey/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/survey/../utils/dist.h: +../deps/nanomsg/src/protocols/survey/../utils/fq.h: +../deps/nanomsg/src/protocols/survey/../utils/priolist.h: +../deps/nanomsg/src/protocols/survey/../../nn.h: +../deps/nanomsg/src/protocols/survey/../../survey.h: +../deps/nanomsg/src/protocols/survey/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/survey/../../utils/cont.h: +../deps/nanomsg/src/protocols/survey/../../utils/alloc.h: +../deps/nanomsg/src/protocols/survey/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o.d new file mode 100644 index 0000000..ee5b05c --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o.d @@ -0,0 +1,23 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o ../deps/nanomsg/src/protocols/utils/dist.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o: \ + ../deps/nanomsg/src/protocols/utils/dist.c \ + ../deps/nanomsg/src/protocols/utils/dist.h \ + ../deps/nanomsg/src/protocols/utils/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/attr.h +../deps/nanomsg/src/protocols/utils/dist.c: +../deps/nanomsg/src/protocols/utils/dist.h: +../deps/nanomsg/src/protocols/utils/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/utils/../../utils/cont.h: +../deps/nanomsg/src/protocols/utils/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o.d new file mode 100644 index 0000000..3a7ef9e --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o.d @@ -0,0 +1,22 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o ../deps/nanomsg/src/protocols/utils/excl.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o: \ + ../deps/nanomsg/src/protocols/utils/excl.c \ + ../deps/nanomsg/src/protocols/utils/excl.h \ + ../deps/nanomsg/src/protocols/utils/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/fast.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/attr.h +../deps/nanomsg/src/protocols/utils/excl.c: +../deps/nanomsg/src/protocols/utils/excl.h: +../deps/nanomsg/src/protocols/utils/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/utils/../../utils/fast.h: +../deps/nanomsg/src/protocols/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/protocols/utils/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o.d new file mode 100644 index 0000000..ddc3ada --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o.d @@ -0,0 +1,23 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o ../deps/nanomsg/src/protocols/utils/fq.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o: \ + ../deps/nanomsg/src/protocols/utils/fq.c \ + ../deps/nanomsg/src/protocols/utils/fq.h \ + ../deps/nanomsg/src/protocols/utils/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/utils/priolist.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/cont.h +../deps/nanomsg/src/protocols/utils/fq.c: +../deps/nanomsg/src/protocols/utils/fq.h: +../deps/nanomsg/src/protocols/utils/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/utils/priolist.h: +../deps/nanomsg/src/protocols/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/utils/../../utils/cont.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o.d new file mode 100644 index 0000000..bb911fb --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o.d @@ -0,0 +1,23 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o ../deps/nanomsg/src/protocols/utils/lb.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o: \ + ../deps/nanomsg/src/protocols/utils/lb.c \ + ../deps/nanomsg/src/protocols/utils/lb.h \ + ../deps/nanomsg/src/protocols/utils/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/utils/priolist.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/cont.h +../deps/nanomsg/src/protocols/utils/lb.c: +../deps/nanomsg/src/protocols/utils/lb.h: +../deps/nanomsg/src/protocols/utils/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/utils/priolist.h: +../deps/nanomsg/src/protocols/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/protocols/utils/../../utils/cont.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o.d new file mode 100644 index 0000000..c652550 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o.d @@ -0,0 +1,24 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o ../deps/nanomsg/src/protocols/utils/priolist.c +Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o: \ + ../deps/nanomsg/src/protocols/utils/priolist.c \ + ../deps/nanomsg/src/protocols/utils/priolist.h \ + ../deps/nanomsg/src/protocols/utils/../../protocol.h \ + ../deps/nanomsg/src/utils/msg.h ../deps/nanomsg/src/utils/chunkref.h \ + ../deps/nanomsg/src/utils/chunk.h ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/cont.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/fast.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/protocols/utils/../../utils/attr.h +../deps/nanomsg/src/protocols/utils/priolist.c: +../deps/nanomsg/src/protocols/utils/priolist.h: +../deps/nanomsg/src/protocols/utils/../../protocol.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/protocols/utils/../../utils/cont.h: +../deps/nanomsg/src/protocols/utils/../../utils/fast.h: +../deps/nanomsg/src/protocols/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/protocols/utils/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o.d new file mode 100644 index 0000000..f1efa41 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o.d @@ -0,0 +1,35 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o ../deps/nanomsg/src/transports/inproc/binproc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o: \ + ../deps/nanomsg/src/transports/inproc/binproc.c \ + ../deps/nanomsg/src/transports/inproc/binproc.h \ + ../deps/nanomsg/src/transports/inproc/ins.h \ + ../deps/nanomsg/src/transports/inproc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/inproc/sinproc.h \ + ../deps/nanomsg/src/transports/inproc/msgqueue.h \ + ../deps/nanomsg/src/transports/inproc/cinproc.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/alloc.h +../deps/nanomsg/src/transports/inproc/binproc.c: +../deps/nanomsg/src/transports/inproc/binproc.h: +../deps/nanomsg/src/transports/inproc/ins.h: +../deps/nanomsg/src/transports/inproc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/inproc/sinproc.h: +../deps/nanomsg/src/transports/inproc/msgqueue.h: +../deps/nanomsg/src/transports/inproc/cinproc.h: +../deps/nanomsg/src/transports/inproc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/inproc/../../utils/cont.h: +../deps/nanomsg/src/transports/inproc/../../utils/alloc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o.d new file mode 100644 index 0000000..d7d499f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o.d @@ -0,0 +1,37 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o ../deps/nanomsg/src/transports/inproc/cinproc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o: \ + ../deps/nanomsg/src/transports/inproc/cinproc.c \ + ../deps/nanomsg/src/transports/inproc/cinproc.h \ + ../deps/nanomsg/src/transports/inproc/ins.h \ + ../deps/nanomsg/src/transports/inproc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/inproc/sinproc.h \ + ../deps/nanomsg/src/transports/inproc/msgqueue.h \ + ../deps/nanomsg/src/transports/inproc/binproc.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/attr.h +../deps/nanomsg/src/transports/inproc/cinproc.c: +../deps/nanomsg/src/transports/inproc/cinproc.h: +../deps/nanomsg/src/transports/inproc/ins.h: +../deps/nanomsg/src/transports/inproc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/inproc/sinproc.h: +../deps/nanomsg/src/transports/inproc/msgqueue.h: +../deps/nanomsg/src/transports/inproc/binproc.h: +../deps/nanomsg/src/transports/inproc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/inproc/../../utils/cont.h: +../deps/nanomsg/src/transports/inproc/../../utils/alloc.h: +../deps/nanomsg/src/transports/inproc/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o.d new file mode 100644 index 0000000..a5a7f9f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o.d @@ -0,0 +1,31 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o ../deps/nanomsg/src/transports/inproc/inproc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o: \ + ../deps/nanomsg/src/transports/inproc/inproc.c \ + ../deps/nanomsg/src/transports/inproc/inproc.h \ + ../deps/nanomsg/src/transports/inproc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/inproc/ins.h \ + ../deps/nanomsg/src/transports/inproc/binproc.h \ + ../deps/nanomsg/src/transports/inproc/cinproc.h \ + ../deps/nanomsg/src/transports/inproc/sinproc.h \ + ../deps/nanomsg/src/transports/inproc/msgqueue.h \ + ../deps/nanomsg/src/transports/inproc/../../inproc.h +../deps/nanomsg/src/transports/inproc/inproc.c: +../deps/nanomsg/src/transports/inproc/inproc.h: +../deps/nanomsg/src/transports/inproc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/inproc/ins.h: +../deps/nanomsg/src/transports/inproc/binproc.h: +../deps/nanomsg/src/transports/inproc/cinproc.h: +../deps/nanomsg/src/transports/inproc/sinproc.h: +../deps/nanomsg/src/transports/inproc/msgqueue.h: +../deps/nanomsg/src/transports/inproc/../../inproc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o.d new file mode 100644 index 0000000..b2d9dea --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o.d @@ -0,0 +1,29 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o ../deps/nanomsg/src/transports/inproc/ins.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o: \ + ../deps/nanomsg/src/transports/inproc/ins.c \ + ../deps/nanomsg/src/transports/inproc/ins.h \ + ../deps/nanomsg/src/transports/inproc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/mutex.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/fast.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/err.h +../deps/nanomsg/src/transports/inproc/ins.c: +../deps/nanomsg/src/transports/inproc/ins.h: +../deps/nanomsg/src/transports/inproc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/inproc/../../utils/mutex.h: +../deps/nanomsg/src/transports/inproc/../../utils/alloc.h: +../deps/nanomsg/src/transports/inproc/../../utils/cont.h: +../deps/nanomsg/src/transports/inproc/../../utils/fast.h: +../deps/nanomsg/src/transports/inproc/../../utils/err.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o.d new file mode 100644 index 0000000..8c60a39 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o.d @@ -0,0 +1,19 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o ../deps/nanomsg/src/transports/inproc/msgqueue.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o: \ + ../deps/nanomsg/src/transports/inproc/msgqueue.c \ + ../deps/nanomsg/src/transports/inproc/msgqueue.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/fast.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h +../deps/nanomsg/src/transports/inproc/msgqueue.c: +../deps/nanomsg/src/transports/inproc/msgqueue.h: +../deps/nanomsg/src/transports/inproc/../../utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/inproc/../../utils/alloc.h: +../deps/nanomsg/src/transports/inproc/../../utils/fast.h: +../deps/nanomsg/src/transports/inproc/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o.d new file mode 100644 index 0000000..cccb2a0 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o.d @@ -0,0 +1,30 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o ../deps/nanomsg/src/transports/inproc/sinproc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o: \ + ../deps/nanomsg/src/transports/inproc/sinproc.c \ + ../deps/nanomsg/src/transports/inproc/sinproc.h \ + ../deps/nanomsg/src/transports/inproc/msgqueue.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/inproc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/inproc/../../utils/attr.h +../deps/nanomsg/src/transports/inproc/sinproc.c: +../deps/nanomsg/src/transports/inproc/sinproc.h: +../deps/nanomsg/src/transports/inproc/msgqueue.h: +../deps/nanomsg/src/transports/inproc/../../utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/inproc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/transports/inproc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/inproc/../../utils/cont.h: +../deps/nanomsg/src/transports/inproc/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o.d new file mode 100644 index 0000000..f420c5b --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o.d @@ -0,0 +1,58 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o ../deps/nanomsg/src/transports/ipc/aipc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o: \ + ../deps/nanomsg/src/transports/ipc/aipc.c \ + ../deps/nanomsg/src/transports/ipc/aipc.h \ + ../deps/nanomsg/src/transports/ipc/sipc.h \ + ../deps/nanomsg/src/transports/ipc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ipc/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ipc/../../ipc.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/attr.h +../deps/nanomsg/src/transports/ipc/aipc.c: +../deps/nanomsg/src/transports/ipc/aipc.h: +../deps/nanomsg/src/transports/ipc/sipc.h: +../deps/nanomsg/src/transports/ipc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ipc/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h: +../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/ipc/../../ipc.h: +../deps/nanomsg/src/transports/ipc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ipc/../../utils/cont.h: +../deps/nanomsg/src/transports/ipc/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o.d new file mode 100644 index 0000000..d058867 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o.d @@ -0,0 +1,60 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o ../deps/nanomsg/src/transports/ipc/bipc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o: \ + ../deps/nanomsg/src/transports/ipc/bipc.c \ + ../deps/nanomsg/src/transports/ipc/bipc.h \ + ../deps/nanomsg/src/transports/ipc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ipc/aipc.h \ + ../deps/nanomsg/src/transports/ipc/sipc.h \ + ../deps/nanomsg/src/transports/ipc/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ipc/../../ipc.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/alloc.h +../deps/nanomsg/src/transports/ipc/bipc.c: +../deps/nanomsg/src/transports/ipc/bipc.h: +../deps/nanomsg/src/transports/ipc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ipc/aipc.h: +../deps/nanomsg/src/transports/ipc/sipc.h: +../deps/nanomsg/src/transports/ipc/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h: +../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/ipc/../../ipc.h: +../deps/nanomsg/src/transports/ipc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ipc/../../utils/cont.h: +../deps/nanomsg/src/transports/ipc/../../utils/alloc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o.d new file mode 100644 index 0000000..5d97786 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o.d @@ -0,0 +1,62 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o ../deps/nanomsg/src/transports/ipc/cipc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o: \ + ../deps/nanomsg/src/transports/ipc/cipc.c \ + ../deps/nanomsg/src/transports/ipc/cipc.h \ + ../deps/nanomsg/src/transports/ipc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ipc/../../ipc.h \ + ../deps/nanomsg/src/transports/ipc/sipc.h \ + ../deps/nanomsg/src/transports/ipc/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ipc/../utils/backoff.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/attr.h +../deps/nanomsg/src/transports/ipc/cipc.c: +../deps/nanomsg/src/transports/ipc/cipc.h: +../deps/nanomsg/src/transports/ipc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ipc/../../ipc.h: +../deps/nanomsg/src/transports/ipc/sipc.h: +../deps/nanomsg/src/transports/ipc/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h: +../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/ipc/../utils/backoff.h: +../deps/nanomsg/src/transports/ipc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ipc/../../utils/cont.h: +../deps/nanomsg/src/transports/ipc/../../utils/alloc.h: +../deps/nanomsg/src/transports/ipc/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o.d new file mode 100644 index 0000000..cdd48cf --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o.d @@ -0,0 +1,33 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o ../deps/nanomsg/src/transports/ipc/ipc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o: \ + ../deps/nanomsg/src/transports/ipc/ipc.c \ + ../deps/nanomsg/src/transports/ipc/ipc.h \ + ../deps/nanomsg/src/transports/ipc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ipc/bipc.h \ + ../deps/nanomsg/src/transports/ipc/cipc.h \ + ../deps/nanomsg/src/transports/ipc/../../ipc.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/cont.h +../deps/nanomsg/src/transports/ipc/ipc.c: +../deps/nanomsg/src/transports/ipc/ipc.h: +../deps/nanomsg/src/transports/ipc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ipc/bipc.h: +../deps/nanomsg/src/transports/ipc/cipc.h: +../deps/nanomsg/src/transports/ipc/../../ipc.h: +../deps/nanomsg/src/transports/ipc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ipc/../../utils/alloc.h: +../deps/nanomsg/src/transports/ipc/../../utils/cont.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o.d new file mode 100644 index 0000000..eb89796 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o.d @@ -0,0 +1,56 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o ../deps/nanomsg/src/transports/ipc/sipc.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o: \ + ../deps/nanomsg/src/transports/ipc/sipc.c \ + ../deps/nanomsg/src/transports/ipc/sipc.h \ + ../deps/nanomsg/src/transports/ipc/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ipc/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/wire.h \ + ../deps/nanomsg/src/transports/ipc/../../utils/attr.h +../deps/nanomsg/src/transports/ipc/sipc.c: +../deps/nanomsg/src/transports/ipc/sipc.h: +../deps/nanomsg/src/transports/ipc/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ipc/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ipc/../utils/streamhdr.h: +../deps/nanomsg/src/transports/ipc/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/ipc/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ipc/../../utils/cont.h: +../deps/nanomsg/src/transports/ipc/../../utils/wire.h: +../deps/nanomsg/src/transports/ipc/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o.d new file mode 100644 index 0000000..3445f70 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o.d @@ -0,0 +1,56 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o ../deps/nanomsg/src/transports/tcp/atcp.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o: \ + ../deps/nanomsg/src/transports/tcp/atcp.c \ + ../deps/nanomsg/src/transports/tcp/atcp.h \ + ../deps/nanomsg/src/transports/tcp/stcp.h \ + ../deps/nanomsg/src/transports/tcp/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/tcp/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/cont.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/attr.h +../deps/nanomsg/src/transports/tcp/atcp.c: +../deps/nanomsg/src/transports/tcp/atcp.h: +../deps/nanomsg/src/transports/tcp/stcp.h: +../deps/nanomsg/src/transports/tcp/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/tcp/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h: +../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/tcp/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/tcp/../../utils/cont.h: +../deps/nanomsg/src/transports/tcp/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o.d new file mode 100644 index 0000000..f476a6b --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o.d @@ -0,0 +1,64 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o ../deps/nanomsg/src/transports/tcp/btcp.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o: \ + ../deps/nanomsg/src/transports/tcp/btcp.c \ + ../deps/nanomsg/src/transports/tcp/btcp.h \ + ../deps/nanomsg/src/transports/tcp/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/tcp/atcp.h \ + ../deps/nanomsg/src/transports/tcp/stcp.h \ + ../deps/nanomsg/src/transports/tcp/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/tcp/../utils/port.h \ + ../deps/nanomsg/src/transports/tcp/../utils/iface.h \ + ../deps/nanomsg/src/transports/tcp/../utils/backoff.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/cont.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/alloc.h +../deps/nanomsg/src/transports/tcp/btcp.c: +../deps/nanomsg/src/transports/tcp/btcp.h: +../deps/nanomsg/src/transports/tcp/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/tcp/atcp.h: +../deps/nanomsg/src/transports/tcp/stcp.h: +../deps/nanomsg/src/transports/tcp/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h: +../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/tcp/../utils/port.h: +../deps/nanomsg/src/transports/tcp/../utils/iface.h: +../deps/nanomsg/src/transports/tcp/../utils/backoff.h: +../deps/nanomsg/src/transports/tcp/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/tcp/../../utils/cont.h: +../deps/nanomsg/src/transports/tcp/../../utils/alloc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o.d new file mode 100644 index 0000000..bf2bef5 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o.d @@ -0,0 +1,72 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o ../deps/nanomsg/src/transports/tcp/ctcp.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o: \ + ../deps/nanomsg/src/transports/tcp/ctcp.c \ + ../deps/nanomsg/src/transports/tcp/ctcp.h \ + ../deps/nanomsg/src/transports/tcp/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/tcp/stcp.h \ + ../deps/nanomsg/src/transports/tcp/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/tcp/../../tcp.h \ + ../deps/nanomsg/src/transports/tcp/../utils/dns.h \ + ../deps/nanomsg/src/transports/tcp/../utils/dns_getaddrinfo.h \ + ../deps/nanomsg/src/transports/tcp/../utils/port.h \ + ../deps/nanomsg/src/transports/tcp/../utils/iface.h \ + ../deps/nanomsg/src/transports/tcp/../utils/backoff.h \ + ../deps/nanomsg/src/transports/tcp/../utils/literal.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/cont.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/attr.h +../deps/nanomsg/src/transports/tcp/ctcp.c: +../deps/nanomsg/src/transports/tcp/ctcp.h: +../deps/nanomsg/src/transports/tcp/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/tcp/stcp.h: +../deps/nanomsg/src/transports/tcp/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h: +../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/tcp/../../tcp.h: +../deps/nanomsg/src/transports/tcp/../utils/dns.h: +../deps/nanomsg/src/transports/tcp/../utils/dns_getaddrinfo.h: +../deps/nanomsg/src/transports/tcp/../utils/port.h: +../deps/nanomsg/src/transports/tcp/../utils/iface.h: +../deps/nanomsg/src/transports/tcp/../utils/backoff.h: +../deps/nanomsg/src/transports/tcp/../utils/literal.h: +../deps/nanomsg/src/transports/tcp/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/tcp/../../utils/cont.h: +../deps/nanomsg/src/transports/tcp/../../utils/alloc.h: +../deps/nanomsg/src/transports/tcp/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o.d new file mode 100644 index 0000000..9f76a86 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o.d @@ -0,0 +1,56 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o ../deps/nanomsg/src/transports/tcp/stcp.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o: \ + ../deps/nanomsg/src/transports/tcp/stcp.c \ + ../deps/nanomsg/src/transports/tcp/stcp.h \ + ../deps/nanomsg/src/transports/tcp/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/tcp/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h \ + ../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/cont.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/wire.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/attr.h +../deps/nanomsg/src/transports/tcp/stcp.c: +../deps/nanomsg/src/transports/tcp/stcp.h: +../deps/nanomsg/src/transports/tcp/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/tcp/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/tcp/../utils/streamhdr.h: +../deps/nanomsg/src/transports/tcp/../utils/../../aio/timer.h: +../deps/nanomsg/src/transports/tcp/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/tcp/../../utils/cont.h: +../deps/nanomsg/src/transports/tcp/../../utils/wire.h: +../deps/nanomsg/src/transports/tcp/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o.d new file mode 100644 index 0000000..e24e895 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o.d @@ -0,0 +1,37 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o ../deps/nanomsg/src/transports/tcp/tcp.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o: \ + ../deps/nanomsg/src/transports/tcp/tcp.c \ + ../deps/nanomsg/src/transports/tcp/tcp.h \ + ../deps/nanomsg/src/transports/tcp/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/tcp/btcp.h \ + ../deps/nanomsg/src/transports/tcp/ctcp.h \ + ../deps/nanomsg/src/transports/tcp/../../tcp.h \ + ../deps/nanomsg/src/transports/tcp/../utils/port.h \ + ../deps/nanomsg/src/transports/tcp/../utils/iface.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/tcp/../../utils/cont.h +../deps/nanomsg/src/transports/tcp/tcp.c: +../deps/nanomsg/src/transports/tcp/tcp.h: +../deps/nanomsg/src/transports/tcp/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/tcp/btcp.h: +../deps/nanomsg/src/transports/tcp/ctcp.h: +../deps/nanomsg/src/transports/tcp/../../tcp.h: +../deps/nanomsg/src/transports/tcp/../utils/port.h: +../deps/nanomsg/src/transports/tcp/../utils/iface.h: +../deps/nanomsg/src/transports/tcp/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/tcp/../../utils/alloc.h: +../deps/nanomsg/src/transports/tcp/../../utils/cont.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o.d new file mode 100644 index 0000000..6825710 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o.d @@ -0,0 +1,32 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o ../deps/nanomsg/src/transports/utils/backoff.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o: \ + ../deps/nanomsg/src/transports/utils/backoff.c \ + ../deps/nanomsg/src/transports/utils/backoff.h \ + ../deps/nanomsg/src/transports/utils/../../aio/timer.h \ + ../deps/nanomsg/src/aio/fsm.h ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/aio/worker.h ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/../utils/list.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h +../deps/nanomsg/src/transports/utils/backoff.c: +../deps/nanomsg/src/transports/utils/backoff.h: +../deps/nanomsg/src/transports/utils/../../aio/timer.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/../utils/list.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o.d new file mode 100644 index 0000000..dc923e4 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o ../deps/nanomsg/src/transports/utils/base64.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o: \ + ../deps/nanomsg/src/transports/utils/base64.c \ + ../deps/nanomsg/src/transports/utils/base64.h \ + ../deps/nanomsg/src/transports/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/transports/utils/base64.c: +../deps/nanomsg/src/transports/utils/base64.h: +../deps/nanomsg/src/transports/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o.d new file mode 100644 index 0000000..e2fd4f0 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o.d @@ -0,0 +1,25 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o ../deps/nanomsg/src/transports/utils/dns.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o: \ + ../deps/nanomsg/src/transports/utils/dns.c \ + ../deps/nanomsg/src/transports/utils/dns.h \ + ../deps/nanomsg/src/transports/utils/../../aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/transports/utils/dns_getaddrinfo.h \ + ../deps/nanomsg/src/transports/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/utils/dns_getaddrinfo.inc \ + ../deps/nanomsg/src/transports/utils/literal.h \ + ../deps/nanomsg/src/transports/utils/../../utils/cont.h \ + ../deps/nanomsg/src/transports/utils/../../utils/attr.h +../deps/nanomsg/src/transports/utils/dns.c: +../deps/nanomsg/src/transports/utils/dns.h: +../deps/nanomsg/src/transports/utils/../../aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/transports/utils/dns_getaddrinfo.h: +../deps/nanomsg/src/transports/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/utils/dns_getaddrinfo.inc: +../deps/nanomsg/src/transports/utils/literal.h: +../deps/nanomsg/src/transports/utils/../../utils/cont.h: +../deps/nanomsg/src/transports/utils/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o.d new file mode 100644 index 0000000..0bb2090 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o.d @@ -0,0 +1,15 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o ../deps/nanomsg/src/transports/utils/iface.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o: \ + ../deps/nanomsg/src/transports/utils/iface.c \ + ../deps/nanomsg/src/transports/utils/iface.h \ + ../deps/nanomsg/src/transports/utils/literal.h \ + ../deps/nanomsg/src/transports/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/utils/../../utils/closefd.h +../deps/nanomsg/src/transports/utils/iface.c: +../deps/nanomsg/src/transports/utils/iface.h: +../deps/nanomsg/src/transports/utils/literal.h: +../deps/nanomsg/src/transports/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/utils/../../utils/closefd.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o.d new file mode 100644 index 0000000..b254e83 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o ../deps/nanomsg/src/transports/utils/literal.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o: \ + ../deps/nanomsg/src/transports/utils/literal.c \ + ../deps/nanomsg/src/transports/utils/literal.h \ + ../deps/nanomsg/src/transports/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/transports/utils/literal.c: +../deps/nanomsg/src/transports/utils/literal.h: +../deps/nanomsg/src/transports/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o.d new file mode 100644 index 0000000..42362b3 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o ../deps/nanomsg/src/transports/utils/port.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o: \ + ../deps/nanomsg/src/transports/utils/port.c \ + ../deps/nanomsg/src/transports/utils/port.h \ + ../deps/nanomsg/src/transports/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/transports/utils/port.c: +../deps/nanomsg/src/transports/utils/port.h: +../deps/nanomsg/src/transports/utils/../../utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o.d new file mode 100644 index 0000000..f80e196 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o.d @@ -0,0 +1,54 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o ../deps/nanomsg/src/transports/utils/streamhdr.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o: \ + ../deps/nanomsg/src/transports/utils/streamhdr.c \ + ../deps/nanomsg/src/transports/utils/streamhdr.h \ + ../deps/nanomsg/src/transports/utils/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/utils/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/utils/../../aio/timer.h \ + ../deps/nanomsg/src/transports/utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/utils/../../utils/cont.h \ + ../deps/nanomsg/src/transports/utils/../../utils/wire.h \ + ../deps/nanomsg/src/transports/utils/../../utils/attr.h +../deps/nanomsg/src/transports/utils/streamhdr.c: +../deps/nanomsg/src/transports/utils/streamhdr.h: +../deps/nanomsg/src/transports/utils/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/utils/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/utils/../../aio/timer.h: +../deps/nanomsg/src/transports/utils/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/utils/../../utils/cont.h: +../deps/nanomsg/src/transports/utils/../../utils/wire.h: +../deps/nanomsg/src/transports/utils/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o.d new file mode 100644 index 0000000..0816ca0 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o.d @@ -0,0 +1,58 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o ../deps/nanomsg/src/transports/ws/aws.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o: \ + ../deps/nanomsg/src/transports/ws/aws.c \ + ../deps/nanomsg/src/transports/ws/aws.h \ + ../deps/nanomsg/src/transports/ws/sws.h \ + ../deps/nanomsg/src/transports/ws/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ws/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ws/ws_handshake.h \ + ../deps/nanomsg/src/transports/ws/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ws/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ws/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ws/../../utils/attr.h \ + ../deps/nanomsg/src/transports/ws/../../ws.h +../deps/nanomsg/src/transports/ws/aws.c: +../deps/nanomsg/src/transports/ws/aws.h: +../deps/nanomsg/src/transports/ws/sws.h: +../deps/nanomsg/src/transports/ws/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ws/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ws/ws_handshake.h: +../deps/nanomsg/src/transports/ws/../../aio/timer.h: +../deps/nanomsg/src/transports/ws/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ws/../../utils/cont.h: +../deps/nanomsg/src/transports/ws/../../utils/attr.h: +../deps/nanomsg/src/transports/ws/../../ws.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o.d new file mode 100644 index 0000000..cf1d4cb --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o.d @@ -0,0 +1,62 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o ../deps/nanomsg/src/transports/ws/bws.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o: \ + ../deps/nanomsg/src/transports/ws/bws.c \ + ../deps/nanomsg/src/transports/ws/bws.h \ + ../deps/nanomsg/src/transports/ws/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ws/aws.h \ + ../deps/nanomsg/src/transports/ws/sws.h \ + ../deps/nanomsg/src/transports/ws/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ws/ws_handshake.h \ + ../deps/nanomsg/src/transports/ws/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ws/../utils/port.h \ + ../deps/nanomsg/src/transports/ws/../utils/iface.h \ + ../deps/nanomsg/src/transports/ws/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ws/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ws/../../utils/alloc.h +../deps/nanomsg/src/transports/ws/bws.c: +../deps/nanomsg/src/transports/ws/bws.h: +../deps/nanomsg/src/transports/ws/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ws/aws.h: +../deps/nanomsg/src/transports/ws/sws.h: +../deps/nanomsg/src/transports/ws/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ws/ws_handshake.h: +../deps/nanomsg/src/transports/ws/../../aio/timer.h: +../deps/nanomsg/src/transports/ws/../utils/port.h: +../deps/nanomsg/src/transports/ws/../utils/iface.h: +../deps/nanomsg/src/transports/ws/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ws/../../utils/cont.h: +../deps/nanomsg/src/transports/ws/../../utils/alloc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o.d new file mode 100644 index 0000000..88ba02c --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o.d @@ -0,0 +1,72 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o ../deps/nanomsg/src/transports/ws/cws.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o: \ + ../deps/nanomsg/src/transports/ws/cws.c \ + ../deps/nanomsg/src/transports/ws/cws.h \ + ../deps/nanomsg/src/transports/ws/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ws/sws.h \ + ../deps/nanomsg/src/transports/ws/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ws/ws_handshake.h \ + ../deps/nanomsg/src/transports/ws/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ws/../../ws.h \ + ../deps/nanomsg/src/transports/ws/../utils/dns.h \ + ../deps/nanomsg/src/transports/ws/../utils/dns_getaddrinfo.h \ + ../deps/nanomsg/src/transports/ws/../utils/port.h \ + ../deps/nanomsg/src/transports/ws/../utils/iface.h \ + ../deps/nanomsg/src/transports/ws/../utils/backoff.h \ + ../deps/nanomsg/src/transports/ws/../utils/literal.h \ + ../deps/nanomsg/src/transports/ws/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ws/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ws/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/ws/../../utils/attr.h +../deps/nanomsg/src/transports/ws/cws.c: +../deps/nanomsg/src/transports/ws/cws.h: +../deps/nanomsg/src/transports/ws/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ws/sws.h: +../deps/nanomsg/src/transports/ws/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ws/ws_handshake.h: +../deps/nanomsg/src/transports/ws/../../aio/timer.h: +../deps/nanomsg/src/transports/ws/../../ws.h: +../deps/nanomsg/src/transports/ws/../utils/dns.h: +../deps/nanomsg/src/transports/ws/../utils/dns_getaddrinfo.h: +../deps/nanomsg/src/transports/ws/../utils/port.h: +../deps/nanomsg/src/transports/ws/../utils/iface.h: +../deps/nanomsg/src/transports/ws/../utils/backoff.h: +../deps/nanomsg/src/transports/ws/../utils/literal.h: +../deps/nanomsg/src/transports/ws/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ws/../../utils/cont.h: +../deps/nanomsg/src/transports/ws/../../utils/alloc.h: +../deps/nanomsg/src/transports/ws/../../utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o.d new file mode 100644 index 0000000..7e99db7 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o.d @@ -0,0 +1,6 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o ../deps/nanomsg/src/transports/ws/sha1.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o: \ + ../deps/nanomsg/src/transports/ws/sha1.c \ + ../deps/nanomsg/src/transports/ws/sha1.h +../deps/nanomsg/src/transports/ws/sha1.c: +../deps/nanomsg/src/transports/ws/sha1.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o.d new file mode 100644 index 0000000..7d04d96 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o.d @@ -0,0 +1,62 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o ../deps/nanomsg/src/transports/ws/sws.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o: \ + ../deps/nanomsg/src/transports/ws/sws.c \ + ../deps/nanomsg/src/transports/ws/sws.h \ + ../deps/nanomsg/src/transports/ws/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ws/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ws/ws_handshake.h \ + ../deps/nanomsg/src/transports/ws/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ws/../../ws.h \ + ../deps/nanomsg/src/transports/ws/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/ws/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ws/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ws/../../utils/wire.h \ + ../deps/nanomsg/src/transports/ws/../../utils/attr.h \ + ../deps/nanomsg/src/transports/ws/../../utils/random.h +../deps/nanomsg/src/transports/ws/sws.c: +../deps/nanomsg/src/transports/ws/sws.h: +../deps/nanomsg/src/transports/ws/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ws/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ws/ws_handshake.h: +../deps/nanomsg/src/transports/ws/../../aio/timer.h: +../deps/nanomsg/src/transports/ws/../../ws.h: +../deps/nanomsg/src/transports/ws/../../utils/alloc.h: +../deps/nanomsg/src/transports/ws/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ws/../../utils/cont.h: +../deps/nanomsg/src/transports/ws/../../utils/wire.h: +../deps/nanomsg/src/transports/ws/../../utils/attr.h: +../deps/nanomsg/src/transports/ws/../../utils/random.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o.d new file mode 100644 index 0000000..580687f --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o.d @@ -0,0 +1,66 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o ../deps/nanomsg/src/transports/ws/ws.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o: \ + ../deps/nanomsg/src/transports/ws/ws.c \ + ../deps/nanomsg/src/transports/ws/ws.h \ + ../deps/nanomsg/src/transports/ws/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ws/bws.h \ + ../deps/nanomsg/src/transports/ws/cws.h \ + ../deps/nanomsg/src/transports/ws/sws.h \ + ../deps/nanomsg/src/transports/ws/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ws/ws_handshake.h \ + ../deps/nanomsg/src/transports/ws/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ws/../../ws.h \ + ../deps/nanomsg/src/transports/ws/../utils/port.h \ + ../deps/nanomsg/src/transports/ws/../utils/iface.h \ + ../deps/nanomsg/src/transports/ws/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ws/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/ws/../../utils/cont.h +../deps/nanomsg/src/transports/ws/ws.c: +../deps/nanomsg/src/transports/ws/ws.h: +../deps/nanomsg/src/transports/ws/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ws/bws.h: +../deps/nanomsg/src/transports/ws/cws.h: +../deps/nanomsg/src/transports/ws/sws.h: +../deps/nanomsg/src/transports/ws/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ws/ws_handshake.h: +../deps/nanomsg/src/transports/ws/../../aio/timer.h: +../deps/nanomsg/src/transports/ws/../../ws.h: +../deps/nanomsg/src/transports/ws/../utils/port.h: +../deps/nanomsg/src/transports/ws/../utils/iface.h: +../deps/nanomsg/src/transports/ws/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ws/../../utils/alloc.h: +../deps/nanomsg/src/transports/ws/../../utils/cont.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o.d new file mode 100644 index 0000000..7a2cf74 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o.d @@ -0,0 +1,83 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o ../deps/nanomsg/src/transports/ws/ws_handshake.c +Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o: \ + ../deps/nanomsg/src/transports/ws/ws_handshake.c \ + ../deps/nanomsg/src/transports/ws/ws_handshake.h \ + ../deps/nanomsg/src/transports/ws/../../transport.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/aio/fsm.h \ + ../deps/nanomsg/src/aio/../utils/queue.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/transports/ws/../../aio/usock.h \ + ../deps/nanomsg/src/aio/usock_posix.h ../deps/nanomsg/src/aio/worker.h \ + ../deps/nanomsg/src/aio/timerset.h \ + ../deps/nanomsg/src/aio/worker_posix.h \ + ../deps/nanomsg/src/aio/../utils/mutex.h \ + ../deps/nanomsg/src/aio/../utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/aio/../utils/efd.h ../deps/nanomsg/src/utils/fd.h \ + ../deps/nanomsg/src/utils/efd_pipe.h ../deps/nanomsg/src/aio/poller.h \ + ../deps/nanomsg/src/aio/poller_kqueue.h \ + ../deps/nanomsg/src/transports/ws/../../aio/timer.h \ + ../deps/nanomsg/src/transports/ws/sha1.h \ + ../deps/nanomsg/src/transports/ws/../../core/sock.h \ + ../deps/nanomsg/src/core/../protocol.h \ + ../deps/nanomsg/src/core/../aio/ctx.h ../deps/nanomsg/src/aio/pool.h \ + ../deps/nanomsg/src/core/../utils/sem.h \ + ../deps/nanomsg/src/transports/ws/../utils/base64.h \ + ../deps/nanomsg/src/transports/ws/../utils/../../utils/err.h \ + ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/transports/ws/../../utils/alloc.h \ + ../deps/nanomsg/src/transports/ws/../../utils/cont.h \ + ../deps/nanomsg/src/transports/ws/../../utils/wire.h \ + ../deps/nanomsg/src/transports/ws/../../utils/attr.h \ + ../deps/nanomsg/src/transports/ws/../../utils/random.h \ + ../deps/nanomsg/src/transports/ws/../../pair.h \ + ../deps/nanomsg/src/transports/ws/../../reqrep.h \ + ../deps/nanomsg/src/transports/ws/../../pubsub.h \ + ../deps/nanomsg/src/transports/ws/../../survey.h \ + ../deps/nanomsg/src/transports/ws/../../pipeline.h \ + ../deps/nanomsg/src/transports/ws/../../bus.h +../deps/nanomsg/src/transports/ws/ws_handshake.c: +../deps/nanomsg/src/transports/ws/ws_handshake.h: +../deps/nanomsg/src/transports/ws/../../transport.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/aio/fsm.h: +../deps/nanomsg/src/aio/../utils/queue.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/transports/ws/../../aio/usock.h: +../deps/nanomsg/src/aio/usock_posix.h: +../deps/nanomsg/src/aio/worker.h: +../deps/nanomsg/src/aio/timerset.h: +../deps/nanomsg/src/aio/worker_posix.h: +../deps/nanomsg/src/aio/../utils/mutex.h: +../deps/nanomsg/src/aio/../utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/aio/../utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/aio/poller.h: +../deps/nanomsg/src/aio/poller_kqueue.h: +../deps/nanomsg/src/transports/ws/../../aio/timer.h: +../deps/nanomsg/src/transports/ws/sha1.h: +../deps/nanomsg/src/transports/ws/../../core/sock.h: +../deps/nanomsg/src/core/../protocol.h: +../deps/nanomsg/src/core/../aio/ctx.h: +../deps/nanomsg/src/aio/pool.h: +../deps/nanomsg/src/core/../utils/sem.h: +../deps/nanomsg/src/transports/ws/../utils/base64.h: +../deps/nanomsg/src/transports/ws/../utils/../../utils/err.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/transports/ws/../../utils/alloc.h: +../deps/nanomsg/src/transports/ws/../../utils/cont.h: +../deps/nanomsg/src/transports/ws/../../utils/wire.h: +../deps/nanomsg/src/transports/ws/../../utils/attr.h: +../deps/nanomsg/src/transports/ws/../../utils/random.h: +../deps/nanomsg/src/transports/ws/../../pair.h: +../deps/nanomsg/src/transports/ws/../../reqrep.h: +../deps/nanomsg/src/transports/ws/../../pubsub.h: +../deps/nanomsg/src/transports/ws/../../survey.h: +../deps/nanomsg/src/transports/ws/../../pipeline.h: +../deps/nanomsg/src/transports/ws/../../bus.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o.d new file mode 100644 index 0000000..f184935 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o.d @@ -0,0 +1,5 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o ../deps/nanomsg/src/utils/alloc.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o: \ + ../deps/nanomsg/src/utils/alloc.c ../deps/nanomsg/src/utils/alloc.h +../deps/nanomsg/src/utils/alloc.c: +../deps/nanomsg/src/utils/alloc.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o.d new file mode 100644 index 0000000..f52a8c9 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o ../deps/nanomsg/src/utils/atomic.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o: \ + ../deps/nanomsg/src/utils/atomic.c ../deps/nanomsg/src/utils/atomic.h \ + ../deps/nanomsg/src/utils/mutex.h ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/atomic.c: +../deps/nanomsg/src/utils/atomic.h: +../deps/nanomsg/src/utils/mutex.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o.d new file mode 100644 index 0000000..dfde669 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o.d @@ -0,0 +1,16 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o ../deps/nanomsg/src/utils/chunk.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o: \ + ../deps/nanomsg/src/utils/chunk.c ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/utils/atomic.h ../deps/nanomsg/src/utils/mutex.h \ + ../deps/nanomsg/src/utils/alloc.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/utils/wire.h ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h +../deps/nanomsg/src/utils/chunk.c: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/atomic.h: +../deps/nanomsg/src/utils/mutex.h: +../deps/nanomsg/src/utils/alloc.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/utils/wire.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o.d new file mode 100644 index 0000000..b120af7 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o.d @@ -0,0 +1,12 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o ../deps/nanomsg/src/utils/chunkref.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o: \ + ../deps/nanomsg/src/utils/chunkref.c \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/chunkref.c: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o.d new file mode 100644 index 0000000..6b33d8b --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o ../deps/nanomsg/src/utils/clock.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o: \ + ../deps/nanomsg/src/utils/clock.c ../deps/nanomsg/src/utils/clock.h \ + ../deps/nanomsg/src/utils/fast.h ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/attr.h +../deps/nanomsg/src/utils/clock.c: +../deps/nanomsg/src/utils/clock.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o.d new file mode 100644 index 0000000..372f845 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o.d @@ -0,0 +1,10 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o ../deps/nanomsg/src/utils/closefd.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o: \ + ../deps/nanomsg/src/utils/closefd.c \ + ../deps/nanomsg/src/utils/closefd.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h +../deps/nanomsg/src/utils/closefd.c: +../deps/nanomsg/src/utils/closefd.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o.d new file mode 100644 index 0000000..76c807a --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o ../deps/nanomsg/src/utils/condvar.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o: \ + ../deps/nanomsg/src/utils/condvar.c ../deps/nanomsg/src/utils/mutex.h \ + ../deps/nanomsg/src/utils/condvar.h ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/condvar.c: +../deps/nanomsg/src/utils/mutex.h: +../deps/nanomsg/src/utils/condvar.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o.d new file mode 100644 index 0000000..cc575a2 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o.d @@ -0,0 +1,18 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o ../deps/nanomsg/src/utils/efd.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o: \ + ../deps/nanomsg/src/utils/efd.c ../deps/nanomsg/src/utils/efd.h \ + ../deps/nanomsg/src/utils/fd.h ../deps/nanomsg/src/utils/efd_pipe.h \ + ../deps/nanomsg/src/utils/clock.h \ + ../deps/nanomsg/src/utils/efd_pipe.inc ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/utils/closefd.h +../deps/nanomsg/src/utils/efd.c: +../deps/nanomsg/src/utils/efd.h: +../deps/nanomsg/src/utils/fd.h: +../deps/nanomsg/src/utils/efd_pipe.h: +../deps/nanomsg/src/utils/clock.h: +../deps/nanomsg/src/utils/efd_pipe.inc: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/utils/closefd.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o.d new file mode 100644 index 0000000..e497bb2 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o.d @@ -0,0 +1,8 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o ../deps/nanomsg/src/utils/err.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o: \ + ../deps/nanomsg/src/utils/err.c ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/err.c: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o.d new file mode 100644 index 0000000..e8cfc13 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o.d @@ -0,0 +1,14 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o ../deps/nanomsg/src/utils/hash.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o: \ + ../deps/nanomsg/src/utils/hash.c ../deps/nanomsg/src/utils/hash.h \ + ../deps/nanomsg/src/utils/list.h ../deps/nanomsg/src/utils/fast.h \ + ../deps/nanomsg/src/utils/alloc.h ../deps/nanomsg/src/utils/cont.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h +../deps/nanomsg/src/utils/hash.c: +../deps/nanomsg/src/utils/hash.h: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/utils/alloc.h: +../deps/nanomsg/src/utils/cont.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o.d new file mode 100644 index 0000000..6229eaf --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o.d @@ -0,0 +1,11 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o ../deps/nanomsg/src/utils/list.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o: \ + ../deps/nanomsg/src/utils/list.c ../deps/nanomsg/src/utils/list.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h ../deps/nanomsg/src/utils/attr.h +../deps/nanomsg/src/utils/list.c: +../deps/nanomsg/src/utils/list.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: +../deps/nanomsg/src/utils/attr.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o.d new file mode 100644 index 0000000..0abe9bd --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o.d @@ -0,0 +1,8 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o ../deps/nanomsg/src/utils/msg.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o: \ + ../deps/nanomsg/src/utils/msg.c ../deps/nanomsg/src/utils/msg.h \ + ../deps/nanomsg/src/utils/chunkref.h ../deps/nanomsg/src/utils/chunk.h +../deps/nanomsg/src/utils/msg.c: +../deps/nanomsg/src/utils/msg.h: +../deps/nanomsg/src/utils/chunkref.h: +../deps/nanomsg/src/utils/chunk.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o.d new file mode 100644 index 0000000..981efe7 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o.d @@ -0,0 +1,10 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o ../deps/nanomsg/src/utils/mutex.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o: \ + ../deps/nanomsg/src/utils/mutex.c ../deps/nanomsg/src/utils/mutex.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/mutex.c: +../deps/nanomsg/src/utils/mutex.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o.d new file mode 100644 index 0000000..333c442 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o.d @@ -0,0 +1,5 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o ../deps/nanomsg/src/utils/once.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o: \ + ../deps/nanomsg/src/utils/once.c ../deps/nanomsg/src/utils/once.h +../deps/nanomsg/src/utils/once.c: +../deps/nanomsg/src/utils/once.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o.d new file mode 100644 index 0000000..2a36006 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o.d @@ -0,0 +1,10 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o ../deps/nanomsg/src/utils/queue.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o: \ + ../deps/nanomsg/src/utils/queue.c ../deps/nanomsg/src/utils/queue.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/queue.c: +../deps/nanomsg/src/utils/queue.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o.d new file mode 100644 index 0000000..63f475b --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o.d @@ -0,0 +1,8 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o ../deps/nanomsg/src/utils/random.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o: \ + ../deps/nanomsg/src/utils/random.c ../deps/nanomsg/src/utils/random.h \ + ../deps/nanomsg/src/utils/clock.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/random.c: +../deps/nanomsg/src/utils/random.h: +../deps/nanomsg/src/utils/clock.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o.d new file mode 100644 index 0000000..5f92cd5 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o.d @@ -0,0 +1,10 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o ../deps/nanomsg/src/utils/sem.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o: \ + ../deps/nanomsg/src/utils/sem.c ../deps/nanomsg/src/utils/sem.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/sem.c: +../deps/nanomsg/src/utils/sem.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o.d new file mode 100644 index 0000000..cf1e276 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o.d @@ -0,0 +1,10 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o ../deps/nanomsg/src/utils/sleep.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o: \ + ../deps/nanomsg/src/utils/sleep.c ../deps/nanomsg/src/utils/sleep.h \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/sleep.c: +../deps/nanomsg/src/utils/sleep.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o.d new file mode 100644 index 0000000..141c5ee --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o.d @@ -0,0 +1,10 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o ../deps/nanomsg/src/utils/stopwatch.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o: \ + ../deps/nanomsg/src/utils/stopwatch.c \ + ../deps/nanomsg/src/utils/stopwatch.h ../deps/nanomsg/src/utils/err.h \ + ../deps/nanomsg/src/utils/../nn.h ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/stopwatch.c: +../deps/nanomsg/src/utils/stopwatch.h: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o.d new file mode 100644 index 0000000..a3595b7 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o.d @@ -0,0 +1,14 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o ../deps/nanomsg/src/utils/thread.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o: \ + ../deps/nanomsg/src/utils/thread.c ../deps/nanomsg/src/utils/thread.h \ + ../deps/nanomsg/src/utils/thread_posix.h \ + ../deps/nanomsg/src/utils/thread_posix.inc \ + ../deps/nanomsg/src/utils/err.h ../deps/nanomsg/src/utils/../nn.h \ + ../deps/nanomsg/src/utils/fast.h +../deps/nanomsg/src/utils/thread.c: +../deps/nanomsg/src/utils/thread.h: +../deps/nanomsg/src/utils/thread_posix.h: +../deps/nanomsg/src/utils/thread_posix.inc: +../deps/nanomsg/src/utils/err.h: +../deps/nanomsg/src/utils/../nn.h: +../deps/nanomsg/src/utils/fast.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o.d new file mode 100644 index 0000000..bf085ed --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o.d @@ -0,0 +1,5 @@ +cmd_Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o := cc '-DNODE_GYP_MODULE_NAME=nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DNN_HAVE_SOCKETPAIR' '-DNN_HAVE_SEMAPHORE' '-DNN_USE_PIPE' '-DNN_HAVE_CLANG' '-DNN_HAVE_OSX' '-DHAVE_PIPE' '-DNN_HAVE_PIPE' '-DNN_HAVE_POLL' '-DNN_USE_KQUEUE' '-DNN_HAVE_MSG_CONTROL' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../deps/nanomsg/src -I../deps/nanomsg/src/aio -I../deps/nanomsg/src/core -I../deps/nanomsg/src/protocols -I../deps/nanomsg/src/transports -I../deps/nanomsg/src/utils -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-strict-aliasing -Wno-unused -MMD -MF ./Release/.deps/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o.d.raw -c -o Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o ../deps/nanomsg/src/utils/wire.c +Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o: \ + ../deps/nanomsg/src/utils/wire.c ../deps/nanomsg/src/utils/wire.h +../deps/nanomsg/src/utils/wire.c: +../deps/nanomsg/src/utils/wire.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/node_nanomsg/src/node_nanomsg.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/node_nanomsg/src/node_nanomsg.o.d new file mode 100644 index 0000000..e310cca --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/node_nanomsg/src/node_nanomsg.o.d @@ -0,0 +1,68 @@ +cmd_Release/obj.target/node_nanomsg/src/node_nanomsg.o := c++ '-DNODE_GYP_MODULE_NAME=node_nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../../nan -I../deps/nanomsg/src -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++0x -stdlib=libc++ -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/node_nanomsg/src/node_nanomsg.o.d.raw -c -o Release/obj.target/node_nanomsg/src/node_nanomsg.o ../src/node_nanomsg.cc +Release/obj.target/node_nanomsg/src/node_nanomsg.o: \ + ../src/node_nanomsg.cc ../deps/nanomsg/src/bus.h \ + ../deps/nanomsg/src/inproc.h ../deps/nanomsg/src/ipc.h \ + ../deps/nanomsg/src/nn.h ../deps/nanomsg/src/pair.h \ + ../deps/nanomsg/src/pipeline.h ../src/poll_ctx.h ../../nan/nan.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node_version.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-errno.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-version.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-unix.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-threadpool.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-darwin.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/pthread-barrier.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/v8.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/v8-version.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/v8config.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node_buffer.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node_object_wrap.h \ + ../../nan/nan_callbacks.h ../../nan/nan_callbacks_12_inl.h \ + ../../nan/nan_maybe_43_inl.h ../../nan/nan_converters.h \ + ../../nan/nan_converters_43_inl.h ../../nan/nan_new.h \ + ../../nan/nan_implementation_12_inl.h \ + ../../nan/nan_persistent_12_inl.h ../../nan/nan_weak.h \ + ../../nan/nan_object_wrap.h ../../nan/nan_typedarray_contents.h \ + ../deps/nanomsg/src/pubsub.h ../deps/nanomsg/src/reqrep.h \ + ../deps/nanomsg/src/survey.h ../deps/nanomsg/src/tcp.h \ + ../deps/nanomsg/src/ws.h +../src/node_nanomsg.cc: +../deps/nanomsg/src/bus.h: +../deps/nanomsg/src/inproc.h: +../deps/nanomsg/src/ipc.h: +../deps/nanomsg/src/nn.h: +../deps/nanomsg/src/pair.h: +../deps/nanomsg/src/pipeline.h: +../src/poll_ctx.h: +../../nan/nan.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node_version.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-errno.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-version.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-unix.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-threadpool.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-darwin.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/pthread-barrier.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/v8.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/v8-version.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/v8config.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node_buffer.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node_object_wrap.h: +../../nan/nan_callbacks.h: +../../nan/nan_callbacks_12_inl.h: +../../nan/nan_maybe_43_inl.h: +../../nan/nan_converters.h: +../../nan/nan_converters_43_inl.h: +../../nan/nan_new.h: +../../nan/nan_implementation_12_inl.h: +../../nan/nan_persistent_12_inl.h: +../../nan/nan_weak.h: +../../nan/nan_object_wrap.h: +../../nan/nan_typedarray_contents.h: +../deps/nanomsg/src/pubsub.h: +../deps/nanomsg/src/reqrep.h: +../deps/nanomsg/src/survey.h: +../deps/nanomsg/src/tcp.h: +../deps/nanomsg/src/ws.h: diff --git a/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/node_nanomsg/src/poll_ctx.o.d b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/node_nanomsg/src/poll_ctx.o.d new file mode 100644 index 0000000..13318a2 --- /dev/null +++ b/node/node_modules/nanomsg/build/Release/.deps/Release/obj.target/node_nanomsg/src/poll_ctx.o.d @@ -0,0 +1,52 @@ +cmd_Release/obj.target/node_nanomsg/src/poll_ctx.o := c++ '-DNODE_GYP_MODULE_NAME=node_nanomsg' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/Users/hwwu/.node-gyp/8.7.0/include/node -I/Users/hwwu/.node-gyp/8.7.0/src -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include -I../../nan -I../deps/nanomsg/src -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++0x -stdlib=libc++ -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/node_nanomsg/src/poll_ctx.o.d.raw -c -o Release/obj.target/node_nanomsg/src/poll_ctx.o ../src/poll_ctx.cc +Release/obj.target/node_nanomsg/src/poll_ctx.o: ../src/poll_ctx.cc \ + ../deps/nanomsg/src/nn.h ../src/poll_ctx.h ../../nan/nan.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node_version.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-errno.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-version.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-unix.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-threadpool.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/uv-darwin.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/pthread-barrier.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/v8.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/v8-version.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/v8config.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node_buffer.h \ + /Users/hwwu/.node-gyp/8.7.0/include/node/node_object_wrap.h \ + ../../nan/nan_callbacks.h ../../nan/nan_callbacks_12_inl.h \ + ../../nan/nan_maybe_43_inl.h ../../nan/nan_converters.h \ + ../../nan/nan_converters_43_inl.h ../../nan/nan_new.h \ + ../../nan/nan_implementation_12_inl.h \ + ../../nan/nan_persistent_12_inl.h ../../nan/nan_weak.h \ + ../../nan/nan_object_wrap.h ../../nan/nan_typedarray_contents.h +../src/poll_ctx.cc: +../deps/nanomsg/src/nn.h: +../src/poll_ctx.h: +../../nan/nan.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node_version.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-errno.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-version.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-unix.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-threadpool.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/uv-darwin.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/pthread-barrier.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/v8.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/v8-version.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/v8config.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node_buffer.h: +/Users/hwwu/.node-gyp/8.7.0/include/node/node_object_wrap.h: +../../nan/nan_callbacks.h: +../../nan/nan_callbacks_12_inl.h: +../../nan/nan_maybe_43_inl.h: +../../nan/nan_converters.h: +../../nan/nan_converters_43_inl.h: +../../nan/nan_new.h: +../../nan/nan_implementation_12_inl.h: +../../nan/nan_persistent_12_inl.h: +../../nan/nan_weak.h: +../../nan/nan_object_wrap.h: +../../nan/nan_typedarray_contents.h: diff --git a/node/node_modules/nanomsg/build/Release/nanomsg.a b/node/node_modules/nanomsg/build/Release/nanomsg.a new file mode 100644 index 0000000..b632c2f Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/nanomsg.a differ diff --git a/node/node_modules/nanomsg/build/Release/node_nanomsg.node b/node/node_modules/nanomsg/build/Release/node_nanomsg.node new file mode 100755 index 0000000..9757550 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/node_nanomsg.node differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o new file mode 100644 index 0000000..74f0595 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/ctx.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o new file mode 100644 index 0000000..a88a5d3 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/fsm.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o new file mode 100644 index 0000000..d1cd9d1 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/poller.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o new file mode 100644 index 0000000..1e49450 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/pool.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o new file mode 100644 index 0000000..ebb0d3b Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timer.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o new file mode 100644 index 0000000..7e26f06 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/timerset.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o new file mode 100644 index 0000000..d720af0 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/usock.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o new file mode 100644 index 0000000..2f84b9d Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/aio/worker.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o new file mode 100644 index 0000000..8fe5f7e Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/ep.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o new file mode 100644 index 0000000..3eceed8 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/epbase.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o new file mode 100644 index 0000000..ec46fba Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/global.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o new file mode 100644 index 0000000..2c09b56 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/pipe.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o new file mode 100644 index 0000000..00aa0f3 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/poll.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o new file mode 100644 index 0000000..d12a322 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/sock.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o new file mode 100644 index 0000000..2c1df44 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/sockbase.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o new file mode 100644 index 0000000..3adf8c8 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/core/symbol.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o new file mode 100644 index 0000000..83f5cc4 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/devices/device.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o new file mode 100644 index 0000000..2880386 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/bus.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o new file mode 100644 index 0000000..011705f Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/bus/xbus.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o new file mode 100644 index 0000000..c8a79ac Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/pair.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o new file mode 100644 index 0000000..f364349 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pair/xpair.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o new file mode 100644 index 0000000..50a267b Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o new file mode 100644 index 0000000..807ff79 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/push.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o new file mode 100644 index 0000000..d50f051 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o new file mode 100644 index 0000000..fece67a Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o new file mode 100644 index 0000000..17aed6d Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o new file mode 100644 index 0000000..4df2226 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o new file mode 100644 index 0000000..02290fa Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o new file mode 100644 index 0000000..2b4b489 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o new file mode 100644 index 0000000..1dc9039 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o new file mode 100644 index 0000000..541d33d Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o new file mode 100644 index 0000000..7d0701c Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/req.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o new file mode 100644 index 0000000..df00da7 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/task.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o new file mode 100644 index 0000000..23ee2a3 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o new file mode 100644 index 0000000..556f0e4 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o new file mode 100644 index 0000000..fd82c7a Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/respondent.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o new file mode 100644 index 0000000..9592f5a Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o new file mode 100644 index 0000000..41a9299 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o new file mode 100644 index 0000000..5308b5d Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o new file mode 100644 index 0000000..dfdccae Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/dist.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o new file mode 100644 index 0000000..5ed9bb2 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/excl.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o new file mode 100644 index 0000000..c756e5a Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/fq.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o new file mode 100644 index 0000000..2f75aa9 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/lb.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o new file mode 100644 index 0000000..314a1ee Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/protocols/utils/priolist.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o new file mode 100644 index 0000000..a93f8dd Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/binproc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o new file mode 100644 index 0000000..81a9f32 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o new file mode 100644 index 0000000..c21cec2 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/inproc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o new file mode 100644 index 0000000..d7603fb Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/ins.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o new file mode 100644 index 0000000..ac06859 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o new file mode 100644 index 0000000..6137dd6 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o new file mode 100644 index 0000000..33dd588 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/aipc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o new file mode 100644 index 0000000..a327c45 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/bipc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o new file mode 100644 index 0000000..e245895 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/cipc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o new file mode 100644 index 0000000..2808431 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/ipc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o new file mode 100644 index 0000000..ec53fdb Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ipc/sipc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o new file mode 100644 index 0000000..41dd0a2 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/atcp.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o new file mode 100644 index 0000000..b2216e4 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/btcp.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o new file mode 100644 index 0000000..2a4d644 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o new file mode 100644 index 0000000..55f7e8f Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/stcp.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o new file mode 100644 index 0000000..baffe32 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/tcp/tcp.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o new file mode 100644 index 0000000..c3ed872 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/backoff.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o new file mode 100644 index 0000000..5cd80d5 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/base64.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o new file mode 100644 index 0000000..bef0189 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/dns.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o new file mode 100644 index 0000000..a2c1e93 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/iface.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o new file mode 100644 index 0000000..0d4e018 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/literal.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o new file mode 100644 index 0000000..717add2 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/port.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o new file mode 100644 index 0000000..2863a54 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o new file mode 100644 index 0000000..e9970bc Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/aws.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o new file mode 100644 index 0000000..fc6dafd Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/bws.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o new file mode 100644 index 0000000..909a2db Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/cws.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o new file mode 100644 index 0000000..e7c0ff6 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sha1.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o new file mode 100644 index 0000000..c13d89d Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/sws.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o new file mode 100644 index 0000000..e78e6b6 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o new file mode 100644 index 0000000..4751492 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o new file mode 100644 index 0000000..79fa677 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/alloc.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o new file mode 100644 index 0000000..b1118de Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/atomic.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o new file mode 100644 index 0000000..4799b74 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunk.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o new file mode 100644 index 0000000..fee4cf5 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/chunkref.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o new file mode 100644 index 0000000..c46ace0 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/clock.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o new file mode 100644 index 0000000..757d72e Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/closefd.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o new file mode 100644 index 0000000..413da9b Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/condvar.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o new file mode 100644 index 0000000..e2d86fe Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/efd.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o new file mode 100644 index 0000000..37ca7ec Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/err.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o new file mode 100644 index 0000000..11dd3e3 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/hash.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o new file mode 100644 index 0000000..52221b0 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/list.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o new file mode 100644 index 0000000..fda446a Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/msg.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o new file mode 100644 index 0000000..20e9c47 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/mutex.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o new file mode 100644 index 0000000..0661ec3 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/once.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o new file mode 100644 index 0000000..bf5da7c Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/queue.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o new file mode 100644 index 0000000..29fd21b Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/random.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o new file mode 100644 index 0000000..0ee0bf7 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sem.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o new file mode 100644 index 0000000..a88a850 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/sleep.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o new file mode 100644 index 0000000..2387541 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/stopwatch.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o new file mode 100644 index 0000000..a3be2e6 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/thread.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o new file mode 100644 index 0000000..22a43d6 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/nanomsg/deps/nanomsg/src/utils/wire.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/node_nanomsg/src/node_nanomsg.o b/node/node_modules/nanomsg/build/Release/obj.target/node_nanomsg/src/node_nanomsg.o new file mode 100644 index 0000000..56655d0 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/node_nanomsg/src/node_nanomsg.o differ diff --git a/node/node_modules/nanomsg/build/Release/obj.target/node_nanomsg/src/poll_ctx.o b/node/node_modules/nanomsg/build/Release/obj.target/node_nanomsg/src/poll_ctx.o new file mode 100644 index 0000000..2dfd420 Binary files /dev/null and b/node/node_modules/nanomsg/build/Release/obj.target/node_nanomsg/src/poll_ctx.o differ diff --git a/node/node_modules/nanomsg/build/binding.Makefile b/node/node_modules/nanomsg/build/binding.Makefile new file mode 100644 index 0000000..0399852 --- /dev/null +++ b/node/node_modules/nanomsg/build/binding.Makefile @@ -0,0 +1,6 @@ +# This file is generated by gyp; do not edit. + +export builddir_name ?= ./build/. +.PHONY: all +all: + $(MAKE) node_nanomsg diff --git a/node/node_modules/nanomsg/build/config.gypi b/node/node_modules/nanomsg/build/config.gypi new file mode 100644 index 0000000..61426a6 --- /dev/null +++ b/node/node_modules/nanomsg/build/config.gypi @@ -0,0 +1,171 @@ +# Do not edit. File was generated by node-gyp's "configure" step +{ + "target_defaults": { + "cflags": [], + "default_configuration": "Release", + "defines": [], + "include_dirs": [], + "libraries": [] + }, + "variables": { + "asan": 0, + "coverage": "false", + "debug_devtools": "node", + "debug_http2": "false", + "debug_nghttp2": "false", + "force_dynamic_crt": 0, + "host_arch": "x64", + "icu_gyp_path": "tools/icu/icu-system.gyp", + "icu_small": "false", + "llvm_version": 0, + "node_byteorder": "little", + "node_enable_d8": "false", + "node_enable_v8_vtunejit": "false", + "node_install_npm": "false", + "node_module_version": 57, + "node_no_browser_globals": "false", + "node_prefix": "/usr/local/Cellar/node/8.7.0", + "node_release_urlbase": "", + "node_shared": "false", + "node_shared_cares": "false", + "node_shared_http_parser": "false", + "node_shared_libuv": "false", + "node_shared_openssl": "false", + "node_shared_zlib": "false", + "node_tag": "", + "node_use_bundled_v8": "true", + "node_use_dtrace": "true", + "node_use_etw": "false", + "node_use_lttng": "false", + "node_use_openssl": "true", + "node_use_perfctr": "false", + "node_use_v8_platform": "true", + "node_without_node_options": "false", + "openssl_fips": "", + "openssl_no_asm": 0, + "shlib_suffix": "57.dylib", + "target_arch": "x64", + "uv_parent_path": "/deps/uv/", + "uv_use_dtrace": "true", + "v8_enable_gdbjit": 0, + "v8_enable_i18n_support": 1, + "v8_enable_inspector": 1, + "v8_no_strict_aliasing": 1, + "v8_optimized_debug": 0, + "v8_promise_internal_field_count": 1, + "v8_random_seed": 0, + "v8_trace_maps": 0, + "v8_use_snapshot": "true", + "want_separate_host_toolset": 0, + "xcode_version": "9.0", + "nodedir": "/Users/hwwu/.node-gyp/8.7.0", + "standalone_static_library": 1, + "dry_run": "", + "legacy_bundling": "", + "save_dev": "", + "browser": "", + "commit_hooks": "true", + "only": "", + "viewer": "man", + "also": "", + "rollback": "true", + "usage": "", + "globalignorefile": "/usr/local/etc/npmignore", + "init_author_url": "", + "maxsockets": "50", + "shell": "/bin/zsh", + "metrics_registry": "https://registry.npmjs.org/", + "parseable": "", + "shrinkwrap": "true", + "init_license": "ISC", + "timing": "", + "if_present": "", + "cache_max": "Infinity", + "init_author_email": "", + "sign_git_tag": "", + "cert": "", + "git_tag_version": "true", + "local_address": "", + "long": "", + "fetch_retries": "2", + "registry": "https://registry.npmjs.org/", + "key": "", + "message": "%s", + "versions": "", + "globalconfig": "/usr/local/etc/npmrc", + "always_auth": "", + "logs_max": "10", + "prefer_online": "", + "cache_lock_retries": "10", + "global_style": "", + "heading": "npm", + "fetch_retry_mintimeout": "10000", + "offline": "", + "searchlimit": "20", + "access": "", + "json": "", + "allow_same_version": "", + "description": "true", + "engine_strict": "", + "https_proxy": "", + "init_module": "/Users/hwwu/.npm-init.js", + "userconfig": "/Users/hwwu/.npmrc", + "node_version": "8.7.0", + "user": "", + "auth_type": "legacy", + "editor": "vi", + "ignore_prepublish": "", + "save": "true", + "script_shell": "", + "tag": "latest", + "global": "", + "progress": "true", + "ham_it_up": "", + "optional": "true", + "searchstaleness": "900", + "bin_links": "true", + "force": "", + "save_prod": "", + "searchopts": "", + "depth": "Infinity", + "rebuild_bundle": "true", + "sso_poll_frequency": "500", + "unicode": "true", + "fetch_retry_maxtimeout": "60000", + "ca": "", + "save_prefix": "^", + "scripts_prepend_node_path": "warn-only", + "sso_type": "oauth", + "strict_ssl": "true", + "tag_version_prefix": "v", + "dev": "", + "fetch_retry_factor": "10", + "group": "20", + "save_exact": "", + "cache_lock_stale": "60000", + "prefer_offline": "", + "version": "", + "cache_min": "10", + "cache": "/Users/hwwu/.npm", + "searchexclude": "", + "color": "true", + "package_lock": "true", + "save_optional": "", + "user_agent": "npm/5.4.2 node/v8.7.0 darwin x64", + "ignore_scripts": "", + "cache_lock_wait": "10000", + "production": "", + "save_bundle": "", + "send_metrics": "", + "init_version": "1.0.0", + "umask": "0022", + "scope": "", + "git": "git", + "init_author_name": "", + "onload_script": "", + "tmp": "/var/folders/jn/5ln03_9j6nz8w5x3bvrbjqpr0000gn/T", + "unsafe_perm": "true", + "prefix": "/usr/local", + "link": "" + } +} diff --git a/node/node_modules/nanomsg/build/deps/nanomsg.Makefile b/node/node_modules/nanomsg/build/deps/nanomsg.Makefile new file mode 100644 index 0000000..11fb09c --- /dev/null +++ b/node/node_modules/nanomsg/build/deps/nanomsg.Makefile @@ -0,0 +1,6 @@ +# This file is generated by gyp; do not edit. + +export builddir_name ?= ./build/deps/. +.PHONY: all +all: + $(MAKE) -C .. nanomsg diff --git a/node/node_modules/nanomsg/build/deps/nanomsg.target.mk b/node/node_modules/nanomsg/build/deps/nanomsg.target.mk new file mode 100644 index 0000000..c816585 --- /dev/null +++ b/node/node_modules/nanomsg/build/deps/nanomsg.target.mk @@ -0,0 +1,302 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := nanomsg +DEFS_Debug := \ + '-DNODE_GYP_MODULE_NAME=nanomsg' \ + '-DUSING_UV_SHARED=1' \ + '-DUSING_V8_SHARED=1' \ + '-DV8_DEPRECATION_WARNINGS=1' \ + '-D_DARWIN_USE_64_BIT_INODE=1' \ + '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-DNN_HAVE_SOCKETPAIR' \ + '-DNN_HAVE_SEMAPHORE' \ + '-DNN_USE_PIPE' \ + '-DNN_HAVE_CLANG' \ + '-DNN_HAVE_OSX' \ + '-DHAVE_PIPE' \ + '-DNN_HAVE_PIPE' \ + '-DNN_HAVE_POLL' \ + '-DNN_USE_KQUEUE' \ + '-DNN_HAVE_MSG_CONTROL' \ + '-DDEBUG' \ + '-D_DEBUG' \ + '-DV8_ENABLE_CHECKS' + +# Flags passed to all source files. +CFLAGS_Debug := \ + -O0 \ + -gdwarf-2 \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -Wall \ + -Wendif-labels \ + -W \ + -Wno-unused-parameter + +# Flags passed to only C files. +CFLAGS_C_Debug := \ + -fno-strict-aliasing \ + -Wno-unused + +# Flags passed to only C++ files. +CFLAGS_CC_Debug := \ + -std=gnu++0x \ + -stdlib=libc++ \ + -fno-rtti \ + -fno-exceptions \ + -fno-threadsafe-statics \ + -fno-strict-aliasing \ + -Wno-unused + +# Flags passed to only ObjC files. +CFLAGS_OBJC_Debug := + +# Flags passed to only ObjC++ files. +CFLAGS_OBJCC_Debug := + +INCS_Debug := \ + -I/Users/hwwu/.node-gyp/8.7.0/include/node \ + -I/Users/hwwu/.node-gyp/8.7.0/src \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include \ + -I$(srcdir)/deps/nanomsg/src \ + -I$(srcdir)/deps/nanomsg/src/aio \ + -I$(srcdir)/deps/nanomsg/src/core \ + -I$(srcdir)/deps/nanomsg/src/protocols \ + -I$(srcdir)/deps/nanomsg/src/transports \ + -I$(srcdir)/deps/nanomsg/src/utils + +DEFS_Release := \ + '-DNODE_GYP_MODULE_NAME=nanomsg' \ + '-DUSING_UV_SHARED=1' \ + '-DUSING_V8_SHARED=1' \ + '-DV8_DEPRECATION_WARNINGS=1' \ + '-D_DARWIN_USE_64_BIT_INODE=1' \ + '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-DNN_HAVE_SOCKETPAIR' \ + '-DNN_HAVE_SEMAPHORE' \ + '-DNN_USE_PIPE' \ + '-DNN_HAVE_CLANG' \ + '-DNN_HAVE_OSX' \ + '-DHAVE_PIPE' \ + '-DNN_HAVE_PIPE' \ + '-DNN_HAVE_POLL' \ + '-DNN_USE_KQUEUE' \ + '-DNN_HAVE_MSG_CONTROL' + +# Flags passed to all source files. +CFLAGS_Release := \ + -Os \ + -gdwarf-2 \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -Wall \ + -Wendif-labels \ + -W \ + -Wno-unused-parameter + +# Flags passed to only C files. +CFLAGS_C_Release := \ + -fno-strict-aliasing \ + -Wno-unused + +# Flags passed to only C++ files. +CFLAGS_CC_Release := \ + -std=gnu++0x \ + -stdlib=libc++ \ + -fno-rtti \ + -fno-exceptions \ + -fno-threadsafe-statics \ + -fno-strict-aliasing \ + -Wno-unused + +# Flags passed to only ObjC files. +CFLAGS_OBJC_Release := + +# Flags passed to only ObjC++ files. +CFLAGS_OBJCC_Release := + +INCS_Release := \ + -I/Users/hwwu/.node-gyp/8.7.0/include/node \ + -I/Users/hwwu/.node-gyp/8.7.0/src \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include \ + -I$(srcdir)/deps/nanomsg/src \ + -I$(srcdir)/deps/nanomsg/src/aio \ + -I$(srcdir)/deps/nanomsg/src/core \ + -I$(srcdir)/deps/nanomsg/src/protocols \ + -I$(srcdir)/deps/nanomsg/src/transports \ + -I$(srcdir)/deps/nanomsg/src/utils + +OBJS := \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/ctx.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/fsm.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/pool.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/timer.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/timerset.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/usock.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/worker.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/ep.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/epbase.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/global.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/pipe.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/poll.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/sock.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/sockbase.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/core/symbol.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/devices/device.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/bus/bus.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/bus/xbus.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pair/pair.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pair/xpair.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pipeline/pull.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pipeline/push.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pipeline/xpull.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pipeline/xpush.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pubsub/pub.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pubsub/sub.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pubsub/trie.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pubsub/xpub.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/pubsub/xsub.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/reqrep/rep.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/reqrep/req.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/reqrep/task.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/reqrep/xrep.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/reqrep/xreq.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/survey/respondent.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/survey/surveyor.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/survey/xrespondent.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/survey/xsurveyor.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/utils/dist.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/utils/excl.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/utils/fq.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/utils/lb.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/protocols/utils/priolist.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/inproc/binproc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/inproc/cinproc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/inproc/inproc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/inproc/ins.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/inproc/msgqueue.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/inproc/sinproc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ipc/aipc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ipc/bipc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ipc/cipc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ipc/ipc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ipc/sipc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/tcp/atcp.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/tcp/btcp.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/tcp/ctcp.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/tcp/stcp.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/tcp/tcp.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/backoff.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/base64.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/dns.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/iface.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/literal.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/port.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/utils/streamhdr.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/aws.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/bws.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/cws.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/sha1.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/sws.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/ws.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/transports/ws/ws_handshake.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/alloc.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/atomic.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/chunk.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/chunkref.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/clock.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/closefd.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/condvar.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/efd.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/err.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/hash.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/list.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/msg.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/mutex.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/once.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/queue.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/random.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/sem.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/sleep.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/stopwatch.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/thread.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/utils/wire.o \ + $(obj).target/$(TARGET)/deps/nanomsg/src/aio/poller.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) +$(OBJS): GYP_OBJCFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE)) +$(OBJS): GYP_OBJCXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Debug := \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -L$(builddir) \ + -stdlib=libc++ + +LIBTOOLFLAGS_Debug := + +LDFLAGS_Release := \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -L$(builddir) \ + -stdlib=libc++ + +LIBTOOLFLAGS_Release := + +LIBS := + +$(builddir)/nanomsg.a: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/nanomsg.a: LIBS := $(LIBS) +$(builddir)/nanomsg.a: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE)) +$(builddir)/nanomsg.a: TOOLSET := $(TOOLSET) +$(builddir)/nanomsg.a: $(OBJS) FORCE_DO_CMD + $(call do_cmd,alink) + +all_deps += $(builddir)/nanomsg.a +# Add target alias +.PHONY: nanomsg +nanomsg: $(builddir)/nanomsg.a + +# Add target alias to "all" target. +.PHONY: all +all: nanomsg + +# Add target alias +.PHONY: nanomsg +nanomsg: $(builddir)/nanomsg.a + +# Short alias for building this static library. +.PHONY: nanomsg.a +nanomsg.a: $(builddir)/nanomsg.a + +# Add static library to "all" target. +.PHONY: all +all: $(builddir)/nanomsg.a + diff --git a/node/node_modules/nanomsg/build/gyp-mac-tool b/node/node_modules/nanomsg/build/gyp-mac-tool new file mode 100755 index 0000000..8ef02b0 --- /dev/null +++ b/node/node_modules/nanomsg/build/gyp-mac-tool @@ -0,0 +1,611 @@ +#!/usr/bin/env python +# Generated by gyp. Do not edit. +# Copyright (c) 2012 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Utility functions to perform Xcode-style build steps. + +These functions are executed via gyp-mac-tool when using the Makefile generator. +""" + +import fcntl +import fnmatch +import glob +import json +import os +import plistlib +import re +import shutil +import string +import subprocess +import sys +import tempfile + + +def main(args): + executor = MacTool() + exit_code = executor.Dispatch(args) + if exit_code is not None: + sys.exit(exit_code) + + +class MacTool(object): + """This class performs all the Mac tooling steps. The methods can either be + executed directly, or dispatched from an argument list.""" + + def Dispatch(self, args): + """Dispatches a string command to a method.""" + if len(args) < 1: + raise Exception("Not enough arguments") + + method = "Exec%s" % self._CommandifyName(args[0]) + return getattr(self, method)(*args[1:]) + + def _CommandifyName(self, name_string): + """Transforms a tool name like copy-info-plist to CopyInfoPlist""" + return name_string.title().replace('-', '') + + def ExecCopyBundleResource(self, source, dest, convert_to_binary): + """Copies a resource file to the bundle/Resources directory, performing any + necessary compilation on each resource.""" + extension = os.path.splitext(source)[1].lower() + if os.path.isdir(source): + # Copy tree. + # TODO(thakis): This copies file attributes like mtime, while the + # single-file branch below doesn't. This should probably be changed to + # be consistent with the single-file branch. + if os.path.exists(dest): + shutil.rmtree(dest) + shutil.copytree(source, dest) + elif extension == '.xib': + return self._CopyXIBFile(source, dest) + elif extension == '.storyboard': + return self._CopyXIBFile(source, dest) + elif extension == '.strings': + self._CopyStringsFile(source, dest, convert_to_binary) + else: + shutil.copy(source, dest) + + def _CopyXIBFile(self, source, dest): + """Compiles a XIB file with ibtool into a binary plist in the bundle.""" + + # ibtool sometimes crashes with relative paths. See crbug.com/314728. + base = os.path.dirname(os.path.realpath(__file__)) + if os.path.relpath(source): + source = os.path.join(base, source) + if os.path.relpath(dest): + dest = os.path.join(base, dest) + + args = ['xcrun', 'ibtool', '--errors', '--warnings', '--notices', + '--output-format', 'human-readable-text', '--compile', dest, source] + ibtool_section_re = re.compile(r'/\*.*\*/') + ibtool_re = re.compile(r'.*note:.*is clipping its content') + ibtoolout = subprocess.Popen(args, stdout=subprocess.PIPE) + current_section_header = None + for line in ibtoolout.stdout: + if ibtool_section_re.match(line): + current_section_header = line + elif not ibtool_re.match(line): + if current_section_header: + sys.stdout.write(current_section_header) + current_section_header = None + sys.stdout.write(line) + return ibtoolout.returncode + + def _ConvertToBinary(self, dest): + subprocess.check_call([ + 'xcrun', 'plutil', '-convert', 'binary1', '-o', dest, dest]) + + def _CopyStringsFile(self, source, dest, convert_to_binary): + """Copies a .strings file using iconv to reconvert the input into UTF-16.""" + input_code = self._DetectInputEncoding(source) or "UTF-8" + + # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call + # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints + # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing + # semicolon in dictionary. + # on invalid files. Do the same kind of validation. + import CoreFoundation + s = open(source, 'rb').read() + d = CoreFoundation.CFDataCreate(None, s, len(s)) + _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None) + if error: + return + + fp = open(dest, 'wb') + fp.write(s.decode(input_code).encode('UTF-16')) + fp.close() + + if convert_to_binary == 'True': + self._ConvertToBinary(dest) + + def _DetectInputEncoding(self, file_name): + """Reads the first few bytes from file_name and tries to guess the text + encoding. Returns None as a guess if it can't detect it.""" + fp = open(file_name, 'rb') + try: + header = fp.read(3) + except e: + fp.close() + return None + fp.close() + if header.startswith("\xFE\xFF"): + return "UTF-16" + elif header.startswith("\xFF\xFE"): + return "UTF-16" + elif header.startswith("\xEF\xBB\xBF"): + return "UTF-8" + else: + return None + + def ExecCopyInfoPlist(self, source, dest, convert_to_binary, *keys): + """Copies the |source| Info.plist to the destination directory |dest|.""" + # Read the source Info.plist into memory. + fd = open(source, 'r') + lines = fd.read() + fd.close() + + # Insert synthesized key/value pairs (e.g. BuildMachineOSBuild). + plist = plistlib.readPlistFromString(lines) + if keys: + plist = dict(plist.items() + json.loads(keys[0]).items()) + lines = plistlib.writePlistToString(plist) + + # Go through all the environment variables and replace them as variables in + # the file. + IDENT_RE = re.compile(r'[/\s]') + for key in os.environ: + if key.startswith('_'): + continue + evar = '${%s}' % key + evalue = os.environ[key] + lines = string.replace(lines, evar, evalue) + + # Xcode supports various suffices on environment variables, which are + # all undocumented. :rfc1034identifier is used in the standard project + # template these days, and :identifier was used earlier. They are used to + # convert non-url characters into things that look like valid urls -- + # except that the replacement character for :identifier, '_' isn't valid + # in a URL either -- oops, hence :rfc1034identifier was born. + evar = '${%s:identifier}' % key + evalue = IDENT_RE.sub('_', os.environ[key]) + lines = string.replace(lines, evar, evalue) + + evar = '${%s:rfc1034identifier}' % key + evalue = IDENT_RE.sub('-', os.environ[key]) + lines = string.replace(lines, evar, evalue) + + # Remove any keys with values that haven't been replaced. + lines = lines.split('\n') + for i in range(len(lines)): + if lines[i].strip().startswith("${"): + lines[i] = None + lines[i - 1] = None + lines = '\n'.join(filter(lambda x: x is not None, lines)) + + # Write out the file with variables replaced. + fd = open(dest, 'w') + fd.write(lines) + fd.close() + + # Now write out PkgInfo file now that the Info.plist file has been + # "compiled". + self._WritePkgInfo(dest) + + if convert_to_binary == 'True': + self._ConvertToBinary(dest) + + def _WritePkgInfo(self, info_plist): + """This writes the PkgInfo file from the data stored in Info.plist.""" + plist = plistlib.readPlist(info_plist) + if not plist: + return + + # Only create PkgInfo for executable types. + package_type = plist['CFBundlePackageType'] + if package_type != 'APPL': + return + + # The format of PkgInfo is eight characters, representing the bundle type + # and bundle signature, each four characters. If that is missing, four + # '?' characters are used instead. + signature_code = plist.get('CFBundleSignature', '????') + if len(signature_code) != 4: # Wrong length resets everything, too. + signature_code = '?' * 4 + + dest = os.path.join(os.path.dirname(info_plist), 'PkgInfo') + fp = open(dest, 'w') + fp.write('%s%s' % (package_type, signature_code)) + fp.close() + + def ExecFlock(self, lockfile, *cmd_list): + """Emulates the most basic behavior of Linux's flock(1).""" + # Rely on exception handling to report errors. + fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666) + fcntl.flock(fd, fcntl.LOCK_EX) + return subprocess.call(cmd_list) + + def ExecFilterLibtool(self, *cmd_list): + """Calls libtool and filters out '/path/to/libtool: file: foo.o has no + symbols'.""" + libtool_re = re.compile(r'^.*libtool: file: .* has no symbols$') + libtool_re5 = re.compile( + r'^.*libtool: warning for library: ' + + r'.* the table of contents is empty ' + + r'\(no object file members in the library define global symbols\)$') + env = os.environ.copy() + # Ref: + # http://www.opensource.apple.com/source/cctools/cctools-809/misc/libtool.c + # The problem with this flag is that it resets the file mtime on the file to + # epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone. + env['ZERO_AR_DATE'] = '1' + libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env) + _, err = libtoolout.communicate() + for line in err.splitlines(): + if not libtool_re.match(line) and not libtool_re5.match(line): + print >>sys.stderr, line + # Unconditionally touch the output .a file on the command line if present + # and the command succeeded. A bit hacky. + if not libtoolout.returncode: + for i in range(len(cmd_list) - 1): + if cmd_list[i] == "-o" and cmd_list[i+1].endswith('.a'): + os.utime(cmd_list[i+1], None) + break + return libtoolout.returncode + + def ExecPackageFramework(self, framework, version): + """Takes a path to Something.framework and the Current version of that and + sets up all the symlinks.""" + # Find the name of the binary based on the part before the ".framework". + binary = os.path.basename(framework).split('.')[0] + + CURRENT = 'Current' + RESOURCES = 'Resources' + VERSIONS = 'Versions' + + if not os.path.exists(os.path.join(framework, VERSIONS, version, binary)): + # Binary-less frameworks don't seem to contain symlinks (see e.g. + # chromium's out/Debug/org.chromium.Chromium.manifest/ bundle). + return + + # Move into the framework directory to set the symlinks correctly. + pwd = os.getcwd() + os.chdir(framework) + + # Set up the Current version. + self._Relink(version, os.path.join(VERSIONS, CURRENT)) + + # Set up the root symlinks. + self._Relink(os.path.join(VERSIONS, CURRENT, binary), binary) + self._Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES) + + # Back to where we were before! + os.chdir(pwd) + + def _Relink(self, dest, link): + """Creates a symlink to |dest| named |link|. If |link| already exists, + it is overwritten.""" + if os.path.lexists(link): + os.remove(link) + os.symlink(dest, link) + + def ExecCompileXcassets(self, keys, *inputs): + """Compiles multiple .xcassets files into a single .car file. + + This invokes 'actool' to compile all the inputs .xcassets files. The + |keys| arguments is a json-encoded dictionary of extra arguments to + pass to 'actool' when the asset catalogs contains an application icon + or a launch image. + + Note that 'actool' does not create the Assets.car file if the asset + catalogs does not contains imageset. + """ + command_line = [ + 'xcrun', 'actool', '--output-format', 'human-readable-text', + '--compress-pngs', '--notices', '--warnings', '--errors', + ] + is_iphone_target = 'IPHONEOS_DEPLOYMENT_TARGET' in os.environ + if is_iphone_target: + platform = os.environ['CONFIGURATION'].split('-')[-1] + if platform not in ('iphoneos', 'iphonesimulator'): + platform = 'iphonesimulator' + command_line.extend([ + '--platform', platform, '--target-device', 'iphone', + '--target-device', 'ipad', '--minimum-deployment-target', + os.environ['IPHONEOS_DEPLOYMENT_TARGET'], '--compile', + os.path.abspath(os.environ['CONTENTS_FOLDER_PATH']), + ]) + else: + command_line.extend([ + '--platform', 'macosx', '--target-device', 'mac', + '--minimum-deployment-target', os.environ['MACOSX_DEPLOYMENT_TARGET'], + '--compile', + os.path.abspath(os.environ['UNLOCALIZED_RESOURCES_FOLDER_PATH']), + ]) + if keys: + keys = json.loads(keys) + for key, value in keys.iteritems(): + arg_name = '--' + key + if isinstance(value, bool): + if value: + command_line.append(arg_name) + elif isinstance(value, list): + for v in value: + command_line.append(arg_name) + command_line.append(str(v)) + else: + command_line.append(arg_name) + command_line.append(str(value)) + # Note: actool crashes if inputs path are relative, so use os.path.abspath + # to get absolute path name for inputs. + command_line.extend(map(os.path.abspath, inputs)) + subprocess.check_call(command_line) + + def ExecMergeInfoPlist(self, output, *inputs): + """Merge multiple .plist files into a single .plist file.""" + merged_plist = {} + for path in inputs: + plist = self._LoadPlistMaybeBinary(path) + self._MergePlist(merged_plist, plist) + plistlib.writePlist(merged_plist, output) + + def ExecCodeSignBundle(self, key, resource_rules, entitlements, provisioning): + """Code sign a bundle. + + This function tries to code sign an iOS bundle, following the same + algorithm as Xcode: + 1. copy ResourceRules.plist from the user or the SDK into the bundle, + 2. pick the provisioning profile that best match the bundle identifier, + and copy it into the bundle as embedded.mobileprovision, + 3. copy Entitlements.plist from user or SDK next to the bundle, + 4. code sign the bundle. + """ + resource_rules_path = self._InstallResourceRules(resource_rules) + substitutions, overrides = self._InstallProvisioningProfile( + provisioning, self._GetCFBundleIdentifier()) + entitlements_path = self._InstallEntitlements( + entitlements, substitutions, overrides) + subprocess.check_call([ + 'codesign', '--force', '--sign', key, '--resource-rules', + resource_rules_path, '--entitlements', entitlements_path, + os.path.join( + os.environ['TARGET_BUILD_DIR'], + os.environ['FULL_PRODUCT_NAME'])]) + + def _InstallResourceRules(self, resource_rules): + """Installs ResourceRules.plist from user or SDK into the bundle. + + Args: + resource_rules: string, optional, path to the ResourceRules.plist file + to use, default to "${SDKROOT}/ResourceRules.plist" + + Returns: + Path to the copy of ResourceRules.plist into the bundle. + """ + source_path = resource_rules + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['CONTENTS_FOLDER_PATH'], + 'ResourceRules.plist') + if not source_path: + source_path = os.path.join( + os.environ['SDKROOT'], 'ResourceRules.plist') + shutil.copy2(source_path, target_path) + return target_path + + def _InstallProvisioningProfile(self, profile, bundle_identifier): + """Installs embedded.mobileprovision into the bundle. + + Args: + profile: string, optional, short name of the .mobileprovision file + to use, if empty or the file is missing, the best file installed + will be used + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + + Returns: + A tuple containing two dictionary: variables substitutions and values + to overrides when generating the entitlements file. + """ + source_path, provisioning_data, team_id = self._FindProvisioningProfile( + profile, bundle_identifier) + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['CONTENTS_FOLDER_PATH'], + 'embedded.mobileprovision') + shutil.copy2(source_path, target_path) + substitutions = self._GetSubstitutions(bundle_identifier, team_id + '.') + return substitutions, provisioning_data['Entitlements'] + + def _FindProvisioningProfile(self, profile, bundle_identifier): + """Finds the .mobileprovision file to use for signing the bundle. + + Checks all the installed provisioning profiles (or if the user specified + the PROVISIONING_PROFILE variable, only consult it) and select the most + specific that correspond to the bundle identifier. + + Args: + profile: string, optional, short name of the .mobileprovision file + to use, if empty or the file is missing, the best file installed + will be used + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + + Returns: + A tuple of the path to the selected provisioning profile, the data of + the embedded plist in the provisioning profile and the team identifier + to use for code signing. + + Raises: + SystemExit: if no .mobileprovision can be used to sign the bundle. + """ + profiles_dir = os.path.join( + os.environ['HOME'], 'Library', 'MobileDevice', 'Provisioning Profiles') + if not os.path.isdir(profiles_dir): + print >>sys.stderr, ( + 'cannot find mobile provisioning for %s' % bundle_identifier) + sys.exit(1) + provisioning_profiles = None + if profile: + profile_path = os.path.join(profiles_dir, profile + '.mobileprovision') + if os.path.exists(profile_path): + provisioning_profiles = [profile_path] + if not provisioning_profiles: + provisioning_profiles = glob.glob( + os.path.join(profiles_dir, '*.mobileprovision')) + valid_provisioning_profiles = {} + for profile_path in provisioning_profiles: + profile_data = self._LoadProvisioningProfile(profile_path) + app_id_pattern = profile_data.get( + 'Entitlements', {}).get('application-identifier', '') + for team_identifier in profile_data.get('TeamIdentifier', []): + app_id = '%s.%s' % (team_identifier, bundle_identifier) + if fnmatch.fnmatch(app_id, app_id_pattern): + valid_provisioning_profiles[app_id_pattern] = ( + profile_path, profile_data, team_identifier) + if not valid_provisioning_profiles: + print >>sys.stderr, ( + 'cannot find mobile provisioning for %s' % bundle_identifier) + sys.exit(1) + # If the user has multiple provisioning profiles installed that can be + # used for ${bundle_identifier}, pick the most specific one (ie. the + # provisioning profile whose pattern is the longest). + selected_key = max(valid_provisioning_profiles, key=lambda v: len(v)) + return valid_provisioning_profiles[selected_key] + + def _LoadProvisioningProfile(self, profile_path): + """Extracts the plist embedded in a provisioning profile. + + Args: + profile_path: string, path to the .mobileprovision file + + Returns: + Content of the plist embedded in the provisioning profile as a dictionary. + """ + with tempfile.NamedTemporaryFile() as temp: + subprocess.check_call([ + 'security', 'cms', '-D', '-i', profile_path, '-o', temp.name]) + return self._LoadPlistMaybeBinary(temp.name) + + def _MergePlist(self, merged_plist, plist): + """Merge |plist| into |merged_plist|.""" + for key, value in plist.iteritems(): + if isinstance(value, dict): + merged_value = merged_plist.get(key, {}) + if isinstance(merged_value, dict): + self._MergePlist(merged_value, value) + merged_plist[key] = merged_value + else: + merged_plist[key] = value + else: + merged_plist[key] = value + + def _LoadPlistMaybeBinary(self, plist_path): + """Loads into a memory a plist possibly encoded in binary format. + + This is a wrapper around plistlib.readPlist that tries to convert the + plist to the XML format if it can't be parsed (assuming that it is in + the binary format). + + Args: + plist_path: string, path to a plist file, in XML or binary format + + Returns: + Content of the plist as a dictionary. + """ + try: + # First, try to read the file using plistlib that only supports XML, + # and if an exception is raised, convert a temporary copy to XML and + # load that copy. + return plistlib.readPlist(plist_path) + except: + pass + with tempfile.NamedTemporaryFile() as temp: + shutil.copy2(plist_path, temp.name) + subprocess.check_call(['plutil', '-convert', 'xml1', temp.name]) + return plistlib.readPlist(temp.name) + + def _GetSubstitutions(self, bundle_identifier, app_identifier_prefix): + """Constructs a dictionary of variable substitutions for Entitlements.plist. + + Args: + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + app_identifier_prefix: string, value for AppIdentifierPrefix + + Returns: + Dictionary of substitutions to apply when generating Entitlements.plist. + """ + return { + 'CFBundleIdentifier': bundle_identifier, + 'AppIdentifierPrefix': app_identifier_prefix, + } + + def _GetCFBundleIdentifier(self): + """Extracts CFBundleIdentifier value from Info.plist in the bundle. + + Returns: + Value of CFBundleIdentifier in the Info.plist located in the bundle. + """ + info_plist_path = os.path.join( + os.environ['TARGET_BUILD_DIR'], + os.environ['INFOPLIST_PATH']) + info_plist_data = self._LoadPlistMaybeBinary(info_plist_path) + return info_plist_data['CFBundleIdentifier'] + + def _InstallEntitlements(self, entitlements, substitutions, overrides): + """Generates and install the ${BundleName}.xcent entitlements file. + + Expands variables "$(variable)" pattern in the source entitlements file, + add extra entitlements defined in the .mobileprovision file and the copy + the generated plist to "${BundlePath}.xcent". + + Args: + entitlements: string, optional, path to the Entitlements.plist template + to use, defaults to "${SDKROOT}/Entitlements.plist" + substitutions: dictionary, variable substitutions + overrides: dictionary, values to add to the entitlements + + Returns: + Path to the generated entitlements file. + """ + source_path = entitlements + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['PRODUCT_NAME'] + '.xcent') + if not source_path: + source_path = os.path.join( + os.environ['SDKROOT'], + 'Entitlements.plist') + shutil.copy2(source_path, target_path) + data = self._LoadPlistMaybeBinary(target_path) + data = self._ExpandVariables(data, substitutions) + if overrides: + for key in overrides: + if key not in data: + data[key] = overrides[key] + plistlib.writePlist(data, target_path) + return target_path + + def _ExpandVariables(self, data, substitutions): + """Expands variables "$(variable)" in data. + + Args: + data: object, can be either string, list or dictionary + substitutions: dictionary, variable substitutions to perform + + Returns: + Copy of data where each references to "$(variable)" has been replaced + by the corresponding value found in substitutions, or left intact if + the key was not found. + """ + if isinstance(data, str): + for key, value in substitutions.iteritems(): + data = data.replace('$(%s)' % key, value) + return data + if isinstance(data, list): + return [self._ExpandVariables(v, substitutions) for v in data] + if isinstance(data, dict): + return {k: self._ExpandVariables(data[k], substitutions) for k in data} + return data + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/node/node_modules/nanomsg/build/node_nanomsg.target.mk b/node/node_modules/nanomsg/build/node_nanomsg.target.mk new file mode 100644 index 0000000..80763a6 --- /dev/null +++ b/node/node_modules/nanomsg/build/node_nanomsg.target.mk @@ -0,0 +1,186 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := node_nanomsg +DEFS_Debug := \ + '-DNODE_GYP_MODULE_NAME=node_nanomsg' \ + '-DUSING_UV_SHARED=1' \ + '-DUSING_V8_SHARED=1' \ + '-DV8_DEPRECATION_WARNINGS=1' \ + '-D_DARWIN_USE_64_BIT_INODE=1' \ + '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-DBUILDING_NODE_EXTENSION' \ + '-DDEBUG' \ + '-D_DEBUG' \ + '-DV8_ENABLE_CHECKS' + +# Flags passed to all source files. +CFLAGS_Debug := \ + -O0 \ + -gdwarf-2 \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -Wall \ + -Wendif-labels \ + -W \ + -Wno-unused-parameter + +# Flags passed to only C files. +CFLAGS_C_Debug := \ + -fno-strict-aliasing + +# Flags passed to only C++ files. +CFLAGS_CC_Debug := \ + -std=gnu++0x \ + -stdlib=libc++ \ + -fno-rtti \ + -fno-exceptions \ + -fno-threadsafe-statics \ + -fno-strict-aliasing + +# Flags passed to only ObjC files. +CFLAGS_OBJC_Debug := + +# Flags passed to only ObjC++ files. +CFLAGS_OBJCC_Debug := + +INCS_Debug := \ + -I/Users/hwwu/.node-gyp/8.7.0/include/node \ + -I/Users/hwwu/.node-gyp/8.7.0/src \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include \ + -I$(srcdir)/../nan \ + -I$(srcdir)/deps/nanomsg/src + +DEFS_Release := \ + '-DNODE_GYP_MODULE_NAME=node_nanomsg' \ + '-DUSING_UV_SHARED=1' \ + '-DUSING_V8_SHARED=1' \ + '-DV8_DEPRECATION_WARNINGS=1' \ + '-D_DARWIN_USE_64_BIT_INODE=1' \ + '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-DBUILDING_NODE_EXTENSION' + +# Flags passed to all source files. +CFLAGS_Release := \ + -Os \ + -gdwarf-2 \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -Wall \ + -Wendif-labels \ + -W \ + -Wno-unused-parameter + +# Flags passed to only C files. +CFLAGS_C_Release := \ + -fno-strict-aliasing + +# Flags passed to only C++ files. +CFLAGS_CC_Release := \ + -std=gnu++0x \ + -stdlib=libc++ \ + -fno-rtti \ + -fno-exceptions \ + -fno-threadsafe-statics \ + -fno-strict-aliasing + +# Flags passed to only ObjC files. +CFLAGS_OBJC_Release := + +# Flags passed to only ObjC++ files. +CFLAGS_OBJCC_Release := + +INCS_Release := \ + -I/Users/hwwu/.node-gyp/8.7.0/include/node \ + -I/Users/hwwu/.node-gyp/8.7.0/src \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/uv/include \ + -I/Users/hwwu/.node-gyp/8.7.0/deps/v8/include \ + -I$(srcdir)/../nan \ + -I$(srcdir)/deps/nanomsg/src + +OBJS := \ + $(obj).target/$(TARGET)/src/node_nanomsg.o \ + $(obj).target/$(TARGET)/src/poll_ctx.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# Make sure our dependencies are built before any of us. +$(OBJS): | $(builddir)/nanomsg.a + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) +$(OBJS): GYP_OBJCFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE)) +$(OBJS): GYP_OBJCXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Debug := \ + -undefined dynamic_lookup \ + -Wl,-no_pie \ + -Wl,-search_paths_first \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -L$(builddir) \ + -stdlib=libc++ + +LIBTOOLFLAGS_Debug := \ + -undefined dynamic_lookup \ + -Wl,-no_pie \ + -Wl,-search_paths_first + +LDFLAGS_Release := \ + -undefined dynamic_lookup \ + -Wl,-no_pie \ + -Wl,-search_paths_first \ + -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -L$(builddir) \ + -stdlib=libc++ + +LIBTOOLFLAGS_Release := \ + -undefined dynamic_lookup \ + -Wl,-no_pie \ + -Wl,-search_paths_first + +LIBS := + +$(builddir)/node_nanomsg.node: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/node_nanomsg.node: LIBS := $(LIBS) +$(builddir)/node_nanomsg.node: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE)) +$(builddir)/node_nanomsg.node: TOOLSET := $(TOOLSET) +$(builddir)/node_nanomsg.node: $(OBJS) $(builddir)/nanomsg.a FORCE_DO_CMD + $(call do_cmd,solink_module) + +all_deps += $(builddir)/node_nanomsg.node +# Add target alias +.PHONY: node_nanomsg +node_nanomsg: $(builddir)/node_nanomsg.node + +# Short alias for building this executable. +.PHONY: node_nanomsg.node +node_nanomsg.node: $(builddir)/node_nanomsg.node + +# Add executable to "all" target. +.PHONY: all +all: $(builddir)/node_nanomsg.node + diff --git a/node/node_modules/nanomsg/deps/common.gypi b/node/node_modules/nanomsg/deps/common.gypi new file mode 100644 index 0000000..da5be0c --- /dev/null +++ b/node/node_modules/nanomsg/deps/common.gypi @@ -0,0 +1,113 @@ +{ + # compiler settings to build the nanomsg library + 'include_dirs': [ + 'nanomsg/src', + 'nanomsg/src/aio', + 'nanomsg/src/core', + 'nanomsg/src/protocols', + 'nanomsg/src/transports', + 'nanomsg/src/utils', + ], + 'sources': [ + 'nanomsg/src/aio/ctx.c', + 'nanomsg/src/aio/fsm.c', + 'nanomsg/src/aio/pool.c', + 'nanomsg/src/aio/timer.c', + 'nanomsg/src/aio/timerset.c', + 'nanomsg/src/aio/usock.c', + 'nanomsg/src/aio/worker.c', + 'nanomsg/src/core/ep.c', + 'nanomsg/src/core/epbase.c', + 'nanomsg/src/core/global.c', + 'nanomsg/src/core/pipe.c', + 'nanomsg/src/core/poll.c', + 'nanomsg/src/core/sock.c', + 'nanomsg/src/core/sockbase.c', + 'nanomsg/src/core/symbol.c', + 'nanomsg/src/devices/device.c', + 'nanomsg/src/protocols/bus/bus.c', + 'nanomsg/src/protocols/bus/xbus.c', + 'nanomsg/src/protocols/pair/pair.c', + 'nanomsg/src/protocols/pair/xpair.c', + 'nanomsg/src/protocols/pipeline/pull.c', + 'nanomsg/src/protocols/pipeline/push.c', + 'nanomsg/src/protocols/pipeline/xpull.c', + 'nanomsg/src/protocols/pipeline/xpush.c', + 'nanomsg/src/protocols/pubsub/pub.c', + 'nanomsg/src/protocols/pubsub/sub.c', + 'nanomsg/src/protocols/pubsub/trie.c', + 'nanomsg/src/protocols/pubsub/xpub.c', + 'nanomsg/src/protocols/pubsub/xsub.c', + 'nanomsg/src/protocols/reqrep/rep.c', + 'nanomsg/src/protocols/reqrep/req.c', + 'nanomsg/src/protocols/reqrep/task.c', + 'nanomsg/src/protocols/reqrep/xrep.c', + 'nanomsg/src/protocols/reqrep/xreq.c', + 'nanomsg/src/protocols/survey/respondent.c', + 'nanomsg/src/protocols/survey/surveyor.c', + 'nanomsg/src/protocols/survey/xrespondent.c', + 'nanomsg/src/protocols/survey/xsurveyor.c', + 'nanomsg/src/protocols/utils/dist.c', + 'nanomsg/src/protocols/utils/excl.c', + 'nanomsg/src/protocols/utils/fq.c', + 'nanomsg/src/protocols/utils/lb.c', + 'nanomsg/src/protocols/utils/priolist.c', + 'nanomsg/src/transports/inproc/binproc.c', + 'nanomsg/src/transports/inproc/cinproc.c', + 'nanomsg/src/transports/inproc/inproc.c', + 'nanomsg/src/transports/inproc/ins.c', + 'nanomsg/src/transports/inproc/msgqueue.c', + 'nanomsg/src/transports/inproc/sinproc.c', + 'nanomsg/src/transports/ipc/aipc.c', + 'nanomsg/src/transports/ipc/bipc.c', + 'nanomsg/src/transports/ipc/cipc.c', + 'nanomsg/src/transports/ipc/ipc.c', + 'nanomsg/src/transports/ipc/sipc.c', + 'nanomsg/src/transports/tcp/atcp.c', + 'nanomsg/src/transports/tcp/btcp.c', + 'nanomsg/src/transports/tcp/ctcp.c', + 'nanomsg/src/transports/tcp/stcp.c', + 'nanomsg/src/transports/tcp/tcp.c', + 'nanomsg/src/transports/utils/backoff.c', + 'nanomsg/src/transports/utils/base64.c', + 'nanomsg/src/transports/utils/dns.c', + 'nanomsg/src/transports/utils/iface.c', + 'nanomsg/src/transports/utils/literal.c', + 'nanomsg/src/transports/utils/port.c', + 'nanomsg/src/transports/utils/streamhdr.c', + 'nanomsg/src/transports/ws/aws.c', + 'nanomsg/src/transports/ws/bws.c', + 'nanomsg/src/transports/ws/cws.c', + 'nanomsg/src/transports/ws/sha1.c', + 'nanomsg/src/transports/ws/sws.c', + 'nanomsg/src/transports/ws/ws.c', + 'nanomsg/src/transports/ws/ws_handshake.c', + 'nanomsg/src/utils/alloc.c', + 'nanomsg/src/utils/atomic.c', + 'nanomsg/src/utils/chunk.c', + 'nanomsg/src/utils/chunkref.c', + 'nanomsg/src/utils/clock.c', + 'nanomsg/src/utils/closefd.c', + 'nanomsg/src/utils/condvar.c', + 'nanomsg/src/utils/efd.c', + 'nanomsg/src/utils/err.c', + 'nanomsg/src/utils/hash.c', + 'nanomsg/src/utils/list.c', + 'nanomsg/src/utils/msg.c', + 'nanomsg/src/utils/mutex.c', + 'nanomsg/src/utils/once.c', + 'nanomsg/src/utils/queue.c', + 'nanomsg/src/utils/random.c', + 'nanomsg/src/utils/sem.c', + 'nanomsg/src/utils/sleep.c', + 'nanomsg/src/utils/stopwatch.c', + 'nanomsg/src/utils/thread.c', + 'nanomsg/src/utils/wire.c', + ], + 'direct_dependent_settings': { + # build nanomsg hub with same compiler flags as the library + 'include_dirs': [ + 'nanomsg/src', + ], + } +} diff --git a/node/node_modules/nanomsg/deps/linux.gypi b/node/node_modules/nanomsg/deps/linux.gypi new file mode 100644 index 0000000..d5a3dc2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/linux.gypi @@ -0,0 +1,28 @@ +{ + # compiler settings to build the nanomsg library + 'defines': [ + 'NN_HAVE_SOCKETPAIR', + 'NN_HAVE_SEMAPHORE', + 'NN_USE_PIPE', + 'NN_HAVE_GCC', + 'NN_HAVE_LINUX', + 'NN_HAVE_EVENTFD', + 'NN_USE_EPOLL', + 'NN_HAVE_PIPE', + 'NN_HAVE_PIPE2', + 'NN_HAVE_CLOCK_MONOTONIC', + 'NN_HAVE_POLL', + 'NN_USE_EPOLL', + 'NN_HAVE_GCC_ATOMIC_BUILTINS', + 'NN_HAVE_MSG_CONTROL', + 'NN_USE_EVENTFD', + ], + 'sources':[ + 'nanomsg/src/aio/poller.c', + ], + 'cflags': [ + '-O3', '-Wall', '-Wextra', '-Wno-sign-compare', '-Wno-strict-aliasing', + '-Wno-unused', '-Wno-char-subscripts', '-Wno-maybe-uninitialized', + '-Wno-implicit-function-declaration', '-lpthread', + ], +} diff --git a/node/node_modules/nanomsg/deps/macosx.gypi b/node/node_modules/nanomsg/deps/macosx.gypi new file mode 100644 index 0000000..cfdfda2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/macosx.gypi @@ -0,0 +1,34 @@ +{ + # compiler settings to build the nanomsg library + # osx ignores 'cflags' and 'CFLAGS' given to .gyp when compiling the lib + # OTHER_CFLAGS is the trick and must be in 'xcode_settings' + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-Wno-unused', + ], + }, + 'conditions': [ + ['asan=="true"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-fsanitize=address' + ] + } + }] + ], + 'defines': [ + 'NN_HAVE_SOCKETPAIR', + 'NN_HAVE_SEMAPHORE', + 'NN_USE_PIPE', + 'NN_HAVE_CLANG', + 'NN_HAVE_OSX', + 'HAVE_PIPE', + 'NN_HAVE_PIPE', + 'NN_HAVE_POLL', + 'NN_USE_KQUEUE', + 'NN_HAVE_MSG_CONTROL', + ], + 'sources':[ + 'nanomsg/src/aio/poller.c', + ], +} diff --git a/node/node_modules/nanomsg/deps/nanomsg.gyp b/node/node_modules/nanomsg/deps/nanomsg.gyp new file mode 100644 index 0000000..d1842eb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg.gyp @@ -0,0 +1,19 @@ +{ + 'targets': [ + { + 'target_name': 'nanomsg', + 'type': 'static_library', + 'includes': [ 'common.gypi' ], + 'conditions': [ + ['OS=="mac"', { + 'includes': [ 'macosx.gypi' ] + }], + ['OS=="linux"', { + 'includes': [ 'linux.gypi' ] + }], + ['OS=="win"', { + 'includes': [ 'win.gypi' ] + }], + ], + }] +} \ No newline at end of file diff --git a/node/node_modules/nanomsg/deps/nanomsg/.appveyor.yml b/node/node_modules/nanomsg/deps/nanomsg/.appveyor.yml new file mode 100644 index 0000000..870dc49 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/.appveyor.yml @@ -0,0 +1,53 @@ +version: 0.8.{build} +environment: + global: + ASCIIDOCTOR_VER: 1.5.4 + CFLAGS: /MP + matrix: + # array of all environments used to test builds + - GENERATOR: NMake Makefiles + CFG: Debug + VS_VERSION: 12.0 + - GENERATOR: Visual Studio 14 2015 + VS_VERSION: 14.0 + CFG: Debug + - GENERATOR: Visual Studio 12 2013 + VS_VERSION: 12.0 + CFG: Debug + - GENERATOR: Visual Studio 14 2015 Win64 + CFG: Debug + VS_VERSION: 14.0 + - GENERATOR: Visual Studio 12 2013 Win64 + CFG: Debug + VS_VERSION: 12.0 + +cache: + - '%USERPROFILE%\asciidoctor-%ASCIIDOCTOR_VER%.gem -> .appveyor.yml' + +install: + # Gem fetching can sometimes be excruciatingly slow due to the rubygems database, + # so we have to manually download our target gem. + - ps: | + $asciidoctor = "$($env:USERPROFILE)\asciidoctor-$($env:ASCIIDOCTOR_VER).gem" + if (-not (Test-Path $asciidoctor)) { + $url = "https://rubygems.org/downloads/asciidoctor-$($env:ASCIIDOCTOR_VER).gem" + Write-Output "Downloading asciidoctor $env:ASCIIDOCTOR_VER from $url" + (New-Object Net.WebClient).DownloadFile($url, $asciidoctor) + } + gem install --no-document --local $asciidoctor + +# This section is a workaround for: https://github.com/nanomsg/nanomsg/issues/683 +before_build: + - del "C:\Program Files (x86)\MSBuild\%VS_VERSION%\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" + +build: + parallel: true +build_script: + - cmd: IF NOT %VS_VERSION% == NONE call "C:/Program Files (x86)/Microsoft Visual Studio %VS_VERSION%/Common7/Tools/vsvars32.bat" + - cmd: cmake --version + - cmd: md build + - cmd: cd build + - cmd: cmake -G "%GENERATOR%" .. + - cmd: cmake --build . +test_script: + - cmd: ctest --output-on-failure -C "%CFG%" diff --git a/node/node_modules/nanomsg/deps/nanomsg/.npmignore b/node/node_modules/nanomsg/deps/nanomsg/.npmignore new file mode 100644 index 0000000..b8ceb3c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/.npmignore @@ -0,0 +1,76 @@ +.*/ +build/ +*.a +*.deps +*.la +*.libs +*.lo +*.o +*.swo +*.swp +*.out +*Makefile +.dirstamp +doc/asciidoc.conf +nanocat +tcpmuxd +*.tar.gz +*.zip +perf/inproc_lat +perf/inproc_thr +perf/local_lat +perf/local_thr +perf/remote_lat +perf/remote_thr +doc/*.1 +doc/*.7 +doc/*.3 +doc/*.html +doc/diagrams +*.log +tests/*.trs +tests/block +tests/bus +tests/device +tests/domain +tests/emfile +tests/pipeline +tests/hash +tests/inproc +tests/inproc_shutdown +tests/iovec +tests/ipc +tests/ipc_shutdown +tests/ipc_stress +tests/list +tests/msg +tests/pair +tests/poll +tests/prio +tests/pubsub +tests/reqrep +tests/separation +tests/shutdown +tests/survey +tests/symbol +tests/tcp +tests/tcp_shutdown +tests/timeo +tests/trie +tests/zerocopy +tests/term +tests/cmsg +tests/ws +tests/tcpmux +*.dir +*.vcxproj +*.vcxproj.filters +*.vcxproj.user +Debug +Release +CMakeFiles +.cproject +.project +.pydevproject +*.sdf +*.opensdf diff --git a/node/node_modules/nanomsg/deps/nanomsg/.travis.yml b/node/node_modules/nanomsg/deps/nanomsg/.travis.yml new file mode 100644 index 0000000..b091d06 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/.travis.yml @@ -0,0 +1,39 @@ +language: c +sudo: false +matrix: + include: + - os: linux + compiler: gcc + - os: linux + compiler: clang +# - os: osx +# compiler: gcc + - os: osx + compiler: clang +before_script: + - gem install asciidoctor +script: + # Print all environment variables to aid in CI development + - printenv + # Print version and available CMake generators to aid in CI development + - cmake --version + - cmake --help + # Perform out-of-source build + - mkdir build + - cd build + # Perform CMake backend generation, build, and test + - cmake .. + - cmake --build . -- -j4 + - ctest --output-on-failure -C Debug -j4 +#deploy: +# provider: releases +# api_key: +# secure: fVMvvlhsginfIB7gEhAoKG7xzvF6D94yl8Z+jjfHQG4YtG3SScKVeQUnpWK7NhT90uoUfPnxd5dN3ZWlApoLBSz7iVD0sT1+VGYerM0Gn3LTUj3xvTB3WAAft6YePKhQeJfduzSNqsRjQ7buKgI1SFH0Ek5xwZe4Kl/O/D2Tsw0= +# file: +# - nanomsg-${TRAVIS_TAG}.zip +# - nanomsg-${TRAVIS_TAG}.tar.gz +# - nanomsg-${TRAVIS_TAG}.tar.bz2 +# skip_cleanup: true +# on: +# tags: true +# repo: nanomsg/nanomsg diff --git a/node/node_modules/nanomsg/deps/nanomsg/.version b/node/node_modules/nanomsg/deps/nanomsg/.version new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/.version @@ -0,0 +1 @@ +1.0.0 diff --git a/node/node_modules/nanomsg/deps/nanomsg/AUTHORS b/node/node_modules/nanomsg/deps/nanomsg/AUTHORS new file mode 100644 index 0000000..ed31724 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/AUTHORS @@ -0,0 +1,70 @@ +Complete list of copyright holders to nanomsg codebase: + +Achille Roussel +Aleksandar Fabijanic +Alex Brem +Andre Jonsson +Andrew Starks +Aram Santogidis +Ark Degtiarov +Bill McCroskey +Boris Zentner +Bruce Mitchener +Bruno Bigras +Chip Salzenberg +David Beck +Dirkjan Ochtman +Dong Fang +Drew Crawford +Dylan Socolobsky +Emeric Chevalier +Emil Renner Berthing +Evan Wies +Franklin "Snaipe" Mathieu +Gareth Roberts +Garrett D'Amore +Gonzalo Diethelm +Gaurav Gupta +Hajime Saito +Harlan Lieberman-Berg +Immanuel Weber +Ivan Pechorin +Ivo Vachkov +Jack R. Dunaway +Joshua Foster +Julien Ammous +Kaspar Schiess +Kristian Lein-Mathisen +Luca Barbato +Manuel Mendez +Mark Ellzey +Martin Sustrik +Matt Howlett +Max Drechsler +Michael John +Mikko Koppanen +Nick Desaulniers +Nicolas Hillegeer +Nir Soffer +Örjan Persson +Oskari Timperi +Paul Colomiets +Pavlo Kapyshin +Remy Brunno +Rob Sciuk +Ryan Killea +Robert G. Jakabosky +Sergey Avseyev +Sergey Kovalevich +Sergei Nikulov +Shivanand Velmurugan +Simon Strandgaard +Stan Mihai +Steve Atkins +Steve McKay +Stuart Wallace +Timothee Besset +Tobias Peters +Victor Guerra +Yonggang Luo +Zoltan Boszormenyi diff --git a/node/node_modules/nanomsg/deps/nanomsg/CMakeLists.txt b/node/node_modules/nanomsg/deps/nanomsg/CMakeLists.txt new file mode 100644 index 0000000..5cffc29 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/CMakeLists.txt @@ -0,0 +1,445 @@ +# +# Copyright (c) 2012 Martin Sustrik All rights reserved. +# Copyright (c) 2013 GoPivotal, Inc. All rights reserved. +# Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. +# Copyright 2016 Garrett D'Amore +# Copyright 2016 Franklin "Snaipe" Mathieu +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +cmake_minimum_required (VERSION 2.8.7) + +project (nanomsg C) +include (CheckFunctionExists) +include (CheckSymbolExists) +include (CheckStructHasMember) +include (CheckLibraryExists) +include (CheckCSourceCompiles) +include (GNUInstallDirs) + +if (POLICY CMP0042) + # Newer cmake on MacOS should use @rpath + cmake_policy (SET CMP0042 NEW) +endif () + +set (NN_DESCRIPTION "High-Performance Scalability Protocols") +set (ISSUE_REPORT_MSG "Please consider opening an issue at https://github.com/nanomsg/nanomsg") + +# Determine library versions. + +file (READ src/nn.h NN_HDR_STR) +string (REGEX REPLACE ".*#define +NN_VERSION_CURRENT +([0-9]+).*" "\\1" NN_VERSION_CURRENT "${NN_HDR_STR}") +string (REGEX REPLACE ".*#define +NN_VERSION_REVISION +([0-9]+).*" "\\1" NN_VERSION_REVISION "${NN_HDR_STR}") +string (REGEX REPLACE ".*#define +NN_VERSION_AGE +([0-9]+).*" "\\1" NN_VERSION_AGE "${NN_HDR_STR}") + +if ((NN_VERSION_CURRENT STREQUAL "") OR (NN_VERSION_REVISION STREQUAL "") OR (NN_VERSION_AGE STREQUAL "")) + message (FATAL_ERROR "Could not read ABI version from nn.h") +else () + set (NN_ABI_VERSION "${NN_VERSION_CURRENT}.${NN_VERSION_REVISION}.${NN_VERSION_AGE}") + message (STATUS "Detected nanomsg ABI v${NN_ABI_VERSION}") +endif () + +# Determine package version. +find_package (Git QUIET) +if (DEFINED ENV{TRAVIS_TAG}) + set (NN_PACKAGE_VERSION "$ENV{TRAVIS_TAG}") +elseif (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + # Working off a git repo, using git versioning + + # Get version from last tag + execute_process ( + COMMAND "${GIT_EXECUTABLE}" describe --always# | sed -e "s:v::" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + OUTPUT_VARIABLE NN_PACKAGE_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # If the sources have been changed locally, add -dirty to the version. + execute_process ( + COMMAND "${GIT_EXECUTABLE}" diff --quiet + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + RESULT_VARIABLE res) + if (res EQUAL 1) + set (NN_PACKAGE_VERSION "${NN_PACKAGE_VERSION}-dirty") + endif() + +elseif (EXISTS ${PROJECT_SOURCE_DIR}/.version) + # If git is not available (e.g. when building from source package) + # we can extract the package version from .version file. + file (STRINGS .version NN_PACKAGE_VERSION) +else () + set (NN_PACKAGE_VERSION "Unknown") +endif() + +# User-defined options. + +option (NN_STATIC_LIB "Build static library instead of shared library." OFF) +option (NN_ENABLE_DOC "Enable building documentation." ON) +option (NN_ENABLE_GETADDRINFO_A "Enable/disable use of getaddrinfo_a in place of getaddrinfo." ON) +option (NN_TESTS "Build and run nanomsg tests" ON) +option (NN_TOOLS "Build nanomsg tools" ON) +option (NN_ENABLE_NANOCAT "Enable building nanocat utility." ${NN_TOOLS}) + +# Platform checks. + +find_package (Threads REQUIRED) + +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + add_definitions (-DNN_HAVE_LINUX) +elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") + add_definitions (-DNN_HAVE_OSX) +elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") + set (NN_HAVE_WINSOCK 1) + add_definitions (-DNN_HAVE_WINDOWS) + add_definitions (-D_CRT_SECURE_NO_WARNINGS) + + # Target Windows Vista and later + add_definitions (-D_WIN32_WINNT=0x0600) + list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_WIN32_WINNT=0x0600) +elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + add_definitions (-DNN_HAVE_FREEBSD) +elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") + add_definitions (-DNN_HAVE_NETBSD) +elseif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") + add_definitions (-DNN_HAVE_OPENBSD) +elseif (CMAKE_SYSTEM_NAME MATCHES "Solaris|SunOS") + add_definitions (-DNN_HAVE_SOLARIS) +elseif (CMAKE_SYSTEM_NAME MATCHES "HP-UX") + add_definitions (-DNN_HAVE_HPUX) +elseif (CMAKE_SYSTEM_NAME MATCHES "QNX") + add_definitions (-DNN_HAVE_QNX) +else () + message (AUTHOR_WARNING "WARNING: This platform may or may not be supported: ${CMAKE_SYSTEM_NAME}") + message (AUTHOR_WARNING "${ISSUE_REPORT_MSG}") +endif () + +if (NN_STATIC_LIB) + add_definitions (-DNN_STATIC_LIB) +endif () + +macro (nn_check_func SYM DEF) + check_function_exists (${SYM} ${DEF}) + if (${DEF}) + add_definitions (-D${DEF}=1) + endif () +endmacro (nn_check_func) + +macro (nn_check_sym SYM HDR DEF) + check_symbol_exists (${SYM} ${HDR} ${DEF}) + if (${DEF}) + add_definitions (-D${DEF}=1) + endif () +endmacro (nn_check_sym) + +macro (nn_check_lib LIB SYM DEF) + check_library_exists (${LIB} ${SYM} "" ${DEF}) + if (${DEF}) + add_definitions (-D${DEF}=1) + set(NN_REQUIRED_LIBRARIES ${NN_REQUIRED_LIBRARIES} ${LIB}) + endif () +endmacro (nn_check_lib) + +macro (nn_check_struct_member STR MEM HDR DEF) + check_struct_has_member ("struct ${STR}" ${MEM} ${HDR} ${DEF}) + if (${DEF}) + add_definitions (-D${DEF}=1) + endif () +endmacro (nn_check_struct_member) + +if (WIN32) + # Windows is a special snowflake. + set(NN_REQUIRED_LIBRARIES ${NN_REQUIRED_LIBRARIES} ws2_32) + set(NN_REQUIRED_LIBRARIES ${NN_REQUIRED_LIBRARIES} mswsock) + set(NN_REQUIRED_LIBRARIES ${NN_REQUIRED_LIBRARIES} advapi32) + nn_check_sym (InitializeConditionVariable windows.h NN_HAVE_CONDVAR) + if (NOT NN_HAVE_CONDVAR) + message (FATAL_ERROR + "Modern Windows API support is missing. " + "Versions of Windows prior to Vista are not supported. " + "Further, the 32-bit MinGW environment is not supported. " + "Ensure you have at least Windows Vista or newer, and are " + "using either Visual Studio 2010 or newer or MinGW-W64.") + endif() +else () + # Unconditionally declare the following feature test macros. These are + # needed for some platforms (glibc and SunOS/illumos) and should be harmless + # on the others. + add_definitions (-D_GNU_SOURCE) + add_definitions (-D_REENTRANT) + add_definitions (-D_THREAD_SAFE) + add_definitions (-D_POSIX_PTHREAD_SEMANTICS) + + nn_check_func (gethrtime NN_HAVE_GETHRTIME) + nn_check_func (socketpair NN_HAVE_SOCKETPAIR) + nn_check_func (eventfd NN_HAVE_EVENTFD) + nn_check_func (pipe NN_HAVE_PIPE) + nn_check_func (pipe2 NN_HAVE_PIPE2) + nn_check_func (accept4 NN_HAVE_ACCEPT4) + nn_check_func (epoll_create NN_HAVE_EPOLL) + nn_check_func (kqueue NN_HAVE_KQUEUE) + nn_check_func (poll NN_HAVE_POLL) + + nn_check_lib (anl getaddrinfo_a NN_HAVE_GETADDRINFO_A) + nn_check_lib (rt clock_gettime NN_HAVE_CLOCK_GETTIME) + nn_check_lib (rt sem_wait NN_HAVE_SEMAPHORE_RT) + nn_check_lib (pthread sem_wait NN_HAVE_SEMAPHORE_PTHREAD) + nn_check_lib (nsl gethostbyname NN_HAVE_LIBNSL) + nn_check_lib (socket socket NN_HAVE_LIBSOCKET) + + nn_check_sym (CLOCK_MONOTONIC time.h NN_HAVE_CLOCK_MONOTONIC) + nn_check_sym (atomic_cas_32 atomic.h NN_HAVE_ATOMIC_SOLARIS) + nn_check_sym (AF_UNIX sys/socket.h NN_HAVE_UNIX_SOCKETS) + nn_check_sym (backtrace_symbols_fd execinfo.h NN_HAVE_BACKTRACE) + nn_check_struct_member(msghdr msg_control sys/socket.h NN_HAVE_MSG_CONTROL) + if (NN_HAVE_SEMAPHORE_RT OR NN_HAVE_SEMAPHORE_PTHREAD) + add_definitions (-DNN_HAVE_SEMAPHORE) + endif () +endif () + + +if (NOT NN_ENABLE_GETADDRINFO_A) + add_definitions (-DNN_DISABLE_GETADDRINFO_A) +endif () + +check_c_source_compiles (" + #include + int main() + { + volatile uint32_t n = 0; + __sync_fetch_and_add (&n, 1); + __sync_fetch_and_sub (&n, 1); + return 0; + } +" NN_HAVE_GCC_ATOMIC_BUILTINS) +if (NN_HAVE_GCC_ATOMIC_BUILTINS) + add_definitions (-DNN_HAVE_GCC_ATOMIC_BUILTINS) +endif () + +add_subdirectory (src) + +# Build the tools + +if (NN_ENABLE_NANOCAT) + add_executable (nanocat tools/nanocat.c tools/options.c) + target_link_libraries (nanocat ${PROJECT_NAME}) +endif () + +if (NN_ENABLE_DOC) + find_program (ASCIIDOCTOR_EXE asciidoctor) + if (NOT ASCIIDOCTOR_EXE) + message (WARNING "Could not find asciidoctor: skipping docs") + set (NN_ENABLE_DOC OFF) + else () + message (STATUS "Using asciidoctor at ${ASCIIDOCTOR_EXE}") + endif () +endif () + +# Build the documenation +if (NN_ENABLE_DOC) + + set (NN_DOCDIR ${CMAKE_CURRENT_SOURCE_DIR}/doc) + set (NN_STYLESHEET ${NN_DOCDIR}/stylesheet.css) + set (NN_TITLE ${PROJECT_NAME} ${NN_PACKAGE_VERSION}) + set (NN_A2M ${ASCIIDOCTOR_EXE} -b manpage -amanmanual='${NN_TITLE}') + set (NN_A2H ${ASCIIDOCTOR_EXE} -d manpage -b html5 -a stylesheeet=${NN_STYLESHEET} -aversion-label=${PROJECT_NAME} -arevnumber=${NN_PACKAGE_VERSION}) + + macro (add_libnanomsg_man NAME SECT) + add_custom_command ( + OUTPUT ${NAME}.${SECT} + COMMAND ${NN_A2M} -o ${NAME}.${SECT} ${NN_DOCDIR}/${NAME}.txt + MAIN_DEPENDENCY ${NN_DOCDIR}/${NAME}.txt + ) + + add_custom_command ( + OUTPUT ${NAME}.${SECT}.html + COMMAND ${NN_A2H} -o ${NAME}.${SECT}.html ${NN_DOCDIR}/${NAME}.txt + DEPENDS ${NN_STYLESHEET} + MAIN_DEPENDENCY ${NN_DOCDIR}/${NAME}.txt + ) + + set(NN_MANS ${NN_MANS} ${NAME}.${SECT}) + set(NN_HTMLS ${NN_HTMLS} ${NAME}.${SECT}.html) + + install ( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.${SECT}.html + DESTINATION ${CMAKE_INSTALL_DOCDIR} + ) + install ( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.${SECT} + DESTINATION ${CMAKE_INSTALL_MANDIR}/man${SECT} + ) + + endmacro (add_libnanomsg_man) + + if (NN_ENABLE_NANOCAT) + add_libnanomsg_man (nanocat 1) + endif () + + add_libnanomsg_man (nn_errno 3) + add_libnanomsg_man (nn_strerror 3) + add_libnanomsg_man (nn_symbol 3) + add_libnanomsg_man (nn_symbol_info 3) + add_libnanomsg_man (nn_allocmsg 3) + add_libnanomsg_man (nn_reallocmsg 3) + add_libnanomsg_man (nn_freemsg 3) + add_libnanomsg_man (nn_socket 3) + add_libnanomsg_man (nn_close 3) + add_libnanomsg_man (nn_get_statistic 3) + add_libnanomsg_man (nn_getsockopt 3) + add_libnanomsg_man (nn_setsockopt 3) + add_libnanomsg_man (nn_bind 3) + add_libnanomsg_man (nn_connect 3) + add_libnanomsg_man (nn_shutdown 3) + add_libnanomsg_man (nn_send 3) + add_libnanomsg_man (nn_recv 3) + add_libnanomsg_man (nn_sendmsg 3) + add_libnanomsg_man (nn_recvmsg 3) + add_libnanomsg_man (nn_device 3) + add_libnanomsg_man (nn_cmsg 3) + add_libnanomsg_man (nn_poll 3) + + add_libnanomsg_man (nanomsg 7) + add_libnanomsg_man (nn_pair 7) + add_libnanomsg_man (nn_reqrep 7) + add_libnanomsg_man (nn_pubsub 7) + add_libnanomsg_man (nn_survey 7) + add_libnanomsg_man (nn_pipeline 7) + add_libnanomsg_man (nn_bus 7) + add_libnanomsg_man (nn_inproc 7) + add_libnanomsg_man (nn_ipc 7) + add_libnanomsg_man (nn_tcp 7) + add_libnanomsg_man (nn_ws 7) + add_libnanomsg_man (nn_env 7) + + add_custom_target (man ALL DEPENDS ${NN_MANS}) + add_custom_target (html ALL DEPENDS ${NN_HTMLS}) + +endif () + +# Build unit tests. + +if (NN_TESTS) + + enable_testing () + set (all_tests "") + + set (TEST_PORT 5500) + macro (add_libnanomsg_test NAME TIMEOUT) + list (APPEND all_tests ${NAME}) + add_executable (${NAME} tests/${NAME}.c) + target_link_libraries (${NAME} ${PROJECT_NAME}) + add_test (NAME ${NAME} COMMAND ${NAME} ${TEST_PORT}) + set_tests_properties (${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) + math (EXPR TEST_PORT "${TEST_PORT}+10") + endmacro (add_libnanomsg_test) + + # Transport tests. + add_libnanomsg_test (inproc 5) + add_libnanomsg_test (inproc_shutdown 5) + add_libnanomsg_test (ipc 5) + add_libnanomsg_test (ipc_shutdown 30) + add_libnanomsg_test (ipc_stress 5) + add_libnanomsg_test (tcp 5) + add_libnanomsg_test (tcp_shutdown 120) + add_libnanomsg_test (ws 5) + + # Protocol tests. + add_libnanomsg_test (pair 5) + add_libnanomsg_test (pubsub 5) + add_libnanomsg_test (reqrep 5) + add_libnanomsg_test (pipeline 5) + add_libnanomsg_test (survey 5) + add_libnanomsg_test (bus 5) + + # Feature tests. + add_libnanomsg_test (async_shutdown 30) + add_libnanomsg_test (block 5) + add_libnanomsg_test (term 5) + add_libnanomsg_test (timeo 5) + add_libnanomsg_test (iovec 5) + add_libnanomsg_test (msg 5) + add_libnanomsg_test (prio 5) + add_libnanomsg_test (poll 5) + add_libnanomsg_test (device 5) + add_libnanomsg_test (device4 5) + add_libnanomsg_test (device5 5) + add_libnanomsg_test (device6 5) + add_libnanomsg_test (device7 30) + add_libnanomsg_test (emfile 5) + add_libnanomsg_test (domain 5) + add_libnanomsg_test (trie 5) + add_libnanomsg_test (list 5) + add_libnanomsg_test (hash 5) + add_libnanomsg_test (stats 5) + add_libnanomsg_test (symbol 5) + add_libnanomsg_test (separation 5) + add_libnanomsg_test (zerocopy 5) + add_libnanomsg_test (shutdown 5) + add_libnanomsg_test (cmsg 5) + add_libnanomsg_test (bug328 5) + add_libnanomsg_test (ws_async_shutdown 5) + add_libnanomsg_test (reqttl 10) + add_libnanomsg_test (surveyttl 10) + + # Platform-specific tests + if (WIN32) + add_libnanomsg_test (win_sec_attr 5) + endif() + + # Build the performance tests. + + macro (add_libnanomsg_perf NAME) + add_executable (${NAME} perf/${NAME}.c) + target_link_libraries (${NAME} ${PROJECT_NAME}) + endmacro (add_libnanomsg_perf) + + add_libnanomsg_perf (inproc_lat) + add_libnanomsg_perf (inproc_thr) + add_libnanomsg_perf (local_lat) + add_libnanomsg_perf (remote_lat) + add_libnanomsg_perf (local_thr) + add_libnanomsg_perf (remote_thr) + +endif () + +install (TARGETS LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install (TARGETS ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install (FILES src/nn.h DESTINATION include/nanomsg) +install (FILES src/inproc.h DESTINATION include/nanomsg) +install (FILES src/ipc.h DESTINATION include/nanomsg) +install (FILES src/tcp.h DESTINATION include/nanomsg) +install (FILES src/ws.h DESTINATION include/nanomsg) +install (FILES src/pair.h DESTINATION include/nanomsg) +install (FILES src/pubsub.h DESTINATION include/nanomsg) +install (FILES src/reqrep.h DESTINATION include/nanomsg) +install (FILES src/pipeline.h DESTINATION include/nanomsg) +install (FILES src/survey.h DESTINATION include/nanomsg) +install (FILES src/bus.h DESTINATION include/nanomsg) + +if (NN_ENABLE_NANOCAT) + install (TARGETS nanocat RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + +set (CPACK_PACKAGE_NAME ${PROJECT_NAME}) +set (CPACK_PACKAGE_VERSION ${NN_PACKAGE_VERSION}) +set (CPACK_SOURCE_GENERATOR "TBZ2;TGZ;ZIP") +set (CPACK_SOURCE_IGNORE_FILES "/build/;/.git/;~$;${CPACK_SOURCE_IGNORE_FILES}") +set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${NN_PACKAGE_VERSION}") +add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) +include (CPack) diff --git a/node/node_modules/nanomsg/deps/nanomsg/COPYING b/node/node_modules/nanomsg/deps/nanomsg/COPYING new file mode 100644 index 0000000..4efdba9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/COPYING @@ -0,0 +1,21 @@ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. + +"nanomsg" is a trademark of Martin Sustrik + diff --git a/node/node_modules/nanomsg/deps/nanomsg/README b/node/node_modules/nanomsg/deps/nanomsg/README new file mode 100644 index 0000000..19d2646 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/README @@ -0,0 +1,69 @@ +Welcome to nanomsg +================== + +[![Release](https://img.shields.io/github/release/nanomsg/nanomsg.svg)](https://github.com/nanomsg/nanomsg/releases/latest) +[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nanomsg/nanomsg/blob/master/COPYING) +[![Linux Status](https://img.shields.io/travis/nanomsg/nanomsg/master.svg?label=linux)](https://travis-ci.org/nanomsg/nanomsg) +[![Windows Status](https://img.shields.io/appveyor/ci/nanomsg/nanomsg/master.svg?label=windows)](https://ci.appveyor.com/project/nanomsg/nanomsg) +[![Gitter](https://img.shields.io/badge/gitter-join-brightgreen.svg)](https://gitter.im/nanomsg/nanomsg) + +The nanomsg library is a simple high-performance implementation of several +"scalability protocols". These scalability protocols are light-weight messaging +protocols which can be used to solve a number of very common messaging +patterns, such as request/reply, publish/subscribe, surveyor/respondent, +and so forth. These protocols can run over a variety of transports such +as TCP, UNIX sockets, and even WebSocket. + +For more information check the [website](http://nanomsg.org). + +Prerequisites +------------- + +1. Windows. + * Windows Vista or newer (Windows XP and 2003 are *NOT* supported) + * Microsoft Visual Studio 2010 (including C++) or newer, or mingw-w64 + (Specifically mingw and older Microsoft compilers are *NOT supported) + * CMake 2.8.7 or newer, available in $PATH as `cmake` + +2. POSIX (Linux, MacOS X, UNIX) + * ANSI C compiler supporting C89 + * POSIX pthreads (should be present on all modern POSIX systems) + * BSD sockets support for both TCP and UNIX domain sockets + * CMake (http://cmake.org) 2.8.7 or newer, available in $PATH as `cmake` + +3. Documentation (optional) + * asciidoctor (http://asciidoctor.org/) available as `asciidoctor` + * If not present, docs are not formatted, but left in readable ASCII + * Also available on-line at http://nanomsg.org/documentation + +Build it with CMake +------------------- + +1. Go to the root directory of the local source repository. +2. To perform an out-of-source build, run: +3. `mkdir build` +4. `cd build` +5. `cmake ..` + (You can add -DCMAKE_INSTALL_PREFIX=/usr/local or some other directory.) +6. `cmake --build .` +7. `ctest -G Debug .` +8. `cmake --build . --target install` + *NB:* This may have to be done as a privileged user. +9. (Linux only). `ldconfig` (As a privileged or root user.) + +Resources +--------- + +Website: [http://nanomsg.org](http://nanomsg.org) + +Source code: [https://github.com/nanomsg/nanomsg](http://github.com/nanomsg/nanomsg) + +Documentation: [http://nanomsg.org/documentation.html](http://nanomsg.org/documentation.html) + +Bug tracker: [https://github.com/nanomsg/nanomsg/issues](http://github.com/nanomsg/nanomsg/issues) + +Mailing list: [nanomsg@freelists.org](http://www.freelists.org/list/nanomsg) + +Gitter Chat: [https://gitter.im/nanomsg/nanomsg](https://gitter.im/nanomsg/nanomsg) + +IRC chatroom: [#nanomsg at irc.freenode.net/8001](http://webchat.freenode.net?channels=%23nanomsg) diff --git a/node/node_modules/nanomsg/deps/nanomsg/RELEASING b/node/node_modules/nanomsg/deps/nanomsg/RELEASING new file mode 100644 index 0000000..ff45899 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/RELEASING @@ -0,0 +1,43 @@ +Release process +=============== + + 1. Check CI + + * Travis: https://travis-ci.org/nanomsg/nanomsg + * AppVeyor: https://ci.appveyor.com/project/nanomsg/nanomsg + + 2. Bump ABI version as appropriate (see the docs on versioning). This happens + in src/nn.h, check links there on which numbers to update. + + 3. Bump the version in the .version file, such as 0.10-beta or 1.0 or + whatever. This should match the tag you are going to use. + + 4. Commit and push both of the above changes back to the public repo. + + 5. Tag the new version, e.g. git tag -a 0.3-beta. (Make sure to use -a + to create an annotated tag.) + + 6. Push the tag to the repo, e.g. git push origin 0.3-beta. + + 7. Wait a little bit for Travis CI to build, and create artifacts. + (Travis does this automatically for tagged releases.) + + 8. Also check the AppVeyor CI again just to be sure. + + 9. Check the github releases page - a release for the tag should have + already been created with artifacts ready to download. + +10. Upload the "download" page on the website (see gh-pages branch of the + repo). The only thing that needs to be updated is the LATEST RELEASE + number and date. + +11. In online docs (gh-pages) make a new folder (e.g. v0.3) and copy the HTML + docs (*.html from build directory) there. + +12. Link the docs from "documentation.html" page. + +13. Send the announcement about the release. These commands might be useful: + git log --oneline 0.2-alpha..0.3-beta | wc -l + git diff -U0 0.2-alpha..0.3-beta AUTHORS + +14. Update the topic in the chatroom accordingly. diff --git a/node/node_modules/nanomsg/deps/nanomsg/configure b/node/node_modules/nanomsg/deps/nanomsg/configure new file mode 100755 index 0000000..ff5ba72 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/configure @@ -0,0 +1,116 @@ +#!/bin/sh +# +# Copyright 2016 Garrett D'Amore +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# +# This configure script provides the usual autoconf style interface for +# installation, but simply uses cmake. +# +SRCDIR=`dirname $0` +CURDIR=`pwd` + +strip_arg() +{ + x=`echo "$1" | sed "s/[^=]*=//"` + eval $2=\"$x\" +} + +warn() { + echo "$*" 1>&2 +} + +find_prog() { + SIFS="${IFS= }" + IFS=: + for p in $PATH; do + if [ -x ${p}/$1 ] + then + IFS="${SIFS}" + echo "${p}/${1}" + return 0 + fi + done + IFS="${SIFS}" + return 1 +} + +need_cmake() { + warn "This program requires CMake 2.6 or newer to build." + warn "Obtain CMake from www.cmake.org" + exit 1 +} + +help() { + echo "This configure script is a convenience wrapper around" + echo "CMake. Only a limited subset of configuration options" + echo "are supported. For a fully featured build, use CMake". + echo + echo "Execute as $0 [options]" + echo + echo "Options supported are:" + echo + echo " --prefix={path} Set installation directory prefix." + echo " --with-cmake={path} Location of CMake executable." + echo + exit 1 +} + +# Argument parsing +PREFIX=/usr/local +while [ -n "$1" ]; do + case "$1" in + --with-cmake) + CMAKE="$2" + shift 2 + ;; + --with-cmake=*) + strip_arg "$1" CMAKE + shift + ;; + --prefix) + if [ -z "$2" ]; then + help + fi + PREFIX="$2" + shift 2 + ;; + --prefix=*) + strip_arg "$1" PREFIX + shift + ;; + *) + help + ;; + esac +done + +if [ -z "${CMAKE}" ]; then + CMAKE=`find_prog cmake` || need_cmake +fi + +if [ -f src/nn.h ] +then + warn "NOTE: Building in the source directory is not recommended." +fi + +GENERATOR="Unix Makefiles" + +"$CMAKE" -G "$GENERATOR" "-DCMAKE_INSTALL_PREFIX=$PREFIX" $SRCDIR diff --git a/node/node_modules/nanomsg/deps/nanomsg/demo/README b/node/node_modules/nanomsg/deps/nanomsg/demo/README new file mode 100644 index 0000000..4ee4cf8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/demo/README @@ -0,0 +1,5 @@ +The programs here are intended to demonstrate how to use the nanomsg API. +The intention is that you can use these programs (or parts thereof) in +your own code. + +We welcome further contributions here. diff --git a/node/node_modules/nanomsg/deps/nanomsg/demo/async_demo.c b/node/node_modules/nanomsg/deps/nanomsg/demo/async_demo.c new file mode 100644 index 0000000..b82a2aa --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/demo/async_demo.c @@ -0,0 +1,284 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + "nanomsg" is a trademark of Martin Sustrik +*/ + +/* This program serves as an example for how to write an async RPC service, + using the RAW request/reply pattern and nn_poll. The server receives + messages and keeps them on a list, replying to them. + + Our demonstration application layer protocol is simple. The client sends + a number of milliseconds to wait before responding. The server just gives + back an empty reply after waiting that long. + + To run this program, start the server as async_demo -s + Then connect to it with the client as async_client . + + For example: + + % ./async_demo tcp://127.0.0.1:5555 -s & + % ./async_demo tcp://127.0.0.1:5555 323 + Request took 324 milliseconds. +*/ + +#include +#include +#include +#include +#include + +#include +#include + +/* MAXJOBS is a limit on the on the number of outstanding requests we + can queue. We will not accept new inbound jobs if we have more than + this queued. The reason for this limit is to prevent a bad client + from consuming all server resources with new job requests. */ + +#define MAXJOBS 100 + +/* The server keeps a list of work items, sorted by expiration time, + so that we can use this to set the timeout to the correct value for + use in poll. */ +struct work { + struct work *next; + struct nn_msghdr request; + uint64_t expire; + void *control; +}; + +/* Return the UNIX time in milliseconds. You'll need a working + gettimeofday(), so this won't work on Windows. */ +uint64_t milliseconds (void) +{ + struct timeval tv; + gettimeofday (&tv, NULL); + return (((uint64_t)tv.tv_sec * 1000) + ((uint64_t)tv.tv_usec / 1000)); +} + +/* The server runs forever. */ +int server(const char *url) +{ + int fd; + struct work *worklist = NULL; + int npending = 0; + + /* Create the socket. */ + fd = nn_socket(AF_SP_RAW, NN_REP); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + /* Bind to the URL. This will bind to the address and listen + synchronously; new clients will be accepted asynchronously + without further action from the calling program. */ + + if (nn_bind (fd, url) < 0) { + fprintf (stderr, "nn_bind: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + /* Main processing loop. */ + + for (;;) { + uint32_t timer; + int rc; + int timeout; + uint64_t now; + struct work *work, **srch; + uint8_t *body; + void *control; + struct nn_iovec iov; + struct nn_msghdr hdr; + struct nn_pollfd pfd[1]; + + /* Figure out if any work requests are finished, and can be + responded to. */ + + timeout = -1; + while ((work = worklist) != NULL) { + + now = milliseconds (); + if (work->expire > now) { + timeout = (work->expire - now); + break; + } + worklist = work->next; + npending--; + rc = nn_sendmsg (fd, &work->request, NN_DONTWAIT); + if (rc < 0) { + fprintf (stderr, "nn_sendmsg: %s\n", + nn_strerror (nn_errno ())); + nn_freemsg (work->request.msg_control); + } + free (work); + } + + /* This check ensures that we don't allow more than a set limit + of concurrent jobs to be queued. This protects us from resource + exhaustion by malicious or defective clients. */ + + if (npending >= MAXJOBS) { + nn_poll (pfd, 0, timeout); + continue; + } + + pfd[0].fd = fd; + pfd[0].events = NN_POLLIN; + pfd[0].revents = 0; + nn_poll (pfd, 1, timeout); + + if ((pfd[0].revents & NN_POLLIN) == 0) { + continue; + } + + /* So there should be a message waiting for us to receive. + We handle it by parsing it, creating a work request for it, + and adding the work request to the worklist. */ + + memset (&hdr, 0, sizeof (hdr)); + control = NULL; + iov.iov_base = &body; + iov.iov_len = NN_MSG; + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = &control; + hdr.msg_controllen = NN_MSG; + + rc = nn_recvmsg (fd, &hdr, 0); + if (rc < 0) { + /* Any error here is unexpected. */ + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + break; + } + if (rc != sizeof (uint32_t)) { + fprintf (stderr, "nn_recv: wanted %d, but got %d\n", + (int) sizeof (uint32_t), rc); + nn_freemsg (body); + nn_freemsg (control); + continue; + } + + memcpy (&timer, body, sizeof (timer)); + nn_freemsg (body); + + work = malloc (sizeof (*work)); + if (work == NULL) { + fprintf (stderr, "malloc: %s\n", strerror (errno)); + /* Fatal error -- other programs can try to handle it better. */ + break; + } + memset (work, 0, sizeof (*work)); + work->expire = milliseconds () + ntohl (timer); + work->control = control; + work->request.msg_iovlen = 0; /* No payload data to send. */ + work->request.msg_iov = NULL; + work->request.msg_control = &work->control; + work->request.msg_controllen = NN_MSG; + + /* Insert the work request into the list in order. */ + srch = &worklist; + for (;;) { + if ((*srch == NULL) || ((*srch)->expire > work->expire)) { + work->next = *srch; + *srch = work; + npending++; + break; + } + srch = &((*srch)->next); + } + } + + /* This may wind up orphaning requests in the queue. We are going + to exit with an error anyway, so don't worry about it. */ + + nn_close (fd); + return (-1); +} + +/* The client runs just once, and then returns. */ +int client (const char *url, const char *msecstr) +{ + int fd; + int rc; + char *greeting; + uint8_t msg[sizeof (uint32_t)]; + uint64_t start; + uint64_t end; + unsigned msec; + + msec = atoi(msecstr); + + fd = nn_socket (AF_SP, NN_REQ); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + if (nn_connect (fd, url) < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + msec = htonl(msec); + memcpy (msg, &msec, sizeof (msec)); + + start = milliseconds (); + + if (nn_send (fd, msg, sizeof (msg), 0) < 0) { + fprintf (stderr, "nn_send: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + rc = nn_recv (fd, &msg, sizeof (msg), 0); + if (rc < 0) { + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + nn_close (fd); + + end = milliseconds (); + + printf ("Request took %u milliseconds.\n", (uint32_t)(end - start)); + return (0); +} + +int main (int argc, char **argv) +{ + int rc; + if (argc < 3) { + fprintf (stderr, "Usage: %s [-s|name]\n", argv[0]); + exit (EXIT_FAILURE); + } + if (strcmp (argv[2], "-s") == 0) { + rc = server (argv[1]); + } else { + rc = client (argv[1], argv[2]); + } + exit (rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/demo/pthread_demo.c b/node/node_modules/nanomsg/deps/nanomsg/demo/pthread_demo.c new file mode 100644 index 0000000..b377682 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/demo/pthread_demo.c @@ -0,0 +1,244 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + "nanomsg" is a trademark of Martin Sustrik +*/ + +/* This program serves as an example for how to write a threaded RPC service, + using the RAW request/reply pattern and pthreads. Multiple worker threads + are spawned on a single socket, and each worker processes jobs in order. + + Our demonstration application layer protocol is simple. The client sends + a number of milliseconds to wait before responding. The server just gives + back an empty reply after waiting that long. + + To run this program, start the server as pthread_demo -s + Then connect to it with the client as pthread_client . + + For example: + + % ./pthread_demo tcp://127.0.0.1:5555 -s & + % ./pthread_demo tcp://127.0.0.1:5555 323 + Request took 324 milliseconds. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* MAXWORKERS is a limit on the on the number of workers we will fire + off. Since each worker processes jobs sequentially, this is a limit + on the concurrency of the server. New inbound messages will queue up + waiting for a worker to receive them. */ + +#define MAXWORKERS 100 + +/* Return the UNIX time in milliseconds. You'll need a working + gettimeofday(), so this won't work on Windows. */ +uint64_t milliseconds (void) +{ + struct timeval tv; + gettimeofday (&tv, NULL); + return (((uint64_t)tv.tv_sec * 1000) + ((uint64_t)tv.tv_usec / 1000)); +} + +void *worker (void *arg) +{ + int fd = (intptr_t)arg; + + /* Main processing loop. */ + + for (;;) { + uint32_t timer; + int rc; + int timeout; + uint8_t *body; + void *control; + struct nn_iovec iov; + struct nn_msghdr hdr; + + memset (&hdr, 0, sizeof (hdr)); + control = NULL; + iov.iov_base = &body; + iov.iov_len = NN_MSG; + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = &control; + hdr.msg_controllen = NN_MSG; + + rc = nn_recvmsg (fd, &hdr, 0); + if (rc < 0) { + if (nn_errno () == EBADF) { + return (NULL); /* Socket closed by another thread. */ + } + /* Any error here is unexpected. */ + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + break; + } + + if (rc != sizeof (uint32_t)) { + fprintf (stderr, "nn_recv: wanted %d, but got %d\n", + (int) sizeof (uint32_t), rc); + nn_freemsg (body); + nn_freemsg (control); + continue; + } + + memcpy (&timer, body, sizeof (timer)); + nn_freemsg (body); + + /* Poor mans usleep but in msec. */ + poll (NULL, 0, ntohl (timer)); + + hdr.msg_iov = NULL; + hdr.msg_iovlen = 0; + + rc = nn_sendmsg (fd, &hdr, 0); + if (rc < 0) { + fprintf (stderr, "nn_send: %s\n", nn_strerror (nn_errno ())); + nn_freemsg (control); + } + } + + /* We got here, so close the file. That will cause the other threads + to shut down too. */ + + nn_close (fd); + return (NULL); +} +/* The server runs forever. */ +int server(const char *url) +{ + int fd; + int i; + pthread_t tids [MAXWORKERS]; + int rc; + + /* Create the socket. */ + fd = nn_socket(AF_SP_RAW, NN_REP); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + /* Bind to the URL. This will bind to the address and listen + synchronously; new clients will be accepted asynchronously + without further action from the calling program. */ + + if (nn_bind (fd, url) < 0) { + fprintf (stderr, "nn_bind: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + memset (tids, 0, sizeof (tids)); + + /* Start up the threads. */ + for (i = 0; i < MAXWORKERS; i++) { + rc = pthread_create (&tids[i], NULL, worker, (void *)(intptr_t)fd); + if (rc < 0) { + fprintf (stderr, "pthread_create: %s\n", strerror (rc)); + nn_close (fd); + break; + } + } + + /* Now wait on them to finish. */ + for (i = 0; i < MAXWORKERS; i++) { + if (tids[i] != NULL) { + pthread_join (tids[i], NULL); + } + } + return (-1); +} + +/* The client runs just once, and then returns. */ +int client (const char *url, const char *msecstr) +{ + int fd; + int rc; + char *greeting; + uint8_t msg[sizeof (uint32_t)]; + uint64_t start; + uint64_t end; + unsigned msec; + + msec = atoi(msecstr); + + fd = nn_socket (AF_SP, NN_REQ); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + if (nn_connect (fd, url) < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + msec = htonl(msec); + memcpy (msg, &msec, sizeof (msec)); + + start = milliseconds (); + + if (nn_send (fd, msg, sizeof (msg), 0) < 0) { + fprintf (stderr, "nn_send: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + rc = nn_recv (fd, &msg, sizeof (msg), 0); + if (rc < 0) { + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + nn_close (fd); + + end = milliseconds (); + + printf ("Request took %u milliseconds.\n", (uint32_t)(end - start)); + return (0); +} + +int main (int argc, char **argv) +{ + int rc; + if (argc < 3) { + fprintf (stderr, "Usage: %s [-s|name]\n", argv[0]); + exit (EXIT_FAILURE); + } + if (strcmp (argv[2], "-s") == 0) { + rc = server (argv[1]); + } else { + rc = client (argv[1], argv[2]); + } + exit (rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/demo/pubsub_demo.c b/node/node_modules/nanomsg/deps/nanomsg/demo/pubsub_demo.c new file mode 100644 index 0000000..f9a8fc7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/demo/pubsub_demo.c @@ -0,0 +1,178 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + "nanomsg" is a trademark of Martin Sustrik +*/ + +/* This program serves as an example for how to write a simple PUB SUB + service, The server is just a single threaded for loop which broadcasts + messages to clients, every so often. The message is a binary format + message, containing two 32-bit unsigned integers. The first is UNIX time, + and the second is the number of directly connected subscribers. + + The clients stay connected and print a message with this information + along with their process ID to standard output. + + To run this program, start the server as pubsub_demo -s + Then connect to it with the client as pubsub_demo + For example: + + % ./pubsub_demo tcp://127.0.0.1:5555 -s & + % ./pubsub_demo tcp://127.0.0.1:5555 & + % ./pubsub_demo tcp://127.0.0.1:5555 & + 11:23:54 There are 2 clients connected. + 11:24:04 There are 2 clients connected. + .. +*/ + +#include +#include +#include +#include +#include /* For htonl and ntohl */ +#include + +#include +#include + +/* The server runs forever. */ +int server(const char *url) +{ + int fd; + + /* Create the socket. */ + fd = nn_socket (AF_SP, NN_PUB); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + /* Bind to the URL. This will bind to the address and listen + synchronously; new clients will be accepted asynchronously + without further action from the calling program. */ + + if (nn_bind (fd, url) < 0) { + fprintf (stderr, "nn_bind: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + /* Now we can just publish results. Note that there is no explicit + accept required. We just start writing the information. */ + + for (;;) { + uint8_t msg[2 * sizeof (uint32_t)]; + uint32_t secs, subs; + int rc; + + secs = (uint32_t) time (NULL); + subs = (uint32_t) nn_get_statistic (fd, NN_STAT_CURRENT_CONNECTIONS); + + secs = htonl (secs); + subs = htonl (subs); + + memcpy (msg, &secs, sizeof (secs)); + memcpy (msg + sizeof (secs), &subs, sizeof (subs)); + + rc = nn_send (fd, msg, sizeof (msg), 0); + if (rc < 0) { + /* There are several legitimate reasons this can fail. + We note them for debugging purposes, but then ignore + otherwise. */ + fprintf (stderr, "nn_send: %s (ignoring)\n", + nn_strerror (nn_errno ())); + } + sleep(10); + } + + /* NOTREACHED */ + nn_close (fd); + return (-1); +} + +/* The client runs in a loop, displaying the content. */ +int client (const char *url) +{ + int fd; + int rc; + + fd = nn_socket (AF_SP, NN_SUB); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + if (nn_connect (fd, url) < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + /* We want all messages, so just subscribe to the empty value. */ + if (nn_setsockopt (fd, NN_SUB, NN_SUB_SUBSCRIBE, "", 0) < 0) { + fprintf (stderr, "nn_setsockopt: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + for (;;) { + uint8_t msg[2 * sizeof (uint32_t)]; + char hhmmss[9]; /* HH:MM:SS\0 */ + uint32_t subs, secs; + time_t t; + + rc = nn_recv (fd, msg, sizeof (msg), 0); + if (rc < 0) { + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + break; + } + if (rc != sizeof (msg)) { + fprintf (stderr, "nn_recv: got %d bytes, wanted %d\n", + rc, (int)sizeof (msg)); + break; + } + memcpy (&secs, msg, sizeof (secs)); + memcpy (&subs, msg + sizeof (secs), sizeof (subs)); + + t = (time_t) ntohl(secs); + strftime (hhmmss, sizeof (hhmmss), "%T", localtime (&t)); + + printf ("%s There are %u clients connected.\n", hhmmss, + (unsigned) getpid(), (unsigned) ntohl(subs)); + } + + nn_close (fd); + return (-1); +} + +int main (int argc, char **argv) +{ + int rc; + if ((argc == 3) && (strcmp (argv[2], "-s") == 0)) { + rc = server (argv[1]); + } else if (argc == 2) { + rc = client (argv[1]); + } else { + fprintf (stderr, "Usage: %s [-s]\n", argv[0]); + exit (EXIT_FAILURE); + } + exit (rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/demo/rpc_demo.c b/node/node_modules/nanomsg/deps/nanomsg/demo/rpc_demo.c new file mode 100644 index 0000000..c8d87d6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/demo/rpc_demo.c @@ -0,0 +1,207 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + "nanomsg" is a trademark of Martin Sustrik +*/ + +/* This program serves as an example for how to write a simple RPC service, + using the request/reply pattern. The server is just a single threaded + for loop, which processes each request. The requests run quickly enough + that there is no need for parallelism. + + Our demonstration application layer protocol is simple. The client sends + a name, and the server replies with a greeting based on the time of day. + The messages are sent in ASCII, and are not zero terminated. + + To run this program, start the server as rpc_demo -s + Then connect to it with the client as rpc_client . + The client will print a timezone appropriate greeting, based on + the time at the server. For example: + + % ./rpc_demo tcp://127.0.0.1:5555 -s & + % ./rpc_demo tcp://127.0.0.1:5555 Garrett + Good morning, Garrett. +*/ + +#include +#include +#include +#include + +#include +#include + +/* The server runs forever. */ +int server(const char *url) +{ + int fd; + + /* Create the socket. */ + fd = nn_socket (AF_SP, NN_REP); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + /* Bind to the URL. This will bind to the address and listen + synchronously; new clients will be accepted asynchronously + without further action from the calling program. */ + + if (nn_bind (fd, url) < 0) { + fprintf (stderr, "nn_bind: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + /* Now we can just process results. Note that there is no explicit + accept required. We just receive a request, and reply to it. + Its important to note that we must not issue two receives in a + row without replying first, or the following receive(s) will + cancel any unreplied requests. */ + + for (;;) { + char username[128]; + char greeting[128]; + time_t secs; + struct tm *now; + char *daytime; + int rc; + char *fmt; + + rc = nn_recv (fd, username, sizeof (username), 0); + if (rc < 0) { + /* Any error here is unexpected. */ + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + break; + } + + secs = time (NULL); + now = localtime (&secs); + if (now->tm_hour < 12) { + daytime = "morning"; + + } else if (now->tm_hour < 17) { + daytime = "afternoon"; + + } else if (now->tm_hour < 20) { + daytime = "evening"; + + } else { + daytime = "night"; + } + + /* Ensure ASCIIZ terminated string. */ + if (rc < sizeof (username)) { + username[rc] = '\0'; + } else { + username[sizeof (username) - 1] = '\0'; + } + + fmt = "Good %s, %s."; + + /* Technically this might be overly pessimistic about size. */ + if ((strlen (username) + strlen (daytime) + strlen (fmt)) >= + sizeof (greeting)) { + + fmt = "I'm sorry, your name is too long. But good %s anyway."; + } + + /* snprintf would be safer, but the above check protects us. */ + sprintf (greeting, fmt, daytime, username); + + rc = nn_send (fd, greeting, strlen (greeting), 0); + if (rc < 0) { + /* There are several legitimate reasons this can fail. + We note them for debugging purposes, but then ignore + otherwise. If the socket is closed or failing, we will + notice in recv above, and exit then. */ + fprintf (stderr, "nn_send: %s (ignoring)\n", + nn_strerror (nn_errno ())); + } + } + + nn_close (fd); + return (-1); +} + +/* The client runs just once, and then returns. */ +int client (const char *url, const char *username) +{ + int fd; + int rc; + char *greeting; + char *msg; + + fd = nn_socket (AF_SP, NN_REQ); + if (fd < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + return (-1); + } + + if (nn_connect (fd, url) < 0) { + fprintf (stderr, "nn_socket: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + if (nn_send (fd, username, strlen (username), 0) < 0) { + fprintf (stderr, "nn_send: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + /* Here we ask the library to allocate response buffer for us (NN_MSG). */ + rc = nn_recv (fd, &msg, NN_MSG, 0); + if (rc < 0) { + fprintf (stderr, "nn_recv: %s\n", nn_strerror (nn_errno ())); + nn_close (fd); + return (-1); + } + + nn_close (fd); + + /* Response is not ASCIIZ terminated. */ + greeting = malloc (rc + 1); + if (greeting == NULL) { + fprintf (stderr, "malloc: %s\n", strerror (errno)); + return (-1); + } + memcpy(greeting, msg, rc); + + nn_freemsg (msg); + printf ("%s\n", greeting); + return (0); +} + +int main (int argc, char **argv) +{ + int rc; + if (argc < 3) { + fprintf (stderr, "Usage: %s [-s|name]\n", argv[0]); + exit (EXIT_FAILURE); + } + if (strcmp (argv[2], "-s") == 0) { + rc = server (argv[1]); + } else { + rc = client (argv[1], argv[2]); + } + exit (rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/README b/node/node_modules/nanomsg/deps/nanomsg/doc/README new file mode 100644 index 0000000..8c4a6e7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/README @@ -0,0 +1,7 @@ +This directory contains the documentation for nanomsg library. To build the +documentation (both man pages and web pages) do "./configure --enable-doc" and +"make" in the build directory; man pages will be installed with "make install". +You must have asciidoctor installed. + +The stylesheet.css file is taken from asciidoctor-stylesheet-factory, and +is the colony theme. diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nanocat.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nanocat.txt new file mode 100644 index 0000000..8154192 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nanocat.txt @@ -0,0 +1,175 @@ +nanocat(1) +========== + +NAME +---- +nanocat - a command-line interface to nanomsg + + +SYNOPSIS +-------- + + nanocat --req {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + nanocat --rep {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-AQ] + nanocat --push {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] + nanocat --pull {--connect ADDR|--bind ADDR} [-AQ] + nanocat --pub {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] + nanocat --sub {--connect ADDR|--bind ADDR} [--subscribe PREFIX ...] [-AQ] + nanocat --surveyor {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + nanocat --respondent {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-AQ] + nanocat --bus {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + nanocat --pair {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + +In the case symlinks are installed: + + nn_req {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + nn_rep {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-AQ] + nn_push {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] + nn_pull {--connect ADDR|--bind ADDR} [-AQ] + nn_pub {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] + nn_sub {--connect ADDR|--bind ADDR} [--subscribe PREFIX ...] [-AQ] + nn_surveyor {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + nn_respondent {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-AQ] + nn_bus {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + nn_pair {--connect ADDR|--bind ADDR} {--data DATA|--file PATH} [-i SEC] [-AQ] + + +DESCRIPTION +----------- + +The nanocat is a command-line tool to send and receive data via nanomsg +sockets. It can be used for debugging purposes, sending files through the +network, health checking the system or whatever else you can think of. + + +OPTIONS +------- + +Generic: + + *--verbose,-v*:: + Increase verbosity of the nanocat + *--silent,-q*:: + Decrease verbosity of the nanocat + *--help,-h*:: + This help text + +Socket Types: + + *--push*:: + Use NN_PUSH socket type + *--pull*:: + Use NN_PULL socket type + *--pub*:: + Use NN_PUB socket type + *--sub*:: + Use NN_SUB socket type + *--req*:: + Use NN_REQ socket type + *--rep*:: + Use NN_REP socket type + *--surveyor*:: + Use NN_SURVEYOR socket type + *--respondent*:: + Use NN_RESPONDENT socket type + *--bus*:: + Use NN_BUS socket type + *--pair*:: + Use NN_PAIR socket type + +Socket Options: + + *--bind* 'ADDR':: + Bind socket to the address ADDR + *--connect* 'ADDR':: + Connect socket to the address ADDR + *--bind-ipc,-X* 'PATH':: + Bind socket to the ipc address "ipc://PATH". + *--connect-ipc,-x* 'PATH':: + Connect socket to the ipc address "ipc://PATH". + *--bind-local,-L* 'PORT':: + Bind socket to the tcp address "tcp://127.0.0.1:PORT". + *--connect-local,-l* 'PORT':: + Connect socket to the tcp address "tcp://127.0.0.1:PORT". + *--recv-timeout* 'SEC':: + Set timeout for receiving a message + *--send-timeout* 'SEC':: + Set timeout for sending a message + +SUB Socket Options: + + *--subscribe* 'PREFIX':: + Subscribe to the prefix PREFIX. Note: socket will be + subscribed to everything (empty prefix) if no prefixes + are specified on the command-line. + +Input Options: + + *--format* 'FORMAT':: + Use echo format FORMAT (same as the options below) + *--raw*:: + Dump message as is (Note: no delimiters are printed) + *--ascii,-A*:: + Print ASCII part of message delimited by newline. All + non-ascii characters replaced by dot. + *--quoted,-Q*:: + Print each message on separate line in double quotes + with C-like character escaping + *--msgpack*:: + Print each message as msgpacked string (raw type). This + is useful for programmatic parsing. + +Output Options: + + *--interval,-i* 'SEC':: + Send message (or request) every SEC seconds + *--delay,-d* 'SEC':: + Wait for SEC seconds before sending message (useful for one-shot + PUB sockets) + *--data,-D* 'DATA':: + Send DATA to the socket and quit for PUB, PUSH, PAIR, + BUS socket. Use DATA to reply for REP or RESPONDENT + socket. Send DATA as request for REQ or SURVEYOR socket. + *--file,-F* 'PATH':: + Same as --data but get data from file PATH + + +EXAMPLES +-------- + +The ping-pong with nn_req/nn_rep sockets (must be run simultaneously): + + nanocat --rep --bind tcp://127.0.0.1:1234 --data pong --format ascii + nanocat --req --connect tcp://127.0.0.1:1234 --data ping --format ascii + +Or in shorter to write form: + + nn_rep -L1234 -Dpong -A + nn_req -l1234 -Dping -A + +Do periodic requests once a second: + + nn_req -l1234 -Dping -A -i 1 + +The rep socket that never reply (no -D option), may be used to check if +resending the requests is actually work: + + nanocat --rep --connect ipc:///var/run/app/req.socket + +Send an output of the ls to whatever would connect to 127.0.0.1:1234 then exit: + + ls | nanocat --push -L1234 -F- + +Send heartbeats to imaginary monitoring service: + + nanocat --pub --connect tpc://monitoring.example.org -D"I am alive!" --interval 10 + + +SEE ALSO +-------- +<> + +AUTHORS +------- + +link:mailto:paul@colomiets.name[Paul Colomiets] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nanomsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nanomsg.txt new file mode 100644 index 0000000..4a8fea4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nanomsg.txt @@ -0,0 +1,131 @@ +nanomsg(7) +========== + + +NAME +---- +nanomsg - scalability protocols library + + +SYNOPSIS +-------- +*cc* ['flags'] 'files' *-lnanomsg* ['libraries'] + + +DESCRIPTION +----------- + +Following functions are exported by nanomsg library: + +Create an SP socket:: + <> + +Close an SP socket:: + <> + +Set a socket option:: + <> + +Retrieve a socket option:: + <> + +Add a local endpoint to the socket:: + <> + +Add a remote endpoint to the socket:: + <> + +Remove an endpoint from the socket:: + <> + +Send a message:: + <> + +Receive a message:: + <> + +Fine-grained alternative to nn_send:: + <> + +Fine-grained alternative to nn_recv:: + <> + +Allocation of messages:: + <> + <> + <> + +Manipulation of message control data:: + <> + +Multiplexing:: + <> + +Retrieve the current errno:: + <> + +Convert an error number into human-readable string:: + <> + +Query the names and values of nanomsg symbols:: + <> + +Query properties of nanomsg symbols:: + <> + +Query statistics on a socket:: + <> + +Start a device:: + <> + +Notify all sockets about process termination:: + <> + +Environment variables that influence nanomsg work:: + <> + +Following scalability protocols are provided by nanomsg: + +One-to-one protocol:: + <> + +Request/reply protocol:: + <> + +Publish/subscribe protocol:: + <> + +Survey protocol:: + <> + +Pipeline protocol:: + <> + +Message bus protocol:: + <> + +Following transport mechanisms are provided by nanomsg: + +In-process transport:: + <> + +Inter-process transport:: + <> + +TCP transport:: + <> + +WebSocket transport:: + <> + +The following tool is installed with the library: + +nanocat:: + <> + +AUTHORS +------- +link:mailto:garrett@damore.org[Garrett D'Amore] +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_allocmsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_allocmsg.txt new file mode 100644 index 0000000..13b509a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_allocmsg.txt @@ -0,0 +1,68 @@ +nn_allocmsg(3) +============== + +NAME +---- +nn_allocmsg - allocate a message + + +SYNOPSIS +-------- +*#include * + +*void *nn_allocmsg (size_t 'size', int 'type');* + + +DESCRIPTION +----------- +Allocate a message of the specified 'size' to be sent in zero-copy fashion. +The content of the message is undefined after allocation and it should be filled +in by the user. While <> and <> allow +to send arbitrary buffers, buffers allocated using _nn_allocmsg()_ can be more +efficient for large messages as they allow for using zero-copy techniques. + +'type' parameter specifies type of allocation mechanism to use. Zero is the +default one, however, individual transport mechanisms may define their +own allocation mechanisms, such as allocating in shared memory or allocating +a memory block pinned down to a physical memory address. Such allocation, +when used with the transport that defines them, should be more efficient +than the default allocation mechanism. + + +RETURN VALUE +------------ +If the function succeeds pointer to newly allocated buffer is returned. +Otherwise, NULL is returned and 'errno' is set to to one of the values +defined below. + + +ERRORS +------ +*EINVAL*:: +Supplied allocation 'type' is invalid. +*ENOMEM*:: +Not enough memory to allocate the message. + + +EXAMPLE +------- + +---- +void *buf = nn_allocmsg (12, 0); +memcpy (buf, "Hello world!", 12); +nn_send (s, &buf, NN_MSG, 0); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_bind.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_bind.txt new file mode 100644 index 0000000..619780f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_bind.txt @@ -0,0 +1,90 @@ +nn_bind(3) +========== + +NAME +---- +nn_bind - add a local endpoint to the socket + + +SYNOPSIS +-------- +*#include * + +*int nn_bind (int 's', const char '*addr');* + + +DESCRIPTION +----------- +Adds a local endpoint to the socket 's'. The endpoint can be then used by other +applications to connect to. + +The 'addr' argument consists of two parts as follows: 'transport'`://`'address'. +The 'transport' specifies the underlying transport protocol to use. The meaning +of the 'address' part is specific to the underlying transport protocol. + +For the list of available transport protocols check the list on +<> manual page. + +Maximum length of the 'addr' parameter is specified by _NN_SOCKADDR_MAX_ +defined in '' header file. + +Note that nn_bind and <> may be called multiple times +on the same socket thus allowing the socket to communicate with multiple +heterogeneous endpoints. + +RETURN VALUE +------------ +If the function succeeds positive endpoint ID is returned. Endpoint ID can be +later used to remove the endpoint from the socket via <> +function. + +If the function fails, then -1 is returned and 'errno' is set to to one of +the values defined below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*EMFILE*:: +Maximum number of active endpoints was reached. +*EINVAL*:: +The syntax of the supplied address is invalid. +*ENAMETOOLONG*:: +The supplied address is too long. +*EPROTONOSUPPORT*:: +The requested transport protocol is not supported. +*EADDRNOTAVAIL*:: +The requested endpoint is not local. +*ENODEV*:: +Address specifies a nonexistent interface. +*EADDRINUSE*:: +The requested local endpoint is already in use. +*ETERM*:: +The library is terminating. + + +EXAMPLE +------- + +---- +s = nn_socket (AF_SP, NN_PUB); +eid1 = nn_bind (s, "inproc://test"); +eid2 = nn_bind (s, "tcp://127.0.0.1:5560"); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_bus.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_bus.txt new file mode 100644 index 0000000..0420fd4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_bus.txt @@ -0,0 +1,57 @@ +nn_bus(7) +========= + +NAME +---- +nn_bus - message bus scalability protocol + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +Broadcasts messages from any node to all other nodes in the topology. The socket +should never receive messages that it sent itself. + +This pattern scales only to local level (within a single machine or within +a single LAN). Trying to scale it further can result in overloading individual +nodes with messages. + +WARNING: For bus topology to function correctly, user is responsible for +ensuring that path from each node to any other node exists within the topology. + +Raw (AF_SP_RAW) BUS socket never sends the message to the peer it was received +from. + +Socket Types +~~~~~~~~~~~~ + +NN_BUS:: + Sent messages are distributed to all nodes in the topology. Incoming + messages from all other nodes in the topology are fair-queued in the + socket. + +Socket Options +~~~~~~~~~~~~~~ + +There are no options defined at the moment. + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_close.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_close.txt new file mode 100644 index 0000000..63b83a5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_close.txt @@ -0,0 +1,59 @@ +nn_close(3) +=========== + +NAME +---- +nn_close - close an SP socket + + +SYNOPSIS +-------- +*#include * + +*int nn_close (int 's');* + + +DESCRIPTION +----------- +Closes the socket 's'. Any buffered inbound messages that were not yet received +by the application will be discarded. The library will try to deliver any +outstanding outbound messages for the time specified by _NN_LINGER_ socket +option. The call will block in the meantime. + + +RETURN VALUE +------------ +If the function succeeds zero is returned. Otherwise, -1 is +returned and 'errno' is set to to one of the values defined below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*EINTR*:: +Operation was interrupted by a signal. The socket is not fully closed yet. +Operation can be re-started by calling _nn_close()_ again. + + +EXAMPLE +------- + +---- +int s = nn_socket (AF_SP, NN_PUB); +assert (s >= 0); +int rc = nn_close (s); +assert (rc == 0); +---- + + +SEE ALSO +-------- +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_cmsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_cmsg.txt new file mode 100644 index 0000000..7ae9825 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_cmsg.txt @@ -0,0 +1,84 @@ +nn_cmsg(3) +========== + +NAME +---- +nn_cmsg - access control information + + +SYNOPSIS +-------- +*#include * + +*struct nn_cmsghdr *NN_CMSG_FIRSTHDR(struct nn_msghdr '*hdr');* + +*struct nn_cmsghdr *NN_CMSG_NXTHDR(struct nn_msghdr '*hdr', struct nn_cmsghdr '*cmsg');* + +*unsigned char *NN_CMSG_DATA(struct nn_cmsghdr '*cmsg');* + +*size_t NN_CMSG_SPACE(size_t 'len');* + +*size_t NN_CMSG_LEN(size_t 'len');* + +DESCRIPTION +----------- + +These functions can be used to iterate over ancillary data attached to a message. + +Structure 'nn_cmsghdr' represents a single ancillary property and contains following members: + + size_t cmsg_len; + int cmsg_level; + int cmsg_type; + +'cmsg_len' is the size of the property data, including the preceding nn_cmsghdr structure. +'cmsg_level' is the level of the property; same values can be used as with <> and <>. +'cmsg_type' is the name of the property. These names are specific for each level. + +_NN_CMSG_FIRSTHDR_ returns a pointer to the first nn_cmsghdr in the control buffer in the supplied nn_msghdr structure. + +_NN_CMSG_NXTHDR_ returns the next nn_cmsghdr after the supplied nn_cmsghdr. Returns NULL if there isn't enough space in the buffer. + +_NN_CMSG_DATA_ returns a pointer to the data associated with supplied nn_cmsghdr. + +_NN_CMSG_SPACE_ returns the number of bytes occupied by nn_cmsghdr with payload of the specified length. + +_NN_CMSG_LEN_ returns the value to store in the cmsg_len member of the cmsghdr structure, taking into account any necessary alignment. + +EXAMPLE +------- + +Iterating over ancillary properties: + +---- +struct nn_cmsghdr *hdr = NN_CMSG_FIRSTHDR (&msg); +while (hdr != NULL) { + size_t len = hdr->cmsg_len - sizeof (nn_cmsghdr); + printf ("level: %d property: %d length: %dB data: ", + (int) hdr->cmsg_level, + (int) hdr->cmsg_type, + (int) len); + unsigned char *data = NN_CMSG_DATA(hdr); + while (len) { + printf ("%02X", *data); + ++data; + --len; + } + printf ("\n"); + hdr = NN_CMSG_NXTHDR (&msg, hdr); +} +---- + +SEE ALSO +-------- +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_connect.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_connect.txt new file mode 100644 index 0000000..a82ec69 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_connect.txt @@ -0,0 +1,86 @@ +nn_connect(3) +============= + +NAME +---- +nn_connect - add a remote endpoint to the socket + + +SYNOPSIS +-------- +*#include * + +*int nn_connect (int 's', const char '*addr');* + + +DESCRIPTION +----------- +Adds a remote endpoint to the socket 's'. The library would then try to connect +to the specified remote endpoint. + +The 'addr' argument consists of two parts as follows: 'transport'`://`'address'. +The 'transport' specifies the underlying transport protocol to use. The meaning +of the 'address' part is specific to the underlying transport protocol. + +For the list of available transport protocols check the list on +<> manual page. + +Maximum length of the 'addr' parameter is specified by _NN_SOCKADDR_MAX_ +defined in '' header file. + +Note that nn_connect and <> may be called multiple times +on the same socket thus allowing the socket to communicate with multiple +heterogeneous endpoints. + +RETURN VALUE +------------ +If the function succeeds positive endpoint ID is returned. Endpoint ID can be +later used to remove the endpoint from the socket via <> +function. + +If the function fails negative value is returned and 'errno' is set to to one of +the values defined below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*EMFILE*:: +Maximum number of active endpoints was reached. +*EINVAL*:: +The syntax of the supplied address is invalid. +*ENAMETOOLONG*:: +The supplied address is too long. +*EPROTONOSUPPORT*:: +The requested transport protocol is not supported. +*ENODEV*:: +Address specifies a nonexistent interface. +*ETERM*:: +The library is terminating. + + +EXAMPLE +------- + +---- +s = nn_socket (AF_SP, NN_PUB); +eid1 = nn_connect (s, "ipc:///tmp/test.ipc"); +eid2 = nn_connect (s, "tcp://server001:5560"); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_device.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_device.txt new file mode 100644 index 0000000..8adb038 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_device.txt @@ -0,0 +1,67 @@ +nn_device(3) +============ + +NAME +---- +nn_device - start a device + + +SYNOPSIS +-------- +*#include * + +*int nn_device (int 's1', int 's2');* + + +DESCRIPTION +----------- +Starts a device to forward messages between two sockets. If both sockets are +valid, _nn_device_ function loops and sends any messages received from 's1' to +'s2' and vice versa. If only one socket is valid and the other is negative, +_nn_device_ works in a "loopback" mode -- it loops and sends any messages +received from the socket back to itself. + +To break the loop and make _nn_device_ function exit use the +<> function. + +RETURN VALUE +------------ +The function loops until it hits an error. In such a case it returns -1 +and sets 'errno' to one of the values defined below. + +ERRORS +------ +*EBADF*:: +One of the provided sockets is invalid. +*EINVAL*:: +Either one of the socket is not an AF_SP_RAW socket; or the two sockets don't +belong to the same protocol; or the directionality of the sockets doesn't fit +(e.g. attempt to join two SINK sockets to form a device). +*EINTR*:: +The operation was interrupted by delivery of a signal. +*ETERM*:: +The library is terminating. + +EXAMPLE +------- + +---- +int s1 = nn_socket (AF_SP_RAW, NN_REQ); +nn_bind (s1, "tcp://127.0.0.1:5555"); +int s2 = nn_socket (AF_SP_RAW, NN_REP); +nn_bind (s2, "tcp://127.0.0.1:5556"); +nn_device (s1, s2); +---- + + +SEE ALSO +-------- +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_env.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_env.txt new file mode 100644 index 0000000..3ccd095 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_env.txt @@ -0,0 +1,50 @@ +nn_env(7) +========== + + +NAME +---- +nn_env - nanomsg environment variables + + +SYNOPSIS +-------- +Environment variables that influence the way nanomsg works + + +DESCRIPTION +----------- + +*This functionality is experimental and a subject to change at any time* + +Following environment variables are used to turn on some debugging for any +nanomsg application. Please, do not try to parse output and do not +build business logic based on it. + +NN_PRINT_ERRORS:: + If set to a non-empty string nanomsg will print errors to stderr. Some + errors will be resolved by nanomsg itself (e.g. if nanomsg can't establish + connection it will retry again in a moment). Some depend on the + environment (e.g. port that is bound by another process need to be + released). In any case nanomsg will not repeat the error message until + error is clear and appear again (e.g. connection established then broken + again). + + +NOTES +----- + +The output of the debugging facility (NN_PRINT_ERRORS) +is intended for reading by a human and a subject for change at any time (even +after 1.0 release). + + +SEE ALSO +-------- +<> + + +AUTHORS +------- +link:mailto:paul@colomiets.name[Paul Colomiets] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_errno.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_errno.txt new file mode 100644 index 0000000..b09ab89 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_errno.txt @@ -0,0 +1,57 @@ +nn_errno(3) +=========== + +NAME +---- +nn_errno - retrieve the current errno + + +SYNOPSIS +-------- +*#include * + +*int nn_errno (void);* + + +DESCRIPTION +----------- +Returns value of 'errno' for the current thread. + +On most systems, 'errno' can be accessed directly and this function is not +needed. However, on Windows, there are multiple implementations of the CRT +library (single-threaded, multi-threaded, release, debug) and each of them +has its own instance of 'errno'. Thus, if nanomsg library and the application +that uses it link with different versions of the CRT library, they don't share +the same instance of 'errno'. Consequently, error codes set by nanomsg cannot be +accessed by the application. To overcome this problem, application can use +_nn_errno()_ function to retrieve nanomsg's value of 'errno'. + +RETURN VALUE +------------ +Returns value of 'errno' for the current thread. + + +ERRORS +------ +No errors are defined. + + +EXAMPLE +------- + +---- +rc = nn_send (s, "ABC", 3, 0); +if (rc < 0) + printf ("nn_send failed with error code %d\n", nn_errno ()); +---- + + +SEE ALSO +-------- +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_freemsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_freemsg.txt new file mode 100644 index 0000000..da8743f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_freemsg.txt @@ -0,0 +1,58 @@ +nn_freemsg(3) +============= + +NAME +---- +nn_freemsg - deallocate a message + + +SYNOPSIS +-------- +*#include * + +*int nn_freemsg (void '*msg');* + + +DESCRIPTION +----------- +Deallocates a message allocated using <> function or +received via <> or <> function. +While <> and <> allow to receive data +into arbitrary buffers, using library-allocated buffers can be more +efficient for large messages as it allows for using zero-copy techniques. + + +RETURN VALUE +------------ +If the function succeeds zero is returned. Otherwise, -1 is +returned and 'errno' is set to to one of the values defined below. + + +ERRORS +------ +*EFAULT*:: +The message pointer is invalid. + + +EXAMPLE +------- + +---- +void *buf; +nn_recv (s, &buf, NN_MSG, 0); +nn_freemsg (buf); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_get_statistic.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_get_statistic.txt new file mode 100644 index 0000000..0360e61 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_get_statistic.txt @@ -0,0 +1,101 @@ +nn_get_statistic(3) +=================== + +NAME +---- +nn_get_statistic - retrieve statistics from nanomsg socket + + +SYNOPSIS +-------- +*#include * + +*uint64_t *nn_get_statistic (int 's', int 'statistic');* + + +DESCRIPTION +----------- +Retrieves the value of a statistic from the socket. + +CAUTION: While this API is stable, these statistics are intended for +human consumption, to facilitate observability and debugging. +The actual statistics themselves as well as their meanings are unstable, +and subject to change without notice. +Programs should not depend on the presence or values of any particular +statistic. + +The following statistics are maintained by the nanomsg core framework; +others may be present. As those are undocumented, no interpretration should +be made from them. Not all statistics are relevant to all transports. +For example, the <> transport does not +maintain any of the connection related statistics. + + +*NN_STAT_ESTABLISHED_CONNECTIONS*:: + The number of connections successfully established that were initiated + from this socket. +*NN_STAT_ACCEPTED_CONNECTIONS*:: + The number of connections successfully established that were accepted + by this socket. +*NN_STAT_DROPPED_CONNECTIONS*:: + The number of established connections that were dropped by this socket. +*NN_STAT_BROKEN_CONNECTIONS*:: + The number of established connections that were closed by this socket, + typically due to protocol errors. +*NN_STAT_CONNECT_ERRORS*:: + The number of errors encountered by this socket trying to connect to + a remote peer. +*NN_STAT_BIND_ERRORS*:: + The number of errors encountered by this socket trying to bind to + a local address. +*NN_STAT_ACCEPT_ERRORS*:: + The number of errors encountered by this socket trying to accept a + a connection from a remote peer. +*NN_STAT_CURRENT_CONNECTIONS*:: + The number of connections currently estabalished to this socket. +*NN_STAT_MESSAGES_SENT*:: + The number messages sent by this socket. +*NN_STAT_MESSAGES_RECEIVED*:: + The number messages received by this socket. +*NN_STAT_BYTES_SENT*:: + The number of bytes sent by this socket. +*NN_STAT_BYTES_RECEIVED*:: + The number of bytes received by this socket. + + +RETURN VALUE +------------ +On success, the value of the statistic is returned, otherwise (uint64_t)-1 +is returned. + + +ERRORS +------ +*EINVAL*:: +The statistic is invalid or unsupported. +*EBADF*:: +The provided socket is invalid. +*ETERM*:: +The library is terminating. + + +EXAMPLE +------- + +---- +val = nn_get_statistic (s, NN_STAT_SENT_MESSAGES); +if (val == 0) + printf ("No messages have been sent yet.\n"); +---- + +SEE ALSO +-------- +<> +<> +<> + + +AUTHORS +------- +link:mailto:garrett@damore.org[Garrett D'Amore] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_getsockopt.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_getsockopt.txt new file mode 100644 index 0000000..7d5810f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_getsockopt.txt @@ -0,0 +1,156 @@ +nn_getsockopt(3) +================ + +NAME +---- +nn_getsockopt - retrieve a socket option + + +SYNOPSIS +-------- +*#include * + +*int nn_getsockopt (int 's', int 'level', int 'option', void '*optval', size_t '*optvallen');* + +DESCRIPTION +----------- +Retrieves the value for the 'option'. The 'level' argument specifies +the protocol level at which the option resides. For generic socket-level options +use _NN_SOL_SOCKET_ level. For socket-type-specific options use socket type +for 'level' argument (e.g. _NN_SUB_). For transport-specific options use ID of +the transport as the 'level' argument (e.g. _NN_TCP_). + +The value is stored in the buffer pointed to by 'optval' argument. Size of the +buffer is specified by the 'optvallen' argument. If the size of the option is +greater than size of the buffer, the value will be silently truncated. +Otherwise, the 'optvallen' will be modified to indicate the actual length of +the option. + +__ header defines generic socket-level options +(_NN_SOL_SOCKET_ level). The options are as follows: + +*NN_DOMAIN*:: + Returns the domain constant as it was passed to _nn_socket()_. +*NN_PROTOCOL*:: + Returns the protocol constant as it was passed to _nn_socket()_. +*NN_LINGER*:: + Specifies how long the socket should try to send pending outbound messages + after _nn_close()_ have been called, in milliseconds. Negative value means + infinite linger. The type of the option is int. Default value + is 1000 (1 second). +*NN_SNDBUF*:: + Size of the send buffer, in bytes. To prevent blocking for messages larger + than the buffer, exactly one message may be buffered in addition to the data + in the send buffer. The type of this option is int. Default value is 128kB. +*NN_RCVBUF*:: + Size of the receive buffer, in bytes. To prevent blocking for messages + larger than the buffer, exactly one message may be buffered in addition + to the data in the receive buffer. The type of this option is int. Default + value is 128kB. +*NN_RCVMAXSIZE*:: + Maximum message size that can be received, in bytes. Negative value means + that the received size is limited only by available addressable memory. The + type of this option is int. Default is 1024kB. +*NN_SNDTIMEO*:: + The timeout for send operation on the socket, in milliseconds. If message + cannot be sent within the specified timeout, EAGAIN error is returned. + Negative value means infinite timeout. The type of the option is int. + Default value is -1. +*NN_RCVTIMEO*:: + The timeout for recv operation on the socket, in milliseconds. If message + cannot be received within the specified timeout, EAGAIN error is returned. + Negative value means infinite timeout. The type of the option is int. + Default value is -1. +*NN_RECONNECT_IVL*:: + For connection-based transports such as TCP, this option specifies how + long to wait, in milliseconds, when connection is broken before trying + to re-establish it. Note that actual reconnect interval may be randomised + to some extent to prevent severe reconnection storms. The type of the option + is int. Default value is 100 (0.1 second). +*NN_RECONNECT_IVL_MAX*:: + This option is to be used only in addition to _NN_RECONNECT_IVL_ option. + It specifies maximum reconnection interval. On each reconnect attempt, + the previous interval is doubled until _NN_RECONNECT_IVL_MAX_ is reached. + Value of zero means that no exponential backoff is performed and reconnect + interval is based only on _NN_RECONNECT_IVL_. If _NN_RECONNECT_IVL_MAX_ is + less than _NN_RECONNECT_IVL_, it is ignored. The type of the option is int. + Default value is 0. +*NN_SNDPRIO*:: + Retrieves outbound priority currently set on the socket. This + option has no effect on socket types that send messages to all the peers. + However, if the socket type sends each message to a single peer + (or a limited set of peers), peers with high priority take precedence + over peers with low priority. The type of the option is int. Highest + priority is 1, lowest priority is 16. Default value is 8. +*NN_RCVPRIO*:: + Sets inbound priority for endpoints subsequently added to the socket. This + option has no effect on socket types that are not able to receive messages. + When receiving a message, messages from peer with higher priority are + received before messages from peer with lower priority. The type of the + option is int. Highest priority is 1, lowest priority is 16. Default value + is 8. +*NN_IPV4ONLY*:: + If set to 1, only IPv4 addresses are used. If set to 0, both IPv4 and IPv6 + addresses are used. The type of the option is int. Default value is 1. +*NN_SNDFD*:: + Retrieves a file descriptor that is readable when a message can be sent + to the socket. The descriptor should be used only for polling and never + read from or written to. The type of the option is same as the type of + file descriptor on the platform. That is, int on POSIX-complaint platforms + and SOCKET on Windows. The descriptor becomes invalid and should not be + used any more once the socket is closed. This socket option is not available + for unidirectional recv-only socket types. +*NN_RCVFD*:: + Retrieves a file descriptor that is readable when a message can be received + from the socket. The descriptor should be used only for polling and never + read from or written to. The type of the option is same as the type of + file descriptor on the platform. That is, int on POSIX-complaint platforms + and SOCKET on Windows. The descriptor becomes invalid and should not be + used any more once the socket is closed. This socket option is not available + for unidirectional send-only socket types. +*NN_SOCKET_NAME*:: + Socket name for error reporting and statistics. The type of the option + is string. Default value is "N" where N is socket integer. + *This option is experimental, see <> for details* +*NN_TTL*:: + Retrieves the maximum number of "hops" a message can go through before + it is dropped. Each time the message is received (for example via + the <> function) counts as a single hop. + This provides a form of protection against inadvertent loops. + + +RETURN VALUE +------------ +If the function succeeds zero is returned. Otherwise, -1 is +returned and 'errno' is set to to one of the values defined below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*ENOPROTOOPT*:: +The option is unknown at the level indicated. +*ETERM*:: +The library is terminating. + +EXAMPLE +------- + +---- +int linger; +size_t sz = sizeof (linger); +nn_getsockopt (s, NN_SOL_SOCKET, NN_LINGER, &linger, &sz); +---- + + +SEE ALSO +-------- +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] +link:mailto:garrett@damore.org[Garrett D'Amore] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_inproc.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_inproc.txt new file mode 100644 index 0000000..7b65bf4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_inproc.txt @@ -0,0 +1,56 @@ +nn_inproc(7) +============ + +NAME +---- +nn_inproc - in-process transport mechanism + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +In-process transport allows to send messages between threads or modules inside a +process. In-process address is an arbitrary case-sensitive string preceded by +'inproc://' protocol specifier. All in-process addresses are visible from any +module within the process. They are not visible from outside of the process. + +The nature of in-process transport makes it easy to pass pointers between +threads instead of actual data. This is, however, considered a bad application +design and violates the scalable share-nothing architecture. If you do pass +pointers among threads, synchronising thread access to shared data becomes +your responsibility. Such design also prevents moving the thread into different +process or machine once the need arises. As a rule of the thumb, don't pass +pointers among threads unless you know what you are doing. + +The overall buffer size for an inproc connection is determined by NN_RCVBUF +socket option on the receiving end of the connection. NN_SNDBUF socket option +is ignored. In addition to the buffer, one message of arbitrary size will fit +into the buffer. That way, even messages larger than the buffer can be +transfered via inproc connection. + +EXAMPLE +------- + +---- +nn_bind (s1, "inproc://test"); +nn_connect (s2, "inproc://test); +---- + +SEE ALSO +-------- +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_ipc.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_ipc.txt new file mode 100644 index 0000000..410dcab --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_ipc.txt @@ -0,0 +1,51 @@ +nn_ipc(7) +========= + +NAME +---- +nn_ipc - inter-process transport mechanism + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +Inter-process transport allows for sending messages between processes within +a single box. The implementation uses native IPC mechanism provided by the local +operating system and the IPC addresses are thus OS-specific. + +On POSIX-compliant systems, UNIX domain sockets are used and IPC addresses are +file references. Note that both relative (ipc://test.ipc) and absolute +(ipc:///tmp/test.ipc) paths may be used. Also note that access rights on the IPC +files must be set in such a way that the appropriate applications can actually +use them. + +On Windows, named pipes are used for IPC. IPC address is an arbitrary +case-insensitive string containing any character except for backslash. +Internally, address ipc://test means that named pipe \\.\pipe\test will be used. + +EXAMPLE +------- + +---- +nn_bind (s1, "ipc:///tmp/test.ipc"); +nn_connect (s2, "ipc:///tmp/test.ipc"); +---- + +SEE ALSO +-------- +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pair.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pair.txt new file mode 100644 index 0000000..e825992 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pair.txt @@ -0,0 +1,58 @@ +nn_pair(7) +========== + +NAME +---- +nn_pair - one-to-one scalability protocol + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +Pair protocol is the simplest and least scalable scalability protocol. It allows +scaling by breaking the application in exactly two pieces. For example, +if a monolithic application handles both accounting and agenda of HR department, +it can be split into two applications (accounting vs. HR) that are run on two +separate servers. These applications can then communicate via PAIR sockets. + +The downside of this protocol is that its scaling properties are very limited. +Splitting the application into two pieces allows to scale the two servers. +To add the third server to the cluster, the application has to be split once +more, say by separating HR functionality into hiring module and salary +computation module. Whenever possible, try to use one of the more scalable +protocols instead. + +Socket Types +~~~~~~~~~~~~ + +NN_PAIR:: + Socket for communication with exactly one peer. Each party can send messages + at any time. If the peer is not available or send buffer is full subsequent + calls to <> will block until it's possible to send the + message. + +Socket Options +~~~~~~~~~~~~~~ + +No protocol-specific socket options are defined at the moment. + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pipeline.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pipeline.txt new file mode 100644 index 0000000..465eef2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pipeline.txt @@ -0,0 +1,49 @@ +nn_pipeline(7) +============== + +NAME +---- +nn_pipeline - scalability protocol for passing tasks through a series of processing steps + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +Fair queues messages from the previous processing step and load balances them +among instances of the next processing step. + +Socket Types +~~~~~~~~~~~~ + +NN_PUSH:: + This socket is used to send messages to a cluster of load-balanced + nodes. Receive operation is not implemented on this socket type. +NN_PULL:: + This socket is used to receive a message from a cluster of nodes. Send + operation is not implemented on this socket type. + +Socket Options +~~~~~~~~~~~~~~ + +No protocol-specific socket options are defined at the moment. + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_poll.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_poll.txt new file mode 100644 index 0000000..8b7542d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_poll.txt @@ -0,0 +1,110 @@ +nn_poll(3) +========== + +NAME +---- +nn_poll - poll a set of SP sockets for readability and/or writability + + +SYNOPSIS +-------- +*#include * + +*int nn_poll (struct nn_pollfd *fds, int nfds, int timeout);* + + +DESCRIPTION +----------- +The function checks a set of SP socket and reports whether it's possible to +send a message to the socket and/or receive a message from each socket. + +'fds' argument is an array of nn_pollfd structures with 'nfds' argument +specifying the size of the array: + +---- +struct nn_pollfd { + int fd; + short events; + short revents; +}; +---- + +Each entry in the array represents an SP socket to check. 'events' field +specifies which events to check for. The value is a bitwise combination of +the following values: + +*NN_POLLIN*:: +Check whether at least one message can be received from the 'fd' socket without +blocking. + +*NN_POLLOUT*:: +Check whether at least one message can be sent to the 'fd' socket without +blocking. + +After the function returns, 'revents' field contains bitwise combination of +NN_POLLIN and NN_POLLOUT according to whether the socket is readable or +writable. + +'timeout' parameter specifies how long (in milliseconds) should the function +block if there are no events to report. + +RETURN VALUE +------------ +Upon successful completion, the number of nn_pollfds structures with events +signaled is returned. In case of timeout, return value is 0. In case of error, +-1 is returned and 'errno' is set the one of the values below. + + +ERRORS +------ +*EBADF*:: +Some of the provided sockets are invalid. +*EINTR*:: +The operation was interrupted by delivery of a signal before the message was +sent. +*ETERM*:: +The library is terminating. + +NOTE +---- +nn_poll is a convenience function. You can achieve same behaviour by using +NN_RCVFD and NN_SNDFD socket options. However, using the socket options +allows for usage that's not possible with nn_poll, such as simultaneous polling +for both SP and OS-level sockets, integration of SP sockets with external event +loops etc. + +EXAMPLE +------- + +---- +struct nn_pollfd pfd [2]; +pfd [0].fd = s1; +pfd [0].events = NN_POLLIN | NN_POLLOUT; +pfd [1].fd = s2; +pfd [1].events = NN_POLLIN; +rc = nn_poll (pfd, 2, 2000); +if (rc == 0) { + printf ("Timeout!"); + exit (1); +} +if (rc == -1) { + printf ("Error!"); + exit (1); +} +if (pfd [0].revents & NN_POLLIN) { + printf ("Message can be received from s1!"); + exit (1); +} +---- + + +SEE ALSO +-------- +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pubsub.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pubsub.txt new file mode 100644 index 0000000..5503692 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_pubsub.txt @@ -0,0 +1,103 @@ +nn_pubsub(7) +============ + +NAME +---- +nn_pubsub - publish/subscribe scalability protocol + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +Broadcasts messages to multiple destinations. + +Messages are sent from NN_PUB sockets and will only be received by NN_SUB +sockets that have subscribed to the matching 'topic'. Topic is an arbitrary +sequence of bytes at the beginning of the message body. The NN_SUB socket will +determine whether a message should be delivered to the user by comparing the +subscribed topics (using NN_SUB_SUBSCRIBE on a full SUB socket) to the bytes +initial bytes in the incoming message, up to the size of the topic. + +---- +nn_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "Hello", 5); +---- + +Will match any message with intial 5 bytes being "Hello", for example, +message "Hello, World!" will match. + +Topic with zero length matches any message. + +If the socket is subscribed to multiple topics, message matching any of them +will be delivered to the user. + +Since the filtering is performed on the Subscriber side, all the messages +from Publisher will be sent over the transport layer. + +The entire message, including the topic, is delivered to the user. + +Socket Types +~~~~~~~~~~~~ + +NN_PUB:: + This socket is used to distribute messages to multiple destinations. + Receive operation is not defined. +NN_SUB:: + Receives messages from the publisher. Only messages that the socket is + subscribed to are received. When the socket is created there are no + subscriptions and thus no messages will be received. Send operation is + not defined on this socket. + +Socket Options +~~~~~~~~~~~~~~ + +NN_SUB_SUBSCRIBE:: + Defined on full SUB socket. Subscribes for a particular topic. Type of the + option is string. A single NN_SUB socket can handle multiple subscriptions. +NN_SUB_UNSUBSCRIBE:: + Defined on full SUB socket. Unsubscribes from a particular topic. Type of + the option is string. + +EXAMPLE +~~~~~~~ + +---- +int pub = nn_socket (AF_SP, NN_PUB); +int sub = nn_socket (AF_SP, NN_SUB); +int nbytes; +void *buf = NULL; + +nn_setsockopt (sub, NN_SUB, NN_SUB_SUBSCRIBE, "foo", 3); +nn_setsockopt (sub, NN_SUB, NN_SUB_SUBSCRIBE, "bar", 3); + +nbytes = nn_send (pub, "foo|Hello!", 10); +assert(nbytes == 10); +nbytes = nn_recv (sub, &buf, NN_MSG, 0); +assert (nbytes == 10); +nn_freemsg (buf); + +nbytes = nn_send (pub, "baz|World!", 10); + +/* Message is not delivered because if matches no subscription. */ +nbytes = nn_recv(sub, &buf, NN_MSG, 0); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_reallocmsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_reallocmsg.txt new file mode 100644 index 0000000..eb82d92 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_reallocmsg.txt @@ -0,0 +1,56 @@ +nn_reallocmsg(3) +================ + +NAME +---- +nn_reallocmsg - reallocate a message + + +SYNOPSIS +-------- +*#include * + +*void *nn_reallocmsg (void *'msg', size_t 'size');* + +DESCRIPTION +----------- +Reallocate a message previously allocated by <> or +received from a peer using NN_MSG mechanism. + +Note that as with the standard _realloc_, the operation may involve copying +the data in the buffer. + + +RETURN VALUE +------------ +If the function succeeds pointer to newly allocated buffer is returned. +Otherwise, NULL is returned and 'errno' is set to to one of the values +defined below. + + +ERRORS +------ +*ENOMEM*:: +Not enough memory to allocate the message. + + +EXAMPLE +------- + +---- +void *buf = nn_allocmsg (12, 0); +void *newbuf = nn_reallocmsg (buf, 20); +nn_freemsg (newbuf); +---- + + +SEE ALSO +-------- +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_recv.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_recv.txt new file mode 100644 index 0000000..1b9272a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_recv.txt @@ -0,0 +1,113 @@ +nn_recv(3) +========== + +NAME +---- +nn_recv - receive a message + + +SYNOPSIS +-------- +*#include * + +*int nn_recv (int 's', void '*buf', size_t 'len', int 'flags');* + + +DESCRIPTION +----------- +Receive a message from the socket 's' and store it in the buffer referenced by +the 'buf' argument. Any bytes exceeding the length specified by the 'len' +argument will be truncated. + +Alternatively, _nanomsg_ can allocate the buffer for you. To do so, +let the 'buf' parameter be a pointer to a void* variable (pointer to pointer) +to the receive buffer and set the 'len' parameter to _NN_MSG_. If the call is +successful the user is responsible for deallocating the message using +the <> function. + +The 'flags' argument is a combination of the flags defined below: + +*NN_DONTWAIT*:: +Specifies that the operation should be performed in non-blocking mode. If the +message cannot be received straight away, the function will fail with 'errno' +set to EAGAIN. + + +RETURN VALUE +------------ +If the function succeeds number of bytes in the message is returned. Otherwise, +-1 is returned and 'errno' is set to to one of the values defined +below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*ENOTSUP*:: +The operation is not supported by this socket type. +*EFSM*:: +The operation cannot be performed on this socket at the moment because socket is +not in the appropriate state. This error may occur with socket types that +switch between several states. +*EAGAIN*:: +Non-blocking mode was requested and there's no message to receive at the moment. +*EINTR*:: +The operation was interrupted by delivery of a signal before the message was +received. +*ETIMEDOUT*:: +Individual socket types may define their own specific timeouts. If such timeout +is hit this error will be returned. +*ETERM*:: +The library is terminating. + +EXAMPLES +-------- + +Receiving a message into a buffer allocated by the user:: + +This example code will retrieve a message of either 100 bytes or less. If a +larger message was sent it will be truncated to 100 bytes. + +---- +char buf [100]; +nbytes = nn_recv (s, buf, sizeof (buf), 0); +---- + +Receiving a message into a buffer allocated by _nanomsg_:: + +The following will get a message from the pipe with a buffer allocated by +the system. It is large enough to accommodate the entire message. This is a good +way to get the entire message without truncating if the size of the message is +unknown. It is the user's responsibility to call <> after +processing the message. + +---- +void *buf = NULL; +nbytes = nn_recv (s, &buf, NN_MSG, 0); + +if (nbytes < 0) { + /* handle error */ + ... +} +else { + /* process message */ + ... + nn_freemsg (buf); +} +---- + +Note that this can be more efficient than manually allocating a buffer since +it is a zero-copy operation. + +SEE ALSO +-------- +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_recvmsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_recvmsg.txt new file mode 100644 index 0000000..b658a4b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_recvmsg.txt @@ -0,0 +1,118 @@ +nn_recvmsg(3) +============= + +NAME +---- +nn_recvmsg - fine-grained alternative to nn_recv + + +SYNOPSIS +-------- +*#include * + +*NN_EXPORT int nn_recvmsg (int 's', struct nn_msghdr '*msghdr', int 'flags');* + + +DESCRIPTION +----------- +Receives a message from socket 's' into buffers specified by 'msghdr' parameter +along with any additional control data. 'msghdr' parameter should be nullified +before being used. + +Structure 'nn_msghdr' contains at least following members: + + struct nn_iovec *msg_iov; + int msg_iovlen; + void *msg_control; + size_t msg_controllen; + +'msg_iov' points to a gather array of buffers to fill in. 'msg_iovlen' specifies +the size of the array. + +'msg_control' points to the buffer to hold control information associated with +the received message. 'msg_controllen' specifies the length of the buffer. +If the control information should not be retrieved, set 'msg_control' parameter +to NULL. For detailed discussion of how to parse the control information check +<> man page. + +Structure 'nn_iovec' defines one element in the gather array (a buffer to be +filled in by message data) and contains following members: + + void *iov_base; + size_t iov_len; + +Alternatively, _nanomsg_ library can allocate the buffer for you. To do so, +let the 'iov_base' point to void* variable to receive the buffer and set +'iov_len' to _NN_MSG_. After successful completion user is responsible +for deallocating the message using <> function. Gather +array in _nn_msghdr_ structure can contain only one element in this case. + +The 'flags' argument is a combination of the flags defined below: + +*NN_DONTWAIT*:: +Specifies that the operation should be performed in non-blocking mode. If the +message cannot be received straight away, the function will fail with 'errno' +set to EAGAIN. + + +RETURN VALUE +------------ +If the function succeeds number of bytes in the message is returned. Otherwise, +-1 is returned and 'errno' is set to to one of the values defined +below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*ENOTSUP*:: +The operation is not supported by this socket type. +*EFSM*:: +The operation cannot be performed on this socket at the moment because socket is +not in the appropriate state. This error may occur with socket types that +switch between several states. +*EAGAIN*:: +Non-blocking mode was requested and there's no message to receive at the moment. +*EINTR*:: +The operation was interrupted by delivery of a signal before the message was +received. +*ETIMEDOUT*:: +Individual socket types may define their own specific timeouts. If such timeout +is hit this error will be returned. +*ETERM*:: +The library is terminating. + +EXAMPLE +------- + +---- +struct nn_msghdr hdr; +struct nn_iovec iov [2]; +char buf0 [4]; +char buf1 [2]; +iov [0].iov_base = buf0; +iov [0].iov_len = sizeof (buf0); +iov [1].iov_base = buf1; +iov [1].iov_len = sizeof (buf1); +memset (&hdr, 0, sizeof (hdr)); +hdr.msg_iov = iov; +hdr.msg_iovlen = 2; +nn_recvmsg (s, &hdr, 0); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_reqrep.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_reqrep.txt new file mode 100644 index 0000000..4624824 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_reqrep.txt @@ -0,0 +1,70 @@ +nn_reqrep(7) +============ + +NAME +---- +nn_reqrep - request/reply scalability protocol + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +This protocol is used to distribute the workload among multiple stateless +workers. + +Please note that request/reply applications should be stateless. + +It's important to include all the information necessary to process the +request in the request itself, including information about the sender or +the originator of the request if this is necessary to respond to the request. + +Sender information cannot be retrieved from the underlying socket connection +since, firstly, transports like IPC may not have a firm notion of a message +origin. Secondly, transports that have some notion may not have a reliable one +-- a TCP disconnect may mean a new sender, or it may mean a temporary loss in +network connectivity. + +For this reason, sender information must be included by the application if +required. Allocating 6 randomly-generated bytes in the message for the lifetime +of the connection is sufficient for most purposes. For longer-lived +applications, an UUID is more suitable. + + +Socket Types +~~~~~~~~~~~~ + +NN_REQ:: + Used to implement the client application that sends requests and + receives replies. +NN_REP:: + Used to implement the stateless worker that receives requests and sends + replies. + +Socket Options +~~~~~~~~~~~~~~ + +NN_REQ_RESEND_IVL:: + This option is defined on the full REQ socket. If reply is not received + in specified amount of milliseconds, the request will be automatically + resent. The type of this option is int. Default value is 60000 (1 minute). + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_send.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_send.txt new file mode 100644 index 0000000..bc00052 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_send.txt @@ -0,0 +1,98 @@ +nn_send(3) +========== + +NAME +---- +nn_send - send a message + + +SYNOPSIS +-------- +*#include * + +*int nn_send (int 's', const void '*buf', size_t 'len', int 'flags');* + +DESCRIPTION +----------- +The function will send a message containing the data from buffer pointed to +by 'buf' parameter to the socket 's'. The message will be 'len' bytes long. + +Alternatively, to send a buffer allocated by <> function +set the buf parameter to point to the pointer to the buffer and 'len' parameter +to _NN_MSG_ constant. In this case a successful call to _nn_send_ will +deallocate the buffer. Trying to deallocate it afterwards will result in +undefined behaviour. + +Which of the peers the message will be sent to is determined by +the particular socket type. + +The 'flags' argument is a combination of the flags defined below: + +*NN_DONTWAIT*:: +Specifies that the operation should be performed in non-blocking mode. If the +message cannot be sent straight away, the function will fail with 'errno' set +to EAGAIN. + + +RETURN VALUE +------------ +If the function succeeds, the number of bytes in the message is returned. +Otherwise, -1 is returned and 'errno' is set to to one of the +values defined below. + + +ERRORS +------ +*EFAULT*:: +'buf' is NULL or 'len' is NN_MSG and the message pointer (pointed to by +'buf') is NULL. +*EBADF*:: +The provided socket is invalid. +*ENOTSUP*:: +The operation is not supported by this socket type. +*EFSM*:: +The operation cannot be performed on this socket at the moment because the socket +is not in the appropriate state. This error may occur with socket types that +switch between several states. +*EAGAIN*:: +Non-blocking mode was requested and the message cannot be sent at the moment. +*EINTR*:: +The operation was interrupted by delivery of a signal before the message was +sent. +*ETIMEDOUT*:: +Individual socket types may define their own specific timeouts. If such timeout +is hit, this error will be returned. +*ETERM*:: +The library is terminating. + +EXAMPLE +------- + +Using data directly: + +---- +nbytes = nn_send (s, "ABC", 3, 0); +assert (nbytes == 3); +---- + +Using a pre-allocated message buffer: + +---- +void *msg = nn_allocmsg(3, 0); +strncpy(msg, "ABC", 3); +nbytes = nn_send (s, &msg, NN_MSG, 0); +assert (nbytes == 3); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_sendmsg.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_sendmsg.txt new file mode 100644 index 0000000..c15dcd4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_sendmsg.txt @@ -0,0 +1,151 @@ +nn_sendmsg(3) +============= + +NAME +---- +nn_sendmsg - fine-grained alternative to nn_send + + +SYNOPSIS +-------- +*#include * + +*int nn_sendmsg (int 's', const struct nn_msghdr '*msghdr', int 'flags');* + +DESCRIPTION +----------- + +Sends data specified by 'msghdr' parameter to socket 's' along with any +additional control data. 'msghdr' structure should be nullified before being +used. + +Structure 'nn_msghdr' contains at least following members: + + struct nn_iovec *msg_iov; + int msg_iovlen; + void *msg_control; + size_t msg_controllen; + +'msg_iov' points to a scatter array of buffers to send. 'msg_iovlen' specifies +the size of the array. + +'msg_control' points to the buffer containing control information to be +associated with the message being sent. 'msg_controllen' specifies the length +of the buffer. If there's no control information to send, 'msg_control' should +be set to NULL. For detailed discussion of how to set control data check +<> man page. + +Structure 'nn_iovec' defines one element in the scatter array (i.e. a buffer +to send to the socket) and contains following members: + + void *iov_base; + size_t iov_len; + +Alternatively, to send a buffer allocated by <> function +set 'iov_base' to point to the pointer to the buffer and 'iov_len' to _NN_MSG_ +constant. In this case a successful call to _nn_sendmsg_ will deallocate the +buffer. Trying to deallocate it afterwards will result in undefined behaviour. +Also, scatter array in _nn_msghdr_ structure can contain only one element +in this case. + +To which of the peers will the message be sent to is determined by +the particular socket type. + +The 'flags' argument is a combination of the flags defined below: + +*NN_DONTWAIT*:: +Specifies that the operation should be performed in non-blocking mode. If the +message cannot be sent straight away, the function will fail with 'errno' set +to EAGAIN. + + +RETURN VALUE +------------ +If the function succeeds number of bytes in the message is returned. Otherwise, +-1 is returned and 'errno' is set to to one of the values defined below. + + +ERRORS +------ +*EINVAL*:: +Either 'msghdr' is NULL, there are multiple scatter buffers but length is +set to 'NN_MSG' for one of them, or the sum of 'iov_len' values for the +scatter buffers overflows 'size_t'. These are early checks and no +pre-allocated message is freed in this case. +*EMSGSIZE*:: +msghdr->msg_iovlen is negative. This is an early check and no pre-allocated +message is freed in this case. +*EFAULT*:: +The supplied pointer for the pre-allocated message buffer or the scatter +buffer is NULL, or the length for the scatter buffer is 0. +*EBADF*:: +The provided socket is invalid. +*ENOTSUP*:: +The operation is not supported by this socket type. +*EFSM*:: +The operation cannot be performed on this socket at the moment because socket is +not in the appropriate state. This error may occur with socket types that +switch between several states. +*EAGAIN*:: +Non-blocking mode was requested and the message cannot be sent at the moment. +*EINTR*:: +The operation was interrupted by delivery of a signal before the message was +sent. +*ETIMEDOUT*:: +Individual socket types may define their own specific timeouts. If such timeout +is hit this error will be returned. +*ETERM*:: +The library is terminating. + + +EXAMPLE +------- + +Usage of multiple scatter buffers: + +---- +struct nn_msghdr hdr; +struct nn_iovec iov [2]; + +iov [0].iov_base = "Hello"; +iov [0].iov_len = 5; +iov [1].iov_base = "World"; +iov [1].iov_len = 5; +memset (&hdr, 0, sizeof (hdr)); +hdr.msg_iov = iov; +hdr.msg_iovlen = 2; +nn_sendmsg (s, &hdr, 0); +---- + +Usage of a single message: + +---- +void *msg; +struct nn_msghdr hdr; +struct nn_iovec iov; + +msg = nn_allocmsg(12, 0); +strcpy(msg, "Hello World"); +iov.iov_base = &msg; +iov.iov_len = NN_MSG; +memset (&hdr, 0, sizeof (hdr)); +hdr.msg_iov = &iov; +hdr.msg_iovlen = 1; +nn_sendmsg (s, &hdr, 0); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_setsockopt.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_setsockopt.txt new file mode 100644 index 0000000..3e53371 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_setsockopt.txt @@ -0,0 +1,138 @@ +nn_setsockopt(3) +================ + +NAME +---- +nn_setsockopt - set a socket option + + +SYNOPSIS +-------- +*#include * + +*int nn_setsockopt (int 's', int 'level', int 'option', const void '*optval', size_t 'optvallen');* + + +DESCRIPTION +----------- +Sets the value of the 'option'. The 'level' argument specifies the protocol +level at which the option resides. For generic socket-level options use +_NN_SOL_SOCKET_ level. For socket-type-specific options use socket type +for 'level' argument (e.g. _NN_SUB_). For transport-specific options use ID of +the transport as the 'level' argument (e.g. _NN_TCP_). + +The new value is pointed to by 'optval' argument. Size of the option is +specified by the 'optvallen' argument. + +__ header defines generic socket-level options +(_NN_SOL_SOCKET_ level). The options are as follows: + +*NN_LINGER*:: + Specifies how long the socket should try to send pending outbound messages + after _nn_close()_ have been called, in milliseconds. Negative value means + infinite linger. The type of the option is int. Default value + is 1000 (1 second). +*NN_SNDBUF*:: + Size of the send buffer, in bytes. To prevent blocking for messages larger + than the buffer, exactly one message may be buffered in addition to the data + in the send buffer. The type of this option is int. Default value is 128kB. +*NN_RCVBUF*:: + Size of the receive buffer, in bytes. To prevent blocking for messages + larger than the buffer, exactly one message may be buffered in addition + to the data in the receive buffer. The type of this option is int. Default + value is 128kB. +*NN_RCVMAXSIZE*:: + Maximum message size that can be received, in bytes. Negative value means + that the received size is limited only by available addressable memory. The + type of this option is int. Default is 1024kB. +*NN_SNDTIMEO*:: + The timeout for send operation on the socket, in milliseconds. If message + cannot be sent within the specified timeout, ETIMEDOUT error is returned. + Negative value means infinite timeout. The type of the option is int. + Default value is -1. +*NN_RCVTIMEO*:: + The timeout for recv operation on the socket, in milliseconds. If message + cannot be received within the specified timeout, ETIMEDOUT error is + returned. Negative value means infinite timeout. The type of the option + is int. Default value is -1. +*NN_RECONNECT_IVL*:: + For connection-based transports such as TCP, this option specifies how + long to wait, in milliseconds, when connection is broken before trying + to re-establish it. Note that actual reconnect interval may be randomised + to some extent to prevent severe reconnection storms. The type of the option + is int. Default value is 100 (0.1 second). +*NN_RECONNECT_IVL_MAX*:: + This option is to be used only in addition to _NN_RECONNECT_IVL_ option. + It specifies maximum reconnection interval. On each reconnect attempt, + the previous interval is doubled until _NN_RECONNECT_IVL_MAX_ is reached. + Value of zero means that no exponential backoff is performed and reconnect + interval is based only on _NN_RECONNECT_IVL_. If _NN_RECONNECT_IVL_MAX_ is + less than _NN_RECONNECT_IVL_, it is ignored. The type of the option is int. + Default value is 0. +*NN_SNDPRIO*:: + Sets outbound priority for endpoints subsequently added to the socket. This + option has no effect on socket types that send messages to all the peers. + However, if the socket type sends each message to a single peer + (or a limited set of peers), peers with high priority take precedence + over peers with low priority. The type of the option is int. Highest + priority is 1, lowest priority is 16. Default value is 8. +*NN_RCVPRIO*:: + Sets inbound priority for endpoints subsequently added to the socket. This + option has no effect on socket types that are not able to receive messages. + When receiving a message, messages from peer with higher priority are + received before messages from peer with lower priority. The type of the + option is int. Highest priority is 1, lowest priority is 16. Default value + is 8. +*NN_IPV4ONLY*:: + If set to 1, only IPv4 addresses are used. If set to 0, both IPv4 and IPv6 + addresses are used. The type of the option is int. Default value is 1. +*NN_SOCKET_NAME*:: + Socket name for error reporting and statistics. The type of the option + is string. Default value is "socket.N" where N is socket integer. + *This option is experimental, see <> for details* +*NN_TTL*:: + Sets the maximum number of "hops" a message can go through before + it is dropped. Each time the message is received (for example via + the <> function) counts as a single hop. + This provides a form of protection against inadvertent loops. + + + +RETURN VALUE +------------ +If the function succeeds zero is returned. Otherwise, -1 is +returned and 'errno' is set to to one of the values defined below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*ENOPROTOOPT*:: +The option is unknown at the level indicated. +*EINVAL*:: +The specified option value is invalid. +*ETERM*:: +The library is terminating. + +EXAMPLE +------- + +---- +int linger = 1000; +nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &linger, sizeof (linger)); +nn_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "ABC", 3); +---- + + +SEE ALSO +-------- +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] +link:mailto:garrett@damore.org[Garrett D'Amore] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_shutdown.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_shutdown.txt new file mode 100644 index 0000000..77cb0dd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_shutdown.txt @@ -0,0 +1,64 @@ +nn_shutdown(3) +============== + +NAME +---- +nn_shutdown - remove an endpoint from a socket + + +SYNOPSIS +-------- +*#include * + +*int nn_shutdown (int 's', int 'how');* + + +DESCRIPTION +----------- +Removes an endpoint from socket 's'. 'how' parameter specifies the ID of the +endpoint to remove as returned by prior call to <> or +<>. _nn_shutdown()_ call will return immediately, +however, the library will try to deliver any outstanding outbound messages to +the endpoint for the time specified by _NN_LINGER_ socket option. + + +RETURN VALUE +------------ +If the function succeeds zero is returned. Otherwise, -1 is +returned and 'errno' is set to to one of the values defined below. + + +ERRORS +------ +*EBADF*:: +The provided socket is invalid. +*EINVAL*:: +The 'how' parameter doesn't correspond to an active endpoint. +*EINTR*:: +Operation was interrupted by a signal. The endpoint is not fully closed yet. +Operation can be re-started by calling _nn_shutdown()_ again. +*ETERM*:: +The library is terminating. + + +EXAMPLE +------- + +---- +s = nn_socket (AF_SP, NN_PUB); +eid = nn_bind (s, "inproc://test"); +nn_shutdown (s, eid); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_socket.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_socket.txt new file mode 100644 index 0000000..060100f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_socket.txt @@ -0,0 +1,92 @@ +nn_socket(3) +============ + +NAME +---- +nn_socket - create an SP socket + + +SYNOPSIS +-------- +*#include * + +*int nn_socket (int 'domain', int 'protocol');* + + +DESCRIPTION +----------- +Creates an SP socket with specified 'domain' and 'protocol'. Returns a file +descriptor for the newly created socket. + +Following domains are defined at the moment: + +*AF_SP*:: +Standard full-blown SP socket. + +*AF_SP_RAW*:: +Raw SP socket. Raw sockets omit the end-to-end functionality found in AF_SP +sockets and thus can be used to implement intermediary devices in SP topologies. + +'protocol' parameter defines the type of the socket, which in turn determines +the exact semantics of the socket. Check manual pages for individual SP +protocols to get the list of available socket types. + +The newly created socket is initially not associated with any endpoints. +In order to establish a message flow at least one endpoint has to be added +to the socket using <> or <> +function. + +Also note that 'type' argument as found in standard _socket(2)_ function is +omitted from _nn_socket_. All the SP sockets are message-based and thus of +_SOCK_SEQPACKET_ type. + + +RETURN VALUE +------------ +If the function succeeds file descriptor of the new socket is returned. +Otherwise, -1 is returned and 'errno' is set to to one of +the values defined below. + +Note that file descriptors returned by _nn_socket_ function are not standard +file descriptors and will exhibit undefined behaviour when used with system +functions. Moreover, it may happen that a system file descriptor and file +descriptor of an SP socket will incidentally collide (be equal). + + +ERRORS +------ +*EAFNOSUPPORT*:: +Specified address family is not supported. +*EINVAL*:: +Unknown protocol. +*EMFILE*:: +The limit on the total number of open SP sockets or OS limit for file +descriptors has been reached. +*ETERM*:: +The library is terminating. + +EXAMPLE +------- + +---- +int s = nn_socket (AF_SP, NN_PUB); +assert (s >= 0); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> +<> +<> +<> + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_strerror.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_strerror.txt new file mode 100644 index 0000000..4e3fe76 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_strerror.txt @@ -0,0 +1,52 @@ +nn_strerror(3) +============== + +NAME +---- +nn_strerror - convert an error number into human-readable string + + +SYNOPSIS +-------- +*#include * + +*const char *nn_strerror (int 'errnum');* + + +DESCRIPTION +----------- +Converts error number (errno) into a human-readable string. As opposed to +'strerror(3)' this function handles nanomsg-specific errors in addition +to standard system errors. + + +RETURN VALUE +------------ +Return error message string. + + +ERRORS +------ +No errors are defined. + + +EXAMPLE +------- + +---- +rc = nn_send (s, "ABC", 3, 0); +if (rc < 0) + printf ("nn_send failed: %s\n", nn_strerror (errno)); +---- + +SEE ALSO +-------- +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_survey.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_survey.txt new file mode 100644 index 0000000..9c1e97d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_survey.txt @@ -0,0 +1,57 @@ +nn_survey(7) +============ + +NAME +---- +nn_survey - survey scalability protocol + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +Allows to broadcast a survey to multiple locations and gather the responses. + +Socket Types +~~~~~~~~~~~~ + +NN_SURVEYOR:: + Used to send the survey. The survey is delivered to all the connected + respondents. Once the query is sent, the socket can be used to receive + the responses. When the survey deadline expires, receive will return + ETIMEDOUT error. +NN_RESPONDENT:: + Use to respond to the survey. Survey is received using receive function, + response is sent using send function. This socket can be connected to + at most one peer. + + +Socket Options +~~~~~~~~~~~~~~ + +NN_SURVEYOR_DEADLINE:: + Specifies how long to wait for responses to the survey. Once the deadline + expires, receive function will return ETIMEDOUT error and all subsequent + responses to the survey will be silently dropped. The deadline is measured + in milliseconds. Option type is int. Default value is 1000 (1 second). + + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_symbol.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_symbol.txt new file mode 100644 index 0000000..b9b572b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_symbol.txt @@ -0,0 +1,74 @@ +nn_symbol(3) +============ + +NAME +---- +nn_symbol - query the names and values of nanomsg symbols + + +SYNOPSIS +-------- +*#include * + +*const char *nn_symbol (int 'i', int '*value');* + + +DESCRIPTION +----------- +Retrieves the symbol name and value at index 'i'. Indices start at 0. An index +has no significance to its associated symbol; the mappings may change between +library versions. + +Typically a client will iterate through the symbols until nn_symbol returns +NULL in order to collect all the symbols. + +All symbols exposed by 'nn_symbol' are available directly in the C API, +generally as preprocessor macros. Thus, this function is useful mostly for +language bindings that can't parse the header file and rely on retrieving the +symbols in the runtime. + +Note that the NN_MSG symbol is not exported by the _nn_symbol_ function. First, +it is a pointer rather than an integer; second, the symbol is not supposed to +be exported from language bindings to the user. Instead, language bindings +should provide the zero-copy functionality in a language-specific way, if at +all (zero-copy functionality may not make sense for some languages/bindings). + + +RETURN VALUE +------------ +If 'i' is valid, returns the name of the symbol at that index. If the pointer +'value' is not NULL, the symbol's value is stored there. + +If 'i' is out-of-range, nn_symbol returns NULL and sets 'errno' to EINVAL. + + +ERRORS +------ +*EINVAL*:: +The passed index 'i' was out-of-range; it was less than zero or greater-than-or- +equal-to the number of symbols. + + +EXAMPLE +------- + +---- +int value, i; +for (i = 0; ; ++i) { + const char* name = nn_symbol (i, &value); + if (name == NULL) break; + printf ("'%s' = %d\n", name, value); +} +---- + +SEE ALSO +-------- +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:evan@neomantra.net[Evan Wies] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_symbol_info.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_symbol_info.txt new file mode 100644 index 0000000..caaf9c4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_symbol_info.txt @@ -0,0 +1,155 @@ +nn_symbol_info(3) +================= + +NAME +---- +nn_symbol_info - query the names and properties of nanomsg symbols + + +SYNOPSIS +-------- +*#include * + +*int nn_symbol_info (int 'i', struct nn_symbol_properties '*buf', int 'buflen');* + + +DESCRIPTION +----------- +Retrieves the symbol name and value at index 'i'. Indices start at 0. An index +has no significance to its associated symbol; the mappings may change between +library versions. + +The nn_symbol_properties has the following definition: + +---- +struct nn_symbol_properties { + + /* The constant value */ + int value; + + /* The constant name */ + const char* name; + + /* The constant namespace, or zero for namespaces themselves */ + int ns; + + /* The option type for socket option constants */ + int type; + + /* The unit for the option value for socket option constants */ + int unit; +}; +---- + +More structure members may be added in future, but the input pointer will be +written only up to 'buflen' so the ABI is forward-compatible. + +Typically a client will iterate through the symbols until nn_symbol_info +returns NULL in order to collect all the symbols. + +All symbols exposed by 'nn_symbol_info' are available directly in the C API, +generally as preprocessor macros. Thus, this function is useful mostly for +language bindings that can't parse the header file and rely on retrieving the +symbols at runtime. + +Note that the NN_MSG symbol is not exported by the 'nn_symbol_info' function. +First, it is a pointer rather than an integer; second, the symbol is not +supposed to be exported from language bindings to the user. Instead, language +bindings should provide the zero-copy functionality in a language-specific way, +if at all (zero-copy functionality may not make sense for some +languages/bindings). + +AVAILABLE NAMESPACES +-------------------- +*NN_NS_NAMESPACE*:: +Equals to zero and denotes the NN_NS_* constants themselves +*NN_NS_VERSION*:: +Nanomsg version constants +*NN_NS_DOMAIN*:: +Socket domain (or address family) constants AF_SP, AF_SP_RAW +*NN_NS_TRANSPORT*:: +Transport name constants (used for socket options mainly) +*NN_NS_PROTOCOL*:: +Socket protocol constants +*NN_NS_OPTION_LEVEL*:: +Socket option level constants (NN_SOL_SOCKET) +*NN_NS_SOCKET_OPTION*:: +Socket options for NN_SOL_SOCKET level +*NN_NS_TRANSPORT_OPTION*:: +Socket options for transport level (used with transport constants) +*NN_NS_OPTION_TYPE*:: +The option types (described below) +*NN_NS_FLAG*:: +The nn_send/nn_recv flags (only NN_DONTWAIT for now) +*NN_NS_ERROR*:: +The errno values +*NN_NS_LIMIT*:: +Various nanomsg limits (only NN_SOCKADDR_MAX for now) +*NN_NS_EVENT*:: +Event flags (bit mask) for use with nn_poll (NN_POLLIN, NN_POLLOUT) + +AVAILABLE OPTION TYPES +---------------------- +*NN_TYPE_NONE*:: +No type, is returned for constants that are not socket options +*NN_TYPE_INT*:: +The integer type +*NN_TYPE_STR*:: +String (char *) type + +More types may be added in the future to nanomsg. You may enumerate all of them +using the 'nn_symbol_info' itself by checking 'NN_NS_OPTION_TYPE' namespace. + +AVAILABLE OPTION UNITS +---------------------- +*NN_UNIT_NONE*:: +No unit, is returned for constants that are not socket options, or do not have +any meaningful unit (strings, integer values) +*NN_UNIT_BYTES*:: +The option value is expressed in bytes +*NN_UNIT_MILLISECONDS*:: +The option value is expressed in milliseconds +*NN_UNIT_PRIORITY*:: +The option value is a priority, an integer from 1 to 16 +*NN_UNIT_BOOLEAN*:: +The option value is boolean, an integer 0 or 1 + +More types may be added in the future to nanomsg. You may enumerate all of them +using the 'nn_symbol_info' itself by checking 'NN_NS_OPTION_TYPE' namespace. + + +RETURN VALUE +------------ +If 'i' is valid, returns the number of bytes stored at the structure. The +maximum value that can be returned is 'buflen'. + +If 'i' is out-of-range, nn_symbol_info returns zero. + + +EXAMPLE +------- + +---- +int i; +for (i = 0; ; ++i) { + struct nn_symbol_properties sym; + int rc = nn_symbol_info (i, &sym, sizeof (sym)); + if(rc == 0) + break; + assert (rc == sizeof (sym)); + printf ("'%s' = %d\n", sym.name, sym.value); +} +---- + +SEE ALSO +-------- +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:paul@colomiets.name[Paul Colomiets] +link:mailto:garrett@damore.org[Garrett D'Amore] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_tcp.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_tcp.txt new file mode 100644 index 0000000..ec308bd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_tcp.txt @@ -0,0 +1,77 @@ +nn_tcp(7) +========= + +NAME +---- +nn_tcp - TCP transport mechanism + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- +TCP transport allows for passing messages over the network using simple reliable +one-to-one connections. TCP is the most widely used transport protocol, it is +virtually ubiquitous and thus the transport of choice for communication over +the network. + +When binding a TCP socket address of the form tcp://interface:port should be +used. Port is the TCP port number to use. Interface is one of the following +(optionally placed within square brackets): + +* Asterisk character (*) meaning all local network interfaces. +* IPv4 address of a local network interface in numeric form (192.168.0.111). +* IPv6 address of a local network interface in numeric form (::1). + +When connecting a TCP socket address of the form tcp://interface;address:port +should be used. Port is the TCP port number to use. Interface is optional and +specifies which local network interface to use. If not specified, OS will select +an appropriate interface itself. If specified it can be one of the following +(optionally placed within square brackets): + +* IPv4 address of a local network interface in numeric form (192.168.0.111). +* IPv6 address of a local network interface in numeric form (::1). + +Finally, address specifies the remote address to connect to. It can be one of +the following (optionally placed within square brackets): + +* IPv4 address of a remote network interface in numeric form (192.168.0.111). +* IPv6 address of a remote network interface in numeric form (::1). +* The DNS name of the remote box. + + +Socket Options +~~~~~~~~~~~~~~ + +NN_TCP_NODELAY:: + This option, when set to 1, disables Nagle's algorithm. It also disables + delaying of TCP acknowledgments. Using this option improves latency at + the expense of throughput. Type of this option is int. Default value is 0. + + +EXAMPLE +------- + +---- +nn_bind (s1, "tcp://*:5555"); +nn_connect (s2, "tcp://myserver:5555"); +---- + +SEE ALSO +-------- +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_term.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_term.txt new file mode 100644 index 0000000..5803acb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_term.txt @@ -0,0 +1,58 @@ +nn_term(3) +========== + +NAME +---- +nn_term - notify all sockets about process termination + + +SYNOPSIS +-------- +*#include * + +*void nn_term (void);* + + +DESCRIPTION +----------- +To help with shutdown of multi-threaded programs nanomsg provides the +_nn_term()_ function which informs all the open sockets that process +termination is underway. + +If a socket is blocked inside a blocking function, such as +<>, it will be unblocked and ETERM error will be returned +to the user. Similarly, any subsequent attempt to invoke a socket function other +than <> after _nn_term()_ was called will result +in ETERM error. + +If waiting for _NN_SNDFD_ or _NN_RCVFD_ using a polling function, such as +_poll()_ or _select()_, the call will unblock with both _NN_SNDFD_ and +_NN_RCVFD_ signaled. + +The _nn_term()_ function itself is non-blocking. + + +EXAMPLE +------- + +---- +s = nn_socket (AF_SP, NN_PAIR); +nn_term (); +rc = nn_send (s, "ABC", 3, 0); +assert (rc == -1 && errno == ETERM); +---- + + +SEE ALSO +-------- +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/nn_ws.txt b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_ws.txt new file mode 100644 index 0000000..102b463 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/nn_ws.txt @@ -0,0 +1,102 @@ +nn_ws(7) +======== + +NAME +---- +nn_ws - WebSocket transport mechanism + + +SYNOPSIS +-------- +*#include * + +*#include * + + +DESCRIPTION +----------- + +The WebSocket transport uses the framing protocol specified in RFC 6455 to +transport messages. The initial handshake is done using HTTP headers, with the +`Sec-Websocket-Protocol` header set to the SP protocol used by the server. +For example, a REQ client will send `rep.sp.nanomsg.org`. + +Each SP message is transported in a single WebSocket frame, with no additional +data or headers applied. By default this library sends and expects to receive +binary frames. + +When calling either `nn_bind()` or `nn_connect()`, omitting the port defaults +to the RFC 6455 default port 80 for HTTP. For example, `ws://127.0.0.1` is +equivalent to `ws://127.0.0.1:80` + +WebSocket over TLS is not supported by this library, at this time. + +URI limitations +~~~~~~~~~~~~~~~ +When calling `nn_connect()`, the URI may also optionally include the path to a +resource and/or query parameters. + +.Path and query parameters +========================== + s1 = nn_socket (AF_SP, NN_PAIR); + nn_connect (s1, "ws://example.com/path?query=value"); +========================== + +This implementation includes the full path and any query parameters in the +HTTP handshake when establishing connections with `nn_connect()`. This +information is not available via the nanomsg API afterwards, however. + +Likewise, this implementation does not examine or use either any path or +query parameters that may be supplied to `nn_bind()`, as it only binds to +the TCP port. This implementation acts as a limited HTTP server that offers +SP over WebSocket at all URIs for the given TCP address. + +Applications, however, should not depend on this behavior; intervening +infrastructure may proxy, filter or route based on URI, and other +implementations of the SP over WebSocket protocol may offer other +HTTP services at the same TCP port, utilizing the path, query parameters, +or both to determine the service to be used. + +Socket Options +~~~~~~~~~~~~~~ + +NN_WS_MSG_TYPE:: + This option may be set to NN_WS_MSG_TYPE_TEXT or NN_WS_MSG_TYPE_BINARY. + The value of this determines whether data messages are sent as WebSocket + text frames, or binary frames, per RFC 6455. Text frames should contain + only valid UTF-8 text in their payload, or they will be rejected. Binary + frames may contain any data. Not all WebSocket implementations support + binary frames. The default is to send binary frames. ++ +This option may also be specified as control data when when sending +a message with `nn_sendmsg()`. + +TODO: NN_TCP_NODELAY:: + This option, when set to 1, disables Nagle's algorithm. It also disables + delaying of TCP acknowledgments. Using this option improves latency at + the expense of throughput. Type of this option is int. Default value is 0. + + +EXAMPLE +------- + +---- +nn_bind (s1, "ws://*:5555"); +nn_connect (s2, "ws://myserver:5555"); +---- + +SEE ALSO +-------- +<> +<> +<> +<> +<> +<> + + +AUTHORS +------- +link:mailto:sustrik@250bpm.com[Martin Sustrik] +link:mailto:jack@wirebirdlabs.com[Jack R. Dunaway] +link:mailto:garrett@damore.org[Garrett D'Amore] diff --git a/node/node_modules/nanomsg/deps/nanomsg/doc/stylesheet.css b/node/node_modules/nanomsg/deps/nanomsg/doc/stylesheet.css new file mode 100644 index 0000000..58f0261 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/doc/stylesheet.css @@ -0,0 +1,691 @@ +/*! normalize.css v2.1.2 | MIT License | git.io/normalize */ +/* ========================================================================== HTML5 display definitions ========================================================================== */ +/** Correct `block` display not defined in IE 8/9. */ +article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; } + +/** Correct `inline-block` display not defined in IE 8/9. */ +audio, canvas, video { display: inline-block; } + +/** Prevent modern browsers from displaying `audio` without controls. Remove excess height in iOS 5 devices. */ +audio:not([controls]) { display: none; height: 0; } + +/** Address `[hidden]` styling not present in IE 8/9. Hide the `template` element in IE, Safari, and Firefox < 22. */ +[hidden], template { display: none; } + +script { display: none !important; } + +/* ========================================================================== Base ========================================================================== */ +/** 1. Set default font family to sans-serif. 2. Prevent iOS text size adjust after orientation change, without disabling user zoom. */ +html { font-family: sans-serif; /* 1 */ -ms-text-size-adjust: 100%; /* 2 */ -webkit-text-size-adjust: 100%; /* 2 */ } + +/** Remove default margin. */ +body { margin: 0; } + +/* ========================================================================== Links ========================================================================== */ +/** Remove the gray background color from active links in IE 10. */ +a { background: transparent; } + +/** Address `outline` inconsistency between Chrome and other browsers. */ +a:focus { outline: thin dotted; } + +/** Improve readability when focused and also mouse hovered in all browsers. */ +a:active, a:hover { outline: 0; } + +/* ========================================================================== Typography ========================================================================== */ +/** Address variable `h1` font-size and margin within `section` and `article` contexts in Firefox 4+, Safari 5, and Chrome. */ +h1 { font-size: 2em; margin: 0.67em 0; } + +/** Address styling not present in IE 8/9, Safari 5, and Chrome. */ +abbr[title] { border-bottom: 1px dotted; } + +/** Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome. */ +b, strong { font-weight: bold; } + +/** Address styling not present in Safari 5 and Chrome. */ +dfn { font-style: italic; } + +/** Address differences between Firefox and other browsers. */ +hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; } + +/** Address styling not present in IE 8/9. */ +mark { background: #ff0; color: #000; } + +/** Correct font family set oddly in Safari 5 and Chrome. */ +code, kbd, pre, samp { font-family: monospace, serif; font-size: 1em; } + +/** Improve readability of pre-formatted text in all browsers. */ +pre { white-space: pre-wrap; } + +/** Set consistent quote types. */ +q { quotes: "\201C" "\201D" "\2018" "\2019"; } + +/** Address inconsistent and variable font size in all browsers. */ +small { font-size: 80%; } + +/** Prevent `sub` and `sup` affecting `line-height` in all browsers. */ +sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } + +sup { top: -0.5em; } + +sub { bottom: -0.25em; } + +/* ========================================================================== Embedded content ========================================================================== */ +/** Remove border when inside `a` element in IE 8/9. */ +img { border: 0; } + +/** Correct overflow displayed oddly in IE 9. */ +svg:not(:root) { overflow: hidden; } + +/* ========================================================================== Figures ========================================================================== */ +/** Address margin not present in IE 8/9 and Safari 5. */ +figure { margin: 0; } + +/* ========================================================================== Forms ========================================================================== */ +/** Define consistent border, margin, and padding. */ +fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } + +/** 1. Correct `color` not being inherited in IE 8/9. 2. Remove padding so people aren't caught out if they zero out fieldsets. */ +legend { border: 0; /* 1 */ padding: 0; /* 2 */ } + +/** 1. Correct font family not being inherited in all browsers. 2. Correct font size not being inherited in all browsers. 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome. */ +button, input, select, textarea { font-family: inherit; /* 1 */ font-size: 100%; /* 2 */ margin: 0; /* 3 */ } + +/** Address Firefox 4+ setting `line-height` on `input` using `!important` in the UA stylesheet. */ +button, input { line-height: normal; } + +/** Address inconsistent `text-transform` inheritance for `button` and `select`. All other form control elements do not inherit `text-transform` values. Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+. Correct `select` style inheritance in Firefox 4+ and Opera. */ +button, select { text-transform: none; } + +/** 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` and `video` controls. 2. Correct inability to style clickable `input` types in iOS. 3. Improve usability and consistency of cursor style between image-type `input` and others. */ +button, html input[type="button"], input[type="reset"], input[type="submit"] { -webkit-appearance: button; /* 2 */ cursor: pointer; /* 3 */ } + +/** Re-set default cursor for disabled elements. */ +button[disabled], html input[disabled] { cursor: default; } + +/** 1. Address box sizing set to `content-box` in IE 8/9. 2. Remove excess padding in IE 8/9. */ +input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ } + +/** 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome. 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome (include `-moz` to future-proof). */ +input[type="search"] { -webkit-appearance: textfield; /* 1 */ -moz-box-sizing: content-box; -webkit-box-sizing: content-box; /* 2 */ box-sizing: content-box; } + +/** Remove inner padding and search cancel button in Safari 5 and Chrome on OS X. */ +input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; } + +/** Remove inner padding and border in Firefox 4+. */ +button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } + +/** 1. Remove default vertical scrollbar in IE 8/9. 2. Improve readability and alignment in all browsers. */ +textarea { overflow: auto; /* 1 */ vertical-align: top; /* 2 */ } + +/* ========================================================================== Tables ========================================================================== */ +/** Remove most spacing between table cells. */ +table { border-collapse: collapse; border-spacing: 0; } + +meta.foundation-mq-small { font-family: "only screen and (min-width: 768px)"; width: 768px; } + +meta.foundation-mq-medium { font-family: "only screen and (min-width:1280px)"; width: 1280px; } + +meta.foundation-mq-large { font-family: "only screen and (min-width:1440px)"; width: 1440px; } + +*, *:before, *:after { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } + +html, body { font-size: 100%; } + +body { background: #fff; color: #222; padding: 0; margin: 0; font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; font-weight: normal; font-style: normal; line-height: 1; position: relative; cursor: auto; } + +a:hover { cursor: pointer; } + +img, object, embed { max-width: 100%; height: auto; } + +object, embed { height: 100%; } + +img { -ms-interpolation-mode: bicubic; } + +#map_canvas img, #map_canvas embed, #map_canvas object, .map_canvas img, .map_canvas embed, .map_canvas object { max-width: none !important; } + +.left { float: left !important; } + +.right { float: right !important; } + +.text-left { text-align: left !important; } + +.text-right { text-align: right !important; } + +.text-center { text-align: center !important; } + +.text-justify { text-align: justify !important; } + +.hide { display: none; } + +.antialiased, body { -webkit-font-smoothing: antialiased; } + +img { display: inline-block; vertical-align: middle; } + +textarea { height: auto; min-height: 50px; } + +select { width: 100%; } + +object, svg { display: inline-block; vertical-align: middle; } + +.center { margin-left: auto; margin-right: auto; } + +.spread { width: 100%; } + +p.lead, .paragraph.lead > p, #preamble > .sectionbody > .paragraph:first-of-type p { font-size: 1.21875em; line-height: 1.6; } + +.subheader, .admonitionblock td.content > .title, .audioblock > .title, .exampleblock > .title, .imageblock > .title, .listingblock > .title, .literalblock > .title, .stemblock > .title, .openblock > .title, .paragraph > .title, .quoteblock > .title, table.tableblock > .title, .verseblock > .title, .videoblock > .title, .dlist > .title, .olist > .title, .ulist > .title, .qlist > .title, .hdlist > .title { line-height: 1.4; color: #003b6b; font-weight: 300; margin-top: 0.2em; margin-bottom: 0.5em; } + +/* Typography resets */ +div, dl, dt, dd, ul, ol, li, h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6, pre, form, p, blockquote, th, td { margin: 0; padding: 0; direction: ltr; } + +/* Default Link Styles */ +a { color: #00579e; text-decoration: none; line-height: inherit; } +a:hover, a:focus { color: #333; } +a img { border: none; } + +/* Default paragraph styles */ +p { font-family: Arial, sans-serif; font-weight: normal; font-size: 1em; line-height: 1.6; margin-bottom: 0.75em; text-rendering: optimizeLegibility; } +p aside { font-size: 0.875em; line-height: 1.35; font-style: italic; } + +/* Default header styles */ +h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { font-family: Arial, sans-serif; font-weight: normal; font-style: normal; color: #7B2D00; text-rendering: optimizeLegibility; margin-top: 0.5em; margin-bottom: 0.5em; line-height: 1.2125em; } +h1 small, h2 small, h3 small, #toctitle small, .sidebarblock > .content > .title small, h4 small, h5 small, h6 small { font-size: 60%; color: #ff6b15; line-height: 0; } + +h1 { font-size: 2.125em; } + +h2 { font-size: 1.6875em; } + +h3, #toctitle, .sidebarblock > .content > .title { font-size: 1.375em; } + +h4 { font-size: 1.125em; } + +h5 { font-size: 1.125em; } + +h6 { font-size: 1em; } + +hr { border: solid #ddd; border-width: 1px 0 0; clear: both; margin: 1.25em 0 1.1875em; height: 0; } + +/* Helpful Typography Defaults */ +em, i { font-style: italic; line-height: inherit; } + +strong, b { font-weight: bold; line-height: inherit; } + +small { font-size: 60%; line-height: inherit; } + +code { font-family: Consolas, "Liberation Mono", Courier, monospace; font-weight: bold; color: #003426; } + +/* Lists */ +ul, ol, dl { font-size: 1em; line-height: 1.6; margin-bottom: 0.75em; list-style-position: outside; font-family: Arial, sans-serif; } + +ul, ol { margin-left: 1.5em; } +ul.no-bullet, ol.no-bullet { margin-left: 1.5em; } + +/* Unordered Lists */ +ul li ul, ul li ol { margin-left: 1.25em; margin-bottom: 0; font-size: 1em; /* Override nested font-size change */ } +ul.square li ul, ul.circle li ul, ul.disc li ul { list-style: inherit; } +ul.square { list-style-type: square; } +ul.circle { list-style-type: circle; } +ul.disc { list-style-type: disc; } +ul.no-bullet { list-style: none; } + +/* Ordered Lists */ +ol li ul, ol li ol { margin-left: 1.25em; margin-bottom: 0; } + +/* Definition Lists */ +dl dt { margin-bottom: 0.3em; font-weight: bold; } +dl dd { margin-bottom: 0.75em; } + +/* Abbreviations */ +abbr, acronym { text-transform: uppercase; font-size: 90%; color: black; border-bottom: 1px dotted #ddd; cursor: help; } + +abbr { text-transform: none; } + +/* Blockquotes */ +blockquote { margin: 0 0 0.75em; padding: 0.5625em 1.25em 0 1.1875em; border-left: 1px solid #ddd; } +blockquote cite { display: block; font-size: 0.8125em; color: #e15200; } +blockquote cite:before { content: "\2014 \0020"; } +blockquote cite a, blockquote cite a:visited { color: #e15200; } + +blockquote, blockquote p { line-height: 1.6; color: #333; } + +/* Microformats */ +.vcard { display: inline-block; margin: 0 0 1.25em 0; border: 1px solid #ddd; padding: 0.625em 0.75em; } +.vcard li { margin: 0; display: block; } +.vcard .fn { font-weight: bold; font-size: 0.9375em; } + +.vevent .summary { font-weight: bold; } +.vevent abbr { cursor: auto; text-decoration: none; font-weight: bold; border: none; padding: 0 0.0625em; } + +@media only screen and (min-width: 768px) { h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { line-height: 1.4; } + h1 { font-size: 2.75em; } + h2 { font-size: 2.3125em; } + h3, #toctitle, .sidebarblock > .content > .title { font-size: 1.6875em; } + h4 { font-size: 1.4375em; } } +/* Tables */ +table { background: #fff; margin-bottom: 1.25em; border: solid 1px #d8d8ce; } +table thead, table tfoot { background: -webkit-linear-gradient(top, #add386, #90b66a); font-weight: bold; } +table thead tr th, table thead tr td, table tfoot tr th, table tfoot tr td { padding: 0.5em 0.625em 0.625em; font-size: inherit; color: #fff; text-align: left; } +table tr th, table tr td { padding: 0.5625em 0.625em; font-size: inherit; color: #6d6e71; } +table tr.even, table tr.alt, table tr:nth-of-type(even) { background: #edf2f2; } +table thead tr th, table tfoot tr th, table tbody tr td, table tr td, table tfoot tr td { display: table-cell; line-height: 1.4; } + +body { tab-size: 4; } + +h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { line-height: 1.4; } + +a:hover, a:focus { text-decoration: underline; } + +.clearfix:before, .clearfix:after, .float-group:before, .float-group:after { content: " "; display: table; } +.clearfix:after, .float-group:after { clear: both; } + +*:not(pre) > code { font-size: inherit; font-style: normal !important; letter-spacing: 0; padding: 3px 2px 1px 2px; background-color: #eee; border: 1px solid #ddd; -webkit-border-radius: 0; border-radius: 0; line-height: inherit; } + +pre, pre > code { line-height: 1.6; color: black; font-family: Consolas, "Liberation Mono", Courier, monospace; font-weight: normal; } + +.keyseq { color: #333333; } + +kbd { font-family: Consolas, "Liberation Mono", Courier, monospace; display: inline-block; color: black; font-size: 0.65em; line-height: 1.45; background-color: #f7f7f7; border: 1px solid #ccc; -webkit-border-radius: 3px; border-radius: 3px; -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 0.1em white inset; -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 0.1em white inset; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 0.1em white inset; margin: 0 0.15em; padding: 0.2em 0.5em; vertical-align: middle; position: relative; top: -0.1em; white-space: nowrap; } + +.keyseq kbd:first-child { margin-left: 0; } + +.keyseq kbd:last-child { margin-right: 0; } + +.menuseq, .menu { color: black; } + +b.button:before, b.button:after { position: relative; top: -1px; font-weight: normal; } + +b.button:before { content: "["; padding: 0 3px 0 2px; } + +b.button:after { content: "]"; padding: 0 2px 0 3px; } + +#header, #content, #footnotes, #footer { width: 100%; margin-left: auto; margin-right: auto; margin-top: 0; margin-bottom: 0; max-width: 62.5em; *zoom: 1; position: relative; padding-left: 1.5em; padding-right: 1.5em; } +#header:before, #header:after, #content:before, #content:after, #footnotes:before, #footnotes:after, #footer:before, #footer:after { content: " "; display: table; } +#header:after, #content:after, #footnotes:after, #footer:after { clear: both; } + +#content { margin-top: 1.25em; } + +#content:before { content: none; } + +#header > h1:first-child { color: #7B2D00; margin-top: 2.25rem; margin-bottom: 0; } +#header > h1:first-child + #toc { margin-top: 8px; border-top: 1px solid #ddd; } +#header > h1:only-child, body.toc2 #header > h1:nth-last-child(2) { border-bottom: 1px solid #ddd; padding-bottom: 8px; } +#header .details { border-bottom: 1px solid #ddd; line-height: 1.45; padding-top: 0.25em; padding-bottom: 0.25em; padding-left: 0.25em; color: #e15200; display: -ms-flexbox; display: -webkit-flex; display: flex; -ms-flex-flow: row wrap; -webkit-flex-flow: row wrap; flex-flow: row wrap; } +#header .details span:first-child { margin-left: -0.125em; } +#header .details span.email a { color: #333; } +#header .details br { display: none; } +#header .details br + span:before { content: "\00a0\2013\00a0"; } +#header .details br + span.author:before { content: "\00a0\22c5\00a0"; color: #333; } +#header .details br + span#revremark:before { content: "\00a0|\00a0"; } +#header #revnumber { text-transform: capitalize; } +#header #revnumber:after { content: "\00a0"; } + +#content > h1:first-child:not([class]) { color: #7B2D00; border-bottom: 1px solid #ddd; padding-bottom: 8px; margin-top: 0; padding-top: 1rem; margin-bottom: 1.25rem; } + +#toc { border-bottom: 0 solid #ddd; padding-bottom: 0.5em; } +#toc > ul { margin-left: 0.125em; } +#toc ul.sectlevel0 > li > a { font-style: italic; } +#toc ul.sectlevel0 ul.sectlevel1 { margin: 0.5em 0; } +#toc ul { font-family: Arial, sans-serif; list-style-type: none; } +#toc li { line-height: 1.3334; margin-top: 0.3334em; } +#toc a { text-decoration: none; } +#toc a:active { text-decoration: underline; } + +#toctitle { color: #003b6b; font-size: 1.2em; } + +@media only screen and (min-width: 768px) { #toctitle { font-size: 1.375em; } + body.toc2 { padding-left: 15em; padding-right: 0; } + #toc.toc2 { margin-top: 0 !important; background-color: #fff; position: fixed; width: 15em; left: 0; top: 0; border-right: 1px solid #ddd; border-top-width: 0 !important; border-bottom-width: 0 !important; z-index: 1000; padding: 1.25em 1em; height: 100%; overflow: auto; } + #toc.toc2 #toctitle { margin-top: 0; margin-bottom: 0.8rem; font-size: 1.2em; } + #toc.toc2 > ul { font-size: 0.9em; margin-bottom: 0; } + #toc.toc2 ul ul { margin-left: 0; padding-left: 1em; } + #toc.toc2 ul.sectlevel0 ul.sectlevel1 { padding-left: 0; margin-top: 0.5em; margin-bottom: 0.5em; } + body.toc2.toc-right { padding-left: 0; padding-right: 15em; } + body.toc2.toc-right #toc.toc2 { border-right-width: 0; border-left: 1px solid #ddd; left: auto; right: 0; } } +@media only screen and (min-width: 1280px) { body.toc2 { padding-left: 20em; padding-right: 0; } + #toc.toc2 { width: 20em; } + #toc.toc2 #toctitle { font-size: 1.375em; } + #toc.toc2 > ul { font-size: 0.95em; } + #toc.toc2 ul ul { padding-left: 1.25em; } + body.toc2.toc-right { padding-left: 0; padding-right: 20em; } } +#content #toc { border-style: solid; border-width: 1px; border-color: #e6e6e6; margin-bottom: 1.25em; padding: 1.25em; background: #fff; -webkit-border-radius: 0; border-radius: 0; } +#content #toc > :first-child { margin-top: 0; } +#content #toc > :last-child { margin-bottom: 0; } + +#footer { max-width: 100%; background-color: none; padding: 1.25em; } + +#footer-text { color: black; line-height: 1.44; } + +.sect1 { padding-bottom: 0.625em; } + +@media only screen and (min-width: 768px) { .sect1 { padding-bottom: 1.25em; } } +.sect1 + .sect1 { border-top: 0 solid #ddd; } + +#content h1 > a.anchor, h2 > a.anchor, h3 > a.anchor, #toctitle > a.anchor, .sidebarblock > .content > .title > a.anchor, h4 > a.anchor, h5 > a.anchor, h6 > a.anchor { position: absolute; z-index: 1001; width: 1.5ex; margin-left: -1.5ex; display: block; text-decoration: none !important; visibility: hidden; text-align: center; font-weight: normal; } +#content h1 > a.anchor:before, h2 > a.anchor:before, h3 > a.anchor:before, #toctitle > a.anchor:before, .sidebarblock > .content > .title > a.anchor:before, h4 > a.anchor:before, h5 > a.anchor:before, h6 > a.anchor:before { content: "\00A7"; font-size: 0.85em; display: block; padding-top: 0.1em; } +#content h1:hover > a.anchor, #content h1 > a.anchor:hover, h2:hover > a.anchor, h2 > a.anchor:hover, h3:hover > a.anchor, #toctitle:hover > a.anchor, .sidebarblock > .content > .title:hover > a.anchor, h3 > a.anchor:hover, #toctitle > a.anchor:hover, .sidebarblock > .content > .title > a.anchor:hover, h4:hover > a.anchor, h4 > a.anchor:hover, h5:hover > a.anchor, h5 > a.anchor:hover, h6:hover > a.anchor, h6 > a.anchor:hover { visibility: visible; } +#content h1 > a.link, h2 > a.link, h3 > a.link, #toctitle > a.link, .sidebarblock > .content > .title > a.link, h4 > a.link, h5 > a.link, h6 > a.link { color: #7B2D00; text-decoration: none; } +#content h1 > a.link:hover, h2 > a.link:hover, h3 > a.link:hover, #toctitle > a.link:hover, .sidebarblock > .content > .title > a.link:hover, h4 > a.link:hover, h5 > a.link:hover, h6 > a.link:hover { color: #622400; } + +.audioblock, .imageblock, .literalblock, .listingblock, .stemblock, .videoblock { margin-bottom: 1.25em; } + +.admonitionblock td.content > .title, .audioblock > .title, .exampleblock > .title, .imageblock > .title, .listingblock > .title, .literalblock > .title, .stemblock > .title, .openblock > .title, .paragraph > .title, .quoteblock > .title, table.tableblock > .title, .verseblock > .title, .videoblock > .title, .dlist > .title, .olist > .title, .ulist > .title, .qlist > .title, .hdlist > .title { text-rendering: optimizeLegibility; text-align: left; } + +table.tableblock > caption.title { white-space: nowrap; overflow: visible; max-width: 0; } + +.paragraph.lead > p, #preamble > .sectionbody > .paragraph:first-of-type p { color: #7B2D00; } + +table.tableblock #preamble > .sectionbody > .paragraph:first-of-type p { font-size: inherit; } + +.admonitionblock > table { border-collapse: separate; border: 0; background: none; width: 100%; } +.admonitionblock > table td.icon { text-align: center; width: 80px; } +.admonitionblock > table td.icon img { max-width: none; } +.admonitionblock > table td.icon .title { font-weight: bold; font-family: Arial, sans-serif; text-transform: uppercase; } +.admonitionblock > table td.content { padding-left: 1.125em; padding-right: 1.25em; border-left: 1px solid #ddd; color: #e15200; } +.admonitionblock > table td.content > :last-child > :last-child { margin-bottom: 0; } + +.exampleblock > .content { border-style: solid; border-width: 1px; border-color: #e6e6e6; margin-bottom: 1.25em; padding: 1.25em; background: #fff; -webkit-border-radius: 0; border-radius: 0; } +.exampleblock > .content > :first-child { margin-top: 0; } +.exampleblock > .content > :last-child { margin-bottom: 0; } + +.sidebarblock { border-style: solid; border-width: 1px; border-color: #e6e6e6; margin-bottom: 1.25em; padding: 1.25em; background: #fff; -webkit-border-radius: 0; border-radius: 0; } +.sidebarblock > :first-child { margin-top: 0; } +.sidebarblock > :last-child { margin-bottom: 0; } +.sidebarblock > .content > .title { color: #003b6b; margin-top: 0; } + +.exampleblock > .content > :last-child > :last-child, .exampleblock > .content .olist > ol > li:last-child > :last-child, .exampleblock > .content .ulist > ul > li:last-child > :last-child, .exampleblock > .content .qlist > ol > li:last-child > :last-child, .sidebarblock > .content > :last-child > :last-child, .sidebarblock > .content .olist > ol > li:last-child > :last-child, .sidebarblock > .content .ulist > ul > li:last-child > :last-child, .sidebarblock > .content .qlist > ol > li:last-child > :last-child { margin-bottom: 0; } + +.literalblock pre, .listingblock pre:not(.highlight), .listingblock pre[class="highlight"], .listingblock pre[class^="highlight "], .listingblock pre.CodeRay, .listingblock pre.prettyprint { background: #eee; } +.sidebarblock .literalblock pre, .sidebarblock .listingblock pre:not(.highlight), .sidebarblock .listingblock pre[class="highlight"], .sidebarblock .listingblock pre[class^="highlight "], .sidebarblock .listingblock pre.CodeRay, .sidebarblock .listingblock pre.prettyprint { background: #f2f1f1; } + +.literalblock pre, .literalblock pre[class], .listingblock pre, .listingblock pre[class] { border: 1px dashed #666; -webkit-border-radius: 0; border-radius: 0; word-wrap: break-word; padding: 1.25em 1.5625em 1.125em 1.5625em; font-size: 0.8125em; } +.literalblock pre.nowrap, .literalblock pre[class].nowrap, .listingblock pre.nowrap, .listingblock pre[class].nowrap { overflow-x: auto; white-space: pre; word-wrap: normal; } +@media only screen and (min-width: 768px) { .literalblock pre, .literalblock pre[class], .listingblock pre, .listingblock pre[class] { font-size: 0.90625em; } } +@media only screen and (min-width: 1280px) { .literalblock pre, .literalblock pre[class], .listingblock pre, .listingblock pre[class] { font-size: 1em; } } + +.literalblock.output pre { color: #eee; background-color: black; } + +.listingblock pre.highlightjs { padding: 0; } +.listingblock pre.highlightjs > code { padding: 1.25em 1.5625em 1.125em 1.5625em; -webkit-border-radius: 0; border-radius: 0; } + +.listingblock > .content { position: relative; } + +.listingblock code[data-lang]:before { display: none; content: attr(data-lang); position: absolute; font-size: 0.75em; top: 0.425rem; right: 0.5rem; line-height: 1; text-transform: uppercase; color: #999; } + +.listingblock:hover code[data-lang]:before { display: block; } + +.listingblock.terminal pre .command:before { content: attr(data-prompt); padding-right: 0.5em; color: #999; } + +.listingblock.terminal pre .command:not([data-prompt]):before { content: "$"; } + +table.pyhltable { border-collapse: separate; border: 0; margin-bottom: 0; background: none; } + +table.pyhltable td { vertical-align: top; padding-top: 0; padding-bottom: 0; line-height: 1.6; } + +table.pyhltable td.code { padding-left: .75em; padding-right: 0; } + +pre.pygments .lineno, table.pyhltable td:not(.code) { color: #999; padding-left: 0; padding-right: .5em; border-right: 1px solid #ddd; } + +pre.pygments .lineno { display: inline-block; margin-right: .25em; } + +table.pyhltable .linenodiv { background: none !important; padding-right: 0 !important; } + +.quoteblock { margin: 0 1em 0.75em 1.5em; display: table; } +.quoteblock > .title { margin-left: -1.5em; margin-bottom: 0.75em; } +.quoteblock blockquote, .quoteblock blockquote p { color: #333; font-size: 1.15rem; line-height: 1.75; word-spacing: 0.1em; letter-spacing: 0; font-style: italic; text-align: justify; } +.quoteblock blockquote { margin: 0; padding: 0; border: 0; } +.quoteblock blockquote:before { content: "\201c"; float: left; font-size: 2.75em; font-weight: bold; line-height: 0.6em; margin-left: -0.6em; color: #003b6b; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); } +.quoteblock blockquote > .paragraph:last-child p { margin-bottom: 0; } +.quoteblock .attribution { margin-top: 0.5em; margin-right: 0.5ex; text-align: right; } +.quoteblock .quoteblock { margin-left: 0; margin-right: 0; padding: 0.5em 0; border-left: 3px solid #e15200; } +.quoteblock .quoteblock blockquote { padding: 0 0 0 0.75em; } +.quoteblock .quoteblock blockquote:before { display: none; } + +.verseblock { margin: 0 1em 0.75em 1em; } +.verseblock pre { font-family: "Open Sans", "DejaVu Sans", sans; font-size: 1.15rem; color: #333; font-weight: 300; text-rendering: optimizeLegibility; } +.verseblock pre strong { font-weight: 400; } +.verseblock .attribution { margin-top: 1.25rem; margin-left: 0.5ex; } + +.quoteblock .attribution, .verseblock .attribution { font-size: 0.8125em; line-height: 1.45; font-style: italic; } +.quoteblock .attribution br, .verseblock .attribution br { display: none; } +.quoteblock .attribution cite, .verseblock .attribution cite { display: block; letter-spacing: -0.025em; color: #e15200; } + +.quoteblock.abstract { margin: 0 0 0.75em 0; display: block; } +.quoteblock.abstract blockquote, .quoteblock.abstract blockquote p { text-align: left; word-spacing: 0; } +.quoteblock.abstract blockquote:before, .quoteblock.abstract blockquote p:first-of-type:before { display: none; } + +table.tableblock { max-width: 100%; border-collapse: separate; } +table.tableblock td > .paragraph:last-child p > p:last-child, table.tableblock th > p:last-child, table.tableblock td > p:last-child { margin-bottom: 0; } + +table.tableblock, th.tableblock, td.tableblock { border: 0 solid #d8d8ce; } + +table.grid-all th.tableblock, table.grid-all td.tableblock { border-width: 0 1px 1px 0; } + +table.grid-all tfoot > tr > th.tableblock, table.grid-all tfoot > tr > td.tableblock { border-width: 1px 1px 0 0; } + +table.grid-cols th.tableblock, table.grid-cols td.tableblock { border-width: 0 1px 0 0; } + +table.grid-all * > tr > .tableblock:last-child, table.grid-cols * > tr > .tableblock:last-child { border-right-width: 0; } + +table.grid-rows th.tableblock, table.grid-rows td.tableblock { border-width: 0 0 1px 0; } + +table.grid-all tbody > tr:last-child > th.tableblock, table.grid-all tbody > tr:last-child > td.tableblock, table.grid-all thead:last-child > tr > th.tableblock, table.grid-rows tbody > tr:last-child > th.tableblock, table.grid-rows tbody > tr:last-child > td.tableblock, table.grid-rows thead:last-child > tr > th.tableblock { border-bottom-width: 0; } + +table.grid-rows tfoot > tr > th.tableblock, table.grid-rows tfoot > tr > td.tableblock { border-width: 1px 0 0 0; } + +table.frame-all { border-width: 1px; } + +table.frame-sides { border-width: 0 1px; } + +table.frame-topbot { border-width: 1px 0; } + +th.halign-left, td.halign-left { text-align: left; } + +th.halign-right, td.halign-right { text-align: right; } + +th.halign-center, td.halign-center { text-align: center; } + +th.valign-top, td.valign-top { vertical-align: top; } + +th.valign-bottom, td.valign-bottom { vertical-align: bottom; } + +th.valign-middle, td.valign-middle { vertical-align: middle; } + +table thead th, table tfoot th { font-weight: bold; } + +tbody tr th { display: table-cell; line-height: 1.4; background: -webkit-linear-gradient(top, #add386, #90b66a); } + +tbody tr th, tbody tr th p, tfoot tr th, tfoot tr th p { color: #fff; font-weight: bold; } + +p.tableblock > code:only-child { background: none; padding: 0; } + +p.tableblock { font-size: 1em; } + +td > div.verse { white-space: pre; } + +ol { margin-left: 1.75em; } + +ul li ol { margin-left: 1.5em; } + +dl dd { margin-left: 1.125em; } + +dl dd:last-child, dl dd:last-child > :last-child { margin-bottom: 0; } + +ol > li p, ul > li p, ul dd, ol dd, .olist .olist, .ulist .ulist, .ulist .olist, .olist .ulist { margin-bottom: 0.375em; } + +ul.unstyled, ol.unnumbered, ul.checklist, ul.none { list-style-type: none; } + +ul.unstyled, ol.unnumbered, ul.checklist { margin-left: 0.625em; } + +ul.checklist li > p:first-child > .fa-square-o:first-child, ul.checklist li > p:first-child > .fa-check-square-o:first-child { width: 1em; font-size: 0.85em; } + +ul.checklist li > p:first-child > input[type="checkbox"]:first-child { width: 1em; position: relative; top: 1px; } + +ul.inline { margin: 0 auto 0.375em auto; margin-left: -1.375em; margin-right: 0; padding: 0; list-style: none; overflow: hidden; } +ul.inline > li { list-style: none; float: left; margin-left: 1.375em; display: block; } +ul.inline > li > * { display: block; } + +.unstyled dl dt { font-weight: normal; font-style: normal; } + +ol.arabic { list-style-type: decimal; } + +ol.decimal { list-style-type: decimal-leading-zero; } + +ol.loweralpha { list-style-type: lower-alpha; } + +ol.upperalpha { list-style-type: upper-alpha; } + +ol.lowerroman { list-style-type: lower-roman; } + +ol.upperroman { list-style-type: upper-roman; } + +ol.lowergreek { list-style-type: lower-greek; } + +.hdlist > table, .colist > table { border: 0; background: none; } +.hdlist > table > tbody > tr, .colist > table > tbody > tr { background: none; } + +td.hdlist1, td.hdlist2 { vertical-align: top; padding: 0 0.625em; } + +td.hdlist1 { font-weight: bold; padding-bottom: 0.75em; } + +.literalblock + .colist, .listingblock + .colist { margin-top: -0.5em; } + +.colist > table tr > td:first-of-type { padding: 0 0.75em; line-height: 1; } +.colist > table tr > td:last-of-type { padding: 0.25em 0; } + +.thumb, .th { line-height: 0; display: inline-block; border: solid 4px #fff; -webkit-box-shadow: 0 0 0 1px #ddd; box-shadow: 0 0 0 1px #ddd; } + +.imageblock.left, .imageblock[style*="float: left"] { margin: 0.25em 0.625em 1.25em 0; } +.imageblock.right, .imageblock[style*="float: right"] { margin: 0.25em 0 1.25em 0.625em; } +.imageblock > .title { margin-bottom: 0; } +.imageblock.thumb, .imageblock.th { border-width: 6px; } +.imageblock.thumb > .title, .imageblock.th > .title { padding: 0 0.125em; } + +.image.left, .image.right { margin-top: 0.25em; margin-bottom: 0.25em; display: inline-block; line-height: 0; } +.image.left { margin-right: 0.625em; } +.image.right { margin-left: 0.625em; } + +a.image { text-decoration: none; display: inline-block; } +a.image object { pointer-events: none; } + +sup.footnote, sup.footnoteref { font-size: 0.875em; position: static; vertical-align: super; } +sup.footnote a, sup.footnoteref a { text-decoration: none; } +sup.footnote a:active, sup.footnoteref a:active { text-decoration: underline; } + +#footnotes { padding-top: 0.75em; padding-bottom: 0.75em; margin-bottom: 0.625em; } +#footnotes hr { width: 20%; min-width: 6.25em; margin: -0.25em 0 0.75em 0; border-width: 1px 0 0 0; } +#footnotes .footnote { padding: 0 0.375em 0 0.225em; line-height: 1.3334; font-size: 0.875em; margin-left: 1.2em; text-indent: -1.05em; margin-bottom: 0.2em; } +#footnotes .footnote a:first-of-type { font-weight: bold; text-decoration: none; } +#footnotes .footnote:last-of-type { margin-bottom: 0; } +#content #footnotes { margin-top: -0.625em; margin-bottom: 0; padding: 0.75em 0; } + +.gist .file-data > table { border: 0; background: #fff; width: 100%; margin-bottom: 0; } +.gist .file-data > table td.line-data { width: 99%; } + +div.unbreakable { page-break-inside: avoid; } + +.big { font-size: larger; } + +.small { font-size: smaller; } + +.underline { text-decoration: underline; } + +.overline { text-decoration: overline; } + +.line-through { text-decoration: line-through; } + +.aqua { color: #00bfbf; } + +.aqua-background { background-color: #00fafa; } + +.black { color: black; } + +.black-background { background-color: black; } + +.blue { color: #0000bf; } + +.blue-background { background-color: #0000fa; } + +.fuchsia { color: #bf00bf; } + +.fuchsia-background { background-color: #fa00fa; } + +.gray { color: #606060; } + +.gray-background { background-color: #7d7d7d; } + +.green { color: #006000; } + +.green-background { background-color: #007d00; } + +.lime { color: #00bf00; } + +.lime-background { background-color: #00fa00; } + +.maroon { color: #600000; } + +.maroon-background { background-color: #7d0000; } + +.navy { color: #000060; } + +.navy-background { background-color: #00007d; } + +.olive { color: #606000; } + +.olive-background { background-color: #7d7d00; } + +.purple { color: #600060; } + +.purple-background { background-color: #7d007d; } + +.red { color: #bf0000; } + +.red-background { background-color: #fa0000; } + +.silver { color: #909090; } + +.silver-background { background-color: #bcbcbc; } + +.teal { color: #006060; } + +.teal-background { background-color: #007d7d; } + +.white { color: #bfbfbf; } + +.white-background { background-color: #fafafa; } + +.yellow { color: #bfbf00; } + +.yellow-background { background-color: #fafa00; } + +span.icon > .fa { cursor: default; } + +.admonitionblock td.icon [class^="fa icon-"] { font-size: 2.5em; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); cursor: default; } +.admonitionblock td.icon .icon-note:before { content: "\f05a"; color: #004177; } +.admonitionblock td.icon .icon-tip:before { content: "\f0eb"; text-shadow: 1px 1px 2px rgba(155, 155, 0, 0.8); color: #111; } +.admonitionblock td.icon .icon-warning:before { content: "\f071"; color: #bf6900; } +.admonitionblock td.icon .icon-caution:before { content: "\f06d"; color: #bf3400; } +.admonitionblock td.icon .icon-important:before { content: "\f06a"; color: #bf0000; } + +.conum[data-value] { display: inline-block; color: #fff !important; background-color: black; -webkit-border-radius: 100px; border-radius: 100px; text-align: center; font-size: 0.75em; width: 1.67em; height: 1.67em; line-height: 1.67em; font-family: "Open Sans", "DejaVu Sans", sans-serif; font-style: normal; font-weight: bold; } +.conum[data-value] * { color: #fff !important; } +.conum[data-value] + b { display: none; } +.conum[data-value]:after { content: attr(data-value); } +pre .conum[data-value] { position: relative; top: -0.125em; } + +b.conum * { color: inherit !important; } + +.conum:not([data-value]):empty { display: none; } + +h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { border-bottom: 1px solid #ddd; } + +.sect1 { padding-bottom: 0; } + +#toctitle { color: #00406F; font-weight: normal; margin-top: 1.5em; } + +.sidebarblock { border-color: #aaa; } + +code { -webkit-border-radius: 4px; border-radius: 4px; } + +p.tableblock.header { color: #6d6e71; } + +.literalblock pre, .listingblock pre { background: #eee; } diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/README b/node/node_modules/nanomsg/deps/nanomsg/perf/README new file mode 100644 index 0000000..f881b18 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/README @@ -0,0 +1,6 @@ +This directory contains simple performance measurement utilities: + +- inproc_lat measures the latency of the inproc transport +- inproc_thr measures the throughput of the inproc transport +- local_lat and remote_lat measure the latency other transports +- local_thr and remote_thr measure the throughput other transports diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/inproc_lat.c b/node/node_modules/nanomsg/deps/nanomsg/perf/inproc_lat.c new file mode 100644 index 0000000..dac16ed --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/inproc_lat.c @@ -0,0 +1,123 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "../src/utils/attr.h" + +#include "../src/utils/err.c" +#include "../src/utils/thread.c" +#include "../src/utils/sleep.c" +#include "../src/utils/stopwatch.c" + +#include +#include +#include +#include + +static size_t message_size; +static int roundtrip_count; + +void worker (NN_UNUSED void *arg) +{ + int rc; + int s; + int i; + char *buf; + + s = nn_socket (AF_SP, NN_PAIR); + assert (s != -1); + rc = nn_connect (s, "inproc://inproc_lat"); + assert (rc >= 0); + + buf = malloc (message_size); + assert (buf); + + for (i = 0; i != roundtrip_count; i++) { + rc = nn_recv (s, buf, message_size, 0); + assert (rc == (int)message_size); + rc = nn_send (s, buf, message_size, 0); + assert (rc == (int)message_size); + } + + free (buf); + rc = nn_close (s); + assert (rc == 0); +} + +int main (int argc, char *argv []) +{ + int rc; + int s; + int i; + char *buf; + struct nn_thread thread; + struct nn_stopwatch stopwatch; + uint64_t elapsed; + double latency; + + if (argc != 3) { + printf ("usage: inproc_lat \n"); + return 1; + } + + message_size = atoi (argv [1]); + roundtrip_count = atoi (argv [2]); + + s = nn_socket (AF_SP, NN_PAIR); + assert (s != -1); + rc = nn_bind (s, "inproc://inproc_lat"); + assert (rc >= 0); + + buf = malloc (message_size); + assert (buf); + memset (buf, 111, message_size); + + /* Wait a bit till the worker thread blocks in nn_recv(). */ + nn_thread_init (&thread, worker, NULL); + nn_sleep (100); + + nn_stopwatch_init (&stopwatch); + + for (i = 0; i != roundtrip_count; i++) { + rc = nn_send (s, buf, message_size, 0); + assert (rc == (int)message_size); + rc = nn_recv (s, buf, message_size, 0); + assert (rc == (int)message_size); + } + + elapsed = nn_stopwatch_term (&stopwatch); + + latency = (double) elapsed / (roundtrip_count * 2); + printf ("message size: %d [B]\n", (int) message_size); + printf ("roundtrip count: %d\n", (int) roundtrip_count); + printf ("average latency: %.3f [us]\n", (double) latency); + + nn_thread_term (&thread); + free (buf); + rc = nn_close (s); + assert (rc == 0); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/inproc_thr.c b/node/node_modules/nanomsg/deps/nanomsg/perf/inproc_thr.c new file mode 100644 index 0000000..4a04d96 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/inproc_thr.c @@ -0,0 +1,130 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "../src/utils/attr.h" + +#include "../src/utils/err.c" +#include "../src/utils/thread.c" +#include "../src/utils/stopwatch.c" + +#include +#include +#include +#include + +static size_t message_size; +static int message_count; + +void worker (NN_UNUSED void *arg) +{ + int rc; + int s; + int i; + char *buf; + + s = nn_socket (AF_SP, NN_PAIR); + assert (s != -1); + rc = nn_connect (s, "inproc://inproc_thr"); + assert (rc >= 0); + + buf = malloc (message_size); + assert (buf); + memset (buf, 111, message_size); + + rc = nn_send (s, NULL, 0, 0); + assert (rc == 0); + + for (i = 0; i != message_count; i++) { + rc = nn_send (s, buf, message_size, 0); + assert (rc == (int)message_size); + } + + free (buf); + rc = nn_close (s); + assert (rc == 0); +} + +int main (int argc, char *argv []) +{ + int rc; + int s; + int i; + char *buf; + struct nn_thread thread; + struct nn_stopwatch stopwatch; + uint64_t elapsed; + unsigned long throughput; + double megabits; + + if (argc != 3) { + printf ("usage: thread_thr \n"); + return 1; + } + + message_size = atoi (argv [1]); + message_count = atoi (argv [2]); + + s = nn_socket (AF_SP, NN_PAIR); + assert (s != -1); + rc = nn_bind (s, "inproc://inproc_thr"); + assert (rc >= 0); + + buf = malloc (message_size); + assert (buf); + + nn_thread_init (&thread, worker, NULL); + + /* First message is used to start the stopwatch. */ + rc = nn_recv (s, buf, message_size, 0); + assert (rc == 0); + + nn_stopwatch_init (&stopwatch); + + for (i = 0; i != message_count; i++) { + rc = nn_recv (s, buf, message_size, 0); + assert (rc == (int)message_size); + } + + elapsed = nn_stopwatch_term (&stopwatch); + + nn_thread_term (&thread); + free (buf); + rc = nn_close (s); + assert (rc == 0); + + if (elapsed == 0) + elapsed = 1; + throughput = (unsigned long) + ((double) message_count / (double) elapsed * 1000000); + megabits = (double) (throughput * message_size * 8) / 1000000; + + printf ("message size: %d [B]\n", (int) message_size); + printf ("message count: %d\n", (int) message_count); + printf ("mean throughput: %d [msg/s]\n", (int) throughput); + printf ("mean throughput: %.3f [Mb/s]\n", (double) megabits); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/local_lat.c b/node/node_modules/nanomsg/deps/nanomsg/perf/local_lat.c new file mode 100644 index 0000000..1f6cb14 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/local_lat.c @@ -0,0 +1,88 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/tcp.h" +#include "../src/pair.h" + +#include +#include +#include + +#include "../src/utils/err.c" +#include "../src/utils/sleep.c" + +int main (int argc, char *argv []) +{ + const char *bind_to; + size_t sz; + int rts; + char *buf; + int nbytes; + int s; + int rc; + int i; + int opt; + + if (argc != 4) { + printf ("usage: local_lat \n"); + return 1; + } + bind_to = argv [1]; + sz = atoi (argv [2]); + rts = atoi (argv [3]); + + s = nn_socket (AF_SP, NN_PAIR); + nn_assert (s != -1); + opt = 1; + rc = nn_setsockopt (s, NN_TCP, NN_TCP_NODELAY, &opt, sizeof (opt)); + nn_assert (rc == 0); + opt = -1; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc == 0); + opt = 1000; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &opt, sizeof (opt)); + nn_assert (rc == 0); + rc = nn_bind (s, bind_to); + nn_assert (rc >= 0); + + buf = malloc (sz); + nn_assert (buf); + memset (buf, 111, sz); + + for (i = 0; i != rts; i++) { + nbytes = nn_recv (s, buf, sz, 0); + nn_assert (nbytes == (int)sz); + nbytes = nn_send (s, buf, sz, 0); + nn_assert (nbytes == (int)sz); + } + + free (buf); + + /* Linger doesn't always work, so stick around another second. */ + nn_sleep (1000); + rc = nn_close (s); + nn_assert (rc == 0); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/local_thr.c b/node/node_modules/nanomsg/deps/nanomsg/perf/local_thr.c new file mode 100644 index 0000000..659f870 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/local_thr.c @@ -0,0 +1,99 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include +#include + +#include "../src/utils/stopwatch.c" +#include "../src/utils/err.c" + +int main (int argc, char *argv []) +{ + const char *bind_to; + size_t sz; + int count; + char *buf; + int nbytes; + int s; + int rc; + int i; + int opt; + struct nn_stopwatch sw; + uint64_t total; + uint64_t thr; + double mbs; + + if (argc != 4) { + printf ("usage: local_thr \n"); + return 1; + } + bind_to = argv [1]; + sz = atoi (argv [2]); + count = atoi (argv [3]); + + s = nn_socket (AF_SP, NN_PAIR); + nn_assert (s != -1); + rc = nn_bind (s, bind_to); + nn_assert (rc >= 0); + + opt = -1; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc == 0); + + opt = 1000; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &opt, sizeof (opt)); + nn_assert (rc == 0); + + buf = malloc (sz); + nn_assert (buf); + + nbytes = nn_recv (s, buf, sz, 0); + nn_assert (nbytes == 0); + + nn_stopwatch_init (&sw); + for (i = 0; i != count; i++) { + nbytes = nn_recv (s, buf, sz, 0); + nn_assert (nbytes == (int)sz); + } + total = nn_stopwatch_term (&sw); + if (total == 0) + total = 1; + + thr = (uint64_t) ((double) count / (double) total * 1000000); + mbs = (double) (thr * sz * 8) / 1000000; + + printf ("message size: %d [B]\n", (int) sz); + printf ("message count: %d\n", (int) count); + printf ("throughput: %d [msg/s]\n", (int) thr); + printf ("throughput: %.3f [Mb/s]\n", (double) mbs); + + free (buf); + + rc = nn_close (s); + nn_assert (rc == 0); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/remote_lat.c b/node/node_modules/nanomsg/deps/nanomsg/perf/remote_lat.c new file mode 100644 index 0000000..81da245 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/remote_lat.c @@ -0,0 +1,94 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/tcp.h" +#include "../src/pair.h" + +#include +#include +#include + +#include "../src/utils/stopwatch.c" +#include "../src/utils/err.c" + +int main (int argc, char *argv []) +{ + const char *connect_to; + size_t sz; + int rts; + char *buf; + int nbytes; + int s; + int rc; + int i; + int opt; + struct nn_stopwatch sw; + uint64_t total; + double lat; + + + if (argc != 4) { + printf ("usage: remote_lat \n"); + return 1; + } + connect_to = argv [1]; + sz = atoi (argv [2]); + rts = atoi (argv [3]); + + s = nn_socket (AF_SP, NN_PAIR); + nn_assert (s != -1); + opt = 1; + rc = nn_setsockopt (s, NN_TCP, NN_TCP_NODELAY, &opt, sizeof (opt)); + nn_assert (rc == 0); + opt = -1; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc == 0); + rc = nn_connect (s, connect_to); + nn_assert (rc >= 0); + + buf = malloc (sz); + nn_assert (buf); + memset (buf, 111, sz); + + nn_stopwatch_init (&sw); + for (i = 0; i != rts; i++) { + nbytes = nn_send (s, buf, sz, 0); + nn_assert (nbytes == (int)sz); + nbytes = nn_recv (s, buf, sz, 0); + nn_assert (nbytes == (int)sz); + } + total = nn_stopwatch_term (&sw); + + lat = (double) total / (rts * 2); + printf ("message size: %d [B]\n", (int) sz); + printf ("roundtrip count: %d\n", (int) rts); + printf ("average latency: %.3f [us]\n", (double) lat); + + free (buf); + + rc = nn_close (s); + nn_assert (rc == 0); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/perf/remote_thr.c b/node/node_modules/nanomsg/deps/nanomsg/perf/remote_thr.c new file mode 100644 index 0000000..0095120 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/perf/remote_thr.c @@ -0,0 +1,88 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include +#include +#include + +#include "../src/utils/err.c" +#include "../src/utils/sleep.c" + +int main (int argc, char *argv []) +{ + const char *connect_to; + size_t sz; + int count; + char *buf; + int nbytes; + int s; + int rc; + int i; + int opt; + + if (argc != 4) { + printf ("usage: remote_thr \n"); + return 1; + } + connect_to = argv [1]; + sz = atoi (argv [2]); + count = atoi (argv [3]); + + s = nn_socket (AF_SP, NN_PAIR); + nn_assert (s != -1); + rc = nn_connect (s, connect_to); + nn_assert (rc >= 0); + + opt = -1; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc == 0); + + opt = 1000; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &opt, sizeof (opt)); + nn_assert (rc == 0); + + buf = malloc (sz); + nn_assert (buf); + memset (buf, 111, sz); + + nbytes = nn_send (s, buf, 0, 0); + nn_assert (nbytes == 0); + + for (i = 0; i != count; i++) { + nbytes = nn_send (s, buf, sz, 0); + nn_assert (nbytes == (int)sz); + } + + free (buf); + + /* Linger doesn't always do the trick, so sleep a bit to be sure. */ + nn_sleep (1000); + + rc = nn_close (s); + nn_assert (rc == 0); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/README b/node/node_modules/nanomsg/deps/nanomsg/rfc/README new file mode 100644 index 0000000..1e5304e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/README @@ -0,0 +1,2 @@ +This folder contains for RFCs implemented by nanomsg. XML files are formatted +according to RFC 2629 and can be processed using xml2rfc utility. diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-ipc-mapping-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-ipc-mapping-01.txt new file mode 100644 index 0000000..b91d27b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-ipc-mapping-01.txt @@ -0,0 +1,224 @@ + + + + +Internet Engineering Task Force G. D'Amore, Ed. +Internet-Draft +Intended status: Informational M. Sustrik +Expires: October 14, 2016 + April 12, 2016 + + + IPC Mapping for Scalability Protocols + sp-ipc-mapping-01 + +Abstract + + This document defines the IPC mapping for scalability protocols. It + deals with how IPC (inter-process communication) should be + implemented on POSIX-compliant platforms. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on October 14, 2016. + +Copyright Notice + + Copyright (c) 2016 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + +D'Amore & Sustrik Expires October 14, 2016 [Page 1] + +Internet-Draft IPC mapping for SPs April 2016 + + +1. Underlying protocol + + This mapping should be layered directly on the top of AF_UNIX sockets + of type SOCK_STREAM. On the platforms where AF_UNIX sockets are not + available IPC mapping may be done in a platform-specific way and + SHOULD be described in a separate RFC. + + There's no fixed file to use for SP communication. Instead, + filenames are assigned to individual services by the user. + +2. Connection initiation + + Before binding the AF_UNIX socket the implementation SHOULD check + whether there's another process bound to the address. If not so it + SHOULD try to delete the associated file, if present. This measure + will prevent subsequent bind from failing if there's a leftover file + from the previous runs of the application. + + The check can be performed in a platform-specific way, however, a + generic way to implement it is to try to connect to the address and + close the connection immediately if successful. + + After establishing underlying AF_UNIX connection, both parties MUST + send the protocol header immediately. Both endpoints MUST then wait + for the protocol header from the peer before proceeding on. + + The protocol header is 8 bytes long and looks like this: + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | 0x00 | 0x53 | 0x50 | version | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | type | reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + First four bytes of the protocol header are used to make sure that + the peer's protocol is compatible with the protocol used by the local + endpoint. + + First four bytes of the protocol header MUST be set to 0x00, 0x53, + 0x50 and 0x00 respectively. If the protocol header received from the + peer differs, the TCP connection MUST be closed immediately. + + The fact that the first byte of the protocol header is binary zero + eliminates any text-based protocols that were accidentally connected + to the endpoint. Subsequent two bytes make the check even more + rigorous. At the same time they can be used as a debugging hint to + + + +D'Amore & Sustrik Expires October 14, 2016 [Page 2] + +Internet-Draft IPC mapping for SPs April 2016 + + + indicate that the connection is supposed to use one of the + scalability protocols -- ASCII representation of these bytes is 'SP'. + Finally, the fourth byte rules out any incompatible versions of this + protocol. + + Fifth and sixth bytes of the header form a 16-bit unsigned integer in + network byte order representing the type of SP endpoint on the layer + above. The value SHOULD NOT be interpreted by the mapping, rather + the interpretation should be delegated to the scalability protocol + above the mapping. For informational purposes, it should be noted + that the field encodes information such as SP protocol ID, protocol + version and the role of endpoint within the protocol. Individual + values are assigned by IANA. + + Finally, the last two bytes of the protocol header are reserved for + future use and must be set to binary zeroes. If the protocol header + from the peer contains anything else than zeroes in this field, the + implementation MUST close the underlying TCP connection. + +3. Message header + + Once the protocol header is accepted, endpoint can send and receive + messages. Every message starts with a message header consisting of + of a single byte called 'message type'. + + The only value of this field that is currently allowed is 0x1, which + means "in-band" message, i.e. message whose body is passed as a + stream of bytes via the AF_UNIX socket. + + The intent of this field is to eventually allow out-of-band transfer + of the message bodies, e.g. via shared memory. + + The in-band message type MUST be implemented. + +4. In-band messages + + For in-band messages, message header is immediately followed by + 64-bit unsigned integer in network byte order representing the + payload size, in bytes. Thus, the message payload can be from 0 to + 2^64-1 bytes long. The payload of the specified size follows + directly after the size field: + + +-----------+------------+-----------------+ + | type (8b) | size (64b) | payload | + +-----------+------------+-----------------+ + + + + + + +D'Amore & Sustrik Expires October 14, 2016 [Page 3] + +Internet-Draft IPC mapping for SPs April 2016 + + +5. IANA Considerations + + This memo includes no request to IANA. + +6. Security Considerations + + The mapping isn't intended to provide any additional security in + addition to what AF_UNIX does. + +Authors' Addresses + + Garrett D'Amore (editor) + + Email: garrett@damore.org + + + Martin Sustrik + + Email: sustrik@250bpm.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +D'Amore & Sustrik Expires October 14, 2016 [Page 4] diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-ipc-mapping-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-ipc-mapping-01.xml new file mode 100644 index 0000000..6bca55a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-ipc-mapping-01.xml @@ -0,0 +1,164 @@ + + + + + + + + + IPC Mapping for Scalability Protocols + + + +

+ garrett@damore.org +
+ + +
+ sustrik@250bpm.com +
+
+ + + + Applications + Internet Engineering Task Force + + IPC + UNIX + SP + + + This document defines the IPC mapping for scalability protocols. + It deals with how IPC (inter-process communication) should be + implemented on POSIX-compliant platforms. + + + + + + +
+ + This mapping should be layered directly on the top of AF_UNIX + sockets of type SOCK_STREAM. On the platforms where AF_UNIX sockets + are not available IPC mapping may be done in a platform-specific way + and SHOULD be described in a separate RFC. + + There's no fixed file to use for SP communication. Instead, filenames + are assigned to individual services by the user. + +
+ +
+ + Before binding the AF_UNIX socket the implementation SHOULD check + whether there's another process bound to the address. If not so + it SHOULD try to delete the associated file, if present. This measure + will prevent subsequent bind from failing if there's a leftover file + from the previous runs of the application. + + The check can be performed in a platform-specific way, however, + a generic way to implement it is to try to connect to the address + and close the connection immediately if successful. + + After establishing underlying AF_UNIX connection, both parties MUST + send the protocol header immediately. Both endpoints MUST then wait + for the protocol header from the peer before proceeding on. + + The protocol header is 8 bytes long and looks like this: + +
+ + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| 0x00 | 0x53 | 0x50 | version | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| type | reserved | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +
+ + First four bytes of the protocol header are used to make sure that + the peer's protocol is compatible with the protocol used by the local + endpoint. + + First four bytes of the protocol header MUST be set to 0x00, 0x53, 0x50 + and 0x00 respectively. If the protocol header received from the peer + differs, the TCP connection MUST be closed immediately. + + The fact that the first byte of the protocol header is binary zero + eliminates any text-based protocols that were accidentally connected + to the endpoint. Subsequent two bytes make the check even more + rigorous. At the same time they can be used as a debugging hint to + indicate that the connection is supposed to use one of the scalability + protocols -- ASCII representation of these bytes is 'SP'. Finally, + the fourth byte rules out any incompatible versions of this + protocol. + + Fifth and sixth bytes of the header form a 16-bit unsigned integer in + network byte order representing the type of SP endpoint on the layer + above. The value SHOULD NOT be interpreted by the mapping, rather + the interpretation should be delegated to the scalability protocol + above the mapping. For informational purposes, it should be noted that + the field encodes information such as SP protocol ID, protocol version + and the role of endpoint within the protocol. Individual values are + assigned by IANA. + + Finally, the last two bytes of the protocol header are reserved for + future use and must be set to binary zeroes. If the protocol header + from the peer contains anything else than zeroes in this field, the + implementation MUST close the underlying TCP connection. + +
+ +
+ + Once the protocol header is accepted, endpoint can send and receive + messages. Every message starts with a message header consisting of + of a single byte called 'message type'. + + The only value of this field that is currently allowed is 0x1, which + means "in-band" message, i.e. message whose body is passed as a stream + of bytes via the AF_UNIX socket. + + The intent of this field is to eventually allow out-of-band transfer + of the message bodies, e.g. via shared memory. + + The in-band message type MUST be implemented. + +
+ +
+ + For in-band messages, message header is immediately followed by 64-bit + unsigned integer in network byte order representing the payload size, + in bytes. Thus, the message payload can be from 0 to 2^64-1 bytes long. + The payload of the specified size follows directly after the size + field: + +
+ ++-----------+------------+-----------------+ +| type (8b) | size (64b) | payload | ++-----------+------------+-----------------+ + +
+ +
+ +
+ This memo includes no request to IANA. +
+ +
+ The mapping isn't intended to provide any additional security in + addition to what AF_UNIX does. +
+ +
+ + diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-protocol-ids-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-protocol-ids-01.txt new file mode 100644 index 0000000..2435e1d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-protocol-ids-01.txt @@ -0,0 +1,171 @@ + + + + +Internet Engineering Task Force M. Sustrik, Ed. +Internet-Draft +Intended status: Informational June 5, 2014 +Expires: December 7, 2014 + + + List of SP protocol IDs + sp-protocol-ids-01 + +Abstract + + This document is intended to be a central repository of SP protocol + IDs. The intention is to pass the task to IANA later on. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on December 7, 2014. + +Copyright Notice + + Copyright (c) 2014 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + + +Sustrik Expires December 7, 2014 [Page 1] + +Internet-Draft List of SP protocol IDs June 2014 + + +1. Introduction + + Different mappings for scalability protocols (see, for example + SPoverTCP [SPoverTCP]) define a protocol header which in turn + contains SP endpoint type ID. The ID consists of protocol ID and end + the endpoint role: + + +-----------------------+------------------------+ + | Protocol ID (12 bits) | Endpoint role (4 bits) | + +-----------------------+------------------------+ + + Protocol IDs denote the SP protocol used (such as request/reply or + publish/subscribe), while endpoint role determines the role of the + endpoint within the topology (requester vs. replier, publisher vs. + subscriber etc.) Both numbers are in network byte order. + + Protocol IDs are global, while endpoint roles are specific to any + given protocol. As such, protocol IDs are defined in this document, + while endpoint roles are defined in specific SP protocol RFCs. + + Note that there's no versioning of SP protocols. New versions of old + protocols should register with new protocol ID. + +2. Protocol IDs + + 1 - pair (v1) + + 2 - publish/subscribe (v1) + + 3 - request/reply (v1) + + 4 - unassigned + + 5 - pipeline (v1) + + 6 - survey (v1) + + 7 - bus (v1) + + 8 - slowsand (v1) + + 9-3839 - unassigned + + 3840-4095 local and experimental + +3. IANA Considerations + + This memo describes numbers that should be eventually managed by + IANA. + + + + +Sustrik Expires December 7, 2014 [Page 2] + +Internet-Draft List of SP protocol IDs June 2014 + + +4. Security Considerations + + There are no security considerations. + +5. References + + [SPoverTCP] + Sustrik, M., "TCP mapping for SPs", August 2013. + +Author's Address + + Martin Sustrik (editor) + + Email: sustrik@250bpm.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sustrik Expires December 7, 2014 [Page 3] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-protocol-ids-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-protocol-ids-01.xml new file mode 100644 index 0000000..064cc16 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-protocol-ids-01.xml @@ -0,0 +1,106 @@ + + + + + + + + + List of SP protocol IDs + + + +
+ sustrik@250bpm.com +
+
+ + + + Applications + Internet Engineering Task Force + + SP + IANA + + + This document is intended to be a central repository of SP protocol + IDs. The intention is to pass the task to IANA later on. + + +
+ + + +
+ Different mappings for scalability protocols (see, for example + SPoverTCP) define a protocol header + which in turn contains SP endpoint type ID. The ID consists of + protocol ID and end the endpoint role: + +
+ ++-----------------------+------------------------+ +| Protocol ID (12 bits) | Endpoint role (4 bits) | ++-----------------------+------------------------+ + +
+ + Protocol IDs denote the SP protocol used (such as request/reply or + publish/subscribe), while endpoint role determines the role of the + endpoint within the topology (requester vs. replier, publisher vs. + subscriber etc.) Both numbers are in network byte order. + + Protocol IDs are global, while endpoint roles are specific to any given + protocol. As such, protocol IDs are defined in this document, while + endpoint roles are defined in specific SP protocol RFCs. + + Note that there's no versioning of SP protocols. New versions of old + protocols should register with new protocol ID. + +
+ +
+ + 1 - pair (v1) + 2 - publish/subscribe (v1) + 3 - request/reply (v1) + 4 - unassigned + 5 - pipeline (v1) + 6 - survey (v1) + 7 - bus (v1) + 8 - slowsand (v1) + 9-3839 - unassigned + 3840-4095 local and experimental + +
+ +
+ This memo describes numbers that should be eventually + managed by IANA. +
+ +
+ There are no security considerations. + +
+ +
+ + + + + + TCP mapping for SPs + + + + + + + + + +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-publish-subscribe-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-publish-subscribe-01.txt new file mode 100644 index 0000000..6585b62 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-publish-subscribe-01.txt @@ -0,0 +1,168 @@ + + + + +Internet Engineering Task Force M. Sustrik, Ed. +Internet-Draft +Intended status: Informational May 4, 2014 +Expires: November 5, 2014 + + + Publish/Subscribe Scalability Protocol + sp-publish-subscribe-01 + +Abstract + + This document defines a scalability protocol used for distributing + data to arbitrary number of subscriber nodes. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on November 5, 2014. + +Copyright Notice + + Copyright (c) 2014 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + + +Sustrik Expires November 5, 2014 [Page 1] + +Internet-Draft Publish/Subscribe SP May 2014 + + +1. Introduction + + Blah-blah. + +2. Underlying protocol + + The publish/subscribe protocol can be run on top of any SP mapping, + such as, for example, SP TCPmapping [SPoverTCP]. + + Also, given that SP protocols describe the behaviour of entire + arbitrarily complex topology rather than of a single node-to-node + communication, several underlying protocols can be used in parallel. + For example, publisher can send a message to intermediary node via + TCP. The intermediate node can then forward the message via PGM etc. + + +---+ TCP +---+ PGM +---+ + | |----------->| |---------->| | + +---+ +---+ +---+ + | + | PGM +---+ + +------------>| | + +---+ + +3. Overview of the algorithm + + Blah-blah. + +4. Hop-by-hop vs. End-to-end + + Blah-blah. + +5. Hop-by-hop functionality + +5.1. PUB endpoint + + Blah-blah. + +5.2. SUB endpoint + + Blah-blah. + +6. End-to-end functionality + + End-to-end functionality is built on top of hop-to-hop functionality. + Thus, an endpoint on the edge of a topology contains all the hop-by- + hop functionality, but also implements additional functionality of + + + + +Sustrik Expires November 5, 2014 [Page 2] + +Internet-Draft Publish/Subscribe SP May 2014 + + + its own. This end-to-end functionality acts basically as a user of + the underlying hop-by-hop functionality. + +6.1. PUB endpoint + + Blah-blah. + +6.2. SUB endpoint + + Blah-blah. + +7. Loop avoidance + + TODO: Do we want any loop avoidance in PUB/SUB? + +8. IANA Considerations + + New SP endpoint types PUB and SUB should be registered by IANA. For + now, value of 32 should be used for PUB endpoints and value of 33 for + SUB endpoints. + + IANA should eventually also register and issue numbers for different + message matching algorithms. + +9. Security Considerations + + The mapping is not intended to provide any additional security to the + underlying protocol. DoS concerns are addressed within the + specification. + +10. References + + [SPoverTCP] + Sustrik, M., "TCP mapping for SPs", August 2013. + +Author's Address + + Martin Sustrik (editor) + + Email: sustrik@250bpm.com + + + + + + + + + + + +Sustrik Expires November 5, 2014 [Page 3] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-publish-subscribe-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-publish-subscribe-01.xml new file mode 100644 index 0000000..06732ac --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-publish-subscribe-01.xml @@ -0,0 +1,145 @@ + + + + + + + + + Publish/Subscribe Scalability Protocol + + + +
+ sustrik@250bpm.com +
+
+ + + + Applications + Internet Engineering Task Force + + Publish + Subscribe + PUB + SUB + distribution + SP + + + This document defines a scalability protocol used for distributing + data to arbitrary number of subscriber nodes. + + +
+ + + +
+ + Blah-blah. + +
+ +
+ + The publish/subscribe protocol can be run on top of any SP mapping, + such as, for example, SP TCPmapping. + + + Also, given that SP protocols describe the behaviour of entire + arbitrarily complex topology rather than of a single node-to-node + communication, several underlying protocols can be used in parallel. + For example, publisher can send a message to intermediary node via TCP. + The intermediate node can then forward the message via PGM etc. + +
+ ++---+ TCP +---+ PGM +---+ +| |----------->| |---------->| | ++---+ +---+ +---+ + | + | PGM +---+ + +------------>| | + +---+ + +
+ +
+ +
+ Blah-blah. +
+ +
+ Blah-blah. +
+ +
+ +
+ Blah-blah. +
+ +
+ Blah-blah. +
+ +
+ +
+ + End-to-end functionality is built on top of hop-to-hop functionality. + Thus, an endpoint on the edge of a topology contains all the + hop-by-hop functionality, but also implements additional + functionality of its own. This end-to-end functionality acts + basically as a user of the underlying hop-by-hop functionality. + +
+ Blah-blah. +
+ +
+ Blah-blah. +
+ +
+ +
+ TODO: Do we want any loop avoidance in PUB/SUB? +
+ +
+ New SP endpoint types PUB and SUB should be registered by IANA. For + now, value of 32 should be used for PUB endpoints and value of 33 for + SUB endpoints. + + IANA should eventually also register and issue numbers for different + message matching algorithms. +
+ +
+ The mapping is not intended to provide any additional security to the + underlying protocol. DoS concerns are addressed within + the specification. +
+ +
+ + + + + + TCP mapping for SPs + + + + + + + + +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-request-reply-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-request-reply-01.txt new file mode 100644 index 0000000..602c8b1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-request-reply-01.txt @@ -0,0 +1,840 @@ + + + + +Internet Engineering Task Force M. Sustrik, Ed. +Internet-Draft +Intended status: Informational August 2013 +Expires: February 2, 2014 + + + Request/Reply Scalability Protocol + sp-request-reply-01 + +Abstract + + This document defines a scalability protocol used for distributing + processing tasks among arbitrary number of stateless processing nodes + and returning the results of the processing. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on February 2, 2014. + +Copyright Notice + + Copyright (c) 2013 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + +Sustrik Expires February 2, 2014 [Page 1] + +Internet-Draft Request/Reply SP August 2013 + + +1. Introduction + + One of the most common problems in distributed applications is how to + delegate a work to another processing node and get the result back to + the original node. In other words, the goal is to utilise the CPU + power of a remote node. + + There's a wide range of RPC systems addressing the problem, however, + instead of relying on simple RPC algorithm, we will aim at solving a + more general version of the problem. First, we want to issue + processing requests from multiple clients, not just a single one. + Second, we want to distribute the tasks to any number processing + nodes instead of a single one so that the processing can be scaled up + by adding new processing nodes as necessary. + + Solving the generalised problem requires that the algorithm executing + the task in question -- also known as "service" -- is stateless. + + To put it simply, the service is called "stateless" when there's no + way for the user to distinguish whether a request was processed by + one instance of the service or another one. + + So, for example, a service which accepts two integers and multiplies + them is stateless. Request for "2x2" is always going to produce "4", + no matter what instance of the service have computed it. + + Service that accepts empty requests and produces the number of + requests processed so far (1, 2, 3 etc.), on the other hand, is not + stateless. To prove it you can run two instances of the service. + First reply, no matter which instance produces it is going to be 1. + Second reply though is going to be either 2 (if processed by the same + instance as the first one) or 1 (if processed by the other instance). + You can distinguish which instance produced the result. Thus, + according to the definition, the service is not stateless. + + Despite the name, being "stateless" doesn't mean that the service has + no state at all. Rather it means that the service doesn't retain any + business-logic-related state in-between processing two subsequent + requests. The service is, of course, allowed to have state while + processing a single request. It can also have state that is + unrelated to its business logic, say statistics about the processing + that are used for administrative purposes and never returned to the + clients. + + Also note that "stateless" doesn't necessarily mean "fully + deterministic". For example, a service that generates random numbers + is non-deterministic. However, the client, after receiving a new + + + + +Sustrik Expires February 2, 2014 [Page 2] + +Internet-Draft Request/Reply SP August 2013 + + + random number cannot tell which instance has produced it, thus, the + service can be considered stateless. + + While stateless services are often implemented by passing the entire + state inside the request, they are not required to do so. Especially + when the state is large, passing it around in each request may be + impractical. In such cases, it's typically just a reference to the + state that's passed in the request, such as ID or path. The state + itself can then be retrieved by the service from a shared database, a + network file system or similar storage mechanism. + + Requiring services to be stateless serves a specific purpose. It + allows for using any number of service instances to handle the + processing load. After all, the client won't be able to tell the + difference between replies from instance A and replies from instance + B. You can even start new instances on the fly and get away with it. + The client still won't be able to tell the difference. In other + words, statelessness is a prerequisite to make your service cluster + fully scalable. + + Once it is ensured that the service is stateless there are several + topologies for a request/reply system to form. What follows are the + most common: + + 1. One client sends a request to one server and gets a reply. The + common RPC scenario. + + 2. Many clients send requests to one server and get replies. The + classic client/server model. Think of a database server and + database clients. Alternatively think of a messaging broker and + messaging clients. + + 3. One client send requests to many servers and gets replies. The + load-balancer model. Think of HTTP load balancers. + + 4. Many clients send requests to be processed by many servers. The + "enterprise service bus" model. In the simplest case the bus can + be implemented as a simple hub-and-spokes topology. In complex + cases the bus can span multiple physical locations or multiple + organisations with intermediate nodes at the boundaries + connecting different parts of the topology. + + In addition to distributing tasks to processing nodes, request/reply + model comes with full end-to-end reliability. The reliability + guarantee can be defined as follows: As long as the client is alive + and there's at least one server accessible from the client, the task + will eventually get processed and the result will be delivered back + to the client. + + + +Sustrik Expires February 2, 2014 [Page 3] + +Internet-Draft Request/Reply SP August 2013 + + + End-to-end reliability is achieved, similar to TCP, by re-sending the + request if the client believes the original instance of the request + has failed. Typically, request is believed to have failed when + there's no reply received within a specified time. + + Note that, unlike with TCP, the reliability algorithm is resistant to + a server failure. Even if server fails while processing a request, + the request will be re-sent and eventually processed by a different + instance of the server. + + As can be seen from the above, one request may be processed multiple + times. For example, reply may be lost on its way back to the client. + Client will assume that the request was not processed yet, it will + resend it and thus cause duplicate execution of the task. + + Some applications may want to prevent duplicate execution of tasks. + It often turns out that hardening such applications to be idempotent + is relatively easy as they already possess the tools to do so. For + example, a payment processing server already has access to a shared + database which it can use to verify that the payment with specified + ID was not yet processed. + + On the other hand, many applications don't care about occasional + duplicate processed tasks. Therefore, request/reply protocol does + not require the service to be idempotent. Instead, the idempotence + issue is left to the user to decide on. + + Finally, it should be noted that this specification discusses several + features that are of little use in simple topologies and are rather + aimed at large, geographically or organisationally distributed + topologies. Features like channel prioritisation and loop avoidance + fall into this category. + +2. Underlying protocol + + The request/reply protocol can be run on top of any SP mapping, such + as, for example, SP TCPmapping [SPoverTCP]. + + Also, given that SP protocols describe the behaviour of entire + arbitrarily complex topology rather than of a single node-to-node + communication, several underlying protocols can be used in parallel. + For example, a client may send a request via WebSocket, then, on the + edge of the company network an intermediary node may retransmit it + using TCP etc. + + + + + + + +Sustrik Expires February 2, 2014 [Page 4] + +Internet-Draft Request/Reply SP August 2013 + + + +---+ WebSocket +---+ TCP +---+ + | |-------------| |-----------| | + +---+ +---+ +---+ + | | + +---+ IPC | | SCTP +---+ DCCP +---+ + | |---------+ +--------| |-----------| | + +---+ +---+ +---+ + +3. Overview of the algorithm + + Request/reply protocol defines two different endpoint types: The + requester or REQ (the client) and the replier or REP (the service). + + REQ endpoint can be connected only to a REP endpoint. REP endpoint + can be connected only to the REQ endpoint. If the underlying + protocol indicates that there's an attempt to create a channel to an + incompatible endpoint, the channel MUST NOT be used. In the case of + TCP mapping, for example, the underlying TCP connection MUST be + closed. + + When creating more complex topologies, REQ and REP endpoints are + paired in the intermediate nodes to form a forwarding component, so + called "device". Device receives requests from the REP endpoint and + forwards them to the REQ endpoint. At the same time it receives + replies from the REQ endpoint and forwards them to the REP endpoint: + + --- requests --> + + +-----+ +-----+-----+ +-----+-----+ +-----+ + | |-->| | |-->| | |-->| | + | REQ | | REP | REQ | | REP | REQ | | REP | + | |<--| | |<--| | |<--| | + +-----+ +-----+-----+ +-----+-----+ +-----+ + + <-- replies --- + + Using devices, arbitrary complex topologies can be built. The rest + of this section explains how are the requests routed through a + topology towards processing nodes and how are replies routed back + from processing nodes to the original clients, as well as how the + reliability is achieved. + + The idea for routing requests is to implement a simple coarse-grained + scheduling algorithm based on pushback capabilities of the underlying + transport. + + + + + + +Sustrik Expires February 2, 2014 [Page 5] + +Internet-Draft Request/Reply SP August 2013 + + + The algorithm works by interpreting pushback on a particular channel + as "the part of topology accessible through this channel is busy at + the moment and doesn't accept any more requests." + + Thus, when a node is about to send a request, it can choose to send + it only to one of the channels that don't report pushback at the + moment. To implement approximately fair distribution of the workload + the node choses a channel from that pool using the round-robin + algorithm. + + As for delivering replies back to the clients, it should be + understood that the client may not be directly accessible (say using + TCP/IP) from the processing node. It may be beyond a firewall, have + no static IP address etc. Furthermore, the client and the processing + may not even speak the same transport protocol -- imagine client + connecting to the topology using WebSockets and processing node via + SCTP. + + Given the above, it becomes obvious that the replies must be routed + back through the existing topology rather than directly. In fact, + request/reply topology may be thought of as an overlay network on the + top of underlying transport mechanisms. + + As for routing replies within the request/topology, it is designed in + such a way that each reply contains the whole routing path, rather + than containing just the address of destination node, as is the case + with, for example, TCP/IP. + + The downside of the design is that replies are a little bit longer + and that is in intermediate node gets restarted, all the requests + that were routed through it will fail to complete and will have to be + resent by request/reply end-to-end reliability mechanism. + + The upside, on the other hand, is that the nodes in the topology + don't have to maintain any routing tables beside the simple table of + adjacent channels along with their IDs. There's also no need for any + additional protocols for distributing routing information within the + topology. + + The most important reason for adopting the design though is that + there's no propagation delay and any nodes becomes accessible + immediately after it is started. Given that some nodes in the + topology may be extremely short-lived this is a crucial requirement. + Imagine a database client that sends a query, reads the result and + terminates. It makes no sense to delay the whole process until the + routing tables are synchronised between the client and the server. + + + + + +Sustrik Expires February 2, 2014 [Page 6] + +Internet-Draft Request/Reply SP August 2013 + + + The algorithm thus works as follows: When request is routed from the + client to the processing node, every REP endpoint determines which + channel it was received from and adds the ID of the channel to the + request. Thus, when the request arrives at the ultimate processing + node it already contains a full backtrace stack, which in turn + contains all the info needed to route a message back to the original + client. + + After processing the request, the processing node attaches the + backtrace stack from the request to the reply and sends it back to + the topology. At that point every REP endpoint can check the + traceback and determine which channel it should send the reply to. + + In addition to routing, request/reply protocol takes care of + reliability, i.e. ensures that every request will be eventually + processed and the reply will be delivered to the user, even when + facing failures of processing nodes, intermediate nodes and network + infrastructure. + + Reliability is achieved by simply re-sending the request, if the + reply is not received with a certain timeframe. To make that + algorithm work flawlessly, the client has to be able to filter out + any stray replies (delayed replies for the requests that we've + already received reply to). + + The client thus adds an unique request ID to the request. The ID + gets copied from the request to the reply by the processing node. + When the reply gets back to the client, it can simply check whether + the request in question is still being processed and if not so, it + can ignore the reply. + + To implement all the functionality described above, messages (both + requests and replies have the following format: + + +-+------------+-+------------+ +-+------------+-------------+ + |0| Channel ID |0| Channel ID |...|1| Request ID | payload | + +-+------------+-+------------+ +-+------------+ ------------+ + + Payload of the message is preceded by a stack of 32-bit tags. The + most significant bit of each tag is set to 0 except for the very last + tag. That allows the algorithm to find out where the tags end and + where the message payload begins. + + As for the remaining 31 bits, they are either request ID (in the last + tag) or a channel ID (in all the remaining tags). The first channel + ID is added and processed by the REP endpoint closest to the + processing node. The last channel ID is added and processed by the + REP endpoint closest to the client. + + + +Sustrik Expires February 2, 2014 [Page 7] + +Internet-Draft Request/Reply SP August 2013 + + + Following picture shows an example of request saying "Hello" being + routed from the client through two intermediate nodes to the + processing node and the reply "World" being routed back. It shows + what messages are passed over the network at each step of the + process: + + client + Hello | World + | +-----+ ^ + | | REQ | | + V +-----+ | + 1|823|Hello | 1|823|World + | +-----+ ^ + | | REP | | + | +-----+ | + | | REQ | | + V +-----+ | + 0|299|1|823|Hello | 0|299|1|823|World + | +-----+ ^ + | | REP | | + | +-----+ | + | | REQ | | + V +-----+ | + 0|446|0|299|1|823|Hello | 0|446|0|299|1|823|World + | +-----+ ^ + | | REP | | + V +-----+ | + Hello | World + service + +4. Hop-by-hop vs. End-to-end + + All endpoints implement so called "hop-by-hop" functionality. It's + the functionality concerned with sending messages to the immediately + adjacent components and receiving messages from them. + + In addition to that, the endpoints on the edge of the topology + implement so called "end-to-end" functionality that is concerned with + issues such as, for example, reliability. + + + + + + + + + + + + +Sustrik Expires February 2, 2014 [Page 8] + +Internet-Draft Request/Reply SP August 2013 + + + end to end + +-----------------------------------------+ + | | + +-----+ +-----+-----+ +-----+-----+ +-----+ + | |-->| | |-->| | |-->| | + | REQ | | REP | REQ | | REP | REQ | | REP | + | |<--| | |<--| | |<--| | + +-----+ +-----+-----+ +-----+-----+ +-----+ + | | | | | | + +---------+ +---------+ +---------+ + hop by hop hop by hop hop by hop + + To make an analogy with the TCP/IP stack, IP provides hop-by-hop + functionality, i.e. routing of the packets to the adjacent node, + while TCP implements end-to-end functionality such resending of lost + packets. + + As a rule of thumb, raw hop-by-hop endpoints are used to build + devices (intermediary nodes in the topology) while end-to-end + endpoints are used directly by the applications. + + To prevent confusion, the specification of the endpoint behaviour + below will discuss hop-by-hop and end end-to-end functionality in + separate chapters. + +5. Hop-by-hop functionality + +5.1. REQ endpoint + + The REQ endpoint is used by the user to send requests to the + processing nodes and receive the replies afterwards. + + When user asks REQ endpoint to send a request, the endpoint should + send it to one of the associated outbound channels (TCP connections + or similar). The request sent is exactly the message supplied by the + user. REQ socket MUST NOT modify an outgoing request in any way. + + If there's no channel to send the request to, the endpoint won't send + the request and MUST report the backpressure condition to the user. + For example, with BSD socket API, backpressure is reported as EAGAIN + error. + + If there are associated channels but none of them is available for + sending, i.e. all of them are already reporting backpressure, the + endpoint won't send the message and MUST report the backpressure + condition to the user. + + + + + +Sustrik Expires February 2, 2014 [Page 9] + +Internet-Draft Request/Reply SP August 2013 + + + Backpressure is used as a means to redirect the requests from the + congested parts of the topology to to the parts that are still + responsive. It can be thought of as a crude scheduling algorithm. + However crude though, it's probably still the best you can get + without knowing estimates of execution time for individual tasks, CPU + capacity of individual processing nodes etc. + + Alternatively, backpressure can be thought of as a congestion control + mechanism. When all available processing nodes are busy, it slows + down the client application, i.e. it prevents the user from sending + any more requests. + + If the channel is not capable of reporting backpressure (e.g. DCCP) + the endpoint SHOULD consider it as always available for sending new + request. However, such channels should be used with care as when the + congestion hits they may suck in a lot of requests just to discard + them silently and thus cause re-transmission storms later on. The + implementation of the REQ endpoint MAY choose to prohibit the use of + such channels altogether. + + When there are multiple channels available for sending the request + endpoint MAY use any prioritisation mechanism to decide which channel + to send the request to. For example, it may use classic priorities + attached to channels and send message to the channel with the highest + priority. That allows for routing algorithms such as: "Use local + processing nodes if any are available. Send the requests to remote + nodes only if there are no local ones available." Alternatively, the + endpoint may implement weighted priorities ("send 20% of the request + to node A and 80% to node B). The endpoint also may not implement + any prioritisation strategy and treat all channels as equal. + + Whatever the case, two rules must apply. + + First, by default the priority settings for all channels MUST be + equal. Creating a channel with different priority MUST be triggered + by an explicit action by the user. + + Second, if there are several channels with equal priority, the + endpoint MUST distribute the messages among them in fair fashion + using round-robin algorithm. The round-robin implementation MUST + also take care not to become unfair when new channels are added or + old ones are removed on the fly. + + As for incoming messages, i.e. replies, REQ endpoint MUST fair-queues + them. In other words, if there are replies available on several + channels, it MUST receive them in a round-robin fashion. It must + also take care not to compromise the fairness when new channels are + added or old ones removed. + + + +Sustrik Expires February 2, 2014 [Page 10] + +Internet-Draft Request/Reply SP August 2013 + + + In addition to providing basic fairness, the goal of fair-queueing is + to prevent DoS attacks where a huge stream of fake replies from one + channel would be able to block the real replies coming from different + channels. Fair queueing ensures that messages from every channel are + received at approximately the same rate. That way, DoS attack can + slow down the system but it can't entirely block it. + + Incoming replies MUST be handed to the user exactly as they were + received. REQ endpoint MUST not modify the replies in any way. + +5.2. REP endpoint + + REP endpoint is used to receive requests from the clients and send + replies back to the clients. + + First of all, REP socket is responsible for assigning unique 31-bit + channel IDs to the individual associated channels. + + First ID assigned MUST be random. Next is computed by adding 1 to + the previous one with potential overflow to 0. + + The implementation MUST ensure that the random number is different + each time the endpoint is re-started, the process that contains it is + restarted or similar. So, for example, using pseudo-random generator + with a constant seed won't do. + + The goal of the algorithm is to the spread of possible channel ID + values and thus minimise the chance that a reply is routed to an + unrelated channel, even in the face of intermediate node failures. + + When receiving a message, REP endpoint MUST fair-queue among the + channels available for receiving. In other words it should round- + robin among such channels and receive one request from a channel at a + time. It MUST also implement the round-robin algorithm is such a way + that adding or removing channels don't break its fairness. + + In addition to guaranteeing basic fairness in access to computing + resources the above algorithm makes it impossible for a malevolent or + misbehaving client to completely block the processing of requests + from other clients by issuing steady stream of requests. + + After getting hold on the request, the REP socket should prepend it + by 32 bit value, consisting of 1 bit set to 0 followed by the 31-bit + ID of the channel the request was received from. The extended + request will be then handed to the user. + + The goal of adding the channel ID to the request is to be able to + route the reply back to the original channel later on. Thus, when + + + +Sustrik Expires February 2, 2014 [Page 11] + +Internet-Draft Request/Reply SP August 2013 + + + the user sends a reply, endpoint strips first 32 bits off and uses + the value to determine where it is to be routed. + + If the reply is shorter than 32 bits, it is malformed and the + endpoint MUST ignore it. Also, if the most relevant bit of the + 32-bit value isn't set to 0, the reply is malformed and MUST be + ignored. + + Otherwise, the endpoint checks whether its table of associated + channels contains the channel with a corresponding ID. If so, it + sends the reply (with first 32 bits stripped off) to that channel. + If the channel is not found, the reply MUST be dropped. If the + channel is not available for sending, i.e. it is applying + backpressure, the reply MUST be dropped. + + Note that when the reply is unroutable two things might have + happened. Either there was some kind of network disruption, in which + case the request will be re-sent later on, or the original client + have failed or been shut down. In such case the request won't be + resent, however, it doesn't really matter because there's no one to + deliver the reply to any more anyway. + + Unlike requests, there's no pushback applied to the replies; they are + simply dropped. If the endpoint blocked and waited for the channel + to become available, all the subsequent replies, possibly destined + for different unblocked channels, would be blocked in the meantime. + That allows for a DoS attack simply by firing a lot of requests and + not receiving the replies. + +6. End-to-end functionality + + End-to-end functionality is built on top of hop-to-hop functionality. + Thus, an endpoint on the edge of a topology contains all the hop-by- + hop functionality, but also implements additional functionality of + its own. This end-to-end functionality acts basically as a user of + the underlying hop-by-hop functionality. + +6.1. REQ endpoint + + End-to-end functionality for REQ sockets is concerned with re-sending + the requests in case of failure and with filtering out stray or + outdated replies. + + To be able to do the latter, the endpoint must tag the requests with + unique 31-bit request IDs. First request ID is picked at random. + All subsequent request IDs are generated by adding 1 to the last + request ID and possibly overflowing to 0. + + + + +Sustrik Expires February 2, 2014 [Page 12] + +Internet-Draft Request/Reply SP August 2013 + + + To improve robustness of the system, the implementation MUST ensure + that the random number is different each time the endpoint, the + process or the machine is restarted. Pseudo-random generator with + fixed seed won't do. + + When user asks the endpoint to send a message, the endpoint prepends + a 32-bit value to the message, consisting of a single bit set to 1 + followed by a 31-bit request ID and passes it on in a standard hop- + by-hop way. + + If the hop-by-hop layer reports pushback condition, the end-to-end + layer considers the request unsent and MUST report pushback condition + to the user. + + If the request is successfully sent, the endpoint stores the request + including its request ID, so that it can be resent later on if + needed. At the same time it sets up a timer to trigger the re- + transmission in case the reply is not received within a specified + timeout. The user MUST be allowed to specify the timeout interval. + The default timeout interval must be 60 seconds. + + When a reply is received from the underlying hop-by-hop + implementation, the endpoint should strip off first 32 bits from the + reply to check whether it is a valid reply. + + If the reply is shorter than 32 bits, it is malformed and the + endpoint MUST ignore it. If the most significant bit of the 32-bit + value is set to 0, the reply is malformed and MUST be ignored. + + Otherwise, the endpoint should check whether the request ID in the + reply matches any of the request IDs of the requests being processed + at the moment. If not so, the reply MUST be ignored. It is either a + stray message or a duplicate reply. + + Please note that the endpoint can support either one or more requests + being processed in parallel. Which one is the case depends on the + API exposed to the user and is not part of this specification. + + If the ID in the reply matches one of the requests in progress, the + reply MUST be passed to the user (with the 32-bit prefix stripped + off). At the same time the stored copy of the original request as + well as re-transmission timer must be deallocated. + + Finally, REQ endpoint MUST make it possible for the user to cancel a + particular request in progress. What it means technically is + deleting the stored copy of the request and cancelling the associated + timer. Thus, once the reply arrives, it will be discarded by the + algorithm above. + + + +Sustrik Expires February 2, 2014 [Page 13] + +Internet-Draft Request/Reply SP August 2013 + + + The cancellation allows, for example, the user to time out a request. + They can simply post a request and if there's no answer in specific + timeframe, they can cancel it. + +6.2. REP endpoint + + End-to-end functionality for REP endpoints is concerned with turning + requests into corresponding replies. + + When user asks to receive a request, the endpoint gets next request + from the hop-by-hop layer and splits it into the traceback stack and + the message payload itself. The traceback stack is stored and the + payload is returned to the user. + + The algorithm for splitting the request is as follows: Strip 32 bit + tags from the message in one-by-one manner. Once the most + significant bit of the tag is set, we've reached the bottom of the + traceback stack and the splitting is done. If the end of the message + is reached without finding the bottom of the stack, the request is + malformed and MUST be ignored. + + Note that the payload produced by this procedure is the same as the + request payload sent by the original client. + + Once the user processes the request and sends the reply, the endpoint + prepends the reply with the stored traceback stack and sends it on + using the hop-by-hop layer. At that point the stored traceback stack + MUST be deallocated. + + Additionally, REP endpoint MUST support cancelling any request being + processed at the moment. What it means, technically, is that state + associated with the request, i.e. the traceback stack stored by the + endpoint is deleted and reply to that particular request is never + sent. + + The most important use of cancellation is allowing the service + instances to ignore malformed requests. If the application-level + part of the request doesn't conform to the application protocol the + service can simply cancel the request. In such case the reply is + never sent. Of course, if application wants to send an application- + specific error massage back to the client it can do so by not + cancelling the request and sending a regular reply. + +7. Loop avoidance + + It may happen that a request/reply topology contains a loop. It + becomes increasingly likely as the topology grows out of scope of a + single organisation and there are multiple administrators involved in + + + +Sustrik Expires February 2, 2014 [Page 14] + +Internet-Draft Request/Reply SP August 2013 + + + maintaining it. Unfortunate interaction between two perfectly + legitimate setups can cause loop to be created. + + With no additional guards against the loops, it's likely that + requests will be caught inside the loop, rotating there forever, each + message gradually growing in size as new prefixes are added to it by + each REP endpoint on the way. Eventually, a loop can cause + congestion and bring the whole system to a halt. + + To deal with the problem REQ endpoints MUST check the depth of the + traceback stack for every outgoing request and discard any requests + where it exceeds certain threshold. The threshold should be defined + by the user. The default value is suggested to be 8. + +8. IANA Considerations + + New SP endpoint types REQ and REP should be registered by IANA. For + now, value of 16 should be used for REQ endpoints and value of 17 for + REP endpoints. + +9. Security Considerations + + The mapping is not intended to provide any additional security to the + underlying protocol. DoS concerns are addressed within the + specification. + +10. References + + [SPoverTCP] + Sustrik, M., "TCP mapping for SPs", August 2013. + +Author's Address + + Martin Sustrik (editor) + + Email: sustrik@250bpm.com + + + + + + + + + + + + + + + +Sustrik Expires February 2, 2014 [Page 15] diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-request-reply-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-request-reply-01.xml new file mode 100644 index 0000000..dbd10a5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-request-reply-01.xml @@ -0,0 +1,745 @@ + + + + + + + + + Request/Reply Scalability Protocol + + + +
+ sustrik@250bpm.com +
+
+ + + + Applications + Internet Engineering Task Force + + Request + Reply + REQ + REP + stateless + service + SP + + + This document defines a scalability protocol used for distributing + processing tasks among arbitrary number of stateless processing nodes + and returning the results of the processing. + + +
+ + + +
+ + One of the most common problems in distributed applications is how to + delegate a work to another processing node and get the result back to + the original node. In other words, the goal is to utilise the CPU + power of a remote node. + + There's a wide range of RPC systems addressing the problem, however, + instead of relying on simple RPC algorithm, we will aim at solving a + more general version of the problem. First, we want to issue processing + requests from multiple clients, not just a single one. Second, we want + to distribute the tasks to any number processing nodes instead of a + single one so that the processing can be scaled up by adding new + processing nodes as necessary. + + Solving the generalised problem requires that the algorithm + executing the task in question -- also known as "service" -- is + stateless. + + To put it simply, the service is called "stateless" when there's no + way for the user to distinguish whether a request was processed by + one instance of the service or another one. + + So, for example, a service which accepts two integers and multiplies + them is stateless. Request for "2x2" is always going to produce "4", + no matter what instance of the service have computed it. + + Service that accepts empty requests and produces the number + of requests processed so far (1, 2, 3 etc.), on the other hand, is + not stateless. To prove it you can run two instances of the service. + First reply, no matter which instance produces it is going to be 1. + Second reply though is going to be either 2 (if processed by the same + instance as the first one) or 1 (if processed by the other instance). + You can distinguish which instance produced the result. Thus, + according to the definition, the service is not stateless. + + Despite the name, being "stateless" doesn't mean that the service has + no state at all. Rather it means that the service doesn't retain any + business-logic-related state in-between processing two subsequent + requests. The service is, of course, allowed to have state while + processing a single request. It can also have state that is unrelated + to its business logic, say statistics about the processing that are + used for administrative purposes and never returned to the clients. + + Also note that "stateless" doesn't necessarily mean "fully + deterministic". For example, a service that generates random numbers is + non-deterministic. However, the client, after receiving a new random + number cannot tell which instance has produced it, thus, the service + can be considered stateless. + + While stateless services are often implemented by passing the entire + state inside the request, they are not required to do so. Especially + when the state is large, passing it around in each request may be + impractical. In such cases, it's typically just a reference to the + state that's passed in the request, such as ID or path. The state + itself can then be retrieved by the service from a shared database, + a network file system or similar storage mechanism. + + Requiring services to be stateless serves a specific purpose. + It allows for using any number of service instances to handle + the processing load. After all, the client won't be able to tell the + difference between replies from instance A and replies from instance B. + You can even start new instances on the fly and get away with it. + The client still won't be able to tell the difference. In other + words, statelessness is a prerequisite to make your service cluster + fully scalable. + + Once it is ensured that the service is stateless there are several + topologies for a request/reply system to form. What follows are + the most common: + + + One client sends a request to one server and gets a reply. + The common RPC scenario. + Many clients send requests to one server and get replies. The + classic client/server model. Think of a database server and + database clients. Alternatively think of a messaging broker and + messaging clients. + One client send requests to many servers and gets replies. + The load-balancer model. Think of HTTP load balancers. + Many clients send requests to be processed by many servers. + The "enterprise service bus" model. In the simplest case the bus + can be implemented as a simple hub-and-spokes topology. In complex + cases the bus can span multiple physical locations or multiple + organisations with intermediate nodes at the boundaries connecting + different parts of the topology. + + + + + In addition to distributing tasks to processing nodes, request/reply + model comes with full end-to-end reliability. The reliability guarantee + can be defined as follows: As long as the client is alive and there's + at least one server accessible from the client, the task will + eventually get processed and the result will be delivered back to + the client. + + End-to-end reliability is achieved, similar to TCP, by re-sending the + request if the client believes the original instance of the request + has failed. Typically, request is believed to have failed when there's + no reply received within a specified time. + + Note that, unlike with TCP, the reliability algorithm is resistant to + a server failure. Even if server fails while processing a request, the + request will be re-sent and eventually processed by a different + instance of the server. + + As can be seen from the above, one request may be processed multiple + times. For example, reply may be lost on its way back to the client. + Client will assume that the request was not processed yet, it will + resend it and thus cause duplicate execution of the task. + + Some applications may want to prevent duplicate execution of tasks. It + often turns out that hardening such applications to be idempotent is + relatively easy as they already possess the tools to do so. For + example, a payment processing server already has access to a shared + database which it can use to verify that the payment with specified ID + was not yet processed. + + On the other hand, many applications don't care about occasional + duplicate processed tasks. Therefore, request/reply protocol does not + require the service to be idempotent. Instead, the idempotence issue + is left to the user to decide on. + + Finally, it should be noted that this specification discusses several + features that are of little use in simple topologies and are rather + aimed at large, geographically or organisationally distributed + topologies. Features like channel prioritisation and loop avoidance + fall into this category. + +
+ +
+ + The request/reply protocol can be run on top of any SP mapping, + such as, for example, SP TCPmapping. + + + Also, given that SP protocols describe the behaviour of entire + arbitrarily complex topology rather than of a single node-to-node + communication, several underlying protocols can be used in parallel. + For example, a client may send a request via WebSocket, then, on the + edge of the company network an intermediary node may retransmit it + using TCP etc. + +
+ ++---+ WebSocket +---+ TCP +---+ +| |-------------| |-----------| | ++---+ +---+ +---+ + | | + +---+ IPC | | SCTP +---+ DCCP +---+ + | |---------+ +--------| |-----------| | + +---+ +---+ +---+ + +
+ +
+ +
+ + Request/reply protocol defines two different endpoint types: + The requester or REQ (the client) and the replier or REP (the + service). + + REQ endpoint can be connected only to a REP endpoint. REP endpoint + can be connected only to the REQ endpoint. If the underlying protocol + indicates that there's an attempt to create a channel to an + incompatible endpoint, the channel MUST NOT be used. In the case of + TCP mapping, for example, the underlying TCP connection MUST + be closed. + + When creating more complex topologies, REQ and REP endpoints are + paired in the intermediate nodes to form a forwarding component, + so called "device". Device receives requests from the REP endpoint + and forwards them to the REQ endpoint. At the same time it receives + replies from the REQ endpoint and forwards them to the REP + endpoint: + +
+ + --- requests --> + ++-----+ +-----+-----+ +-----+-----+ +-----+ +| |-->| | |-->| | |-->| | +| REQ | | REP | REQ | | REP | REQ | | REP | +| |<--| | |<--| | |<--| | ++-----+ +-----+-----+ +-----+-----+ +-----+ + + <-- replies --- + +
+ + Using devices, arbitrary complex topologies can be built. The rest + of this section explains how are the requests routed through a topology + towards processing nodes and how are replies routed back from + processing nodes to the original clients, as well as how the + reliability is achieved. + + The idea for routing requests is to implement a simple coarse-grained + scheduling algorithm based on pushback capabilities of the underlying + transport. + + The algorithm works by interpreting pushback on a particular channel + as "the part of topology accessible through this channel is busy at + the moment and doesn't accept any more requests." + + Thus, when a node is about to send a request, it can choose to send + it only to one of the channels that don't report pushback at the + moment. To implement approximately fair distribution of the workload + the node choses a channel from that pool using the round-robin + algorithm. + + As for delivering replies back to the clients, it should be understood + that the client may not be directly accessible (say using TCP/IP) from + the processing node. It may be beyond a firewall, have no static IP + address etc. Furthermore, the client and the processing may not even + speak the same transport protocol -- imagine client connecting to the + topology using WebSockets and processing node via SCTP. + + Given the above, it becomes obvious that the replies must be routed + back through the existing topology rather than directly. In fact, + request/reply topology may be thought of as an overlay network on the + top of underlying transport mechanisms. + + As for routing replies within the request/topology, it is designed in + such a way that each reply contains the whole routing path, rather + than containing just the address of destination node, as is the case + with, for example, TCP/IP. + + The downside of the design is that replies are a little bit longer + and that is in intermediate node gets restarted, all the requests + that were routed through it will fail to complete and will have to be + resent by request/reply end-to-end reliability mechanism. + + The upside, on the other hand, is that the nodes in the topology don't + have to maintain any routing tables beside the simple table of + adjacent channels along with their IDs. There's also no need for any + additional protocols for distributing routing information within + the topology. + + The most important reason for adopting the design though is that + there's no propagation delay and any nodes becomes accessible + immediately after it is started. Given that some nodes in the topology + may be extremely short-lived this is a crucial requirement. Imagine + a database client that sends a query, reads the result and terminates. + It makes no sense to delay the whole process until the routing tables + are synchronised between the client and the server. + + The algorithm thus works as follows: When request is routed from the + client to the processing node, every REP endpoint determines which + channel it was received from and adds the ID of the channel to the + request. Thus, when the request arrives at the ultimate processing node + it already contains a full backtrace stack, which in turn contains + all the info needed to route a message back to the original client. + + After processing the request, the processing node attaches the + backtrace stack from the request to the reply and sends it back + to the topology. At that point every REP endpoint can check the + traceback and determine which channel it should send the reply to. + + In addition to routing, request/reply protocol takes care of + reliability, i.e. ensures that every request will be eventually + processed and the reply will be delivered to the user, even when + facing failures of processing nodes, intermediate nodes and network + infrastructure. + + Reliability is achieved by simply re-sending the request, if the reply + is not received with a certain timeframe. To make that algorithm + work flawlessly, the client has to be able to filter out any stray + replies (delayed replies for the requests that we've already received + reply to). + + The client thus adds an unique request ID to the request. The ID gets + copied from the request to the reply by the processing node. When the + reply gets back to the client, it can simply check whether the request + in question is still being processed and if not so, it can ignore + the reply. + + To implement all the functionality described above, messages (both + requests and replies have the following format: + +
+ ++-+------------+-+------------+ +-+------------+-------------+ +|0| Channel ID |0| Channel ID |...|1| Request ID | payload | ++-+------------+-+------------+ +-+------------+ ------------+ + +
+ + Payload of the message is preceded by a stack of 32-bit tags. The most + significant bit of each tag is set to 0 except for the very last tag. + That allows the algorithm to find out where the tags end and where + the message payload begins. + + As for the remaining 31 bits, they are either request ID (in the last + tag) or a channel ID (in all the remaining tags). The first channel ID + is added and processed by the REP endpoint closest to the processing + node. The last channel ID is added and processed by the REP endpoint + closest to the client. + + Following picture shows an example of request saying "Hello" being + routed from the client through two intermediate nodes to the + processing node and the reply "World" being routed back. It shows + what messages are passed over the network at each step of the + process: + +
+ + client + Hello | World + | +-----+ ^ + | | REQ | | + V +-----+ | + 1|823|Hello | 1|823|World + | +-----+ ^ + | | REP | | + | +-----+ | + | | REQ | | + V +-----+ | + 0|299|1|823|Hello | 0|299|1|823|World + | +-----+ ^ + | | REP | | + | +-----+ | + | | REQ | | + V +-----+ | +0|446|0|299|1|823|Hello | 0|446|0|299|1|823|World + | +-----+ ^ + | | REP | | + V +-----+ | + Hello | World + service + +
+ +
+ +
+ + All endpoints implement so called "hop-by-hop" functionality. It's + the functionality concerned with sending messages to the immediately + adjacent components and receiving messages from them. + + In addition to that, the endpoints on the edge of the topology + implement so called "end-to-end" functionality that is concerned + with issues such as, for example, reliability. + +
+ + end to end + +-----------------------------------------+ + | | ++-----+ +-----+-----+ +-----+-----+ +-----+ +| |-->| | |-->| | |-->| | +| REQ | | REP | REQ | | REP | REQ | | REP | +| |<--| | |<--| | |<--| | ++-----+ +-----+-----+ +-----+-----+ +-----+ + | | | | | | + +---------+ +---------+ +---------+ + hop by hop hop by hop hop by hop + +
+ + To make an analogy with the TCP/IP stack, IP provides hop-by-hop + functionality, i.e. routing of the packets to the adjacent node, + while TCP implements end-to-end functionality such resending of + lost packets. + + As a rule of thumb, raw hop-by-hop endpoints are used to build + devices (intermediary nodes in the topology) while end-to-end + endpoints are used directly by the applications. + + To prevent confusion, the specification of the endpoint behaviour + below will discuss hop-by-hop and end end-to-end functionality in + separate chapters. + +
+ +
+ +
+ + The REQ endpoint is used by the user to send requests to the + processing nodes and receive the replies afterwards. + + When user asks REQ endpoint to send a request, the endpoint should + send it to one of the associated outbound channels (TCP connections + or similar). The request sent is exactly the message supplied by + the user. REQ socket MUST NOT modify an outgoing request in any + way. + + If there's no channel to send the request to, the endpoint won't send + the request and MUST report the backpressure condition to the user. + For example, with BSD socket API, backpressure is reported as EAGAIN + error. + + If there are associated channels but none of them is available for + sending, i.e. all of them are already reporting backpressure, the + endpoint won't send the message and MUST report the backpressure + condition to the user. + + Backpressure is used as a means to redirect the requests from the + congested parts of the topology to to the parts that are still + responsive. It can be thought of as a crude scheduling algorithm. + However crude though, it's probably still the best you can get + without knowing estimates of execution time for individual tasks, + CPU capacity of individual processing nodes etc. + + Alternatively, backpressure can be thought of as a congestion control + mechanism. When all available processing nodes are busy, it slows + down the client application, i.e. it prevents the user from sending + any more requests. + + If the channel is not capable of reporting backpressure (e.g. DCCP) + the endpoint SHOULD consider it as always available for sending new + request. However, such channels should be used with care as when the + congestion hits they may suck in a lot of requests just to discard + them silently and thus cause re-transmission storms later on. The + implementation of the REQ endpoint MAY choose to prohibit the use + of such channels altogether. + + When there are multiple channels available for sending the request + endpoint MAY use any prioritisation mechanism to decide which channel + to send the request to. For example, it may use classic priorities + attached to channels and send message to the channel with the highest + priority. That allows for routing algorithms such as: "Use local + processing nodes if any are available. Send the requests to remote + nodes only if there are no local ones available." Alternatively, + the endpoint may implement weighted priorities ("send 20% of the + request to node A and 80% to node B). The endpoint also may not + implement any prioritisation strategy and treat all channels as + equal. + + Whatever the case, two rules must apply. + + First, by default the priority settings for all channels MUST be + equal. Creating a channel with different priority MUST be triggered + by an explicit action by the user. + + Second, if there are several channels with equal priority, the + endpoint MUST distribute the messages among them in fair fashion + using round-robin algorithm. The round-robin implementation MUST also + take care not to become unfair when new channels are added or old + ones are removed on the fly. + + As for incoming messages, i.e. replies, REQ endpoint MUST fair-queues + them. In other words, if there are replies available on several + channels, it MUST receive them in a round-robin fashion. It must also + take care not to compromise the fairness when new channels are + added or old ones removed. + + In addition to providing basic fairness, the goal of fair-queueing is + to prevent DoS attacks where a huge stream of fake replies from one + channel would be able to block the real replies coming from different + channels. Fair queueing ensures that messages from every channel are + received at approximately the same rate. That way, DoS attack can + slow down the system but it can't entirely block it. + + Incoming replies MUST be handed to the user exactly as they were + received. REQ endpoint MUST not modify the replies in any way. + +
+ +
+ + REP endpoint is used to receive requests from the clients and send + replies back to the clients. + + First of all, REP socket is responsible for assigning unique 31-bit + channel IDs to the individual associated channels. + + First ID assigned MUST be random. Next is computed by adding 1 to + the previous one with potential overflow to 0. + + The implementation MUST ensure that the random number is different + each time the endpoint is re-started, the process that contains + it is restarted or similar. So, for example, using pseudo-random + generator with a constant seed won't do. + + The goal of the algorithm is to the spread of possible channel ID + values and thus minimise the chance that a reply is routed to an + unrelated channel, even in the face of intermediate node + failures. + + When receiving a message, REP endpoint MUST fair-queue among the + channels available for receiving. In other words it should + round-robin among such channels and receive one request from + a channel at a time. It MUST also implement the round-robin + algorithm is such a way that adding or removing channels don't + break its fairness. + + In addition to guaranteeing basic fairness in access to computing + resources the above algorithm makes it impossible for a malevolent + or misbehaving client to completely block the processing of requests + from other clients by issuing steady stream of requests. + + After getting hold on the request, the REP socket should prepend it + by 32 bit value, consisting of 1 bit set to 0 followed by the 31-bit + ID of the channel the request was received from. The extended request + will be then handed to the user. + + The goal of adding the channel ID to the request is to be able to + route the reply back to the original channel later on. Thus, when + the user sends a reply, endpoint strips first 32 bits off and uses + the value to determine where it is to be routed. + + If the reply is shorter than 32 bits, it is malformed and + the endpoint MUST ignore it. Also, if the most relevant bit of the + 32-bit value isn't set to 0, the reply is malformed and MUST + be ignored. + + Otherwise, the endpoint checks whether its table of associated + channels contains the channel with a corresponding ID. If so, it + sends the reply (with first 32 bits stripped off) to that channel. + If the channel is not found, the reply MUST be dropped. If the + channel is not available for sending, i.e. it is applying + backpressure, the reply MUST be dropped. + + Note that when the reply is unroutable two things might have + happened. Either there was some kind of network disruption, in which + case the request will be re-sent later on, or the original client + have failed or been shut down. In such case the request won't be + resent, however, it doesn't really matter because there's no one to + deliver the reply to any more anyway. + + Unlike requests, there's no pushback applied to the replies; they are + simply dropped. If the endpoint blocked and waited for the channel to + become available, all the subsequent replies, possibly destined for + different unblocked channels, would be blocked in the meantime. That + allows for a DoS attack simply by firing a lot of requests and not + receiving the replies. + +
+ +
+ +
+ + End-to-end functionality is built on top of hop-to-hop functionality. + Thus, an endpoint on the edge of a topology contains all the + hop-by-hop functionality, but also implements additional + functionality of its own. This end-to-end functionality acts + basically as a user of the underlying hop-by-hop functionality. + +
+ + End-to-end functionality for REQ sockets is concerned with re-sending + the requests in case of failure and with filtering out stray or + outdated replies. + + To be able to do the latter, the endpoint must tag the requests with + unique 31-bit request IDs. First request ID is picked at random. All + subsequent request IDs are generated by adding 1 to the last request + ID and possibly overflowing to 0. + + To improve robustness of the system, the implementation MUST ensure + that the random number is different each time the endpoint, the + process or the machine is restarted. Pseudo-random generator with + fixed seed won't do. + + When user asks the endpoint to send a message, the endpoint prepends + a 32-bit value to the message, consisting of a single bit set to 1 + followed by a 31-bit request ID and passes it on in a standard + hop-by-hop way. + + If the hop-by-hop layer reports pushback condition, the end-to-end + layer considers the request unsent and MUST report pushback condition + to the user. + + If the request is successfully sent, the endpoint stores the request + including its request ID, so that it can be resent later on if + needed. At the same time it sets up a timer to trigger the + re-transmission in case the reply is not received within a specified + timeout. The user MUST be allowed to specify the timeout interval. + The default timeout interval must be 60 seconds. + + When a reply is received from the underlying hop-by-hop + implementation, the endpoint should strip off first 32 bits from + the reply to check whether it is a valid reply. + + If the reply is shorter than 32 bits, it is malformed and the + endpoint MUST ignore it. If the most significant bit of the 32-bit + value is set to 0, the reply is malformed and MUST be ignored. + + Otherwise, the endpoint should check whether the request ID in + the reply matches any of the request IDs of the requests being + processed at the moment. If not so, the reply MUST be ignored. + It is either a stray message or a duplicate reply. + + Please note that the endpoint can support either one or more + requests being processed in parallel. Which one is the case depends + on the API exposed to the user and is not part of this + specification. + + If the ID in the reply matches one of the requests in progress, the + reply MUST be passed to the user (with the 32-bit prefix stripped + off). At the same time the stored copy of the original request as + well as re-transmission timer must be deallocated. + + Finally, REQ endpoint MUST make it possible for the user to cancel + a particular request in progress. What it means technically is + deleting the stored copy of the request and cancelling the associated + timer. Thus, once the reply arrives, it will be discarded by the + algorithm above. + + The cancellation allows, for example, the user to time out a request. + They can simply post a request and if there's no answer in specific + timeframe, they can cancel it. + +
+ +
+ + End-to-end functionality for REP endpoints is concerned with turning + requests into corresponding replies. + + When user asks to receive a request, the endpoint gets next request + from the hop-by-hop layer and splits it into the traceback stack and + the message payload itself. The traceback stack is stored and the + payload is returned to the user. + + The algorithm for splitting the request is as follows: Strip 32 bit + tags from the message in one-by-one manner. Once the most significant + bit of the tag is set, we've reached the bottom of the traceback + stack and the splitting is done. If the end of the message is reached + without finding the bottom of the stack, the request is malformed and + MUST be ignored. + + Note that the payload produced by this procedure is the same as the + request payload sent by the original client. + + Once the user processes the request and sends the reply, the endpoint + prepends the reply with the stored traceback stack and sends it on + using the hop-by-hop layer. At that point the stored traceback stack + MUST be deallocated. + + Additionally, REP endpoint MUST support cancelling any request being + processed at the moment. What it means, technically, is that + state associated with the request, i.e. the traceback stack stored + by the endpoint is deleted and reply to that particular + request is never sent. + + The most important use of cancellation is allowing the service + instances to ignore malformed requests. If the application-level + part of the request doesn't conform to the application protocol + the service can simply cancel the request. In such case the reply + is never sent. Of course, if application wants to send an + application-specific error massage back to the client it can do so + by not cancelling the request and sending a regular reply. + +
+ +
+ +
+ + It may happen that a request/reply topology contains a loop. It becomes + increasingly likely as the topology grows out of scope of a single + organisation and there are multiple administrators involved + in maintaining it. Unfortunate interaction between two perfectly + legitimate setups can cause loop to be created. + + With no additional guards against the loops, it's likely that + requests will be caught inside the loop, rotating there forever, + each message gradually growing in size as new prefixes are added to it + by each REP endpoint on the way. Eventually, a loop can cause + congestion and bring the whole system to a halt. + + To deal with the problem REQ endpoints MUST check the depth of the + traceback stack for every outgoing request and discard any requests + where it exceeds certain threshold. The threshold should be defined + by the user. The default value is suggested to be 8. + +
+ +
+ New SP endpoint types REQ and REP should be registered by IANA. For + now, value of 16 should be used for REQ endpoints and value of 17 for + REP endpoints. +
+ +
+ The mapping is not intended to provide any additional security to the + underlying protocol. DoS concerns are addressed within + the specification. +
+ +
+ + + + + + TCP mapping for SPs + + + + + + + + +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-surveyor-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-surveyor-01.txt new file mode 100644 index 0000000..9e2a1e7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-surveyor-01.txt @@ -0,0 +1,728 @@ + + + + +Internet Engineering Task Force G. D'Amore, Ed. +Internet-Draft March 18, 2015 +Intended status: Informational +Expires: September 19, 2015 + + + Surveyor/Respondent Scalability Protocol + sp-surveyor-01 + +Abstract + + This document defines a scalability protocol used for performing + surveys and collecting responses amongst a number of stateless + processing nodes, and returning the results of those surveyors. This + protocol can be used for solving such problems as voting (consensus + algorithms), presence detection, and peer discovery. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on September 19, 2015. + +Copyright Notice + + Copyright (c) 2015 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + +D'Amore Expires September 19, 2015 [Page 1] + +Internet-Draft Surveor/Respondent SP March 2015 + + +1. Introduction + + A fairly common problem in building distributed applications is peer + discovery -- or how do you find your peers. For example, imagine an + internet chat type application, where server wants to determine the + presence of all peers, including perhaps some information such as + their unique social networking handle. + + Another similar problem involves voting algorithms, where a survey of + all connected peers is required to arrive to some solution to a + problem. This is common with distributed consensus algorithms. + + One of the most common problems in distributed applications is how to + delegate a work to another processing node and get the result back to + the original node. In other words, the goal is to utilise the CPU + power of a remote node. + + It turns out that these problems are very similar. We can assume + potential participants will register with a central process. Once + that is done, the central process can send out a survey request to + the participants when it wants to perform a survey. + + Also, note that it is reasonable and possible for a participant to + decline to participate (i.e. decline to respond.) This can happen + due to loss of network connectivity, or can represent a conscious + decision on the part of the respondent. + + For example, a real-world example of this would be asking audience + members to raise their hands if they like the color red. The act of + raising one's hand can be thought of as responding. + + As a consequence, taken generally, the surveyor should not infer any + thing about parties it doesn't get a response from. Perhaps the + respondent simply didn't hear the question, or perhaps she declines + to self-identify. + + This measn that surveying should be thought of as a best-effort + service. Applications which need more resilience may repeat their + inquiries. It is common in other networking protocols to do so + periodically, and only "expire" the response from a peer that is non- + responsive after it has missed several successive surveys. + + Furthermore, the act of asking a question has to be time bounded. + This is particularly important if multiple surveys are to be issued. + Sufficient time for responses from the first survey to occur must + pass before starting a new one, unless some other identifying content + is present to distinguish the results from one survey from another. + (Going back to our raised hands, imagine two questions asked in rapid + + + +D'Amore Expires September 19, 2015 [Page 2] + +Internet-Draft Surveor/Respondent SP March 2015 + + + succession, one if you like the color red, the other if you like the + color blue. If only one hand is used, and there is not sufficient + time between the questions, it becomes impossible to distinguish + which color is preferred. Of course, if one uses two hands -- a + distinguishing identifier, now we can have two surveys running in + parallel. Fortunately we usually have more bits available for + conveying this kind of information in network protocols.) + + In all cases the act of surveying and replying can be thought of as + state-less. In otherwords, a given response should not depend upon + the content of any prior surveys. Ideally, because of the best- + effort nature of this, it is also beneficial if surveying is itself + idempotent, i.e. the act of responding to a survey should not itself + change state on the respondent. + + Generally there are few common scenarios that come up with real-world + situations. Here are some of them. + + 1. One surveyor issues one survey, and then zero, one or many + responders reply. The surveyor collects then these responses + over a period of time before issuing a new survey. + + 2. One surveyor issues multiple surveys, distinguishing which + replies are to which survey based on some identifying content. + For example, this can be thought of like ARP, where multiple + requests can be outstanding. + + 3. Multiple surveyors issue surveys, but one each at a time. + Responders reply to each of these as appropriate. For example, + imagine a network with two print clients and a number of + networked printers. Both clients may occasionally desire to + inquire as supply levels, and since they don't talk to each + other, the replies may go to either system. + + 4. Multiple surveyors issuing multiple surveys concurrently. This + is the combination of the second and third cases above. + +2. Underlying protocol + + The surveyor/respondent protocol can be run on top of any SP mapping, + such as, for example, SP TCPmapping [SPoverTCP]. + + Also, given that SP protocols describe the behaviour of entire + arbitrarily complex topology rather than of a single node-to-node + communication, several underlying protocols can be used in parallel. + For example, a client may send a request via WebSocket, then, on the + edge of the company network an intermediary node may retransmit it + using TCP etc. + + + +D'Amore Expires September 19, 2015 [Page 3] + +Internet-Draft Surveor/Respondent SP March 2015 + + + +---+ WebSocket +---+ TCP +---+ + | |-------------| |-----------| | + +---+ +---+ +---+ + | | + +---+ IPC | | SCTP +---+ DCCP +---+ + | |---------+ +--------| |-----------| | + +---+ +---+ +---+ + +3. Overview of the algorithm + + Surveyor/respondent protocol defines two different endpoint types: + The SURVEYOR and the replier or RESPONDENT. + + A SURVEYOR endpoint can be connected only to a RESPONDENT endpoint, + and vice versa. If the underlying protocol indicates that there's an + attempt to create a channel to an incompatible endpoint, the channel + MUST NOT be used. In the case of TCP mapping, for example, the + underlying TCP connection MUST be closed. + + When creating more complex topologies, SURVEYOR and RESPONDENT + endpoints are paired in the intermediate nodes to form a forwarding + component, so called "device". Device receives requests from the + SURVEYOR endpoint and forwards them to the RESPONDENT endpoint. At + the same time it receives replies from the RESPONDENT endpoint and + forwards them to the SURVEYOR endpoint: + + --- surveys --> + + +----------+ +------------+----------+ +------------+ + | |-->| | |-->| | + | SURVEYOR | | RESPONDENT | SURVEYOR | | RESPONDENT | + | |<--| | |<--| | + +----------+ +------------+----------+ +------------+ + + <-- responses --- + + Using devices, arbitrary complex topologies can be built. The rest + of this section explains how are the requests routed through a + topology towards processing nodes and how are responses routed back + from processing nodes to the original clients. + + Because the delivery of both surveys and responses is handled on a + best-effort basis, when the transport is faced with pushback, it is + acceptable for the implementation to drop the message. + + Applications expecting resilience in the face of such events should + expect to perform multiple surveys over time; a failure to respond to + a survey shall not be taken as a critical fault. + + + +D'Amore Expires September 19, 2015 [Page 4] + +Internet-Draft Surveor/Respondent SP March 2015 + + + As for delivering replies back to the clients, it should be + understood that the client may not be directly accessible (say using + TCP/IP) from the processing node. It may be beyond a firewall, have + no static IP address etc. Furthermore, the client and the processing + may not even speak the same transport protocol -- imagine client + connecting to the topology using WebSockets and processing node via + SCTP. + + Given the above, it becomes obvious that the replies must be routed + back through the existing topology rather than directly. In fact, + surveyor/respondent topology may be thought of as an overlay network + on the top of underlying transport mechanisms. + + As for routing replies within the surveyor/respondent topology, it is + designed in such a way that each reply contains the whole routing + path, rather than containing just the address of destination node, as + is the case with, for example, TCP/IP. + + The downside of the design is that surveys and responses are a little + bit longer. Also this assumes symmetric connectivity in the + underlying transports. + + The upside, on the other hand, is that the nodes in the topology + don't have to maintain any routing tables beside the simple table of + adjacent channels along with their IDs. There's also no need for any + additional protocols for distributing routing information within the + topology. + + The most important reason for adopting the design though is that + there's no propagation delay and any nodes becomes accessible + immediately after it is started. Given that some nodes in the + topology may be extremely short-lived this is a crucial requirement. + Imagine a database client that sends a survey, gets a single + response, and then immediately answers. (Think of a simple question + like "is anyone here?" A single reply is sufficies to answer the + question.) It makes no sense to delay the whole process until the + routing tables are synchronised between the client and the server. + + The algorithm thus works as follows: When a survey is routed from the + client to the processing node, every RESPONDENT endpoint determines + which channel it was received from and adds the ID of the channel to + the survey. Thus, when the survey arrives at the ultimate respondent + it already contains a full backtrace stack, which in turn contains + all the info needed to route a message back to the original surveyor. + + After processing the survey, the responding node attaches the + backtrace stack from the survey to the response and sends it back to + + + + +D'Amore Expires September 19, 2015 [Page 5] + +Internet-Draft Surveor/Respondent SP March 2015 + + + the topology. At that point every RESPONDENT endpoint can check the + traceback and determine which channel it should send the reply to. + + In addition to routing, surveyor/respondent protocol takes care of + matching responses and surveys. That is, it can ensure that a given + response cannot be mismatched to a different survey. + + In order to avoid confusion, after the surveyor has received all the + responses it expects to (typically when a period of time has passed), + it should discard further stray responses. + + The surveyor thus adds an unique request ID to the survey. The ID + gets copied from the survey to the response by the responding node. + When the response gets back to the surveyor, it can simply check + whether the survey in question is still being outstanding and if not + so, it can ignore the response. + + To implement all the functionality described above, messages (both + surveys and responses have the following format: + + +-+------------+-+------------+ +-+------------+-------------+ + |0| Channel ID |0| Channel ID |...|1| Request ID | payload | + +-+------------+-+------------+ +-+------------+ ------------+ + + The payload of the message is preceded by a stack of 32-bit tags. + The most significant bit of each tag is set to 0 except for the very + last tag. That allows the algorithm to find out where the tags end + and where the message payload begins. + + As for the remaining 31 bits, they are either survey ID (in the last + tag) or a channel ID (in all the remaining tags). The first channel + ID is added and processed by the RESPONDENT endpoint closest to the + processing node. The last channel ID is added and processed by the + RESPONDENT endpoint closest to the client. + + Following picture shows an example of request saying "Hello" being + routed from the client through two intermediate nodes to the + processing node and the reply "World" being routed back. It shows + what messages are passed over the network at each step of the + process: + + + + + + + + + + + +D'Amore Expires September 19, 2015 [Page 6] + +Internet-Draft Surveor/Respondent SP March 2015 + + + client + Hello | World + | +------------+ ^ + | | SURVEYOR | | + V +------------+ | + 1|823|Hello | 1|823|World + | +------------+ ^ + | | RESPONDENT | | + | +------------+ | + | | SURVEYOR | | + V +------------+ | + 0|299|1|823|Hello | 0|299|1|823|World + | +------------+ ^ + | | RESPONDENT | | + | +------------+ | + | | SURVEYOR | | + V +------------+ | + 0|446|0|299|1|823|Hello | 0|446|0|299|1|823|World + | +------------+ ^ + | | RESPONDENT | | + V +------------+ | + Hello | World + server + +4. Hop-by-hop vs. End-to-end + + All endpoints implement so called "hop-by-hop" functionality. It's + the functionality concerned with sending messages to the immediately + adjacent components and receiving messages from them. + + To make an analogy with the TCP/IP stack, IP provides hop-by-hop + functionality, i.e. routing of the packets to the adjacent node, + while TCP implements end-to-end functionality such resending of lost + packets. + + As a rule of thumb, raw hop-by-hop endpoints are used to build + devices (intermediary nodes in the topology) while end-to-end + endpoints are used directly by the applications. + + To prevent confusion, the specification of the endpoint behaviour + below will discuss hop-by-hop and end end-to-end functionality in + separate chapters. + +5. Hop-by-hop functionality + + + + + + + +D'Amore Expires September 19, 2015 [Page 7] + +Internet-Draft Surveor/Respondent SP March 2015 + + +5.1. SURVEYOR endpoint + + The SURVEYOR endpoint is used by the user to send surveyor to the + responding nodes and receive the responses afterwards. + + When user asks the SURVEYOR endpoint to send a request, the endpoint + should send it to ALL of the associated outbound channels (TCP + connections or similar). The request sent is exactly the message + supplied by the user. SURVEYOR sockets MUST NOT modify an outgoing + survey in any way. + + If there's no channel to send the survey to, the survey is merely + discarded. The endpoint MAY report the backpressure condition to the + user as well. + + If there are associated channels but none of them is available for + sending, i.e. all of them are already reporting backpressure, the + endpoint won't send the message and MAY report the backpressure + condition to the user. The actual survey is discarded. + + If the channel is not capable of reporting backpressure (e.g. DCCP) + the endpoint SHOULD consider it as always available for sending new + request. + + When there are multiple channels available for sending the survey + endpoint MUST deliver the survey to all of them. + + As for incoming messages, i.e. responses, SURVEYOR endpoints MUST + fair-queue them. In other words, if there are replies available on + several channels, they MUST receive them in a round-robin fashion. + They must also take care not to compromise the fairness when new + channels are added or old ones removed. + + In addition to providing basic fairness, the goal of fair-queueing is + to prevent DoS attacks where a huge stream of fake responses from one + channel would be able to block the real replies coming from different + channels. Fair queueing ensures that messages from every channel are + received at approximately the same rate. That way, DoS attack can + slow down the system but it can't entirely block it. + + Incoming responses MUST be handed to the user exactly as they were + received. SURVEYOR endpoints MUST not modify the responses in any + way. + + + + + + + + +D'Amore Expires September 19, 2015 [Page 8] + +Internet-Draft Surveor/Respondent SP March 2015 + + +5.2. RESPONDENT endpoint + + RESPONDENT endpoints are used to receive surveys from the clients and + send resopnses back to the clients. + + First of all, each RESPONDENT socket is responsible for assigning + unique 31-bit channel IDs to the individual associated channels. + + The first ID assigned MUST be random. Next is computed by adding 1 + to the previous one with potential overflow to 0. + + The implementation MUST ensure that the random number is different + each time the endpoint is re-started, the process that contains it is + restarted or similar. So, for example, using pseudo-random generator + with a constant seed won't do. + + The goal of the algorithm is to the spread of possible channel ID + values and thus minimise the chance that a response is routed to an + unrelated channel, even in the face of intermediate node failures. + + When receiving a message, RESPONDENT endpoints MUST fair-queue among + the channels available for receiving. In other words they should + round-robin among such channels and receive one request from a + channel at a time. They MUST also implement the round-robin + algorithm is such a way that adding or removing channels doesn't + break the fairness. + + In addition to guaranteeing basic fairness in access to computing + resources the above algorithm makes it impossible for a malevolent or + misbehaving client to completely block the processing of requests + from other clients by issuing steady stream of surveys. + + After receiving the survey, the RESPONDENT socket should prepend it + by 32 bit value, consisting of 1 bit set to 0 followed by the 31-bit + ID of the channel the request was received from. The extended survey + will be then handed to the user. + + The goal of adding the channel ID to the response is to be able to + route the response back to the original channel later on. Thus, when + the user sends a response, endpoint strips first 32 bits off and uses + the value to determine where it is to be routed. + + If the response is shorter than 32 bits, it is malformed and the + endpoint MUST ignore it. Also, if the most relevant bit of the + 32-bit value isn't set to 0, the response is malformed and MUST be + ignored. + + + + + +D'Amore Expires September 19, 2015 [Page 9] + +Internet-Draft Surveor/Respondent SP March 2015 + + + Otherwise, the endpoint checks whether its table of associated + channels contains the channel with a corresponding ID. If so, it + sends the response (with first 32 bits stripped off) to that channel. + If the channel is not found, the response MUST be dropped. If the + channel is not available for sending, i.e. it is applying + backpressure, the response MUST be dropped. + + Note that when the response is unroutable two things might have + happened. Either there was some kind of network disruption, in which + case the survey may be re-sent later on, or the original client have + failed or been shut down. In such case the survey won't be resent, + however, it doesn't really matter because there's no one to deliver + the response to any more anyway. + + Unlike surveys, there's never pushback applied to the responses; they + are simply dropped. If the endpoint blocked and waited for the + channel to become available, all the subsequent replies, possibly + destined for different unblocked channels, would be blocked in the + meantime. That allows for a DoS attack simply by firing a lot of + surveys and not receiving the responses. + +6. End-to-end functionality + + End-to-end functionality is built on top of hop-to-hop functionality. + Thus, an endpoint on the edge of a topology contains all the hop-by- + hop functionality, but also implements additional functionality of + its own. This end-to-end functionality acts basically as a user of + the underlying hop-by-hop functionality. + +6.1. SURVEYOR endpoint + + End-to-end functionality for SURVEYOR sockets is concerned with + matching the responses to surveys, and with filtering out stray or + outdated responses. + + To be able to do this, the endpoint must tag the survey with unique + 31-bit survey IDs. First survey ID is picked at random. All + subsequent survey IDs are generated by adding 1 to the last survey ID + and possibly overflowing to 0. + + To improve robustness of the system, the implementation MUST ensure + that the random number is different each time the endpoint, the + process or the machine is restarted. Pseudo-random generator with + fixed seed won't do. + + When user asks the endpoint to send a message, the endpoint prepends + a 32-bit value to the message, consisting of a single bit set to 1 + + + + +D'Amore Expires September 19, 2015 [Page 10] + +Internet-Draft Surveor/Respondent SP March 2015 + + + followed by a 31-bit survey ID and passes it on in a standard hop-by- + hop way. + + If the hop-by-hop layer reports pushback condition, the end-to-end + layer considers the survey unsent and MAY report pushback condition + to the user. + + If the survey is successfully sent, the endpoint stores the survey + including its survey ID, so that it can be resent later on if needed. + At the same time it sets up a timer to receive all of the responses. + The user MUST be allowed to specify the timeout interval. The + default timeout interval must be 60 seconds. + + When a response is received from the underlying hop-by-hop + implementation, the endpoint should strip off first 32 bits from the + response to check whether it is a valid reply. + + If the response is shorter than 32 bits, it is malformed and the + endpoint MUST ignore it. If the most significant bit of the 32-bit + value is set to 0, the reply is malformed and MUST be ignored. + + Otherwise, the endpoint should check whether the survey ID in the + response matches any of the survey IDs of the surveys being processed + at the moment. If not so, the response MUST be ignored. It is + either a stray message or a too-long delayed response. + + Please note that the endpoint can support either one or more surveys + being processed in parallel. Which one is the case depends on the + API exposed to the user and is not part of this specification. + + If the ID in the response matches one of the surveys in progress, the + response MUST be passed to the user (with the 32-bit prefix stripped + off). + + A SURVEYOR endpoint MUST make it possible for the user to cancel a + particular survey in progress. What it means technically is deleting + the stored copy of the survey and cancelling the associated timer. + Thus, once the response arrives, it will be discarded by the + algorithm above. + + Finally, when the timeout for a survey expires, then the survey must + be canceled in a manner similar to user-initiated cancelation. That + is, the stored copy of the survey must be deleted, the timer removed, + and any further responses received with the same survey ID are + subsequently discarded. + + + + + + +D'Amore Expires September 19, 2015 [Page 11] + +Internet-Draft Surveor/Respondent SP March 2015 + + +6.2. RESPONDENT endpoint + + End-to-end functionality for RESPONDENT endpoints is concerned with + turning surveys into corresponding responses. + + When user asks to receive a survey, the endpoint gets next request + from the hop-by-hop layer and splits it into the traceback stack and + the message payload itself. The traceback stack is stored and the + payload is returned to the user. + + The algorithm for splitting the survey is as follows: Strip 32 bit + tags from the message in one-by-one manner. Once the most + significant bit of the tag is set, we've reached the bottom of the + traceback stack and the splitting is done. If the end of the message + is reached without finding the bottom of the stack, the survey is + malformed and MUST be ignored. + + Note that the payload produced by this procedure is the same as the + survey payload sent by the original client. + + Once the user processes the survey and sends the response, the + endpoint prepends the response with the stored traceback stack and + sends it on using the hop-by-hop layer. At that point the stored + traceback stack MUST be deallocated. + + Additionally, RESPONDENT endpoints MUST support cancelling any survey + being processed at the moment. What it means, technically, is that + state associated with the survey, i.e. the traceback stack stored by + the endpoint is deleted and reply to that particular survey is never + sent. + + The most important use of cancellation is allowing the service + instances to ignore surveys (whether due to malformation or for other + application specific reasons.) In such case the reply is never sent. + Of course, if application wants to send an application-specific error + massage back to the client it can do so by not cancelling the survey + and sending a regular response. + +7. Loop avoidance + + It may happen that a request/reply topology contains a loop. It + becomes increasingly likely as the topology grows out of scope of a + single organisation and there are multiple administrators involved in + maintaining it. Unfortunate interaction between two perfectly + legitimate setups can cause loop to be created. + + With no additional guards against the loops, it's likely that + requests will be caught inside the loop, rotating there forever, each + + + +D'Amore Expires September 19, 2015 [Page 12] + +Internet-Draft Surveor/Respondent SP March 2015 + + + message gradually growing in size as new prefixes are added to it by + each RESPONDENT endpoint on the way. Eventually, a loop can cause + congestion and bring the whole system to a halt. + + To deal with the problem SURVEYOR endpoints MUST check the depth of + the traceback stack for every outgoing request and discard any + requests where it exceeds certain threshold. The threshold SHOULD be + defined by the user. The default value is suggested to be 8. + +8. IANA Considerations + + New SP endpoint types SURVEYOR and RESPONDENT should be registered by + IANA. For now, value of 98 should be used for SURVEYOR endpoints and + value of 99 for RESPONDENT endpoints. (An earlier similar protocol + without the backtrace headers used protocol numbers 96 and 97.) + +9. Security Considerations + + The mapping is not intended to provide any additional security to the + underlying protocol. DoS concerns are addressed within the + specification. + +10. References + + [SPoverTCP] + Sustrik, M., "TCP mapping for SPs", August 2013. + +Author's Address + + Garrett D'Amore (editor) + + Email: garrett@damore.org + + + + + + + + + + + + + + + + + + + +D'Amore Expires September 19, 2015 [Page 13] diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-surveyor-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-surveyor-01.xml new file mode 100644 index 0000000..21ce322 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-surveyor-01.xml @@ -0,0 +1,647 @@ + + + + + + + + + Surveyor/Respondent Scalability Protocol + + + +
+ garrett@damore.org +
+
+ + + + Applications + Internet Engineering Task Force + + Surveyor + Respondent + SURVEYOR + RESPONDENT + stateless + service + SP + + + This document defines a scalability protocol used for performing + surveys and collecting responses amongst a number of stateless + processing nodes, and returning the results of those + surveyors. This protocol can be used for solving such problems + as voting (consensus algorithms), presence detection, and peer + discovery. + + +
+ + + +
+ + A fairly common problem in building distributed applications is + peer discovery -- or how do you find your peers. For example, imagine + an internet chat type application, where server wants to determine + the presence of all peers, including perhaps some information such + as their unique social networking handle. + + Another similar problem involves voting algorithms, where a survey + of all connected peers is required to arrive to some solution to + a problem. This is common with distributed consensus algorithms. + + One of the most common problems in distributed applications is how to + delegate a work to another processing node and get the result back to + the original node. In other words, the goal is to utilise the CPU + power of a remote node. + + It turns out that these problems are very similar. We can assume + potential participants will register with a central process. Once + that is done, the central process can send out a survey request + to the participants when it wants to perform a survey. + + Also, note that it is reasonable and possible for a participant to + decline to participate (i.e. decline to respond.) This can happen + due to loss of network connectivity, or can represent a conscious + decision on the part of the respondent. + + For example, a real-world example of this would be asking audience + members to raise their hands if they like the color red. The act of + raising one's hand can be thought of as responding. + + As a consequence, taken generally, the surveyor should not infer any + thing about parties it doesn't get a response from. Perhaps the + respondent simply + didn't hear the question, or perhaps she declines to self-identify. + + This measn that surveying should be thought of as a best-effort + service. Applications which need more resilience may repeat + their inquiries. It is common in other networking protocols to + do so periodically, and only "expire" the response from a peer that + is non-responsive after it has missed several successive surveys. + + Furthermore, the act of asking a question has to be time bounded. + This is particularly important if multiple surveys are to be issued. + Sufficient time for responses from the first survey to occur must + pass before starting a new one, unless some other identifying + content is present to distinguish the results from one survey from + another. (Going back to our raised hands, imagine two questions + asked in rapid succession, one if you like the color red, the other + if you like the color blue. If only one hand is used, and there is + not sufficient time between the questions, it becomes impossible to + distinguish which color is preferred. Of course, if one uses two + hands -- a distinguishing identifier, now we can have two surveys + running in parallel. Fortunately we usually have more bits available + for conveying this kind of information in network protocols.) + + In all cases the act of surveying and replying can be thought of as + state-less. In otherwords, a given response should not depend upon + the content of any prior surveys. Ideally, because of the best-effort + nature of this, it is also beneficial if surveying is itself + idempotent, i.e. the act of responding to a survey should not itself + change state on the respondent. + + Generally there are few common scenarios that come up with real-world + situations. Here are some of them. + + + One surveyor issues one survey, and then zero, one or many + responders reply. The surveyor collects then these responses + over a period of time before issuing a new survey. + + One surveyor issues multiple surveys, distinguishing which + replies are to which survey based on some identifying content. + For example, this can be thought of like ARP, where multiple + requests can be outstanding. + + Multiple surveyors issue surveys, but one each at a time. + Responders reply to each of these as appropriate. For + example, imagine a network with two print clients and a number + of networked printers. Both clients may occasionally desire + to inquire as supply levels, and since they don't talk to + each other, the replies may go to either system. + + Multiple surveyors issuing multiple surveys concurrently. + This is the combination of the second and third cases above. + + + + + +
+ +
+ + The surveyor/respondent protocol can be run on top of any SP mapping, + such as, for example, SP TCPmapping. + + + Also, given that SP protocols describe the behaviour of entire + arbitrarily complex topology rather than of a single node-to-node + communication, several underlying protocols can be used in parallel. + For example, a client may send a request via WebSocket, then, on the + edge of the company network an intermediary node may retransmit it + using TCP etc. + +
+ ++---+ WebSocket +---+ TCP +---+ +| |-------------| |-----------| | ++---+ +---+ +---+ + | | + +---+ IPC | | SCTP +---+ DCCP +---+ + | |---------+ +--------| |-----------| | + +---+ +---+ +---+ + +
+ +
+ +
+ + Surveyor/respondent protocol defines two different endpoint types: + The SURVEYOR and the replier or RESPONDENT. + + A SURVEYOR endpoint can be connected only to a RESPONDENT endpoint, + and vice versa. If the underlying protocol + indicates that there's an attempt to create a channel to an + incompatible endpoint, the channel MUST NOT be used. In the case of + TCP mapping, for example, the underlying TCP connection MUST + be closed. + + When creating more complex topologies, SURVEYOR and RESPONDENT + endpoints are paired in the intermediate nodes to form a + forwarding component, + so called "device". Device receives requests from the SURVEYOR endpoint + and forwards them to the RESPONDENT endpoint. At the same time it + receives replies from the RESPONDENT endpoint and forwards them to + the SURVEYOR endpoint: + +
+ + --- surveys --> + ++----------+ +------------+----------+ +------------+ +| |-->| | |-->| | +| SURVEYOR | | RESPONDENT | SURVEYOR | | RESPONDENT | +| |<--| | |<--| | ++----------+ +------------+----------+ +------------+ + + <-- responses --- + +
+ + Using devices, arbitrary complex topologies can be built. The rest + of this section explains how are the requests routed through a topology + towards processing nodes and how are responses routed back from + processing nodes to the original clients. + + Because the delivery of both surveys and responses is handled on + a best-effort basis, when the transport is faced with pushback, it + is acceptable for the implementation to drop the message. + + Applications expecting resilience in the face of such events should + expect to perform multiple surveys over time; a failure to respond + to a survey shall not be taken as a critical fault. + + As for delivering replies back to the clients, it should be understood + that the client may not be directly accessible (say using TCP/IP) from + the processing node. It may be beyond a firewall, have no static IP + address etc. Furthermore, the client and the processing may not even + speak the same transport protocol -- imagine client connecting to the + topology using WebSockets and processing node via SCTP. + + Given the above, it becomes obvious that the replies must be routed + back through the existing topology rather than directly. In fact, + surveyor/respondent topology may be thought of as an overlay network + on the top of underlying transport mechanisms. + + As for routing replies within the surveyor/respondent topology, it + is designed in + such a way that each reply contains the whole routing path, rather + than containing just the address of destination node, as is the case + with, for example, TCP/IP. + + The downside of the design is that surveys and responses are a + little bit longer. Also this assumes symmetric connectivity in the + underlying transports. + + The upside, on the other hand, is that the nodes in the topology don't + have to maintain any routing tables beside the simple table of + adjacent channels along with their IDs. There's also no need for any + additional protocols for distributing routing information within + the topology. + + The most important reason for adopting the design though is that + there's no propagation delay and any nodes becomes accessible + immediately after it is started. Given that some nodes in the topology + may be extremely short-lived this is a crucial requirement. Imagine + a database client that sends a survey, gets a single response, and + then immediately answers. (Think of a simple question like "is + anyone here?" A single reply is sufficies to answer the question.) + It makes no sense to delay the whole process until the routing tables + are synchronised between the client and the server. + + The algorithm thus works as follows: When a survey is routed from the + client to the processing node, every RESPONDENT endpoint determines + which channel it was received from and adds the ID of the channel to + the survey. Thus, when the survey arrives at the ultimate respondent + it already contains a full backtrace stack, which in turn contains + all the info needed to route a message back to the original + surveyor. + + After processing the survey, the responding node attaches the + backtrace stack from the survey to the response and sends it back + to the topology. At that point every RESPONDENT endpoint can check the + traceback and determine which channel it should send the reply to. + + In addition to routing, surveyor/respondent protocol takes care of + matching responses and surveys. That is, it can ensure that a given + response cannot be mismatched to a different survey. + + In order to avoid confusion, after the surveyor has received all the + responses it expects to (typically when a period of time has passed), + it should discard further stray responses. + + The surveyor thus adds an unique request ID to the survey. The ID gets + copied from the survey to the response by the responding node. When the + response gets back to the surveyor, it can simply check whether the + survey in question is still being outstanding and if not so, it can + ignore the response. + + To implement all the functionality described above, messages (both + surveys and responses have the following format: + +
+ ++-+------------+-+------------+ +-+------------+-------------+ +|0| Channel ID |0| Channel ID |...|1| Request ID | payload | ++-+------------+-+------------+ +-+------------+ ------------+ + +
+ + The payload of the message is preceded by a stack of 32-bit tags. + The most significant bit of each tag is set to 0 except for the very + last tag. + That allows the algorithm to find out where the tags end and where + the message payload begins. + + As for the remaining 31 bits, they are either survey ID (in the last + tag) or a channel ID (in all the remaining tags). The first channel ID + is added and processed by the RESPONDENT endpoint closest to the + processing + node. The last channel ID is added and processed by the RESPONDENT + endpoint closest to the client. + + Following picture shows an example of request saying "Hello" being + routed from the client through two intermediate nodes to the + processing node and the reply "World" being routed back. It shows + what messages are passed over the network at each step of the + process: + +
+ + client + Hello | World + | +------------+ ^ + | | SURVEYOR | | + V +------------+ | + 1|823|Hello | 1|823|World + | +------------+ ^ + | | RESPONDENT | | + | +------------+ | + | | SURVEYOR | | + V +------------+ | + 0|299|1|823|Hello | 0|299|1|823|World + | +------------+ ^ + | | RESPONDENT | | + | +------------+ | + | | SURVEYOR | | + V +------------+ | +0|446|0|299|1|823|Hello | 0|446|0|299|1|823|World + | +------------+ ^ + | | RESPONDENT | | + V +------------+ | + Hello | World + server + +
+ +
+ +
+ + All endpoints implement so called "hop-by-hop" functionality. It's + the functionality concerned with sending messages to the immediately + adjacent components and receiving messages from them. + + To make an analogy with the TCP/IP stack, IP provides hop-by-hop + functionality, i.e. routing of the packets to the adjacent node, + while TCP implements end-to-end functionality such resending of + lost packets. + + As a rule of thumb, raw hop-by-hop endpoints are used to build + devices (intermediary nodes in the topology) while end-to-end + endpoints are used directly by the applications. + + To prevent confusion, the specification of the endpoint behaviour + below will discuss hop-by-hop and end end-to-end functionality in + separate chapters. + +
+ +
+ +
+ + The SURVEYOR endpoint is used by the user to send surveyor to the + responding nodes and receive the responses afterwards. + + When user asks the SURVEYOR endpoint to send a request, the + endpoint should + send it to ALL of the associated outbound channels (TCP connections + or similar). The request sent is exactly the message supplied by + the user. SURVEYOR sockets MUST NOT modify an outgoing survey in + any way. + + If there's no channel to send the survey to, the survey is merely + discarded. The endpoint MAY report the backpressure condition to + the user as well. + + If there are associated channels but none of them is available for + sending, i.e. all of them are already reporting backpressure, the + endpoint won't send the message and MAY report the backpressure + condition to the user. The actual survey is discarded. + + If the channel is not capable of reporting backpressure (e.g. DCCP) + the endpoint SHOULD consider it as always available for sending new + request. + + When there are multiple channels available for sending the survey + endpoint MUST deliver the survey to all of them. + + As for incoming messages, i.e. responses, SURVEYOR endpoints MUST + fair-queue them. In other words, if there are replies available + on several channels, they MUST receive them in a round-robin fashion. + They must also take care not to compromise the fairness when new + channels are added or old ones removed. + + In addition to providing basic fairness, the goal of fair-queueing is + to prevent DoS attacks where a huge stream of fake responses from one + channel would be able to block the real replies coming from different + channels. Fair queueing ensures that messages from every channel are + received at approximately the same rate. That way, DoS attack can + slow down the system but it can't entirely block it. + + Incoming responses MUST be handed to the user exactly as they were + received. SURVEYOR endpoints MUST not modify the responses in any + way. + +
+ +
+ + RESPONDENT endpoints are used to receive surveys from the clients + and send resopnses back to the clients. + + First of all, each RESPONDENT socket is responsible for assigning + unique 31-bit channel IDs to the individual associated channels. + + The first ID assigned MUST be random. Next is computed by adding 1 to + the previous one with potential overflow to 0. + + The implementation MUST ensure that the random number is different + each time the endpoint is re-started, the process that contains + it is restarted or similar. So, for example, using pseudo-random + generator with a constant seed won't do. + + The goal of the algorithm is to the spread of possible channel ID + values and thus minimise the chance that a response is routed to an + unrelated channel, even in the face of intermediate node + failures. + + When receiving a message, RESPONDENT endpoints MUST fair-queue + among the channels available for receiving. In other words they + should round-robin among such channels and receive one request from + a channel at a time. They MUST also implement the round-robin + algorithm is such a way that adding or removing channels doesn't + break the fairness. + + In addition to guaranteeing basic fairness in access to computing + resources the above algorithm makes it impossible for a malevolent + or misbehaving client to completely block the processing of requests + from other clients by issuing steady stream of surveys. + + After receiving the survey, the RESPONDENT socket should prepend it + by 32 bit value, consisting of 1 bit set to 0 followed by the 31-bit + ID of the channel the request was received from. The extended survey + will be then handed to the user. + + The goal of adding the channel ID to the response is to be able to + route the response back to the original channel later on. Thus, when + the user sends a response, endpoint strips first 32 bits off and uses + the value to determine where it is to be routed. + + If the response is shorter than 32 bits, it is malformed and + the endpoint MUST ignore it. Also, if the most relevant bit of the + 32-bit value isn't set to 0, the response is malformed and MUST + be ignored. + + Otherwise, the endpoint checks whether its table of associated + channels contains the channel with a corresponding ID. If so, it + sends the response (with first 32 bits stripped off) to that channel. + If the channel is not found, the response MUST be dropped. If the + channel is not available for sending, i.e. it is applying + backpressure, the response MUST be dropped. + + Note that when the response is unroutable two things might have + happened. Either there was some kind of network disruption, in which + case the survey may be re-sent later on, or the original client + have failed or been shut down. In such case the survey won't be + resent, however, it doesn't really matter because there's no one to + deliver the response to any more anyway. + + Unlike surveys, there's never pushback applied to the responses; they + are simply dropped. If the endpoint blocked and waited for the + channel to become available, all the subsequent replies, possibly + destined for + different unblocked channels, would be blocked in the meantime. That + allows for a DoS attack simply by firing a lot of surveys and not + receiving the responses. + +
+ +
+ +
+ + End-to-end functionality is built on top of hop-to-hop functionality. + Thus, an endpoint on the edge of a topology contains all the + hop-by-hop functionality, but also implements additional + functionality of its own. This end-to-end functionality acts + basically as a user of the underlying hop-by-hop functionality. + +
+ + End-to-end functionality for SURVEYOR sockets is concerned with + matching the responses to surveys, and with filtering out stray or + outdated responses. + + To be able to do this, the endpoint must tag the survey with + unique 31-bit survey IDs. First survey ID is picked at random. All + subsequent survey IDs are generated by adding 1 to the last survey + ID and possibly overflowing to 0. + + To improve robustness of the system, the implementation MUST ensure + that the random number is different each time the endpoint, the + process or the machine is restarted. Pseudo-random generator with + fixed seed won't do. + + When user asks the endpoint to send a message, the endpoint prepends + a 32-bit value to the message, consisting of a single bit set to 1 + followed by a 31-bit survey ID and passes it on in a standard + hop-by-hop way. + + If the hop-by-hop layer reports pushback condition, the end-to-end + layer considers the survey unsent and MAY report pushback condition + to the user. + + If the survey is successfully sent, the endpoint stores the survey + including its survey ID, so that it can be resent later on if + needed. At the same time it sets up a timer to receive all of the + responses. The user MUST be allowed to specify the timeout interval. + The default timeout interval must be 60 seconds. + + When a response is received from the underlying hop-by-hop + implementation, the endpoint should strip off first 32 bits from + the response to check whether it is a valid reply. + + If the response is shorter than 32 bits, it is malformed and the + endpoint MUST ignore it. If the most significant bit of the 32-bit + value is set to 0, the reply is malformed and MUST be ignored. + + Otherwise, the endpoint should check whether the survey ID in + the response matches any of the survey IDs of the surveys being + processed at the moment. If not so, the response MUST be ignored. + It is either a stray message or a too-long delayed response. + + Please note that the endpoint can support either one or more + surveys being processed in parallel. Which one is the case depends + on the API exposed to the user and is not part of this + specification. + + If the ID in the response matches one of the surveys in progress, the + response MUST be passed to the user (with the 32-bit prefix stripped + off). + + A SURVEYOR endpoint MUST make it possible for the user to + cancel a particular survey in progress. What it means technically is + deleting the stored copy of the survey and cancelling the associated + timer. Thus, once the response arrives, it will be discarded by the + algorithm above. + + Finally, when the timeout for a survey expires, then the survey + must be canceled in a manner similar to user-initiated cancelation. + That is, the stored copy of the survey must be deleted, the timer + removed, and any further responses received with the same survey ID + are subsequently discarded. + +
+ +
+ + End-to-end functionality for RESPONDENT endpoints is concerned with + turning surveys into corresponding responses. + + When user asks to receive a survey, the endpoint gets next request + from the hop-by-hop layer and splits it into the traceback stack and + the message payload itself. The traceback stack is stored and the + payload is returned to the user. + + The algorithm for splitting the survey is as follows: Strip 32 bit + tags from the message in one-by-one manner. Once the most significant + bit of the tag is set, we've reached the bottom of the traceback + stack and the splitting is done. If the end of the message is reached + without finding the bottom of the stack, the survey is malformed and + MUST be ignored. + + Note that the payload produced by this procedure is the same as the + survey payload sent by the original client. + + Once the user processes the survey and sends the response, the + endpoint prepends the response with the stored traceback stack and + sends it on using the hop-by-hop layer. At that point the stored + traceback stack MUST be deallocated. + + Additionally, RESPONDENT endpoints MUST support cancelling any + survey being processed at the moment. What it means, technically, + is that state associated with the survey, i.e. the traceback stack + stored by the endpoint is deleted and reply to that particular + survey is never sent. + + The most important use of cancellation is allowing the service + instances to ignore surveys (whether due to malformation or for + other application specific reasons.) In such case the reply + is never sent. Of course, if application wants to send an + application-specific error massage back to the client it can do so + by not cancelling the survey and sending a regular response. + +
+ +
+ +
+ + It may happen that a request/reply topology contains a loop. It becomes + increasingly likely as the topology grows out of scope of a single + organisation and there are multiple administrators involved + in maintaining it. Unfortunate interaction between two perfectly + legitimate setups can cause loop to be created. + + With no additional guards against the loops, it's likely that + requests will be caught inside the loop, rotating there forever, + each message gradually growing in size as new prefixes are added to it + by each RESPONDENT endpoint on the way. Eventually, a loop can cause + congestion and bring the whole system to a halt. + + To deal with the problem SURVEYOR endpoints MUST check the depth of the + traceback stack for every outgoing request and discard any requests + where it exceeds certain threshold. The threshold SHOULD be defined + by the user. The default value is suggested to be 8. + +
+ +
+ New SP endpoint types SURVEYOR and RESPONDENT should be registered by + IANA. For now, value of 98 should be used for SURVEYOR endpoints and + value of 99 for RESPONDENT endpoints. (An earlier similar protocol + without the backtrace headers used protocol numbers 96 and 97.) +
+ +
+ The mapping is not intended to provide any additional security to the + underlying protocol. DoS concerns are addressed within + the specification. +
+ +
+ + + + + + TCP mapping for SPs + + + + + + + + +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tcp-mapping-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tcp-mapping-01.txt new file mode 100644 index 0000000..21a11c2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tcp-mapping-01.txt @@ -0,0 +1,281 @@ + + + + +Internet Engineering Task Force M. Sustrik, Ed. +Internet-Draft +Intended status: Informational March 2014 +Expires: September 2, 2014 + + + TCP Mapping for Scalability Protocols + sp-tcp-mapping-01 + +Abstract + + This document defines the TCP mapping for scalability protocols. The + main purpose of the mapping is to turn the stream of bytes into + stream of messages. Additionally, the mapping provides some + additional checks during the connection establishment phase. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on September 2, 2014. + +Copyright Notice + + Copyright (c) 2014 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + +Sustrik Expires September 2, 2014 [Page 1] + +Internet-Draft TCP mapping for SPs March 2014 + + +1. Underlying protocol + + This mapping should be layered directly on the top of TCP. + + There's no fixed TCP port to use for the communication. Instead, + port numbers are assigned to individual services by the user. + +2. Connection initiation + + As soon as the underlying TCP connection is established, both parties + MUST send the protocol header (described in detail below) + immediately. Both endpoints MUST then wait for the protocol header + from the peer before proceeding on. + + The goal of this design is to keep connection establishment as fast + as possible by avoiding any additional protocol handshakes, i.e. + network round-trips. Specifically, the protocol headers can be + bundled directly with to the last packets of TCP handshake and thus + have virtually zero performance impact. + + The protocol header is 8 bytes long and looks like this: + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | 0x00 | 0x53 | 0x50 | version | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | type | reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + First four bytes of the protocol header are used to make sure that + the peer's protocol is compatible with the protocol used by the local + endpoint. Keep in mind that this protocol is designed to run on an + arbitrary TCP port, thus the standard compatibility check -- if it + runs on port X and protocol Y is assigned to X by IANA, it speaks + protocol Y -- does not apply. We have to use an alternative + mechanism. + + First four bytes of the protocol header MUST be set to 0x00, 0x53, + 0x50 and 0x00 respectively. If the protocol header received from the + peer differs, the TCP connection MUST be closed immediately. + + The fact that the first byte of the protocol header is binary zero + eliminates any text-based protocols that were accidentally connected + to the endpoint. Subsequent two bytes make the check even more + rigorous. At the same time they can be used as a debugging hint to + indicate that the connection is supposed to use one of the + scalability protocols -- ASCII representation of these bytes is 'SP' + + + +Sustrik Expires September 2, 2014 [Page 2] + +Internet-Draft TCP mapping for SPs March 2014 + + + that can be easily spotted in when capturing the network traffic. + Finally, the fourth byte rules out any incompatible versions of this + protocol. + + Fifth and sixth bytes of the header form a 16-bit unsigned integer in + network byte order representing the type of SP endpoint on the layer + above. The value SHOULD NOT be interpreted by the mapping, rather + the interpretation should be delegated to the scalability protocol + above the mapping. For informational purposes, it should be noted + that the field encodes information such as SP protocol ID, protocol + version and the role of endpoint within the protocol. Individual + values are assigned by IANA. + + Finally, the last two bytes of the protocol header are reserved for + future use and must be set to binary zeroes. If the protocol header + from the peer contains anything else than zeroes in this field, the + implementation MUST close the underlying TCP connection. + +3. Message delimitation + + Once the protocol header is accepted, endpoint can send and receive + messages. Message is an arbitrarily large chunk of binary data. + Every message starts with 64-bit unsigned integer in network byte + order representing the size, in bytes, of the remaining part of the + message. Thus, the message payload can be from 0 to 2^64-1 bytes + long. The payload of the specified size follows directly after the + size field: + + +------------+-----------------+ + | size (64b) | payload | + +------------+-----------------+ + + It may seem that 64 bit message size is excessive and consumes too + much of valuable bandwidth, especially given that most scenarios call + for relatively small messages, in order of bytes or kilobytes. + + Variable length field may seem like a better solution, however, our + experience is that variable length size field doesn't provide any + performance benefit in the real world. + + For large messages, 64 bits used by the field form a negligible + portion of the message and the performance impact is not even + measurable. + + For small messages, the overall throughput is heavily CPU-bound, + never I/O-bound. In other words, CPU processing associated with each + individual message limits the message rate in such a way that network + bandwidth limit is never reached. In the future we expect it to be + + + +Sustrik Expires September 2, 2014 [Page 3] + +Internet-Draft TCP mapping for SPs March 2014 + + + even more so: network bandwidth is going to grow faster than CPU + speed. All in all, some performance improvement could be achieved + using variable length size field with huge streams of very small + messages on very slow networks. We consider that scenario to be a + corner case that's almost never seen in a real world. + + On the other hand, it may be argued that limiting the messages to + 2^64-1 bytes can prove insufficient in the future. However, + extrapolating the message size growth size seen in the past indicates + that 64 bit size should be sufficient for the expected lifetime of + the protocol (30-50 years). + + Finally, it may be argued that chaining arbitrary number of smaller + data chunks can yield unlimited message size. The downside of this + approach is that the message payload cannot be continuous on the + wire, it has to be interleaved with chunk headers. That typically + requires one more copy of the data in the receiving part of the stack + which may be a problem for very large messages. + +4. Note on multiplexing + + Several modern general-purpose protocols built on top of TCP provide + multiplexing capability, i.e. a way to transfer multiple independent + message streams over a single TCP connection. This mapping + deliberately opts to provide no such functionality. Instead, + independent message streams should be implemented as different TCP + connections. This section provides the rationale for the design + decision. + + First of all, multiplexing is typically added to protocols to avoid + the overhead of establishing additional TCP connections. This need + arises in environments where the TCP connections are extremely short- + lived, often used only for a single handshake between the peers. + Scalability protocols, on the other hand, require long-lived + connections which doesn't make the feature necessary. + + At the same time, multiplexing on top of TCP, while doable, is + inferior to the real multiplexing done using multiple TCP + connections. Specifically, TCP's head-of-line blocking feature means + that a single lost TCP packet will hinder delivery for all the + streams on the top of the connection, not just the one the missing + packets belonged to. + + At the same time, implementing multiplexing is a non-trivial matter + and results in increased development cost, more bugs and larger + attack surface. + + + + + +Sustrik Expires September 2, 2014 [Page 4] + +Internet-Draft TCP mapping for SPs March 2014 + + + Finally, for multiplexing to work properly, large messages have to be + split into smaller data chunks interleaved by chunk headers, which + makes receiving stack less efficient, as already discussed above. + +5. IANA Considerations + + This memo includes no request to IANA. + +6. Security Considerations + + The mapping isn't intended to provide any additional security in + addition to what TCP does. DoS concerns are addressed within the + specification. + +Author's Address + + Martin Sustrik (editor) + + Email: sustrik@250bpm.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Sustrik Expires September 2, 2014 [Page 5] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tcp-mapping-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tcp-mapping-01.xml new file mode 100644 index 0000000..66b11ba --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tcp-mapping-01.xml @@ -0,0 +1,210 @@ + + + + + + + + + TCP Mapping for Scalability Protocols + + + +
+ sustrik@250bpm.com +
+
+ + + + Applications + Internet Engineering Task Force + + TCP + SP + + + This document defines the TCP mapping for scalability protocols. + The main purpose of the mapping is to turn the stream of bytes + into stream of messages. Additionally, the mapping provides some + additional checks during the connection establishment phase. + + +
+ + + +
+ + This mapping should be layered directly on the top of TCP. + + There's no fixed TCP port to use for the communication. Instead, port + numbers are assigned to individual services by the user. + +
+ +
+ + As soon as the underlying TCP connection is established, both parties + MUST send the protocol header (described in detail below) immediately. + Both endpoints MUST then wait for the protocol header from the peer + before proceeding on. + + The goal of this design is to keep connection establishment as + fast as possible by avoiding any additional protocol handshakes, + i.e. network round-trips. Specifically, the protocol headers + can be bundled directly with to the last packets of TCP handshake + and thus have virtually zero performance impact. + + The protocol header is 8 bytes long and looks like this: + +
+ + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| 0x00 | 0x53 | 0x50 | version | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| type | reserved | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +
+ + First four bytes of the protocol header are used to make sure that + the peer's protocol is compatible with the protocol used by the local + endpoint. Keep in mind that this protocol is designed to run on an + arbitrary TCP port, thus the standard compatibility check -- if it runs + on port X and protocol Y is assigned to X by IANA, it speaks protocol Y + -- does not apply. We have to use an alternative mechanism. + + First four bytes of the protocol header MUST be set to 0x00, 0x53, 0x50 + and 0x00 respectively. If the protocol header received from the peer + differs, the TCP connection MUST be closed immediately. + + The fact that the first byte of the protocol header is binary zero + eliminates any text-based protocols that were accidentally connected + to the endpoint. Subsequent two bytes make the check even more + rigorous. At the same time they can be used as a debugging hint to + indicate that the connection is supposed to use one of the scalability + protocols -- ASCII representation of these bytes is 'SP' that can + be easily spotted in when capturing the network traffic. Finally, + the fourth byte rules out any incompatible versions of this + protocol. + + Fifth and sixth bytes of the header form a 16-bit unsigned integer in + network byte order representing the type of SP endpoint on the layer + above. The value SHOULD NOT be interpreted by the mapping, rather + the interpretation should be delegated to the scalability protocol + above the mapping. For informational purposes, it should be noted that + the field encodes information such as SP protocol ID, protocol version + and the role of endpoint within the protocol. Individual values are + assigned by IANA. + + Finally, the last two bytes of the protocol header are reserved for + future use and must be set to binary zeroes. If the protocol header + from the peer contains anything else than zeroes in this field, the + implementation MUST close the underlying TCP connection. + +
+ +
+ + Once the protocol header is accepted, endpoint can send and receive + messages. Message is an arbitrarily large chunk of binary data. Every + message starts with 64-bit unsigned integer in network byte order + representing the size, in bytes, of the remaining part of the message. + Thus, the message payload can be from 0 to 2^64-1 bytes long. + The payload of the specified size follows directly after the size + field: + +
+ ++------------+-----------------+ +| size (64b) | payload | ++------------+-----------------+ + +
+ + It may seem that 64 bit message size is excessive and consumes too much + of valuable bandwidth, especially given that most scenarios call for + relatively small messages, in order of bytes or kilobytes. + + Variable length field may seem like a better solution, however, our + experience is that variable length size field doesn't provide any + performance benefit in the real world. + + For large messages, 64 bits used by the field form a negligible portion + of the message and the performance impact is not even measurable. + + For small messages, the overall throughput is heavily CPU-bound, never + I/O-bound. In other words, CPU processing associated with each + individual message limits the message rate in such a way that network + bandwidth limit is never reached. In the future we expect it to be + even more so: network bandwidth is going to grow faster than CPU speed. + All in all, some performance improvement could be achieved using + variable length size field with huge streams of very small messages + on very slow networks. We consider that scenario to be a corner case + that's almost never seen in a real world. + + On the other hand, it may be argued that limiting the messages to + 2^64-1 bytes can prove insufficient in the future. However, + extrapolating the message size growth size seen in the past indicates + that 64 bit size should be sufficient for the expected lifetime of + the protocol (30-50 years). + + Finally, it may be argued that chaining arbitrary number of smaller + data chunks can yield unlimited message size. The downside of this + approach is that the message payload cannot be continuous on the wire, + it has to be interleaved with chunk headers. That typically requires + one more copy of the data in the receiving part of the stack which + may be a problem for very large messages. + +
+ +
+ + Several modern general-purpose protocols built on top of TCP provide + multiplexing capability, i.e. a way to transfer multiple independent + message streams over a single TCP connection. This mapping deliberately + opts to provide no such functionality. Instead, independent message + streams should be implemented as different TCP connections. This + section provides the rationale for the design decision. + + First of all, multiplexing is typically added to protocols to avoid + the overhead of establishing additional TCP connections. This need + arises in environments where the TCP connections are extremely + short-lived, often used only for a single handshake between the peers. + Scalability protocols, on the other hand, require long-lived + connections which doesn't make the feature necessary. + + At the same time, multiplexing on top of TCP, while doable, is inferior + to the real multiplexing done using multiple TCP connections. + Specifically, TCP's head-of-line blocking feature means that a single + lost TCP packet will hinder delivery for all the streams on the top of + the connection, not just the one the missing packets belonged to. + + At the same time, implementing multiplexing is a non-trivial matter + and results in increased development cost, more bugs and larger + attack surface. + + Finally, for multiplexing to work properly, large messages have to be + split into smaller data chunks interleaved by chunk headers, which + makes receiving stack less efficient, as already discussed above. + +
+ +
+ This memo includes no request to IANA. +
+ +
+ The mapping isn't intended to provide any additional security in + addition to what TCP does. DoS concerns are addressed within + the specification. +
+ +
+ +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tls-mapping-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tls-mapping-01.txt new file mode 100644 index 0000000..64b7127 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tls-mapping-01.txt @@ -0,0 +1,169 @@ + + + + +Internet Engineering Task Force G. D'Amore, Ed. +Internet-Draft +Intended status: Informational March 27, 2014 +Expires: September 28, 2014 + + + TLS Mapping for Scalability Protocols + sp-tls-mapping-01 + +Abstract + + This document defines the mapping for scalability protocols (SP) + running on top of Transport Layer Security (TLS) v1.2 on top of TCP. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on September 28, 2014. + +Copyright Notice + + Copyright (c) 2014 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + + +D'Amore Expires September 28, 2014 [Page 1] + +Internet-Draft TLS/TCP mapping for SPs March 2014 + + +1. Underlying protocol + + This mapping should be layered directly on the top of TLS [TLS] + secured connections. While it is possible to use TLS on top of other + transports, this document specifically concerns itself with TLS + running on top of TCP [TCP]. + + Other combinations may be contemplated, and should follow the same + details as discussed here. + + As when running SP over TCP directly, the TCP port number is + determined by the application or user. + + This mapping follows the details of SP over TCP [SPoverTCP]. + +2. Connection initiation + + An initial connection is first established using TCP, then performing + a TLS handshake. This handshake establishes the security parameters + of the connection, including negotiation of cipher suites, exchanging + keys, and possibly performing one or two-way authentication. + + The specific details of the TLS negotiation are determined by the + application(s) involved, and are not specified here. This includes + selection of the specific version of TLS or possibly falling back to + SSL version 3 (but not SSL version 1 or 2). + + TLS presents an encrypted channel that may be treated as a full + duplex byte stream between peers. This mapping sits within that + channel. + + Note also that TLS peers may rekey periodically. This happens in the + without involving the upper protocol, and the details need not + concern us here. + + Once the TLS layer connection has been established, the communication + commences as detailed in SPoverTCP [SPoverTCP]. This includes the + exchange of the initial protocol headers identifying the version of + SP in use, and the specific protocol type, as well as requirements to + disconnect upon receipt of an invalid protocol header or an + unrecognized SP version. + +3. IANA Considerations + + This memo includes no request to IANA. + + + + + + +D'Amore Expires September 28, 2014 [Page 2] + +Internet-Draft TLS/TCP mapping for SPs March 2014 + + +4. Security Considerations + + Security considerations are explored in depth as part of TLS [TLS]. + This document does not provide any further implications beyond that + in TLS itself. + + The use of SSLv2 is explicitly forbidden [RFC6176], as SSLv2 contains + known weaknesses. + +5. References + + [TCP] Postel, J., "Transmission Control Protocol", STD 7, RFC + 793, September 1981. + + [TLS] Dierks, T. and E. Rescorla, "The Transport Layer Security + (TLS) Protocol Version 1.2", RFC 5246, August 2008. + + [RFC6176] Turner, S. and T. Polk, "Prohibiting Secure Sockets Layer + (SSL) Version 2.0", RFC 6176, March 2011. + + [SPoverTCP] + Sustrik, M., "TCP mapping for SPs", August 2013. + +Author's Address + + Garrett D'Amore (editor) + + Email: garrett@damore.org + + + + + + + + + + + + + + + + + + + + + + + +D'Amore Expires September 28, 2014 [Page 3] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tls-mapping-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tls-mapping-01.xml new file mode 100644 index 0000000..0028a33 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-tls-mapping-01.xml @@ -0,0 +1,153 @@ + + + + + + + + + TLS Mapping for Scalability Protocols + + + +
+ garrett@damore.org +
+
+ + + + Applications + Internet Engineering Task Force + + TLS + SP + + + This document defines the mapping for scalability protocols (SP) + running on top of Transport Layer Security (TLS) v1.2 on top of TCP. + + +
+ + + +
+ + This mapping should be layered directly on the top of + TLS secured + connections. While it is possible to use TLS on top of other + transports, this document specifically concerns itself with TLS + running on top of TCP. + + Other combinations may be contemplated, + and should follow the same details as discussed here. + + As when running SP over TCP directly, the TCP port number is + determined by the application or user. + + This mapping follows the details of + SP over TCP. + +
+ +
+ + An initial connection is first established using TCP, then performing + a TLS handshake. This handshake establishes the security parameters + of the connection, including negotiation of cipher suites, exchanging + keys, and possibly performing one or two-way authentication. + + The specific details of the TLS negotiation are determined by the + application(s) involved, and are not specified here. This includes + selection of the specific version of TLS or possibly falling back to + SSL version 3 (but not SSL version 1 or 2). + + TLS presents an encrypted channel that may be treated as a full duplex + byte stream between peers. This mapping sits within that channel. + + Note also that TLS peers may rekey periodically. This happens in the + without involving the upper protocol, and the details need not concern + us here. + + Once the TLS layer connection has been established, the communication + commences as detailed in SPoverTCP. + This includes the exchange of the initial protocol headers identifying + the version of SP in use, and the specific protocol type, as well as + requirements to disconnect upon receipt of an invalid + protocol header or an unrecognized SP version. + +
+ + +
+ This memo includes no request to IANA. +
+ +
+ Security considerations are explored in depth as part of + TLS. This document does not provide + any further implications beyond that in TLS itself. + + The use of SSLv2 is explicitly forbidden, + as SSLv2 contains known weaknesses. + +
+ +
+ + + + + + Transmission Control Protocol + + + + + + + + + + + The Transport Layer Security (TLS) Protocol Version 1.2 + + Independent + + + RTFM, Inc. + + + + + + + + + Prohibiting Secure Sockets Layer (SSL) Version 2.0 + + IECA + + + NIST. + + + + + + + + + TCP mapping for SPs + + + + + + + + + +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-udp-mapping-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-udp-mapping-01.txt new file mode 100644 index 0000000..1c635c4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-udp-mapping-01.txt @@ -0,0 +1,169 @@ + + + + +Internet Engineering Task Force M. Sustrik, Ed. +Internet-Draft +Intended status: Informational March 2014 +Expires: September 2, 2014 + + + UDP Mapping for Scalability Protocols + sp-udp-mapping-01 + +Abstract + + This document defines the UDP mapping for scalability protocols. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on September 2, 2014. + +Copyright Notice + + Copyright (c) 2014 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + + + +Sustrik Expires September 2, 2014 [Page 1] + +Internet-Draft UDP mapping for SPs March 2014 + + +1. Underlying protocol + + This mapping should be layered directly on the top of UDP. + + There's no fixed UDP port to use for the communication. Instead, + port numbers are assigned to individual services by the user. + +2. Message delimitation + + Each UDP packet maps to exactly one SP message. + + There is no way to split one SP message into multiple UDP packets and + therefore SP messages larger than existing path MTU will be dropped + silently. + + There is also no way to pack multiple SP messages into a single UDP + packet. + +3. Packet layout + + Each packet consists of an 8-byte header followed by the opaque + message payload: + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | 0x00 | 0x53 | 0x50 | version | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | type | reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | payload ... + +-+-+-+-+-+-+-+-+-+-+-+-+- + + First four bytes of the protocol header are used to make sure that + the peer's protocol is compatible with the protocol used by the local + endpoint. Keep in mind that this protocol is designed to run on an + arbitrary UDP port, thus the standard compatibility check -- if it + runs on port X and protocol Y is assigned to X by IANA, it speaks + protocol Y -- does not apply. We have to use an alternative + mechanism. + + First four bytes of the protocol header MUST be set to 0x00, 0x53, + 0x50 and 0x00 respectively. If the protocol header received from the + peer differs, the UDP packets MUST be ignored. + + The fact that the first byte of the protocol header is binary zero + eliminates any text-based protocols that were accidentally sending to + the endpoint. Subsequent two bytes make the check even more + + + +Sustrik Expires September 2, 2014 [Page 2] + +Internet-Draft UDP mapping for SPs March 2014 + + + rigorous. At the same time they can be used as a debugging hint to + indicate that the connection is supposed to use one of the + scalability protocols -- ASCII representation of these bytes is 'SP' + that can be easily spotted in when capturing the network traffic. + Finally, the fourth byte rules out any incompatible versions of this + protocol. + + Fifth and sixth bytes of the header form a 16-bit unsigned integer in + network byte order representing the type of SP endpoint on the layer + above. The value SHOULD NOT be interpreted by the mapping, rather + the interpretation should be delegated to the scalability protocol + above the mapping. For informational purposes, it should be noted + that the field encodes information such as SP protocol ID, protocol + version and the role of endpoint within the protocol. Individual + values are assigned by IANA. + + Finally, the last two bytes of the protocol header are reserved for + future use and must be set to binary zeroes. If the protocol header + from the peer contains anything else than zeroes in this field, the + implementation MUST ignore the UDP packet. + + Packet header is followed by opaque message payload which spans all + the way to the end of the packet. + +4. IANA Considerations + + This memo includes no request to IANA. + +5. Security Considerations + + The mapping isn't intended to provide any additional security in + addition to what UDP does. + +Author's Address + + Martin Sustrik (editor) + + Email: sustrik@250bpm.com + + + + + + + + + + + + + +Sustrik Expires September 2, 2014 [Page 3] + diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-udp-mapping-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-udp-mapping-01.xml new file mode 100644 index 0000000..5503e99 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-udp-mapping-01.xml @@ -0,0 +1,128 @@ + + + + + + + + + UDP Mapping for Scalability Protocols + + + +
+ sustrik@250bpm.com +
+
+ + + + Applications + Internet Engineering Task Force + + UDP + SP + + + This document defines the UDP mapping for scalability protocols. + + +
+ + + +
+ + This mapping should be layered directly on the top of UDP. + + There's no fixed UDP port to use for the communication. Instead, port + numbers are assigned to individual services by the user. + +
+ +
+ + Each UDP packet maps to exactly one SP message. + + There is no way to split one SP message into multiple UDP packets + and therefore SP messages larger than existing path MTU will be + dropped silently. + + There is also no way to pack multiple SP messages into a single + UDP packet. + +
+ +
+ + Each packet consists of an 8-byte header followed by the opaque + message payload: + +
+ + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| 0x00 | 0x53 | 0x50 | version | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| type | reserved | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| payload ... ++-+-+-+-+-+-+-+-+-+-+-+-+- + +
+ + First four bytes of the protocol header are used to make sure that + the peer's protocol is compatible with the protocol used by the local + endpoint. Keep in mind that this protocol is designed to run on an + arbitrary UDP port, thus the standard compatibility check -- if it runs + on port X and protocol Y is assigned to X by IANA, it speaks protocol Y + -- does not apply. We have to use an alternative mechanism. + + First four bytes of the protocol header MUST be set to 0x00, 0x53, 0x50 + and 0x00 respectively. If the protocol header received from the peer + differs, the UDP packets MUST be ignored. + + The fact that the first byte of the protocol header is binary zero + eliminates any text-based protocols that were accidentally sending + to the endpoint. Subsequent two bytes make the check even more + rigorous. At the same time they can be used as a debugging hint to + indicate that the connection is supposed to use one of the scalability + protocols -- ASCII representation of these bytes is 'SP' that can + be easily spotted in when capturing the network traffic. Finally, + the fourth byte rules out any incompatible versions of this + protocol. + + Fifth and sixth bytes of the header form a 16-bit unsigned integer in + network byte order representing the type of SP endpoint on the layer + above. The value SHOULD NOT be interpreted by the mapping, rather + the interpretation should be delegated to the scalability protocol + above the mapping. For informational purposes, it should be noted that + the field encodes information such as SP protocol ID, protocol version + and the role of endpoint within the protocol. Individual values are + assigned by IANA. + + Finally, the last two bytes of the protocol header are reserved for + future use and must be set to binary zeroes. If the protocol header + from the peer contains anything else than zeroes in this field, the + implementation MUST ignore the UDP packet. + + Packet header is followed by opaque message payload which spans all + the way to the end of the packet. + +
+ +
+ This memo includes no request to IANA. +
+ +
+ The mapping isn't intended to provide any additional security in + addition to what UDP does. +
+ +
+ +
+ diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-websocket-mapping-01.txt b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-websocket-mapping-01.txt new file mode 100644 index 0000000..0d28d7f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-websocket-mapping-01.txt @@ -0,0 +1,168 @@ + + + + +Internet Engineering Task Force M. Sustrik, Ed. +Internet-Draft +Intended status: Informational G. D'Amore +Expires: August 7, 2015 + February 3, 2015 + + + WebSocket Mapping for Scalability Protocols + sp-websocket-mapping-01 + +Abstract + + This document defines the WebSocket mapping for scalability + protocols. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on August 7, 2015. + +Copyright Notice + + Copyright (c) 2015 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + + + + +Sustrik & D'Amore Expires August 7, 2015 [Page 1] + +Internet-Draft WebSocket mapping for SPs February 2015 + + +1. Underlying protocol + + This mapping should be layered on the top of WebSocket protocol as + defined in RFC 6455. + +2. Connection initiation + + Standard WebSocket handshake is done following RFC 6455. + + The Sec-WebSocket-Protocol field MUST be set in the client's HTTP + request to match the protocol used by the WebSocket server. + Accordingly, the following values should be used. + + pair.sp.nanomsg.org (NN_PAIR client and server) + + req.sp.nanomsg.org (NN_REQ server, NN_REP client) + + rep.sp.nanomsg.org (NN_REP server, NN_REQ client) + + pub.sp.nanomsg.org (NN_PUB server, NN_SUB client) + + sub.sp.nanomsg.org (NN_SUB server, NN_PUB client) + + surveyor.sp.nanomsg.org (NN_SURVEYOR server, NN_RESPONDENT client) + + respondent.sp.nanomsg.org (NN_RESPONDENT server, NN_SURVEYOR client) + + push.sp.nanomsg.org (NN_PUSH server, NN_PULL client) + + pull.sp.nanomsg.org (NN_PULL server, NN_PUSH client) + + bus.sp.nanomsg.org (NN_BUS client and server) + + If the server supports the requested SP protocol as indicated by the + Sec-WebSocket-Protocol header, then it MUST respond with the same + Sec-WebSocket-Protocol value sent by the client. + + If the server does support the requested SP protocol, then it MUST + fail the WebSocket connection using the Close code of 1002, as + specified in RFC 6455. + + For example, an NN_REQ client socket, connecting to an NN_REP server, + will send the value rep.sp.nanomsg.org in the Sec-WebSocket-Protocol + field. The NN_REP socket on the server would then include the same + rep.sp.nanomsg.org in its response. + + + + + + +Sustrik & D'Amore Expires August 7, 2015 [Page 2] + +Internet-Draft WebSocket mapping for SPs February 2015 + + +3. Message + + SP message maps directly to WebSocket message. The message can be + fragmented as needed. Frame boundaries are ignored by the SP layer. + + When possible, binary frames SHOULD be used in preference to text + frames. If text frames are in use, then SP message payloads MUST be + comprised of legal UTF-8 text only. + +4. IANA Considerations + + This memo includes no request to IANA. + +5. Security Considerations + + The mapping isn't intended to provide any additional security in + addition to what WebSocket does. DoS concerns are addressed within + the specification. + +Authors' Addresses + + Martin Sustrik (editor) + + Email: sustrik@250bpm.com + + + Garrett D'Amore + + Email: garrett@damore.org + + + + + + + + + + + + + + + + + + + + + + +Sustrik & D'Amore Expires August 7, 2015 [Page 3] diff --git a/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-websocket-mapping-01.xml b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-websocket-mapping-01.xml new file mode 100644 index 0000000..28cadcd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/rfc/sp-websocket-mapping-01.xml @@ -0,0 +1,109 @@ + + + + + + + + + WebSocket Mapping for Scalability Protocols + + + +
+ sustrik@250bpm.com +
+
+ +
+ garrett@damore.org +
+
+ + + + Applications + Internet Engineering Task Force + + WebSocket + SP + + + This document defines the WebSocket mapping for scalability + protocols. + + +
+ + + +
+ + This mapping should be layered on the top of WebSocket protocol + as defined in RFC 6455. + +
+ +
+ + Standard WebSocket handshake is done following RFC 6455. + + The Sec-WebSocket-Protocol field + MUST be set in the client's HTTP request to match the protocol used + by the WebSocket server. Accordingly, the following values should + be used. + + pair.sp.nanomsg.org (NN_PAIR client and server) + req.sp.nanomsg.org (NN_REQ server, NN_REP client) + rep.sp.nanomsg.org (NN_REP server, NN_REQ client) + pub.sp.nanomsg.org (NN_PUB server, NN_SUB client) + sub.sp.nanomsg.org (NN_SUB server, NN_PUB client) + surveyor.sp.nanomsg.org (NN_SURVEYOR server, NN_RESPONDENT client) + respondent.sp.nanomsg.org (NN_RESPONDENT server, NN_SURVEYOR client) + push.sp.nanomsg.org (NN_PUSH server, NN_PULL client) + pull.sp.nanomsg.org (NN_PULL server, NN_PUSH client) + bus.sp.nanomsg.org (NN_BUS client and server) + + If the server supports the requested SP protocol as indicated + by the Sec-WebSocket-Protocol header, then it MUST respond with + the same Sec-WebSocket-Protocol value sent by the client. + + If the server does support the requested SP protocol, then it MUST + fail the WebSocket connection using the Close code of 1002, as + specified in RFC 6455. + + For example, an NN_REQ client socket, connecting to + an NN_REP server, will send the value rep.sp.nanomsg.org in + the Sec-WebSocket-Protocol field. The NN_REP socket on the + server would then include the same rep.sp.nanomsg.org in its + response. + +
+ +
+ + SP message maps directly to WebSocket message. The message can be + fragmented as needed. Frame boundaries are ignored by the SP + layer. + + When possible, binary frames SHOULD be used in preference to + text frames. If text frames are in use, then SP message payloads + MUST be comprised of legal UTF-8 text only. + +
+ +
+ This memo includes no request to IANA. +
+ +
+ The mapping isn't intended to provide any additional security in + addition to what WebSocket does. DoS concerns are addressed within + the specification. +
+ +
+ +
diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/CMakeLists.txt b/node/node_modules/nanomsg/deps/nanomsg/src/CMakeLists.txt new file mode 100644 index 0000000..4d0839e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/CMakeLists.txt @@ -0,0 +1,381 @@ +# +# Copyright (c) 2012-2013 Martin Sustrik All rights reserved. +# Copyright (c) 2013 GoPivotal, Inc. All rights reserved. +# Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +set (NN_SOURCES + nn.h + inproc.h + ipc.h + tcp.h + ws.h + pair.h + pubsub.h + reqrep.h + pipeline.h + survey.h + bus.h + + core/ep.h + core/ep.c + core/epbase.c + core/global.h + core/global.c + core/pipe.c + core/poll.c + core/sock.h + core/sock.c + core/sockbase.c + core/symbol.c + + aio/ctx.h + aio/ctx.c + aio/fsm.h + aio/fsm.c + aio/pool.h + aio/pool.c + aio/timer.h + aio/timer.c + aio/timerset.h + aio/timerset.c + aio/usock.h + aio/usock.c + aio/worker.h + aio/worker.c + + utils/alloc.h + utils/alloc.c + utils/atomic.h + utils/atomic.c + utils/attr.h + utils/chunk.h + utils/chunk.c + utils/chunkref.h + utils/chunkref.c + utils/clock.h + utils/clock.c + utils/closefd.h + utils/closefd.c + utils/cont.h + utils/efd.h + utils/efd.c + utils/err.h + utils/err.c + utils/fast.h + utils/fd.h + utils/hash.h + utils/hash.c + utils/list.h + utils/list.c + utils/msg.h + utils/msg.c + utils/condvar.h + utils/condvar.c + utils/mutex.h + utils/mutex.c + utils/once.h + utils/once.c + utils/queue.h + utils/queue.c + utils/random.h + utils/random.c + utils/sem.h + utils/sem.c + utils/sleep.h + utils/sleep.c + utils/thread.h + utils/thread.c + utils/wire.h + utils/wire.c + + devices/device.h + devices/device.c + + protocols/utils/dist.h + protocols/utils/dist.c + protocols/utils/excl.h + protocols/utils/excl.c + protocols/utils/fq.h + protocols/utils/fq.c + protocols/utils/lb.h + protocols/utils/lb.c + protocols/utils/priolist.h + protocols/utils/priolist.c + + protocols/bus/bus.h + protocols/bus/bus.c + protocols/bus/xbus.h + protocols/bus/xbus.c + + protocols/pipeline/push.h + protocols/pipeline/push.c + protocols/pipeline/pull.h + protocols/pipeline/pull.c + protocols/pipeline/xpull.h + protocols/pipeline/xpull.c + protocols/pipeline/xpush.h + protocols/pipeline/xpush.c + + protocols/pair/pair.h + protocols/pair/pair.c + protocols/pair/xpair.h + protocols/pair/xpair.c + + protocols/pubsub/pub.h + protocols/pubsub/pub.c + protocols/pubsub/sub.h + protocols/pubsub/sub.c + protocols/pubsub/trie.h + protocols/pubsub/trie.c + protocols/pubsub/xpub.h + protocols/pubsub/xpub.c + protocols/pubsub/xsub.h + protocols/pubsub/xsub.c + + protocols/reqrep/req.h + protocols/reqrep/req.c + protocols/reqrep/rep.h + protocols/reqrep/rep.c + protocols/reqrep/task.h + protocols/reqrep/task.c + protocols/reqrep/xrep.h + protocols/reqrep/xrep.c + protocols/reqrep/xreq.h + protocols/reqrep/xreq.c + + protocols/survey/respondent.h + protocols/survey/respondent.c + protocols/survey/surveyor.h + protocols/survey/surveyor.c + protocols/survey/xrespondent.h + protocols/survey/xrespondent.c + protocols/survey/xsurveyor.h + protocols/survey/xsurveyor.c + + transports/utils/backoff.h + transports/utils/backoff.c + transports/utils/dns.h + transports/utils/dns.c + transports/utils/dns_getaddrinfo.h + transports/utils/dns_getaddrinfo.inc + transports/utils/dns_getaddrinfo_a.h + transports/utils/dns_getaddrinfo_a.inc + transports/utils/iface.h + transports/utils/iface.c + transports/utils/literal.h + transports/utils/literal.c + transports/utils/port.h + transports/utils/port.c + transports/utils/streamhdr.h + transports/utils/streamhdr.c + transports/utils/base64.h + transports/utils/base64.c + + transports/inproc/binproc.h + transports/inproc/binproc.c + transports/inproc/cinproc.h + transports/inproc/cinproc.c + transports/inproc/inproc.h + transports/inproc/inproc.c + transports/inproc/ins.h + transports/inproc/ins.c + transports/inproc/msgqueue.h + transports/inproc/msgqueue.c + transports/inproc/sinproc.h + transports/inproc/sinproc.c + + transports/ipc/aipc.h + transports/ipc/aipc.c + transports/ipc/bipc.h + transports/ipc/bipc.c + transports/ipc/cipc.h + transports/ipc/cipc.c + transports/ipc/ipc.h + transports/ipc/ipc.c + transports/ipc/sipc.h + transports/ipc/sipc.c + + transports/tcp/atcp.h + transports/tcp/atcp.c + transports/tcp/btcp.h + transports/tcp/btcp.c + transports/tcp/ctcp.h + transports/tcp/ctcp.c + transports/tcp/stcp.h + transports/tcp/stcp.c + transports/tcp/tcp.h + transports/tcp/tcp.c + + transports/ws/aws.h + transports/ws/aws.c + transports/ws/bws.h + transports/ws/bws.c + transports/ws/cws.h + transports/ws/cws.c + transports/ws/sws.h + transports/ws/sws.c + transports/ws/ws.h + transports/ws/ws.c + transports/ws/ws_handshake.h + transports/ws/ws_handshake.c + transports/ws/sha1.h + transports/ws/sha1.c +) + +if (WIN32) + list (APPEND NN_SOURCES + aio/usock_win.h + aio/usock_win.inc + aio/worker_win.h + aio/worker_win.inc + utils/thread_win.h + utils/thread_win.inc + utils/win.h + ) +elseif (UNIX) + list (APPEND NN_SOURCES + aio/usock_posix.h + aio/usock_posix.inc + aio/worker_posix.h + aio/worker_posix.inc + utils/thread_posix.h + utils/thread_posix.inc + ) +else () + message (FATAL_ERROR "Assertion failed; this path is unreachable.") +endif () + +if (NN_HAVE_EPOLL) + add_definitions (-DNN_USE_EPOLL) + list (APPEND NN_SOURCES + aio/poller.h + aio/poller.c + aio/poller_epoll.h + aio/poller_epoll.inc + ) +elseif (NN_HAVE_KQUEUE) + add_definitions (-DNN_USE_KQUEUE) + list (APPEND NN_SOURCES + aio/poller.h + aio/poller.c + aio/poller_kqueue.h + aio/poller_kqueue.inc + ) +elseif (NN_HAVE_POLL) + add_definitions (-DNN_USE_POLL) + list (APPEND NN_SOURCES + aio/poller.h + aio/poller.c + aio/poller_poll.h + aio/poller_poll.inc + ) +elseif (NN_HAVE_WINSOCK) + # No operation +else () + message (SEND_ERROR "ERROR: could not determine socket polling method.") + message (SEND_ERROR "${ISSUE_REPORT_MSG}" ) +endif () + +if (NN_HAVE_EVENTFD) + add_definitions (-DNN_USE_EVENTFD) + list (APPEND NN_SOURCES + utils/efd_eventfd.h + utils/efd_eventfd.inc + ) +elseif (NN_HAVE_PIPE) + add_definitions (-DNN_USE_PIPE) + list (APPEND NN_SOURCES + utils/efd_pipe.h + utils/efd_pipe.inc + ) +elseif (NN_HAVE_SOCKETPAIR) + add_definitions (-DNN_USE_SOCKETPAIR) + list (APPEND NN_SOURCES + utils/efd_socketpair.h + utils/efd_socketpair.inc + ) +elseif (NN_HAVE_WINSOCK) + add_definitions (-DNN_USE_WINSOCK) + list (APPEND NN_SOURCES + utils/efd_win.h + utils/efd_win.inc + ) +else () + message (SEND_ERROR "ERROR: could not determine socket signaling method.") + message (SEND_ERROR "${ISSUE_REPORT_MSG}" ) +endif () + +# Provide same folder structure in IDE as on disk +foreach (f ${NN_SOURCES}) + # Get the path of the file relative to source directory + if (IS_ABSOLUTE "${f}") + file (RELATIVE_PATH f ${CMAKE_CURRENT_SOURCE_DIR} ${f}) + endif () + set (SRC_GROUP "${f}") + set (f "${CMAKE_CURRENT_SOURCE_DIR}/${f}") + + # Remove the filename part + string (REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRC_GROUP ${SRC_GROUP}) + + # CMake source_group expects \\, not / + string (REPLACE / \\ SRC_GROUP ${SRC_GROUP}) + source_group ("${SRC_GROUP}" FILES ${f}) +endforeach () + +if (NN_STATIC_LIB) + add_library (${PROJECT_NAME} STATIC ${NN_SOURCES}) +else () + add_library (${PROJECT_NAME} SHARED ${NN_SOURCES}) + add_definitions (-DNN_SHARED_LIB) + set_target_properties (${PROJECT_NAME} PROPERTIES + VERSION "${NN_PACKAGE_VERSION}" + SOVERSION "${NN_ABI_VERSION}") +endif () + +# Set library outputs same as top-level project binary outputs +set_target_properties (${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties (${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties (${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +target_link_libraries (${PROJECT_NAME} ${NN_REQUIRED_LIBRARIES}) +if(THREADS_HAVE_PTHREAD_ARG) + add_definitions (-pthread) +endif() +if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries (${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}") +endif() + +# pkg-config file +if(NN_REQUIRED_LIBRARIES) + foreach (lib ${NN_REQUIRED_LIBRARIES}) + set (NN_REQUIRED_LFLAGS "${NN_REQUIRED_LFLAGS} -l${lib}") + endforeach() +endif() +configure_file (pkgconfig.in ${PROJECT_NAME}.pc @ONLY) +install ( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install (TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/README b/node/node_modules/nanomsg/deps/nanomsg/src/README new file mode 100644 index 0000000..0fa0184 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/README @@ -0,0 +1,2 @@ +This directory contains all headers that interconnect various parts of +the system. The public API, the interface for protocols and transports etc. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/ctx.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/ctx.c new file mode 100644 index 0000000..f6ea105 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/ctx.c @@ -0,0 +1,112 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ctx.h" + +#include "../utils/err.h" +#include "../utils/cont.h" +#include "../utils/fast.h" + +void nn_ctx_init (struct nn_ctx *self, struct nn_pool *pool, + nn_ctx_onleave onleave) +{ + nn_mutex_init (&self->sync); + self->pool = pool; + nn_queue_init (&self->events); + nn_queue_init (&self->eventsto); + self->onleave = onleave; +} + +void nn_ctx_term (struct nn_ctx *self) +{ + nn_queue_term (&self->eventsto); + nn_queue_term (&self->events); + nn_mutex_term (&self->sync); +} + +void nn_ctx_enter (struct nn_ctx *self) +{ + nn_mutex_lock (&self->sync); +} + +void nn_ctx_leave (struct nn_ctx *self) +{ + struct nn_queue_item *item; + struct nn_fsm_event *event; + struct nn_queue eventsto; + + /* Process any queued events before leaving the context. */ + while (1) { + item = nn_queue_pop (&self->events); + event = nn_cont (item, struct nn_fsm_event, item); + if (!event) + break; + nn_fsm_event_process (event); + } + + /* Notify the owner that we are leaving the context. */ + if (nn_fast (self->onleave != NULL)) + self->onleave (self); + + /* Shortcut in the case there are no external events. */ + if (nn_queue_empty (&self->eventsto)) { + nn_mutex_unlock (&self->sync); + return; + } + + /* Make a copy of the queue of the external events so that it does not + get corrupted once we unlock the context. */ + eventsto = self->eventsto; + nn_queue_init (&self->eventsto); + + nn_mutex_unlock (&self->sync); + + /* Process any queued external events. Before processing each event + lock the context it belongs to. */ + while (1) { + item = nn_queue_pop (&eventsto); + event = nn_cont (item, struct nn_fsm_event, item); + if (!event) + break; + nn_ctx_enter (event->fsm->ctx); + nn_fsm_event_process (event); + nn_ctx_leave (event->fsm->ctx); + } + + nn_queue_term (&eventsto); +} + +struct nn_worker *nn_ctx_choose_worker (struct nn_ctx *self) +{ + return nn_pool_choose_worker (self->pool); +} + +void nn_ctx_raise (struct nn_ctx *self, struct nn_fsm_event *event) +{ + nn_queue_push (&self->events, &event->item); +} + +void nn_ctx_raiseto (struct nn_ctx *self, struct nn_fsm_event *event) +{ + nn_queue_push (&self->eventsto, &event->item); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/ctx.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/ctx.h new file mode 100644 index 0000000..2ad570f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/ctx.h @@ -0,0 +1,58 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CTX_INCLUDED +#define NN_CTX_INCLUDED + +#include "../utils/mutex.h" +#include "../utils/queue.h" + +#include "worker.h" +#include "pool.h" +#include "fsm.h" + +/* AIO context for objects using AIO subsystem. */ + +typedef void (*nn_ctx_onleave) (struct nn_ctx *self); + +struct nn_ctx { + struct nn_mutex sync; + struct nn_pool *pool; + struct nn_queue events; + struct nn_queue eventsto; + nn_ctx_onleave onleave; +}; + +void nn_ctx_init (struct nn_ctx *self, struct nn_pool *pool, + nn_ctx_onleave onleave); +void nn_ctx_term (struct nn_ctx *self); + +void nn_ctx_enter (struct nn_ctx *self); +void nn_ctx_leave (struct nn_ctx *self); + +struct nn_worker *nn_ctx_choose_worker (struct nn_ctx *self); + +void nn_ctx_raise (struct nn_ctx *self, struct nn_fsm_event *event); +void nn_ctx_raiseto (struct nn_ctx *self, struct nn_fsm_event *event); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/fsm.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/fsm.c new file mode 100644 index 0000000..33250de --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/fsm.c @@ -0,0 +1,199 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "fsm.h" +#include "ctx.h" + +#include "../utils/err.h" +#include "../utils/attr.h" + +#include + +#define NN_FSM_STATE_IDLE 1 +#define NN_FSM_STATE_ACTIVE 2 +#define NN_FSM_STATE_STOPPING 3 + +void nn_fsm_event_init (struct nn_fsm_event *self) +{ + self->fsm = NULL; + self->src = -1; + self->srcptr = NULL; + self->type = -1; + nn_queue_item_init (&self->item); +} + +void nn_fsm_event_term (NN_UNUSED struct nn_fsm_event *self) +{ + /* We don't term the queue item, although one might think we ought to. + It turns out that there are some hairy recursions which can cause + events to get submitted to queues even after the FSM is stopped. + We could spend more effort fixing this, and perhaps we ought to. + But given that the assertion itself is harmless, if an FSM event + is orphaned it should be pretty harmless -- the event won't be + processed but the FSM is shutting down anyway. So skip it for now. + Later, if we don't rewrite/gut the entire FSM machinery, we can + revisit this. */ + /* nn_queue_item_term (&self->item); */ +} + +int nn_fsm_event_active (struct nn_fsm_event *self) +{ + return nn_queue_item_isinqueue (&self->item); +} + +void nn_fsm_event_process (struct nn_fsm_event *self) +{ + int src; + int type; + void *srcptr; + + src = self->src; + type = self->type; + srcptr = self->srcptr; + self->src = -1; + self->type = -1; + self->srcptr = NULL; + + nn_fsm_feed (self->fsm, src, type, srcptr); +} + +void nn_fsm_feed (struct nn_fsm *self, int src, int type, void *srcptr) +{ + if (nn_slow (self->state != NN_FSM_STATE_STOPPING)) { + self->fn (self, src, type, srcptr); + } else { + self->shutdown_fn (self, src, type, srcptr); + } +} + +void nn_fsm_init_root (struct nn_fsm *self, nn_fsm_fn fn, + nn_fsm_fn shutdown_fn, struct nn_ctx *ctx) +{ + self->fn = fn; + self->shutdown_fn = shutdown_fn; + self->state = NN_FSM_STATE_IDLE; + self->src = -1; + self->srcptr = NULL; + self->owner = NULL; + self->ctx = ctx; + nn_fsm_event_init (&self->stopped); +} + +void nn_fsm_init (struct nn_fsm *self, nn_fsm_fn fn, + nn_fsm_fn shutdown_fn, int src, void *srcptr, struct nn_fsm *owner) +{ + self->fn = fn; + self->shutdown_fn = shutdown_fn; + self->state = NN_FSM_STATE_IDLE; + self->src = src; + self->srcptr = srcptr; + self->owner = owner; + self->ctx = owner->ctx; + nn_fsm_event_init (&self->stopped); +} + +void nn_fsm_term (struct nn_fsm *self) +{ + nn_assert (nn_fsm_isidle (self)); + nn_fsm_event_term (&self->stopped); +} + +void nn_fsm_start (struct nn_fsm *self) +{ + nn_assert (nn_fsm_isidle (self)); + self->fn (self, NN_FSM_ACTION, NN_FSM_START, NULL); + self->state = NN_FSM_STATE_ACTIVE; +} + +int nn_fsm_isidle (struct nn_fsm *self) +{ + return self->state == NN_FSM_STATE_IDLE && + !nn_fsm_event_active (&self->stopped) ? 1 : 0; +} + +void nn_fsm_stop (struct nn_fsm *self) +{ + /* If stopping of the state machine was already requested, do nothing. */ + if (self->state != NN_FSM_STATE_ACTIVE) + return; + + self->state = NN_FSM_STATE_STOPPING; + self->shutdown_fn (self, NN_FSM_ACTION, NN_FSM_STOP, NULL); +} + +void nn_fsm_stopped (struct nn_fsm *self, int type) +{ + nn_assert_state (self, NN_FSM_STATE_STOPPING); + nn_fsm_raise (self, &self->stopped, type); + self->state = NN_FSM_STATE_IDLE; +} + +void nn_fsm_stopped_noevent (struct nn_fsm *self) +{ + nn_assert_state (self, NN_FSM_STATE_STOPPING); + self->state = NN_FSM_STATE_IDLE; +} + +void nn_fsm_swap_owner (struct nn_fsm *self, struct nn_fsm_owner *owner) +{ + int oldsrc; + struct nn_fsm *oldowner; + + oldsrc = self->src; + oldowner = self->owner; + self->src = owner->src; + self->owner = owner->fsm; + owner->src = oldsrc; + owner->fsm = oldowner; +} + +struct nn_worker *nn_fsm_choose_worker (struct nn_fsm *self) +{ + return nn_ctx_choose_worker (self->ctx); +} + +void nn_fsm_action (struct nn_fsm *self, int type) +{ + nn_assert (type > 0); + nn_fsm_feed (self, NN_FSM_ACTION, type, NULL); +} + +void nn_fsm_raise (struct nn_fsm *self, struct nn_fsm_event *event, int type) +{ + event->fsm = self->owner; + event->src = self->src; + event->srcptr = self->srcptr; + event->type = type; + nn_ctx_raise (self->ctx, event); +} + +void nn_fsm_raiseto (struct nn_fsm *self, struct nn_fsm *dst, + struct nn_fsm_event *event, int src, int type, void *srcptr) +{ + event->fsm = dst; + event->src = src; + event->srcptr = srcptr; + event->type = type; + nn_ctx_raiseto (self->ctx, event); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/fsm.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/fsm.h new file mode 100644 index 0000000..19eca1a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/fsm.h @@ -0,0 +1,117 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_FSM_INCLUDED +#define NN_FSM_INCLUDED + +#include "../utils/queue.h" + +/* Base class for state machines. */ + +struct nn_ctx; +struct nn_fsm; +struct nn_worker; + +struct nn_fsm_event { + struct nn_fsm *fsm; + int src; + void *srcptr; + int type; + struct nn_queue_item item; +}; + +void nn_fsm_event_init (struct nn_fsm_event *self); +void nn_fsm_event_term (struct nn_fsm_event *self); +int nn_fsm_event_active (struct nn_fsm_event *self); +void nn_fsm_event_process (struct nn_fsm_event *self); + +/* Special source for actions. It's negative not to clash with user-defined + sources. */ +#define NN_FSM_ACTION -2 + +/* Actions generated by fsm object. The values are negative not to clash + with user-defined actions. */ +#define NN_FSM_START -2 +#define NN_FSM_STOP -3 + +/* Virtual function to be implemented by the derived class to handle the + incoming events. */ +typedef void (*nn_fsm_fn) (struct nn_fsm *self, int src, int type, + void *srcptr); + +struct nn_fsm_owner { + int src; + struct nn_fsm *fsm; +}; + +struct nn_fsm { + nn_fsm_fn fn; + nn_fsm_fn shutdown_fn; + int state; + int src; + void *srcptr; + struct nn_fsm *owner; + struct nn_ctx *ctx; + struct nn_fsm_event stopped; +}; + +void nn_fsm_init_root (struct nn_fsm *self, nn_fsm_fn fn, + nn_fsm_fn shutdown_fn, struct nn_ctx *ctx); +void nn_fsm_init (struct nn_fsm *self, nn_fsm_fn fn, + nn_fsm_fn shutdown_fn, + int src, void *srcptr, struct nn_fsm *owner); +void nn_fsm_term (struct nn_fsm *self); + +int nn_fsm_isidle (struct nn_fsm *self); +void nn_fsm_start (struct nn_fsm *self); +void nn_fsm_stop (struct nn_fsm *self); +void nn_fsm_stopped (struct nn_fsm *self, int type); +void nn_fsm_stopped_noevent (struct nn_fsm *self); + +/* Replaces current owner of the fsm by the owner speicified by 'owner' + parameter. The parameter will hold the old owner afrer the call. */ +void nn_fsm_swap_owner (struct nn_fsm *self, struct nn_fsm_owner *owner); + +struct nn_worker *nn_fsm_choose_worker (struct nn_fsm *self); + +/* Using this function state machine can trigger an action on itself. */ +void nn_fsm_action (struct nn_fsm *self, int type); + +/* Send event from the state machine to its owner. */ +void nn_fsm_raise (struct nn_fsm *self, struct nn_fsm_event *event, int type); + + +/* Send event to the specified state machine. It's caller's responsibility + to ensure that the destination state machine will still exist when the + event is delivered. + NOTE: This function is a hack to make inproc transport work in the most + efficient manner. Do not use it outside of inproc transport! */ +void nn_fsm_raiseto (struct nn_fsm *self, struct nn_fsm *dst, + struct nn_fsm_event *event, int src, int type, void *srcptr); + +/* This function is very lowlevel action feeding + Used in worker threads and timers, shouldn't be used by others + use nn_fsm_action/nn_fsm_raise/nn_fsm_raiseto instread*/ +void nn_fsm_feed (struct nn_fsm *self, int src, int type, void *srcptr); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller.c new file mode 100644 index 0000000..4e911f2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller.c @@ -0,0 +1,34 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "poller.h" + +#if defined NN_USE_EPOLL + #include "poller_epoll.inc" +#elif defined NN_USE_KQUEUE + #include "poller_kqueue.inc" +#elif defined NN_USE_POLL + #include "poller_poll.inc" +#else + #error +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller.h new file mode 100644 index 0000000..bcb8f95 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller.h @@ -0,0 +1,54 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_POLLER_INCLUDED +#define NN_POLLER_INCLUDED + +#define NN_POLLER_IN 1 +#define NN_POLLER_OUT 2 +#define NN_POLLER_ERR 3 + +#if defined NN_USE_EPOLL + #include "poller_epoll.h" +#elif defined NN_USE_KQUEUE + #include "poller_kqueue.h" +#elif defined NN_USE_POLL + #include "poller_poll.h" +#else + #error +#endif + +int nn_poller_init (struct nn_poller *self); +void nn_poller_term (struct nn_poller *self); +void nn_poller_add (struct nn_poller *self, int fd, + struct nn_poller_hndl *hndl); +void nn_poller_rm (struct nn_poller *self, struct nn_poller_hndl *hndl); +void nn_poller_set_in (struct nn_poller *self, struct nn_poller_hndl *hndl); +void nn_poller_reset_in (struct nn_poller *self, struct nn_poller_hndl *hndl); +void nn_poller_set_out (struct nn_poller *self, struct nn_poller_hndl *hndl); +void nn_poller_reset_out (struct nn_poller *self, struct nn_poller_hndl *hndl); +int nn_poller_wait (struct nn_poller *self, int timeout); +int nn_poller_event (struct nn_poller *self, int *event, + struct nn_poller_hndl **hndl); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_epoll.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_epoll.h new file mode 100644 index 0000000..6d8c7bf --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_epoll.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include +#include +#include + +#define NN_POLLER_HAVE_ASYNC_ADD 1 + +#define NN_POLLER_MAX_EVENTS 32 + +struct nn_poller_hndl { + int fd; + uint32_t events; +}; + +struct nn_poller { + + /* Current pollset. */ + int ep; + + /* Number of events being processed at the moment. */ + int nevents; + + /* Index of the event being processed at the moment. */ + int index; + + /* Events being processed at the moment. */ + struct epoll_event events [NN_POLLER_MAX_EVENTS]; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_epoll.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_epoll.inc new file mode 100644 index 0000000..3b566f1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_epoll.inc @@ -0,0 +1,219 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../utils/fast.h" +#include "../utils/err.h" +#include "../utils/closefd.h" + +#include +#include +#include + +int nn_poller_init (struct nn_poller *self) +{ +#ifndef EPOLL_CLOEXEC + int rc; +#endif + +#ifdef EPOLL_CLOEXEC + self->ep = epoll_create1 (EPOLL_CLOEXEC); +#else + /* Size parameter is unused, we can safely set it to 1. */ + self->ep = epoll_create (1); + rc = fcntl (self->ep, F_SETFD, FD_CLOEXEC); + errno_assert (rc != -1); +#endif + if (self->ep == -1) { + if (errno == ENFILE || errno == EMFILE) + return -EMFILE; + errno_assert (0); + } + self->nevents = 0; + self->index = 0; + + return 0; +} + +void nn_poller_term (struct nn_poller *self) +{ + nn_closefd (self->ep); +} + +void nn_poller_add (struct nn_poller *self, int fd, + struct nn_poller_hndl *hndl) +{ + int rc; + struct epoll_event ev; + + /* Initialise the handle and add the file descriptor to the pollset. */ + hndl->fd = fd; + hndl->events = 0; + memset (&ev, 0, sizeof (ev)); + ev.events = 0; + ev.data.ptr = (void*) hndl; + epoll_ctl (self->ep, EPOLL_CTL_ADD, fd, &ev); +} + +void nn_poller_rm (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int i; + + /* Remove the file descriptor from the pollset. */ + epoll_ctl (self->ep, EPOLL_CTL_DEL, hndl->fd, NULL); + + /* Invalidate any subsequent events on this file descriptor. */ + for (i = self->index; i != self->nevents; ++i) + if (self->events [i].data.ptr == hndl) + self->events [i].events = 0; +} + +void nn_poller_set_in (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + struct epoll_event ev; + + /* If already polling for IN, do nothing. */ + if (nn_slow (hndl->events & EPOLLIN)) + return; + + /* Start polling for IN. */ + hndl->events |= EPOLLIN; + memset (&ev, 0, sizeof (ev)); + ev.events = hndl->events; + ev.data.ptr = (void*) hndl; + epoll_ctl (self->ep, EPOLL_CTL_MOD, hndl->fd, &ev); +} + +void nn_poller_reset_in (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int i; + struct epoll_event ev; + + /* If not polling for IN, do nothing. */ + if (nn_slow (!(hndl->events & EPOLLIN))) + return; + + /* Stop polling for IN. */ + hndl->events &= ~EPOLLIN; + memset (&ev, 0, sizeof (ev)); + ev.events = hndl->events; + ev.data.ptr = (void*) hndl; + epoll_ctl (self->ep, EPOLL_CTL_MOD, hndl->fd, &ev); + + /* Invalidate any subsequent IN events on this file descriptor. */ + for (i = self->index; i != self->nevents; ++i) + if (self->events [i].data.ptr == hndl) + self->events [i].events &= ~EPOLLIN; +} + +void nn_poller_set_out (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + struct epoll_event ev; + int fd = hndl->fd; + + /* If already polling for OUT, do nothing. */ + if (nn_slow (hndl->events & EPOLLOUT)) + return; + + /* Start polling for OUT. */ + hndl->events |= EPOLLOUT; + memset (&ev, 0, sizeof (ev)); + ev.events = hndl->events; + ev.data.ptr = (void*) hndl; + epoll_ctl (self->ep, EPOLL_CTL_MOD, fd, &ev); +} + +void nn_poller_reset_out (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int i; + struct epoll_event ev; + + /* If not polling for OUT, do nothing. */ + if (nn_slow (!(hndl->events & EPOLLOUT))) + return; + + /* Stop polling for OUT. */ + hndl->events &= ~EPOLLOUT; + memset (&ev, 0, sizeof (ev)); + ev.events = hndl->events; + ev.data.ptr = (void*) hndl; + epoll_ctl (self->ep, EPOLL_CTL_MOD, hndl->fd, &ev); + + /* Invalidate any subsequent OUT events on this file descriptor. */ + for (i = self->index; i != self->nevents; ++i) + if (self->events [i].data.ptr == hndl) + self->events [i].events &= ~EPOLLOUT; +} + +int nn_poller_wait (struct nn_poller *self, int timeout) +{ + int nevents; + + /* Clear all existing events. */ + self->nevents = 0; + self->index = 0; + + /* Wait for new events. */ + while (1) { + nevents = epoll_wait (self->ep, self->events, + NN_POLLER_MAX_EVENTS, timeout); + if (nn_slow (nevents == -1 && errno == EINTR)) + continue; + break; + } + errno_assert (self->nevents != -1); + self->nevents = nevents; + return 0; +} + +int nn_poller_event (struct nn_poller *self, int *event, + struct nn_poller_hndl **hndl) +{ + /* Skip over empty events. */ + while (self->index < self->nevents) { + if (self->events [self->index].events != 0) + break; + ++self->index; + } + + /* If there is no stored event, let the caller know. */ + if (nn_slow (self->index >= self->nevents)) + return -EAGAIN; + + /* Return next event to the caller. Remove the event from the set. */ + *hndl = (struct nn_poller_hndl*) self->events [self->index].data.ptr; + if (nn_fast (self->events [self->index].events & EPOLLIN)) { + *event = NN_POLLER_IN; + self->events [self->index].events &= ~EPOLLIN; + return 0; + } + else if (nn_fast (self->events [self->index].events & EPOLLOUT)) { + *event = NN_POLLER_OUT; + self->events [self->index].events &= ~EPOLLOUT; + return 0; + } + else { + *event = NN_POLLER_ERR; + ++self->index; + return 0; + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_kqueue.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_kqueue.h new file mode 100644 index 0000000..62eb33c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_kqueue.h @@ -0,0 +1,51 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include +#include +#include + +#define NN_POLLER_MAX_EVENTS 32 + +#define NN_POLLER_EVENT_IN 1 +#define NN_POLLER_EVENT_OUT 2 + +struct nn_poller_hndl { + int fd; + int events; +}; + +struct nn_poller { + + /* Current pollset. */ + int kq; + + /* Number of events being processed at the moment. */ + int nevents; + + /* Index of the event being processed at the moment. */ + int index; + + /* Cached events. */ + struct kevent events [NN_POLLER_MAX_EVENTS]; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_kqueue.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_kqueue.inc new file mode 100644 index 0000000..eaf94e5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_kqueue.inc @@ -0,0 +1,211 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../utils/attr.h" +#include "../utils/fast.h" +#include "../utils/err.h" +#include "../utils/closefd.h" + +#include + +/* NetBSD has different definition of udata. */ +#if defined NN_HAVE_NETBSD +#define nn_poller_udata intptr_t +#else +#define nn_poller_udata void* +#endif + +int nn_poller_init (struct nn_poller *self) +{ + self->kq = kqueue (); + if (self->kq == -1) { + if (errno == ENFILE || errno == EMFILE) + return -EMFILE; + errno_assert (0); + } + self->nevents = 0; + self->index = 0; + + return 0; +} + +void nn_poller_term (struct nn_poller *self) +{ + nn_closefd (self->kq); +} + +void nn_poller_add (NN_UNUSED struct nn_poller *self, int fd, + struct nn_poller_hndl *hndl) +{ + /* Initialise the handle. */ + hndl->fd = fd; + hndl->events = 0; +} + +void nn_poller_rm (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + struct kevent ev; + int i; + + if (hndl->events & NN_POLLER_EVENT_IN) { + EV_SET (&ev, hndl->fd, EVFILT_READ, EV_DELETE, 0, 0, 0); + kevent (self->kq, &ev, 1, NULL, 0, NULL); + } + + if (hndl->events & NN_POLLER_EVENT_OUT) { + EV_SET (&ev, hndl->fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0); + kevent (self->kq, &ev, 1, NULL, 0, NULL); + } + + /* Invalidate any subsequent events on this file descriptor. */ + for (i = self->index; i != self->nevents; ++i) + if (self->events [i].ident == (unsigned) hndl->fd) + self->events [i].udata = (nn_poller_udata) NULL; +} + +void nn_poller_set_in (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int rc; + struct kevent ev; + + if (!(hndl->events & NN_POLLER_EVENT_IN)) { + EV_SET (&ev, hndl->fd, EVFILT_READ, EV_ADD, 0, 0, + (nn_poller_udata) hndl); + rc = kevent (self->kq, &ev, 1, NULL, 0, NULL); + if (rc != -1) + hndl->events |= NN_POLLER_EVENT_IN; + } +} + +void nn_poller_reset_in (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int rc; + struct kevent ev; + int i; + + if (hndl->events & NN_POLLER_EVENT_IN) { + EV_SET (&ev, hndl->fd, EVFILT_READ, EV_DELETE, 0, 0, 0); + rc = kevent (self->kq, &ev, 1, NULL, 0, NULL); + hndl->events &= ~NN_POLLER_EVENT_IN; + } + + /* Invalidate any subsequent IN events on this file descriptor. */ + for (i = self->index; i != self->nevents; ++i) + if (self->events [i].ident == (unsigned) hndl->fd && + self->events [i].filter == EVFILT_READ) + self->events [i].udata = (nn_poller_udata) NULL; +} + +void nn_poller_set_out (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int rc; + struct kevent ev; + int fd = hndl->fd; + + if (!(hndl->events & NN_POLLER_EVENT_OUT)) { + EV_SET (&ev, fd, EVFILT_WRITE, EV_ADD, 0, 0, (nn_poller_udata) hndl); + rc = kevent (self->kq, &ev, 1, NULL, 0, NULL); + if (rc != -1) + hndl->events |= NN_POLLER_EVENT_OUT; + } +} + +void nn_poller_reset_out (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + int rc; + struct kevent ev; + int i; + int fd = hndl->fd; + + if (hndl->events & NN_POLLER_EVENT_OUT) { + EV_SET (&ev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0); + rc = kevent (self->kq, &ev, 1, NULL, 0, NULL); + if (rc != -1) { + hndl->events &= ~NN_POLLER_EVENT_OUT; + } + } + + /* Invalidate any subsequent OUT events on this file descriptor. */ + for (i = self->index; i != self->nevents; ++i) + if (self->events [i].ident == (unsigned) hndl->fd && + self->events [i].filter == EVFILT_WRITE) + self->events [i].udata = (nn_poller_udata) NULL; +} + +int nn_poller_wait (struct nn_poller *self, int timeout) +{ + struct timespec ts; + int nevents; + + /* Clear all existing events. */ + self->nevents = 0; + self->index = 0; + + /* Wait for new events. */ +#if defined NN_IGNORE_EINTR +again: +#endif + ts.tv_sec = timeout / 1000; + ts.tv_nsec = (timeout % 1000) * 1000000; + nevents = kevent (self->kq, NULL, 0, &self->events [0], + NN_POLLER_MAX_EVENTS, timeout >= 0 ? &ts : NULL); + if (nevents == -1 && errno == EINTR) +#if defined NN_IGNORE_EINTR + goto again; +#else + return -EINTR; +#endif + errno_assert (nevents != -1); + + self->nevents = nevents; + return 0; +} + +int nn_poller_event (struct nn_poller *self, int *event, + struct nn_poller_hndl **hndl) +{ + /* Skip over empty events. */ + while (self->index < self->nevents) { + if (self->events [self->index].udata) + break; + ++self->index; + } + + /* If there is no stored event, let the caller know. */ + if (nn_slow (self->index >= self->nevents)) + return -EAGAIN; + + /* Return next event to the caller. Remove the event from the set. */ + *hndl = (struct nn_poller_hndl*) self->events [self->index].udata; + if (self->events [self->index].flags & EV_EOF) + *event = NN_POLLER_ERR; + else if (self->events [self->index].filter == EVFILT_WRITE) + *event = NN_POLLER_OUT; + else if (self->events [self->index].filter == EVFILT_READ) + *event = NN_POLLER_IN; + else + nn_assert (0); + ++self->index; + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_poll.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_poll.h new file mode 100644 index 0000000..31fcadb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_poll.h @@ -0,0 +1,57 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include + +#define NN_POLLER_HAVE_ASYNC_ADD 0 + +struct nn_poller_hndl { + int index; +}; + +struct nn_poller { + + /* Actual number of elements in the pollset. */ + int size; + + /* Index of the event being processed at the moment. */ + int index; + + /* Number of allocated elements in the pollset. */ + int capacity; + + /* The pollset. */ + struct pollfd *pollset; + + /* List of handles associated with elements in the pollset. Either points + to the handle associated with the file descriptor (hndl) or is part + of the list of removed pollitems (removed). */ + struct nn_hndls_item { + struct nn_poller_hndl *hndl; + int prev; + int next; + } *hndls; + + /* List of removed pollitems, linked by indices. -1 means empty list. */ + int removed; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_poll.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_poll.inc new file mode 100644 index 0000000..a0959aa --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/poller_poll.inc @@ -0,0 +1,200 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../utils/alloc.h" +#include "../utils/err.h" + +#define NN_POLLER_GRANULARITY 16 + +int nn_poller_init (struct nn_poller *self) +{ + self->size = 0; + self->index = 0; + self->capacity = NN_POLLER_GRANULARITY; + self->pollset = + nn_alloc (sizeof (struct pollfd) * NN_POLLER_GRANULARITY, + "pollset"); + alloc_assert (self->pollset); + self->hndls = + nn_alloc (sizeof (struct nn_hndls_item) * NN_POLLER_GRANULARITY, + "hndlset"); + alloc_assert (self->hndls); + self->removed = -1; + + return 0; +} + +void nn_poller_term (struct nn_poller *self) +{ + nn_free (self->pollset); + nn_free (self->hndls); +} + +void nn_poller_add (struct nn_poller *self, int fd, + struct nn_poller_hndl *hndl) +{ + int rc; + + /* If the capacity is too low to accommodate the next item, resize it. */ + if (nn_slow (self->size >= self->capacity)) { + self->capacity *= 2; + self->pollset = nn_realloc (self->pollset, + sizeof (struct pollfd) * self->capacity); + alloc_assert (self->pollset); + self->hndls = nn_realloc (self->hndls, + sizeof (struct nn_hndls_item) * self->capacity); + alloc_assert (self->hndls); + } + + /* Add the fd to the pollset. */ + self->pollset [self->size].fd = fd; + self->pollset [self->size].events = 0; + self->pollset [self->size].revents = 0; + hndl->index = self->size; + self->hndls [self->size].hndl = hndl; + ++self->size; +} + +void nn_poller_rm (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + /* No more events will be reported on this fd. */ + self->pollset [hndl->index].revents = 0; + + /* Add the fd into the list of removed fds. */ + if (self->removed != -1) + self->hndls [self->removed].prev = hndl->index; + self->hndls [hndl->index].hndl = NULL; + self->hndls [hndl->index].prev = -1; + self->hndls [hndl->index].next = self->removed; + self->removed = hndl->index; +} + +void nn_poller_set_in (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + self->pollset [hndl->index].events |= POLLIN; +} + +void nn_poller_reset_in (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + self->pollset [hndl->index].events &= ~POLLIN; + self->pollset [hndl->index].revents &= ~POLLIN; +} + +void nn_poller_set_out (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + self->pollset [hndl->index].events |= POLLOUT; +} + +void nn_poller_reset_out (struct nn_poller *self, struct nn_poller_hndl *hndl) +{ + self->pollset [hndl->index].events &= ~POLLOUT; + self->pollset [hndl->index].revents &= ~POLLOUT; +} + +int nn_poller_wait (struct nn_poller *self, int timeout) +{ + int rc; + int i; + + /* First, get rid of removed fds. */ + while (self->removed != -1) { + + /* Remove the fd from the list of removed fds. */ + i = self->removed; + self->removed = self->hndls [i].next; + + /* Replace the removed fd by the one at the end of the pollset. */ + --self->size; + if (i != self->size) { + self->pollset [i] = self->pollset [self->size]; + if (self->hndls [i].next != -1) + self->hndls [self->hndls [i].next].prev = -1; + self->hndls [i] = self->hndls [self->size]; + if (self->hndls [i].hndl) + self->hndls [i].hndl->index = i; + } + + /* The fd from the end of the pollset may have been on removed fds + list itself. If so, adjust the removed list. */ + if (nn_slow (!self->hndls [i].hndl)) { + if (self->hndls [i].prev != -1) + self->hndls [self->hndls [i].prev].next = i; + if (self->hndls [i].next != -1) + self->hndls [self->hndls [i].next].prev = i; + if (self->removed == self->size) + self->removed = i; + } + } + + self->index = 0; + + /* Wait for new events. */ +#if defined NN_IGNORE_EINTR +again: +#endif + rc = poll (self->pollset, self->size, timeout); + if (nn_slow (rc < 0 && errno == EINTR)) +#if defined NN_IGNORE_EINTR + goto again; +#else + return -EINTR; +#endif + errno_assert (rc >= 0); + return 0; +} + +int nn_poller_event (struct nn_poller *self, int *event, + struct nn_poller_hndl **hndl) +{ + int rc; + + /* Skip over empty events. This will also skip over removed fds as they + have their revents nullified. */ + while (self->index < self->size) { + if (self->pollset [self->index].revents != 0) + break; + ++self->index; + } + + /* If there is no available event, let the caller know. */ + if (nn_slow (self->index >= self->size)) + return -EAGAIN; + + /* Return next event to the caller. Remove the event from revents. */ + *hndl = self->hndls [self->index].hndl; + if (nn_fast (self->pollset [self->index].revents & POLLIN)) { + *event = NN_POLLER_IN; + self->pollset [self->index].revents &= ~POLLIN; + return 0; + } + else if (nn_fast (self->pollset [self->index].revents & POLLOUT)) { + *event = NN_POLLER_OUT; + self->pollset [self->index].revents &= ~POLLOUT; + return 0; + } + else { + *event = NN_POLLER_ERR; + ++self->index; + return 0; + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/pool.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/pool.c new file mode 100644 index 0000000..0fe1db2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/pool.c @@ -0,0 +1,41 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "pool.h" + +/* TODO: The dummy implementation of a thread pool. As for now there's only + one worker thread created. */ + +int nn_pool_init (struct nn_pool *self) +{ + return nn_worker_init (&self->worker); +} + +void nn_pool_term (struct nn_pool *self) +{ + nn_worker_term (&self->worker); +} + +struct nn_worker *nn_pool_choose_worker (struct nn_pool *self) +{ + return &self->worker; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/pool.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/pool.h new file mode 100644 index 0000000..c5b33e6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/pool.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_POOL_INCLUDED +#define NN_POOL_INCLUDED + +#include "worker.h" + +/* Worker thread pool. */ + +struct nn_pool { + struct nn_worker worker; +}; + +int nn_pool_init (struct nn_pool *self); +void nn_pool_term (struct nn_pool *self); +struct nn_worker *nn_pool_choose_worker (struct nn_pool *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/timer.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timer.c new file mode 100644 index 0000000..73ba604 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timer.c @@ -0,0 +1,178 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "timer.h" + +#include "../utils/cont.h" +#include "../utils/fast.h" +#include "../utils/err.h" +#include "../utils/attr.h" + +/* Timer state reflects the state as seen by the user thread. It says nothing + about the state of affairs in the worker thread. */ +#define NN_TIMER_STATE_IDLE 1 +#define NN_TIMER_STATE_ACTIVE 2 +#define NN_TIMER_STATE_STOPPING 3 + +#define NN_TIMER_SRC_START_TASK 1 +#define NN_TIMER_SRC_STOP_TASK 2 + +/* Private functions. */ +static void nn_timer_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_timer_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_timer_init (struct nn_timer *self, int src, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_timer_handler, nn_timer_shutdown, + src, self, owner); + self->state = NN_TIMER_STATE_IDLE; + nn_worker_task_init (&self->start_task, NN_TIMER_SRC_START_TASK, + &self->fsm); + nn_worker_task_init (&self->stop_task, NN_TIMER_SRC_STOP_TASK, &self->fsm); + nn_worker_timer_init (&self->wtimer, &self->fsm); + nn_fsm_event_init (&self->done); + self->worker = nn_fsm_choose_worker (&self->fsm); + self->timeout = -1; +} + +void nn_timer_term (struct nn_timer *self) +{ + nn_assert_state (self, NN_TIMER_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_worker_timer_term (&self->wtimer); + nn_worker_task_term (&self->stop_task); + nn_worker_task_term (&self->start_task); + nn_fsm_term (&self->fsm); +} + +int nn_timer_isidle (struct nn_timer *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_timer_start (struct nn_timer *self, int timeout) +{ + /* Negative timeout make no sense. */ + nn_assert (timeout >= 0); + + self->timeout = timeout; + nn_fsm_start (&self->fsm); +} + +void nn_timer_stop (struct nn_timer *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_timer_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_timer *timer; + + timer = nn_cont (self, struct nn_timer, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + timer->state = NN_TIMER_STATE_STOPPING; + nn_worker_execute (timer->worker, &timer->stop_task); + return; + } + if (nn_slow (timer->state == NN_TIMER_STATE_STOPPING)) { + if (src != NN_TIMER_SRC_STOP_TASK) + return; + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_rm_timer (timer->worker, &timer->wtimer); + timer->state = NN_TIMER_STATE_IDLE; + nn_fsm_stopped (&timer->fsm, NN_TIMER_STOPPED); + return; + } + + nn_fsm_bad_state(timer->state, src, type); +} + +static void nn_timer_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_timer *timer; + + timer = nn_cont (self, struct nn_timer, fsm); + + switch (timer->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_TIMER_STATE_IDLE: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + + /* Send start event to the worker thread. */ + timer->state = NN_TIMER_STATE_ACTIVE; + nn_worker_execute (timer->worker, &timer->start_task); + return; + default: + nn_fsm_bad_action (timer->state, src, type); + } + default: + nn_fsm_bad_source (timer->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_TIMER_STATE_ACTIVE: + if (src == NN_TIMER_SRC_START_TASK) { + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_assert (timer->timeout >= 0); + nn_worker_add_timer (timer->worker, timer->timeout, + &timer->wtimer); + timer->timeout = -1; + return; + } + if (srcptr == &timer->wtimer) { + switch (type) { + case NN_WORKER_TIMER_TIMEOUT: + + /* Notify the user about the timeout. */ + nn_assert (timer->timeout == -1); + nn_fsm_raise (&timer->fsm, &timer->done, NN_TIMER_TIMEOUT); + return; + + default: + nn_fsm_bad_action (timer->state, src, type); + } + } + nn_fsm_bad_source (timer->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (timer->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/timer.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timer.h new file mode 100644 index 0000000..52ad3aa --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timer.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_TIMER_INCLUDED +#define NN_TIMER_INCLUDED + +#include "fsm.h" +#include "worker.h" + +#define NN_TIMER_TIMEOUT 1 +#define NN_TIMER_STOPPED 2 + +struct nn_timer { + struct nn_fsm fsm; + int state; + struct nn_worker_task start_task; + struct nn_worker_task stop_task; + struct nn_worker_timer wtimer; + struct nn_fsm_event done; + struct nn_worker *worker; + int timeout; +}; + +void nn_timer_init (struct nn_timer *self, int src, struct nn_fsm *owner); +void nn_timer_term (struct nn_timer *self); + +int nn_timer_isidle (struct nn_timer *self); +void nn_timer_start (struct nn_timer *self, int timeout); +void nn_timer_stop (struct nn_timer *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/timerset.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timerset.c new file mode 100644 index 0000000..dac23ea --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timerset.c @@ -0,0 +1,128 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "timerset.h" + +#include "../utils/fast.h" +#include "../utils/cont.h" +#include "../utils/clock.h" +#include "../utils/err.h" + +void nn_timerset_init (struct nn_timerset *self) +{ + nn_list_init (&self->timeouts); +} + +void nn_timerset_term (struct nn_timerset *self) +{ + nn_list_term (&self->timeouts); +} + +int nn_timerset_add (struct nn_timerset *self, int timeout, + struct nn_timerset_hndl *hndl) +{ + struct nn_list_item *it; + struct nn_timerset_hndl *ith; + int first; + + /* Compute the instant when the timeout will be due. */ + hndl->timeout = nn_clock_ms() + timeout; + + /* Insert it into the ordered list of timeouts. */ + for (it = nn_list_begin (&self->timeouts); + it != nn_list_end (&self->timeouts); + it = nn_list_next (&self->timeouts, it)) { + ith = nn_cont (it, struct nn_timerset_hndl, list); + if (hndl->timeout < ith->timeout) + break; + } + + /* If the new timeout happens to be the first one to expire, let the user + know that the current waiting interval has to be changed. */ + first = nn_list_begin (&self->timeouts) == it ? 1 : 0; + nn_list_insert (&self->timeouts, &hndl->list, it); + return first; +} + +int nn_timerset_rm (struct nn_timerset *self, struct nn_timerset_hndl *hndl) +{ + int first; + + /* Ignore if handle is not in the timeouts list. */ + if (!nn_list_item_isinlist (&hndl->list)) + return 0; + + /* If it was the first timeout that was removed, the actual waiting time + may have changed. We'll thus return 1 to let the user know. */ + first = nn_list_begin (&self->timeouts) == &hndl->list ? 1 : 0; + nn_list_erase (&self->timeouts, &hndl->list); + return first; +} + +int nn_timerset_timeout (struct nn_timerset *self) +{ + int timeout; + + if (nn_fast (nn_list_empty (&self->timeouts))) + return -1; + + timeout = (int) (nn_cont (nn_list_begin (&self->timeouts), + struct nn_timerset_hndl, list)->timeout - nn_clock_ms()); + return timeout < 0 ? 0 : timeout; +} + +int nn_timerset_event (struct nn_timerset *self, struct nn_timerset_hndl **hndl) +{ + struct nn_timerset_hndl *first; + + /* If there's no timeout, there's no event to report. */ + if (nn_fast (nn_list_empty (&self->timeouts))) + return -EAGAIN; + + /* If no timeout have expired yet, there's no event to return. */ + first = nn_cont (nn_list_begin (&self->timeouts), + struct nn_timerset_hndl, list); + if (first->timeout > nn_clock_ms()) + return -EAGAIN; + + /* Return the first timeout and remove it from the list of active + timeouts. */ + nn_list_erase (&self->timeouts, &first->list); + *hndl = first; + return 0; +} + +void nn_timerset_hndl_init (struct nn_timerset_hndl *self) +{ + nn_list_item_init (&self->list); +} + +void nn_timerset_hndl_term (struct nn_timerset_hndl *self) +{ + nn_list_item_term (&self->list); +} + +int nn_timerset_hndl_isactive (struct nn_timerset_hndl *self) +{ + return nn_list_item_isinlist (&self->list); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/timerset.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timerset.h new file mode 100644 index 0000000..d3ec5c1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/timerset.h @@ -0,0 +1,55 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_TIMERSET_INCLUDED +#define NN_TIMERSET_INCLUDED + +#include + +#include "../utils/list.h" + +/* This class stores a list of timeouts and reports the next one to expire + along with the time till it happens. */ + +struct nn_timerset_hndl { + struct nn_list_item list; + uint64_t timeout; +}; + +struct nn_timerset { + struct nn_list timeouts; +}; + +void nn_timerset_init (struct nn_timerset *self); +void nn_timerset_term (struct nn_timerset *self); +int nn_timerset_add (struct nn_timerset *self, int timeout, + struct nn_timerset_hndl *hndl); +int nn_timerset_rm (struct nn_timerset *self, struct nn_timerset_hndl *hndl); +int nn_timerset_timeout (struct nn_timerset *self); +int nn_timerset_event (struct nn_timerset *self, struct nn_timerset_hndl **hndl); + +void nn_timerset_hndl_init (struct nn_timerset_hndl *self); +void nn_timerset_hndl_term (struct nn_timerset_hndl *self); +int nn_timerset_hndl_isactive (struct nn_timerset_hndl *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock.c new file mode 100644 index 0000000..ed78062 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock.c @@ -0,0 +1,33 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "usock.h" + +#if defined NN_HAVE_WINDOWS +#include "usock_win.inc" +#else +#include "usock_posix.inc" +#endif + +int nn_usock_geterrno (struct nn_usock *self) { + return self->errnum; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock.h new file mode 100644 index 0000000..6a92e58 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock.h @@ -0,0 +1,94 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_USOCK_INCLUDED +#define NN_USOCK_INCLUDED + +/* Import the definition of nn_iovec. */ +#include "../nn.h" + +/* OS-level sockets. */ + +/* Event types generated by nn_usock. */ +#define NN_USOCK_CONNECTED 1 +#define NN_USOCK_ACCEPTED 2 +#define NN_USOCK_SENT 3 +#define NN_USOCK_RECEIVED 4 +#define NN_USOCK_ERROR 5 +#define NN_USOCK_ACCEPT_ERROR 6 +#define NN_USOCK_STOPPED 7 +#define NN_USOCK_SHUTDOWN 8 + +/* Maximum number of iovecs that can be passed to nn_usock_send function. */ +#define NN_USOCK_MAX_IOVCNT 3 + +/* Size of the buffer used for batch-reads of inbound data. To keep the + performance optimal make sure that this value is larger than network MTU. */ +#define NN_USOCK_BATCH_SIZE 2048 + +#if defined NN_HAVE_WINDOWS +#include "usock_win.h" +#else +#include "usock_posix.h" +#endif + +void nn_usock_init (struct nn_usock *self, int src, struct nn_fsm *owner); +void nn_usock_term (struct nn_usock *self); + +int nn_usock_isidle (struct nn_usock *self); +int nn_usock_start (struct nn_usock *self, + int domain, int type, int protocol); +void nn_usock_start_fd (struct nn_usock *self, int fd); +void nn_usock_stop (struct nn_usock *self); + +void nn_usock_swap_owner (struct nn_usock *self, struct nn_fsm_owner *owner); + +int nn_usock_setsockopt (struct nn_usock *self, int level, int optname, + const void *optval, size_t optlen); + +int nn_usock_bind (struct nn_usock *self, const struct sockaddr *addr, + size_t addrlen); +int nn_usock_listen (struct nn_usock *self, int backlog); + +/* Accept a new connection from a listener. When done, NN_USOCK_ACCEPTED + event will be delivered to the accepted socket. To cancel the operation, + stop the socket being accepted. Listening socket should not be stopped + while accepting a new socket is underway. */ +void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener); + +/* When all the tuning is done on the accepted socket, call this function + to activate standard data transfer phase. */ +void nn_usock_activate (struct nn_usock *self); + +/* Start connecting. Prior to this call the socket has to be bound to a local + address. When connecting is done NN_USOCK_CONNECTED event will be reaised. + If connecting fails NN_USOCK_ERROR event will be raised. */ +void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, + size_t addrlen); + +void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, + int iovcnt); +void nn_usock_recv (struct nn_usock *self, void *buf, size_t len, int *fd); + +int nn_usock_geterrno (struct nn_usock *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_posix.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_posix.h new file mode 100644 index 0000000..db288e6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_posix.h @@ -0,0 +1,95 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "fsm.h" +#include "worker.h" + +#include +#include +#include + +struct nn_usock { + + /* State machine base class. */ + struct nn_fsm fsm; + int state; + + /* The worker thread the usock is associated with. */ + struct nn_worker *worker; + + /* The underlying OS socket and handle that represents it in the poller. */ + int s; + struct nn_worker_fd wfd; + + /* Members related to receiving data. */ + struct { + + /* The buffer being filled in at the moment. */ + uint8_t *buf; + size_t len; + + /* Buffer for batch-reading inbound data. */ + uint8_t *batch; + + /* Size of the batch buffer. */ + size_t batch_len; + + /* Current position in the batch buffer. The data preceding this + position were already received by the user. The data that follow + will be received in the future. */ + size_t batch_pos; + + /* File descriptor received via SCM_RIGHTS, if any. */ + int *pfd; + } in; + + /* Members related to sending data. */ + struct { + + /* msghdr being sent at the moment. */ + struct msghdr hdr; + + /* List of buffers being sent at the moment. Referenced from 'hdr'. */ + struct iovec iov [NN_USOCK_MAX_IOVCNT]; + } out; + + /* Asynchronous tasks for the worker. */ + struct nn_worker_task task_connecting; + struct nn_worker_task task_connected; + struct nn_worker_task task_accept; + struct nn_worker_task task_send; + struct nn_worker_task task_recv; + struct nn_worker_task task_stop; + + /* Events raised by the usock. */ + struct nn_fsm_event event_established; + struct nn_fsm_event event_sent; + struct nn_fsm_event event_received; + struct nn_fsm_event event_error; + + /* In ACCEPTING state points to the socket being accepted. + In BEING_ACCEPTED state points to the listener socket. */ + struct nn_usock *asock; + + /* Errno remembered in NN_USOCK_ERROR state */ + int errnum; +}; diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_posix.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_posix.inc new file mode 100644 index 0000000..ef9cb16 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_posix.inc @@ -0,0 +1,1210 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../utils/alloc.h" +#include "../utils/closefd.h" +#include "../utils/cont.h" +#include "../utils/fast.h" +#include "../utils/err.h" +#include "../utils/attr.h" + +#include +#include +#include +#include + +#define NN_USOCK_STATE_IDLE 1 +#define NN_USOCK_STATE_STARTING 2 +#define NN_USOCK_STATE_BEING_ACCEPTED 3 +#define NN_USOCK_STATE_ACCEPTED 4 +#define NN_USOCK_STATE_CONNECTING 5 +#define NN_USOCK_STATE_ACTIVE 6 +#define NN_USOCK_STATE_REMOVING_FD 7 +#define NN_USOCK_STATE_DONE 8 +#define NN_USOCK_STATE_LISTENING 9 +#define NN_USOCK_STATE_ACCEPTING 10 +#define NN_USOCK_STATE_CANCELLING 11 +#define NN_USOCK_STATE_STOPPING 12 +#define NN_USOCK_STATE_STOPPING_ACCEPT 13 +#define NN_USOCK_STATE_ACCEPTING_ERROR 14 + +#define NN_USOCK_ACTION_ACCEPT 1 +#define NN_USOCK_ACTION_BEING_ACCEPTED 2 +#define NN_USOCK_ACTION_CANCEL 3 +#define NN_USOCK_ACTION_LISTEN 4 +#define NN_USOCK_ACTION_CONNECT 5 +#define NN_USOCK_ACTION_ACTIVATE 6 +#define NN_USOCK_ACTION_DONE 7 +#define NN_USOCK_ACTION_ERROR 8 +#define NN_USOCK_ACTION_STARTED 9 + +#define NN_USOCK_SRC_FD 1 +#define NN_USOCK_SRC_TASK_CONNECTING 2 +#define NN_USOCK_SRC_TASK_CONNECTED 3 +#define NN_USOCK_SRC_TASK_ACCEPT 4 +#define NN_USOCK_SRC_TASK_SEND 5 +#define NN_USOCK_SRC_TASK_RECV 6 +#define NN_USOCK_SRC_TASK_STOP 7 + +/* Private functions. */ +static void nn_usock_init_from_fd (struct nn_usock *self, int s); +static int nn_usock_send_raw (struct nn_usock *self, struct msghdr *hdr); +static int nn_usock_recv_raw (struct nn_usock *self, void *buf, size_t *len); +static int nn_usock_geterr (struct nn_usock *self); +static void nn_usock_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_usock_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_usock_init (struct nn_usock *self, int src, struct nn_fsm *owner) +{ + /* Initalise the state machine. */ + nn_fsm_init (&self->fsm, nn_usock_handler, nn_usock_shutdown, + src, self, owner); + self->state = NN_USOCK_STATE_IDLE; + + /* Choose a worker thread to handle this socket. */ + self->worker = nn_fsm_choose_worker (&self->fsm); + + /* Actual file descriptor will be generated during 'start' step. */ + self->s = -1; + self->errnum = 0; + + self->in.buf = NULL; + self->in.len = 0; + self->in.batch = NULL; + self->in.batch_len = 0; + self->in.batch_pos = 0; + self->in.pfd = NULL; + + memset (&self->out.hdr, 0, sizeof (struct msghdr)); + + /* Initialise tasks for the worker thread. */ + nn_worker_fd_init (&self->wfd, NN_USOCK_SRC_FD, &self->fsm); + nn_worker_task_init (&self->task_connecting, NN_USOCK_SRC_TASK_CONNECTING, + &self->fsm); + nn_worker_task_init (&self->task_connected, NN_USOCK_SRC_TASK_CONNECTED, + &self->fsm); + nn_worker_task_init (&self->task_accept, NN_USOCK_SRC_TASK_ACCEPT, + &self->fsm); + nn_worker_task_init (&self->task_send, NN_USOCK_SRC_TASK_SEND, &self->fsm); + nn_worker_task_init (&self->task_recv, NN_USOCK_SRC_TASK_RECV, &self->fsm); + nn_worker_task_init (&self->task_stop, NN_USOCK_SRC_TASK_STOP, &self->fsm); + + /* Intialise events raised by usock. */ + nn_fsm_event_init (&self->event_established); + nn_fsm_event_init (&self->event_sent); + nn_fsm_event_init (&self->event_received); + nn_fsm_event_init (&self->event_error); + + /* accepting is not going on at the moment. */ + self->asock = NULL; +} + +void nn_usock_term (struct nn_usock *self) +{ + nn_assert_state (self, NN_USOCK_STATE_IDLE); + + if (self->in.batch) + nn_free (self->in.batch); + + nn_fsm_event_term (&self->event_error); + nn_fsm_event_term (&self->event_received); + nn_fsm_event_term (&self->event_sent); + nn_fsm_event_term (&self->event_established); + + nn_worker_cancel (self->worker, &self->task_recv); + + nn_worker_task_term (&self->task_stop); + nn_worker_task_term (&self->task_recv); + nn_worker_task_term (&self->task_send); + nn_worker_task_term (&self->task_accept); + nn_worker_task_term (&self->task_connected); + nn_worker_task_term (&self->task_connecting); + nn_worker_fd_term (&self->wfd); + + nn_fsm_term (&self->fsm); +} + +int nn_usock_isidle (struct nn_usock *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +int nn_usock_start (struct nn_usock *self, int domain, int type, int protocol) +{ + int s; + + /* If the operating system allows to directly open the socket with CLOEXEC + flag, do so. That way there are no race conditions. */ +#ifdef SOCK_CLOEXEC + type |= SOCK_CLOEXEC; +#endif + + /* Open the underlying socket. */ + s = socket (domain, type, protocol); + if (nn_slow (s < 0)) + return -errno; + + nn_usock_init_from_fd (self, s); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + return 0; +} + +void nn_usock_start_fd (struct nn_usock *self, int fd) +{ + nn_usock_init_from_fd (self, fd); + nn_fsm_start (&self->fsm); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_STARTED); +} + +static void nn_usock_init_from_fd (struct nn_usock *self, int s) +{ + int rc; + int opt; + + nn_assert (self->state == NN_USOCK_STATE_IDLE || + NN_USOCK_STATE_BEING_ACCEPTED); + + /* Store the file descriptor. */ + nn_assert (self->s == -1); + self->s = s; + + /* Setting FD_CLOEXEC option immediately after socket creation is the + second best option after using SOCK_CLOEXEC. There is a race condition + here (if process is forked between socket creation and setting + the option) but the problem is pretty unlikely to happen. */ +#if defined FD_CLOEXEC + rc = fcntl (self->s, F_SETFD, FD_CLOEXEC); +#if defined NN_HAVE_OSX + errno_assert (rc != -1 || errno == EINVAL); +#else + errno_assert (rc != -1); +#endif +#endif + + /* If applicable, prevent SIGPIPE signal when writing to the connection + already closed by the peer. */ +#ifdef SO_NOSIGPIPE + opt = 1; + rc = setsockopt (self->s, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof (opt)); +#if defined NN_HAVE_OSX + errno_assert (rc == 0 || errno == EINVAL); +#else + errno_assert (rc == 0); +#endif +#endif + + /* Switch the socket to the non-blocking mode. All underlying sockets + are always used in the callbackhronous mode. */ + opt = fcntl (self->s, F_GETFL, 0); + if (opt == -1) + opt = 0; + if (!(opt & O_NONBLOCK)) { + rc = fcntl (self->s, F_SETFL, opt | O_NONBLOCK); +#if defined NN_HAVE_OSX + errno_assert (rc != -1 || errno == EINVAL); +#else + errno_assert (rc != -1); +#endif + } +} + +void nn_usock_stop (struct nn_usock *self) +{ + nn_fsm_stop (&self->fsm); +} + +void nn_usock_async_stop (struct nn_usock *self) +{ + nn_worker_execute (self->worker, &self->task_stop); + nn_fsm_raise (&self->fsm, &self->event_error, NN_USOCK_SHUTDOWN); +} + +void nn_usock_swap_owner (struct nn_usock *self, struct nn_fsm_owner *owner) +{ + nn_fsm_swap_owner (&self->fsm, owner); +} + +int nn_usock_setsockopt (struct nn_usock *self, int level, int optname, + const void *optval, size_t optlen) +{ + int rc; + + /* The socket can be modified only before it's active. */ + nn_assert (self->state == NN_USOCK_STATE_STARTING || + self->state == NN_USOCK_STATE_ACCEPTED); + + /* EINVAL errors are ignored on OSX platform. The reason for that is buggy + OSX behaviour where setsockopt returns EINVAL if the peer have already + disconnected. Thus, nn_usock_setsockopt() can succeed on OSX even though + the option value was invalid, but the peer have already closed the + connection. This behaviour should be relatively harmless. */ + rc = setsockopt (self->s, level, optname, optval, (socklen_t) optlen); +#if defined NN_HAVE_OSX + if (nn_slow (rc != 0 && errno != EINVAL)) + return -errno; +#else + if (nn_slow (rc != 0)) + return -errno; +#endif + + return 0; +} + +int nn_usock_bind (struct nn_usock *self, const struct sockaddr *addr, + size_t addrlen) +{ + int rc; + int opt; + + /* The socket can be bound only before it's connected. */ + nn_assert_state (self, NN_USOCK_STATE_STARTING); + + /* Allow re-using the address. */ + opt = 1; + rc = setsockopt (self->s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)); + errno_assert (rc == 0); + + rc = bind (self->s, addr, (socklen_t) addrlen); + if (nn_slow (rc != 0)) + return -errno; + + return 0; +} + +int nn_usock_listen (struct nn_usock *self, int backlog) +{ + int rc; + + /* You can start listening only before the socket is connected. */ + nn_assert_state (self, NN_USOCK_STATE_STARTING); + + /* Start listening for incoming connections. */ + rc = listen (self->s, backlog); + if (nn_slow (rc != 0)) + return -errno; + + /* Notify the state machine. */ + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_LISTEN); + + return 0; +} + +void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener) +{ + int s; + + /* Start the actual accepting. */ + if (nn_fsm_isidle(&self->fsm)) { + nn_fsm_start (&self->fsm); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_BEING_ACCEPTED); + } + nn_fsm_action (&listener->fsm, NN_USOCK_ACTION_ACCEPT); + + /* Try to accept new connection in synchronous manner. */ +#if NN_HAVE_ACCEPT4 + s = accept4 (listener->s, NULL, NULL, SOCK_CLOEXEC); +#else + s = accept (listener->s, NULL, NULL); +#endif + + /* Immediate success. */ + if (nn_fast (s >= 0)) { + /* Disassociate the listener socket from the accepted + socket. Is useful if we restart accepting on ACCEPT_ERROR */ + listener->asock = NULL; + self->asock = NULL; + + nn_usock_init_from_fd (self, s); + nn_fsm_action (&listener->fsm, NN_USOCK_ACTION_DONE); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_DONE); + return; + } + + /* Detect a failure. Note that in ECONNABORTED case we simply ignore + the error and wait for next connection in asynchronous manner. */ + errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || + errno == ECONNABORTED || errno == ENFILE || errno == EMFILE || + errno == ENOBUFS || errno == ENOMEM); + + /* Pair the two sockets. They are already paired in case + previous attempt failed on ACCEPT_ERROR */ + nn_assert (!self->asock || self->asock == listener); + self->asock = listener; + nn_assert (!listener->asock || listener->asock == self); + listener->asock = self; + + /* Some errors are just ok to ignore for now. We also stop repeating + any errors until next IN_FD event so that we are not in a tight loop + and allow processing other events in the meantime */ + if (nn_slow (errno != EAGAIN && errno != EWOULDBLOCK + && errno != ECONNABORTED && errno != listener->errnum)) + { + listener->errnum = errno; + listener->state = NN_USOCK_STATE_ACCEPTING_ERROR; + nn_fsm_raise (&listener->fsm, + &listener->event_error, NN_USOCK_ACCEPT_ERROR); + return; + } + + /* Ask the worker thread to wait for the new connection. */ + nn_worker_execute (listener->worker, &listener->task_accept); +} + +void nn_usock_activate (struct nn_usock *self) +{ + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ACTIVATE); +} + +void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, + size_t addrlen) +{ + int rc; + + /* Notify the state machine that we've started connecting. */ + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_CONNECT); + + /* Do the connect itself. */ + rc = connect (self->s, addr, (socklen_t) addrlen); + + /* Immediate success. */ + if (nn_fast (rc == 0)) { + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_DONE); + return; + } + + /* Immediate error. */ + if (nn_slow (errno != EINPROGRESS)) { + self->errnum = errno; + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + /* Start asynchronous connect. */ + nn_worker_execute (self->worker, &self->task_connecting); +} + +void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, + int iovcnt) +{ + int rc; + int i; + int out; + + /* Make sure that the socket is actually alive. */ + if (self->state != NN_USOCK_STATE_ACTIVE) { + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + /* Copy the iovecs to the socket. */ + nn_assert (iovcnt <= NN_USOCK_MAX_IOVCNT); + self->out.hdr.msg_iov = self->out.iov; + out = 0; + for (i = 0; i != iovcnt; ++i) { + if (iov [i].iov_len == 0) + continue; + self->out.iov [out].iov_base = iov [i].iov_base; + self->out.iov [out].iov_len = iov [i].iov_len; + out++; + } + self->out.hdr.msg_iovlen = out; + + /* Try to send the data immediately. */ + rc = nn_usock_send_raw (self, &self->out.hdr); + + /* Success. */ + if (nn_fast (rc == 0)) { + nn_fsm_raise (&self->fsm, &self->event_sent, NN_USOCK_SENT); + return; + } + + /* Errors. */ + if (nn_slow (rc != -EAGAIN)) { + errnum_assert (rc == -ECONNRESET, -rc); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + /* Ask the worker thread to send the remaining data. */ + nn_worker_execute (self->worker, &self->task_send); +} + +void nn_usock_recv (struct nn_usock *self, void *buf, size_t len, int *fd) +{ + int rc; + size_t nbytes; + + /* Make sure that the socket is actually alive. */ + if (self->state != NN_USOCK_STATE_ACTIVE) { + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + /* Try to receive the data immediately. */ + nbytes = len; + self->in.pfd = fd; + rc = nn_usock_recv_raw (self, buf, &nbytes); + if (nn_slow (rc < 0)) { + errnum_assert (rc == -ECONNRESET, -rc); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + /* Success. */ + if (nn_fast (nbytes == len)) { + nn_fsm_raise (&self->fsm, &self->event_received, NN_USOCK_RECEIVED); + return; + } + + /* There are still data to receive in the background. */ + self->in.buf = ((uint8_t*) buf) + nbytes; + self->in.len = len - nbytes; + + /* Ask the worker thread to receive the remaining data. */ + nn_worker_execute (self->worker, &self->task_recv); +} + +static int nn_internal_tasks (struct nn_usock *usock, int src, int type) +{ + +/******************************************************************************/ +/* Internal tasks sent from the user thread to the worker thread. */ +/******************************************************************************/ + switch (src) { + case NN_USOCK_SRC_TASK_SEND: + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_set_out (usock->worker, &usock->wfd); + return 1; + case NN_USOCK_SRC_TASK_RECV: + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_set_in (usock->worker, &usock->wfd); + return 1; + case NN_USOCK_SRC_TASK_CONNECTED: + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_add_fd (usock->worker, usock->s, &usock->wfd); + return 1; + case NN_USOCK_SRC_TASK_CONNECTING: + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_add_fd (usock->worker, usock->s, &usock->wfd); + nn_worker_set_out (usock->worker, &usock->wfd); + return 1; + case NN_USOCK_SRC_TASK_ACCEPT: + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_add_fd (usock->worker, usock->s, &usock->wfd); + nn_worker_set_in (usock->worker, &usock->wfd); + return 1; + } + + return 0; +} + +static void nn_usock_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_usock *usock; + + usock = nn_cont (self, struct nn_usock, fsm); + + if (nn_internal_tasks (usock, src, type)) + return; + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + + /* Socket in ACCEPTING or CANCELLING state cannot be closed. + Stop the socket being accepted first. */ + nn_assert (usock->state != NN_USOCK_STATE_ACCEPTING && + usock->state != NN_USOCK_STATE_CANCELLING); + + usock->errnum = 0; + + /* Synchronous stop. */ + if (usock->state == NN_USOCK_STATE_IDLE) + goto finish3; + if (usock->state == NN_USOCK_STATE_DONE) + goto finish2; + if (usock->state == NN_USOCK_STATE_STARTING || + usock->state == NN_USOCK_STATE_ACCEPTED || + usock->state == NN_USOCK_STATE_ACCEPTING_ERROR || + usock->state == NN_USOCK_STATE_LISTENING) + goto finish1; + + /* When socket that's being accepted is asked to stop, we have to + ask the listener socket to stop accepting first. */ + if (usock->state == NN_USOCK_STATE_BEING_ACCEPTED) { + nn_fsm_action (&usock->asock->fsm, NN_USOCK_ACTION_CANCEL); + usock->state = NN_USOCK_STATE_STOPPING_ACCEPT; + return; + } + + /* Asynchronous stop. */ + if (usock->state != NN_USOCK_STATE_REMOVING_FD) + nn_usock_async_stop (usock); + usock->state = NN_USOCK_STATE_STOPPING; + return; + } + if (nn_slow (usock->state == NN_USOCK_STATE_STOPPING_ACCEPT)) { + nn_assert (src == NN_FSM_ACTION && type == NN_USOCK_ACTION_DONE); + goto finish2; + } + if (nn_slow (usock->state == NN_USOCK_STATE_STOPPING)) { + if (src != NN_USOCK_SRC_TASK_STOP) + return; + nn_assert (type == NN_WORKER_TASK_EXECUTE); + nn_worker_rm_fd (usock->worker, &usock->wfd); +finish1: + nn_closefd (usock->s); + usock->s = -1; +finish2: + usock->state = NN_USOCK_STATE_IDLE; + nn_fsm_stopped (&usock->fsm, NN_USOCK_STOPPED); +finish3: + return; + } + + nn_fsm_bad_state(usock->state, src, type); +} + +static void nn_usock_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + int rc; + struct nn_usock *usock; + int s; + size_t sz; + int sockerr; + + usock = nn_cont (self, struct nn_usock, fsm); + + if(nn_internal_tasks(usock, src, type)) + return; + + switch (usock->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* nn_usock object is initialised, but underlying OS socket is not yet */ +/* created. */ +/******************************************************************************/ + case NN_USOCK_STATE_IDLE: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + usock->state = NN_USOCK_STATE_STARTING; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* STARTING state. */ +/* Underlying OS socket is created, but it's not yet passed to the worker */ +/* thread. In this state we can set socket options, local and remote */ +/* address etc. */ +/******************************************************************************/ + case NN_USOCK_STATE_STARTING: + + /* Events from the owner of the usock. */ + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_LISTEN: + usock->state = NN_USOCK_STATE_LISTENING; + return; + case NN_USOCK_ACTION_CONNECT: + usock->state = NN_USOCK_STATE_CONNECTING; + return; + case NN_USOCK_ACTION_BEING_ACCEPTED: + usock->state = NN_USOCK_STATE_BEING_ACCEPTED; + return; + case NN_USOCK_ACTION_STARTED: + nn_worker_add_fd (usock->worker, usock->s, &usock->wfd); + usock->state = NN_USOCK_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* BEING_ACCEPTED state. */ +/* accept() was called on the usock. Now the socket is waiting for a new */ +/* connection to arrive. */ +/******************************************************************************/ + case NN_USOCK_STATE_BEING_ACCEPTED: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_DONE: + usock->state = NN_USOCK_STATE_ACCEPTED; + nn_fsm_raise (&usock->fsm, &usock->event_established, + NN_USOCK_ACCEPTED); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* ACCEPTED state. */ +/* Connection was accepted, now it can be tuned. Afterwards, it'll move to */ +/* the active state. */ +/******************************************************************************/ + case NN_USOCK_STATE_ACCEPTED: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ACTIVATE: + nn_worker_add_fd (usock->worker, usock->s, &usock->wfd); + usock->state = NN_USOCK_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* CONNECTING state. */ +/* Asynchronous connecting is going on. */ +/******************************************************************************/ + case NN_USOCK_STATE_CONNECTING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_DONE: + usock->state = NN_USOCK_STATE_ACTIVE; + nn_worker_execute (usock->worker, &usock->task_connected); + nn_fsm_raise (&usock->fsm, &usock->event_established, + NN_USOCK_CONNECTED); + return; + case NN_USOCK_ACTION_ERROR: + nn_closefd (usock->s); + usock->s = -1; + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, &usock->event_error, + NN_USOCK_ERROR); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_USOCK_SRC_FD: + switch (type) { + case NN_WORKER_FD_OUT: + nn_worker_reset_out (usock->worker, &usock->wfd); + usock->state = NN_USOCK_STATE_ACTIVE; + sockerr = nn_usock_geterr(usock); + if (sockerr == 0) { + nn_fsm_raise (&usock->fsm, &usock->event_established, + NN_USOCK_CONNECTED); + } else { + usock->errnum = sockerr; + nn_worker_rm_fd (usock->worker, &usock->wfd); + rc = close (usock->s); + errno_assert (rc == 0); + usock->s = -1; + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, + &usock->event_error, NN_USOCK_ERROR); + } + return; + case NN_WORKER_FD_ERR: + nn_worker_rm_fd (usock->worker, &usock->wfd); + nn_closefd (usock->s); + usock->s = -1; + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, &usock->event_error, NN_USOCK_ERROR); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* Socket is connected. It can be used for sending and receiving data. */ +/******************************************************************************/ + case NN_USOCK_STATE_ACTIVE: + switch (src) { + case NN_USOCK_SRC_FD: + switch (type) { + case NN_WORKER_FD_IN: + sz = usock->in.len; + rc = nn_usock_recv_raw (usock, usock->in.buf, &sz); + if (nn_fast (rc == 0)) { + usock->in.len -= sz; + usock->in.buf += sz; + if (!usock->in.len) { + nn_worker_reset_in (usock->worker, &usock->wfd); + nn_fsm_raise (&usock->fsm, &usock->event_received, + NN_USOCK_RECEIVED); + } + return; + } + errnum_assert (rc == -ECONNRESET, -rc); + goto error; + case NN_WORKER_FD_OUT: + rc = nn_usock_send_raw (usock, &usock->out.hdr); + if (nn_fast (rc == 0)) { + nn_worker_reset_out (usock->worker, &usock->wfd); + nn_fsm_raise (&usock->fsm, &usock->event_sent, + NN_USOCK_SENT); + return; + } + if (nn_fast (rc == -EAGAIN)) + return; + errnum_assert (rc == -ECONNRESET, -rc); + goto error; + case NN_WORKER_FD_ERR: +error: + nn_worker_rm_fd (usock->worker, &usock->wfd); + nn_closefd (usock->s); + usock->s = -1; + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, &usock->event_error, NN_USOCK_ERROR); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ERROR: + usock->state = NN_USOCK_STATE_REMOVING_FD; + nn_usock_async_stop (usock); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source(usock->state, src, type); + } + +/******************************************************************************/ +/* REMOVING_FD state. */ +/******************************************************************************/ + case NN_USOCK_STATE_REMOVING_FD: + switch (src) { + case NN_USOCK_SRC_TASK_STOP: + switch (type) { + case NN_WORKER_TASK_EXECUTE: + nn_worker_rm_fd (usock->worker, &usock->wfd); + nn_closefd (usock->s); + usock->s = -1; + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, &usock->event_error, NN_USOCK_ERROR); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + + /* Events from the file descriptor are ignored while it is being + removed. */ + case NN_USOCK_SRC_FD: + return; + + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ERROR: + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/* Socket is closed. The only thing that can be done in this state is */ +/* stopping the usock. */ +/******************************************************************************/ + case NN_USOCK_STATE_DONE: + return; + +/******************************************************************************/ +/* LISTENING state. */ +/* Socket is listening for new incoming connections, however, user is not */ +/* accepting a new connection. */ +/******************************************************************************/ + case NN_USOCK_STATE_LISTENING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ACCEPT: + usock->state = NN_USOCK_STATE_ACCEPTING; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* ACCEPTING state. */ +/* User is waiting asynchronouslyfor a new inbound connection */ +/* to be accepted. */ +/******************************************************************************/ + case NN_USOCK_STATE_ACCEPTING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_DONE: + usock->state = NN_USOCK_STATE_LISTENING; + return; + case NN_USOCK_ACTION_CANCEL: + usock->state = NN_USOCK_STATE_CANCELLING; + nn_worker_execute (usock->worker, &usock->task_stop); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_USOCK_SRC_FD: + switch (type) { + case NN_WORKER_FD_IN: + + /* New connection arrived in asynchronous manner. */ +#if NN_HAVE_ACCEPT4 + s = accept4 (usock->s, NULL, NULL, SOCK_CLOEXEC); +#else + s = accept (usock->s, NULL, NULL); +#endif + + /* ECONNABORTED is an valid error. New connection was closed + by the peer before we were able to accept it. If it happens + do nothing and wait for next incoming connection. */ + if (nn_slow (s < 0 && errno == ECONNABORTED)) + return; + + /* Resource allocation errors. It's not clear from POSIX + specification whether the new connection is closed in this + case or whether it remains in the backlog. In the latter + case it would be wise to wait here for a while to prevent + busy looping. */ + if (nn_slow (s < 0 && (errno == ENFILE || errno == EMFILE || + errno == ENOBUFS || errno == ENOMEM))) { + usock->errnum = errno; + usock->state = NN_USOCK_STATE_ACCEPTING_ERROR; + + /* Wait till the user starts accepting once again. */ + nn_worker_rm_fd (usock->worker, &usock->wfd); + + nn_fsm_raise (&usock->fsm, + &usock->event_error, NN_USOCK_ACCEPT_ERROR); + return; + } + + /* Any other error is unexpected. */ + errno_assert (s >= 0); + + /* Initialise the new usock object. */ + nn_usock_init_from_fd (usock->asock, s); + usock->asock->state = NN_USOCK_STATE_ACCEPTED; + + /* Notify the user that connection was accepted. */ + nn_fsm_raise (&usock->asock->fsm, + &usock->asock->event_established, NN_USOCK_ACCEPTED); + + /* Disassociate the listener socket from the accepted + socket. */ + usock->asock->asock = NULL; + usock->asock = NULL; + + /* Wait till the user starts accepting once again. */ + nn_worker_rm_fd (usock->worker, &usock->wfd); + usock->state = NN_USOCK_STATE_LISTENING; + + return; + + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* ACCEPTING_ERROR state. */ +/* Waiting the socket to accept the error and restart */ +/******************************************************************************/ + case NN_USOCK_STATE_ACCEPTING_ERROR: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ACCEPT: + usock->state = NN_USOCK_STATE_ACCEPTING; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* CANCELLING state. */ +/******************************************************************************/ + case NN_USOCK_STATE_CANCELLING: + switch (src) { + case NN_USOCK_SRC_TASK_STOP: + switch (type) { + case NN_WORKER_TASK_EXECUTE: + nn_worker_rm_fd (usock->worker, &usock->wfd); + usock->state = NN_USOCK_STATE_LISTENING; + + /* Notify the accepted socket that it was stopped. */ + nn_fsm_action (&usock->asock->fsm, NN_USOCK_ACTION_DONE); + + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_USOCK_SRC_FD: + switch (type) { + case NN_WORKER_FD_IN: + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/******************************************************************************/ +/* Invalid state */ +/******************************************************************************/ + default: + nn_fsm_bad_state (usock->state, src, type); + } +} + +static int nn_usock_send_raw (struct nn_usock *self, struct msghdr *hdr) +{ + ssize_t nbytes; + + /* Try to send the data. */ +#if defined MSG_NOSIGNAL + nbytes = sendmsg (self->s, hdr, MSG_NOSIGNAL); +#else + nbytes = sendmsg (self->s, hdr, 0); +#endif + + /* Handle errors. */ + if (nn_slow (nbytes < 0)) { + if (nn_fast (errno == EAGAIN || errno == EWOULDBLOCK)) + nbytes = 0; + else { + + /* If the connection fails, return ECONNRESET. */ + return -ECONNRESET; + } + } + + /* Some bytes were sent. Adjust the iovecs accordingly. */ + while (nbytes) { + if (nbytes >= (ssize_t)hdr->msg_iov->iov_len) { + --hdr->msg_iovlen; + if (!hdr->msg_iovlen) { + nn_assert (nbytes == (ssize_t)hdr->msg_iov->iov_len); + return 0; + } + nbytes -= hdr->msg_iov->iov_len; + ++hdr->msg_iov; + } + else { + *((uint8_t**) &(hdr->msg_iov->iov_base)) += nbytes; + hdr->msg_iov->iov_len -= nbytes; + return -EAGAIN; + } + } + + if (hdr->msg_iovlen > 0) + return -EAGAIN; + + return 0; +} + +static int nn_usock_recv_raw (struct nn_usock *self, void *buf, size_t *len) +{ + size_t sz; + size_t length; + ssize_t nbytes; + struct iovec iov; + struct msghdr hdr; + unsigned char ctrl [256]; +#if defined NN_HAVE_MSG_CONTROL + struct cmsghdr *cmsg; +#endif + + /* If batch buffer doesn't exist, allocate it. The point of delayed + deallocation to allow non-receiving sockets, such as TCP listening + sockets, to do without the batch buffer. */ + if (nn_slow (!self->in.batch)) { + self->in.batch = nn_alloc (NN_USOCK_BATCH_SIZE, "AIO batch buffer"); + alloc_assert (self->in.batch); + } + + /* Try to satisfy the recv request by data from the batch buffer. */ + length = *len; + sz = self->in.batch_len - self->in.batch_pos; + if (sz) { + if (sz > length) + sz = length; + memcpy (buf, self->in.batch + self->in.batch_pos, sz); + self->in.batch_pos += sz; + buf = ((char*) buf) + sz; + length -= sz; + if (!length) + return 0; + } + + /* If recv request is greater than the batch buffer, get the data directly + into the place. Otherwise, read data to the batch buffer. */ + if (length > NN_USOCK_BATCH_SIZE) { + iov.iov_base = buf; + iov.iov_len = length; + } + else { + iov.iov_base = self->in.batch; + iov.iov_len = NN_USOCK_BATCH_SIZE; + } + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; +#if defined NN_HAVE_MSG_CONTROL + hdr.msg_control = ctrl; + hdr.msg_controllen = sizeof (ctrl); +#else + *((int*) ctrl) = -1; + hdr.msg_accrights = ctrl; + hdr.msg_accrightslen = sizeof (int); +#endif + nbytes = recvmsg (self->s, &hdr, 0); + + /* Handle any possible errors. */ + if (nn_slow (nbytes <= 0)) { + + if (nn_slow (nbytes == 0)) + return -ECONNRESET; + + /* Zero bytes received. */ + if (nn_fast (errno == EAGAIN || errno == EWOULDBLOCK)) + nbytes = 0; + else { + + /* If the peer closes the connection, return ECONNRESET. */ + return -ECONNRESET; + } + } + + /* Extract the associated file descriptor, if any. */ + if (nbytes > 0) { +#if defined NN_HAVE_MSG_CONTROL + cmsg = CMSG_FIRSTHDR (&hdr); + while (cmsg) { + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { + if (self->in.pfd) { + *self->in.pfd = *((int*) CMSG_DATA (cmsg)); + self->in.pfd = NULL; + } + else { + nn_closefd (*((int*) CMSG_DATA (cmsg))); + } + break; + } + cmsg = CMSG_NXTHDR (&hdr, cmsg); + } +#else + if (hdr.msg_accrightslen > 0) { + nn_assert (hdr.msg_accrightslen == sizeof (int)); + if (self->in.pfd) { + *self->in.pfd = *((int*) hdr.msg_accrights); + self->in.pfd = NULL; + } + else { + nn_closefd (*((int*) hdr.msg_accrights)); + } + } +#endif + } + + /* If the data were received directly into the place we can return + straight away. */ + if (length > NN_USOCK_BATCH_SIZE) { + length -= nbytes; + *len -= length; + return 0; + } + + /* New data were read to the batch buffer. Copy the requested amount of it + to the user-supplied buffer. */ + self->in.batch_len = nbytes; + self->in.batch_pos = 0; + if (nbytes) { + sz = nbytes > (ssize_t)length ? length : (size_t)nbytes; + memcpy (buf, self->in.batch, sz); + length -= sz; + self->in.batch_pos += sz; + } + + *len -= length; + return 0; +} + +static int nn_usock_geterr (struct nn_usock *self) +{ + int rc; + int opt; +#if defined NN_HAVE_HPUX + int optsz; +#else + socklen_t optsz; +#endif + + opt = 0; + optsz = sizeof (opt); + rc = getsockopt (self->s, SOL_SOCKET, SO_ERROR, &opt, &optsz); + + /* The following should handle both Solaris and UNIXes derived from BSD. */ + if (rc == -1) + return errno; + errno_assert (rc == 0); + nn_assert (optsz == sizeof (opt)); + return opt; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_win.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_win.h new file mode 100644 index 0000000..e44576d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_win.h @@ -0,0 +1,87 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "fsm.h" +#include "worker.h" + +#include "../utils/win.h" + +struct nn_usock { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + union { + + /* The actual underlying socket. Can be used as a HANDLE too. */ + SOCKET s; + + /* Named pipe handle. Cannot be used as a SOCKET. */ + HANDLE p; + }; + + /* For NamedPipes, closing an accepted pipe differs from other pipes. + If the NamedPipe was accepted, this member is set to 1. 0 otherwise. */ + int isaccepted; + + /* Asynchronous operations being executed on the socket. */ + struct nn_worker_op in; + struct nn_worker_op out; + + /* When accepting new socket, they have to be created with same + type as the listening socket. Thus, in listening socket we + have to store its exact type. */ + int domain; + int type; + int protocol; + + /* Events raised by the usock. */ + struct nn_fsm_event event_established; + struct nn_fsm_event event_sent; + struct nn_fsm_event event_received; + struct nn_fsm_event event_error; + + /* In ACCEPTING state points to the socket being accepted. + In BEING_ACCEPTED state points to the listener socket. */ + struct nn_usock *asock; + + /* Buffer allocated for output of AcceptEx function. If accepting is not + done on this socket, the field is set to NULL. */ + void *ainfo; + + /* For NamedPipes, we store the address inside the socket. */ + struct sockaddr_un pipename; + + /* For now we allocate a new buffer for each write to a named pipe. */ + void *pipesendbuf; + + /* Pointer to the security attribute structure */ + SECURITY_ATTRIBUTES *sec_attr; + + /* Out Buffer and In Buffer size */ + int outbuffersz; + int inbuffersz; + + /* Errno remembered in NN_USOCK_ERROR state */ + int errnum; +}; diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_win.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_win.inc new file mode 100644 index 0000000..0af756d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/usock_win.inc @@ -0,0 +1,1067 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "worker.h" + +#include "../utils/err.h" +#include "../utils/cont.h" +#include "../utils/alloc.h" + +#include +#include +#include + +#define NN_USOCK_STATE_IDLE 1 +#define NN_USOCK_STATE_STARTING 2 +#define NN_USOCK_STATE_BEING_ACCEPTED 3 +#define NN_USOCK_STATE_ACCEPTED 4 +#define NN_USOCK_STATE_CONNECTING 5 +#define NN_USOCK_STATE_ACTIVE 6 +#define NN_USOCK_STATE_CANCELLING_IO 7 +#define NN_USOCK_STATE_DONE 8 +#define NN_USOCK_STATE_LISTENING 9 +#define NN_USOCK_STATE_ACCEPTING 10 +#define NN_USOCK_STATE_CANCELLING 11 +#define NN_USOCK_STATE_STOPPING 12 +#define NN_USOCK_STATE_STOPPING_ACCEPT 13 + +#define NN_USOCK_ACTION_ACCEPT 1 +#define NN_USOCK_ACTION_BEING_ACCEPTED 2 +#define NN_USOCK_ACTION_CANCEL 3 +#define NN_USOCK_ACTION_LISTEN 4 +#define NN_USOCK_ACTION_CONNECT 5 +#define NN_USOCK_ACTION_ACTIVATE 6 +#define NN_USOCK_ACTION_DONE 7 +#define NN_USOCK_ACTION_ERROR 8 + +#define NN_USOCK_SRC_IN 1 +#define NN_USOCK_SRC_OUT 2 + +/* Private functions. */ +static void nn_usock_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_usock_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static int nn_usock_cancel_io (struct nn_usock *self); +static void nn_usock_create_io_completion (struct nn_usock *self); +DWORD nn_usock_open_pipe (struct nn_usock *self, const char *name); +void nn_usock_accept_pipe (struct nn_usock *self, struct nn_usock *listener); + +void nn_usock_init (struct nn_usock *self, int src, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_usock_handler, nn_usock_shutdown, + src, self, owner); + self->state = NN_USOCK_STATE_IDLE; + self->s = INVALID_SOCKET; + self->isaccepted = 0; + nn_worker_op_init (&self->in, NN_USOCK_SRC_IN, &self->fsm); + nn_worker_op_init (&self->out, NN_USOCK_SRC_OUT, &self->fsm); + self->domain = -1; + self->type = -1; + self->protocol = -1; + + /* Intialise events raised by usock. */ + nn_fsm_event_init (&self->event_established); + nn_fsm_event_init (&self->event_sent); + nn_fsm_event_init (&self->event_received); + nn_fsm_event_init (&self->event_error); + + /* No accepting is going on at the moment. */ + self->asock = NULL; + self->ainfo = NULL; + + /* NamedPipe-related stuff. */ + memset (&self->pipename, 0, sizeof (self->pipename)); + self->pipesendbuf = NULL; + self->sec_attr = NULL; + + /* default size for both in and out buffers is 4096 */ + self->outbuffersz = 4096; + self->inbuffersz = 4096; +} + +void nn_usock_term (struct nn_usock *self) +{ + nn_assert_state (self, NN_USOCK_STATE_IDLE); + + if (self->ainfo) + nn_free (self->ainfo); + if (self->pipesendbuf) + nn_free (self->pipesendbuf); + nn_fsm_event_term (&self->event_error); + nn_fsm_event_term (&self->event_received); + nn_fsm_event_term (&self->event_sent); + nn_fsm_event_term (&self->event_established); + nn_worker_op_term (&self->out); + nn_worker_op_term (&self->in); + nn_fsm_term (&self->fsm); +} + +int nn_usock_isidle (struct nn_usock *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +int nn_usock_start (struct nn_usock *self, int domain, int type, int protocol) +{ + int rc; +#if defined IPV6_V6ONLY + DWORD only; +#endif +#if defined HANDLE_FLAG_INHERIT + BOOL brc; +#endif + + /* NamedPipes aren't sockets. They don't need all the socket + initialisation stuff. */ + if (domain != AF_UNIX) { + + /* Open the underlying socket. */ + self->s = socket (domain, type, protocol); + if (self->s == INVALID_SOCKET) + return -nn_err_wsa_to_posix (WSAGetLastError ()); + + /* Disable inheriting the socket to the child processes. */ +#if defined HANDLE_FLAG_INHERIT + brc = SetHandleInformation (self->p, HANDLE_FLAG_INHERIT, 0); + win_assert (brc); +#endif + + /* IPv4 mapping for IPv6 sockets is disabled by default. Switch it on. */ +#if defined IPV6_V6ONLY + if (domain == AF_INET6) { + only = 0; + rc = setsockopt (self->s, IPPROTO_IPV6, IPV6_V6ONLY, + (const char*) &only, sizeof (only)); + wsa_assert (rc != SOCKET_ERROR); + } +#endif + + /* Associate the socket with a worker thread/completion port. */ + nn_usock_create_io_completion (self); + } + + /* Remember the type of the socket. */ + self->domain = domain; + self->type = type; + self->protocol = protocol; + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + return 0; +} + +void nn_usock_start_fd (struct nn_usock *self, int fd) +{ + nn_assert (0); +} + +void nn_usock_stop (struct nn_usock *self) +{ + nn_fsm_stop (&self->fsm); +} + +void nn_usock_swap_owner (struct nn_usock *self, struct nn_fsm_owner *owner) +{ + nn_fsm_swap_owner (&self->fsm, owner); +} + +int nn_usock_setsockopt (struct nn_usock *self, int level, int optname, + const void *optval, size_t optlen) +{ + int rc; + + /* NamedPipes aren't sockets. We can't set socket options on them. + For now we'll ignore the options. */ + if (self->domain == AF_UNIX) + return 0; + + /* The socket can be modified only before it's active. */ + nn_assert (self->state == NN_USOCK_STATE_STARTING || + self->state == NN_USOCK_STATE_ACCEPTED); + + nn_assert (optlen < INT_MAX); + + rc = setsockopt (self->s, level, optname, (char*) optval, (int) optlen); + if (nn_slow (rc == SOCKET_ERROR)) + return -nn_err_wsa_to_posix (WSAGetLastError ()); + + return 0; +} + +int nn_usock_bind (struct nn_usock *self, const struct sockaddr *addr, + size_t addrlen) +{ + int rc; + ULONG opt; + + /* In the case of named pipes, let's save the address + for the later use. */ + if (self->domain == AF_UNIX) { + if (addrlen > sizeof (struct sockaddr_un)) + return -EINVAL; + memcpy (&self->pipename, addr, addrlen); + return 0; + } + + /* You can set socket options only before the socket is connected. */ + nn_assert_state (self, NN_USOCK_STATE_STARTING); + + /* On Windows, the bound port can be hijacked + if SO_EXCLUSIVEADDRUSE is not set. */ + opt = 1; + rc = setsockopt (self->s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, + (const char*) &opt, sizeof (opt)); + wsa_assert (rc != SOCKET_ERROR); + + nn_assert (addrlen < INT_MAX); + rc = bind (self->s, addr, (int) addrlen); + if (nn_slow (rc == SOCKET_ERROR)) + return -nn_err_wsa_to_posix (WSAGetLastError ()); + + return 0; +} + +int nn_usock_listen (struct nn_usock *self, int backlog) +{ + int rc; + + /* You can start listening only before the socket is connected. */ + nn_assert_state (self, NN_USOCK_STATE_STARTING); + + /* Start listening for incoming connections. NamedPipes are already + created in the listening state, so no need to do anything here. */ + if (self->domain != AF_UNIX) { + rc = listen (self->s, backlog); + if (nn_slow (rc == SOCKET_ERROR)) + return -nn_err_wsa_to_posix (WSAGetLastError ()); + } + + /* Notify the state machine. */ + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_LISTEN); + + return 0; +} + +void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener) +{ + int rc; + BOOL brc; + DWORD nbytes; + + /* NamedPipes have their own accepting mechanism. */ + if (listener->domain == AF_UNIX) { + nn_usock_accept_pipe (self, listener); + return; + } + + rc = nn_usock_start (self, listener->domain, listener->type, + listener->protocol); + /* TODO: EMFILE can be returned here. */ + errnum_assert (rc == 0, -rc); + nn_fsm_action (&listener->fsm, NN_USOCK_ACTION_ACCEPT); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_BEING_ACCEPTED); + + /* If the memory for accept information is not yet allocated, do so. */ + if (!listener->ainfo) { + listener->ainfo = nn_alloc (512, "accept info"); + alloc_assert (listener->ainfo); + } + + /* Wait for the incoming connection. */ + memset (&listener->in.olpd, 0, sizeof (listener->in.olpd)); + brc = AcceptEx (listener->s, self->s, listener->ainfo, 0, 256, 256, &nbytes, + &listener->in.olpd); + + /* Immediate success. */ + if (nn_fast (brc == TRUE)) { + nn_fsm_action (&listener->fsm, NN_USOCK_ACTION_DONE); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_DONE); + return; + } + + /* We don't expect a synchronous failure at this point. */ + wsa_assert (nn_slow (WSAGetLastError () == WSA_IO_PENDING)); + + /* Pair the two sockets. */ + nn_assert (!self->asock); + self->asock = listener; + nn_assert (!listener->asock); + listener->asock = self; + + /* Asynchronous accept. */ + nn_worker_op_start (&listener->in, 0); +} + +void nn_usock_activate (struct nn_usock *self) +{ + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ACTIVATE); +} + +void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, + size_t addrlen) +{ + BOOL brc; + GUID fid = WSAID_CONNECTEX; + LPFN_CONNECTEX pconnectex; + DWORD nbytes; + DWORD winerror; + + /* Fail if the socket is already connected, closed or such. */ + nn_assert_state (self, NN_USOCK_STATE_STARTING); + + /* Notify the state machine that we've started connecting. */ + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_CONNECT); + + memset (&self->out.olpd, 0, sizeof (self->out.olpd)); + + if (self->domain == AF_UNIX) { + winerror = nn_usock_open_pipe (self, ((struct sockaddr_un*) addr)->sun_path); + } + else + { + /* Get the pointer to connect function. */ + brc = WSAIoctl (self->s, SIO_GET_EXTENSION_FUNCTION_POINTER, + &fid, sizeof (fid), &pconnectex, sizeof (pconnectex), + &nbytes, NULL, NULL) == 0; + wsa_assert (brc == TRUE); + nn_assert (nbytes == sizeof (pconnectex)); + + /* Ensure it is safe to cast this value to what might be a smaller + integer type to conform to the pconnectex function signature. */ + nn_assert (addrlen < INT_MAX); + + /* Connect itself. */ + brc = pconnectex (self->s, addr, (int) addrlen, NULL, 0, NULL, + &self->out.olpd); + winerror = brc ? ERROR_SUCCESS : WSAGetLastError (); + } + + /* Immediate success. */ + if (nn_fast (winerror == ERROR_SUCCESS)) { + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_DONE); + return; + } + + /* Immediate error. */ + if (nn_slow (winerror != WSA_IO_PENDING)) { + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + /* Asynchronous connect. */ + nn_worker_op_start (&self->out, 0); +} + +void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, + int iovcnt) +{ + int rc; + BOOL brc; + WSABUF wbuf [NN_USOCK_MAX_IOVCNT]; + int i; + size_t len; + size_t idx; + DWORD error; + + /* Make sure that the socket is actually alive. */ + nn_assert_state (self, NN_USOCK_STATE_ACTIVE); + + /* Create a WinAPI-style iovec. */ + len = 0; + nn_assert (iovcnt <= NN_USOCK_MAX_IOVCNT); + for (i = 0; i != iovcnt; ++i) { + wbuf [i].buf = (char FAR*) iov [i].iov_base; + wbuf [i].len = (ULONG) iov [i].iov_len; + len += iov [i].iov_len; + } + + /* Start the send operation. */ + memset (&self->out.olpd, 0, sizeof (self->out.olpd)); + if (self->domain == AF_UNIX) + { + /* TODO: Do not copy the buffer, find an efficent way to Write + multiple buffers that doesn't affect the state machine. */ + + /* Ensure the total buffer size does not exceed size limitation + of WriteFile. */ + nn_assert (len <= MAXDWORD); + + nn_assert (!self->pipesendbuf); + self->pipesendbuf = nn_alloc (len, "named pipe sendbuf"); + + idx = 0; + for (i = 0; i != iovcnt; ++i) { + memcpy ((char*)(self->pipesendbuf) + idx, iov [i].iov_base, iov [i].iov_len); + idx += iov [i].iov_len; + } + brc = WriteFile (self->p, self->pipesendbuf, (DWORD) len, NULL, &self->out.olpd); + if (nn_fast (brc || GetLastError() == ERROR_IO_PENDING)) { + nn_worker_op_start (&self->out, 0); + return; + } + error = GetLastError(); + win_assert (error == ERROR_NO_DATA); + self->errnum = EINVAL; + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + rc = WSASend (self->s, wbuf, iovcnt, NULL, 0, &self->out.olpd, NULL); + if (nn_fast (rc == 0)) { + nn_worker_op_start (&self->out, 0); + return; + } + error = WSAGetLastError(); + if (nn_fast (error == WSA_IO_PENDING)) { + nn_worker_op_start (&self->out, 0); + return; + } + wsa_assert (error == WSAECONNABORTED || error == WSAECONNRESET || + error == WSAENETDOWN || error == WSAENETRESET || + error == WSAENOBUFS || error == WSAEWOULDBLOCK); + self->errnum = nn_err_wsa_to_posix (error); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); +} + +void nn_usock_recv (struct nn_usock *self, void *buf, size_t len, int *fd) +{ + int rc; + BOOL brc; + WSABUF wbuf; + DWORD wflags; + DWORD error; + + /* Passing file descriptors is not implemented on Windows platform. */ + if (fd) + *fd = -1; + + /* Make sure that the socket is actually alive. */ + nn_assert_state (self, NN_USOCK_STATE_ACTIVE); + + /* Start the receive operation. */ + wbuf.len = (ULONG) len; + wbuf.buf = (char FAR*) buf; + wflags = MSG_WAITALL; + memset (&self->in.olpd, 0, sizeof (self->in.olpd)); + + if (self->domain == AF_UNIX) { + + /* Ensure the total buffer size does not exceed size limitation + of WriteFile. */ + nn_assert (len <= MAXDWORD); + brc = ReadFile (self->p, buf, (DWORD) len, NULL, &self->in.olpd); + error = brc ? ERROR_SUCCESS : GetLastError (); + } + else { + rc = WSARecv (self->s, &wbuf, 1, NULL, &wflags, &self->in.olpd, NULL); + error = (rc == 0) ? ERROR_SUCCESS : WSAGetLastError (); + } + + if (nn_fast (error == ERROR_SUCCESS)) { + nn_worker_op_start (&self->in, 1); + return; + } + + if (nn_fast (error == WSA_IO_PENDING)) { + nn_worker_op_start (&self->in, 1); + return; + } + + if (error == WSAECONNABORTED || error == WSAECONNRESET || + error == WSAENETDOWN || error == WSAENETRESET || + error == WSAETIMEDOUT || error == WSAEWOULDBLOCK || + error == ERROR_PIPE_NOT_CONNECTED || error == ERROR_BROKEN_PIPE) { + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR); + return; + } + + wsa_assert (0); +} + +static void nn_usock_create_io_completion (struct nn_usock *self) +{ + struct nn_worker *worker; + HANDLE cp; + + /* Associate the socket with a worker thread/completion port. */ + worker = nn_fsm_choose_worker (&self->fsm); + cp = CreateIoCompletionPort ( + self->p, + nn_worker_getcp(worker), + (ULONG_PTR) NULL, + 0); + nn_assert(cp); +} + +static void nn_usock_create_pipe (struct nn_usock *self, const char *name) +{ + char fullname [256]; + /* First, create a fully qualified name for the named pipe. */ + _snprintf(fullname, sizeof (fullname), "\\\\.\\pipe\\%s", name); + + self->p = CreateNamedPipeA ( + (char*) fullname, + PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | + PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS, + PIPE_UNLIMITED_INSTANCES, + self->outbuffersz, + self->inbuffersz, + 0, + self->sec_attr); + + /* TODO: How to properly handle self->p == INVALID_HANDLE_VALUE? */ + win_assert (self->p != INVALID_HANDLE_VALUE); + + self->isaccepted = 1; + nn_usock_create_io_completion (self); +} + +DWORD nn_usock_open_pipe (struct nn_usock *self, const char *name) +{ + char fullname [256]; + DWORD winerror; + DWORD mode; + BOOL brc; + + /* First, create a fully qualified name for the named pipe. */ + _snprintf(fullname, sizeof (fullname), "\\\\.\\pipe\\%s", name); + + self->p = CreateFileA ( + fullname, + GENERIC_READ | GENERIC_WRITE, + 0, + self->sec_attr, + OPEN_ALWAYS, + FILE_FLAG_OVERLAPPED, + NULL); + + if (self->p == INVALID_HANDLE_VALUE) + return GetLastError (); + + mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT; + brc = SetNamedPipeHandleState ( + self->p, + &mode, + NULL, + NULL); + if (!brc) { + CloseHandle (self->p); + self->p = INVALID_HANDLE_VALUE; + return GetLastError (); + } + self->isaccepted = 0; + nn_usock_create_io_completion (self); + + winerror = GetLastError (); + if (winerror != ERROR_SUCCESS && winerror != ERROR_ALREADY_EXISTS) + return winerror; + + return ERROR_SUCCESS; +} + +void nn_usock_accept_pipe (struct nn_usock *self, struct nn_usock *listener) +{ + int rc; + BOOL brc; + DWORD winerror; + + /* TODO: EMFILE can be returned here. */ + rc = nn_usock_start (self, listener->domain, listener->type, + listener->protocol); + errnum_assert(rc == 0, -rc); + + nn_fsm_action(&listener->fsm, NN_USOCK_ACTION_ACCEPT); + nn_fsm_action(&self->fsm, NN_USOCK_ACTION_BEING_ACCEPTED); + + /* If the memory for accept information is not yet allocated, do so now. */ + if (!listener->ainfo) { + listener->ainfo = nn_alloc (512, "accept info"); + alloc_assert (listener->ainfo); + } + + /* Wait for the incoming connection. */ + memset (&listener->in.olpd, 0, sizeof(listener->in.olpd)); + nn_usock_create_pipe (self, listener->pipename.sun_path); + brc = ConnectNamedPipe (self->p, (LPOVERLAPPED) &listener->in.olpd); + + /* TODO: Can this function possibly succeed? */ + nn_assert (brc == 0); + winerror = GetLastError(); + + /* Immediate success. */ + if (nn_fast (winerror == ERROR_PIPE_CONNECTED)) { + nn_fsm_action (&listener->fsm, NN_USOCK_ACTION_DONE); + nn_fsm_action (&self->fsm, NN_USOCK_ACTION_DONE); + return; + } + + /* We don't expect a synchronous failure at this point. */ + wsa_assert (nn_slow (winerror == WSA_IO_PENDING)); + + /* Pair the two sockets. */ + nn_assert (!self->asock); + self->asock = listener; + nn_assert (!listener->asock); + listener->asock = self; + + /* Asynchronous accept. */ + nn_worker_op_start (&listener->in, 0); +} + +static void nn_usock_close (struct nn_usock *self) +{ + int rc; + BOOL brc; + + if (self->domain == AF_UNIX) { + if (self->p == INVALID_HANDLE_VALUE) + return; + if (self->isaccepted) + DisconnectNamedPipe(self->p); + brc = CloseHandle (self->p); + self->p = INVALID_HANDLE_VALUE; + win_assert (brc); + } + else + { + rc = closesocket (self->s); + self->s = INVALID_SOCKET; + wsa_assert (rc == 0); + } +} + +static void nn_usock_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_usock *usock; + + usock = nn_cont (self, struct nn_usock, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + + /* Socket in ACCEPTING state cannot be closed. + Stop the socket being accepted first. */ + nn_assert (usock->state != NN_USOCK_STATE_ACCEPTING); + + /* Synchronous stop. */ + if (usock->state == NN_USOCK_STATE_IDLE) + goto finish3; + if (usock->state == NN_USOCK_STATE_DONE) + goto finish2; + if (usock->state == NN_USOCK_STATE_STARTING || + usock->state == NN_USOCK_STATE_ACCEPTED || + usock->state == NN_USOCK_STATE_LISTENING) + goto finish1; + + /* When socket that's being accepted is asked to stop, we have to + ask the listener socket to stop accepting first. */ + if (usock->state == NN_USOCK_STATE_BEING_ACCEPTED) { + nn_fsm_action (&usock->asock->fsm, NN_USOCK_ACTION_CANCEL); + usock->state = NN_USOCK_STATE_STOPPING_ACCEPT; + return; + } + + /* If we were already in the process of cancelling overlapped + operations, we don't have to do anything. Continue waiting + till cancelling is finished. */ + if (usock->state == NN_USOCK_STATE_CANCELLING_IO) { + usock->state = NN_USOCK_STATE_STOPPING; + return; + } + + /* Notify our parent that pipe socket is shutting down */ + nn_fsm_raise (&usock->fsm, &usock->event_error, NN_USOCK_SHUTDOWN); + + /* In all remaining states we'll simply cancel all overlapped + operations. */ + if (nn_usock_cancel_io (usock) == 0) + goto finish1; + usock->state = NN_USOCK_STATE_STOPPING; + return; + } + if (nn_slow (usock->state == NN_USOCK_STATE_STOPPING_ACCEPT)) { + nn_assert (src == NN_FSM_ACTION && type == NN_USOCK_ACTION_DONE); + goto finish1; + } + if (nn_slow (usock->state == NN_USOCK_STATE_STOPPING)) { + if (!nn_worker_op_isidle (&usock->in) || + !nn_worker_op_isidle (&usock->out)) + return; +finish1: + nn_usock_close(usock); +finish2: + usock->state = NN_USOCK_STATE_IDLE; + nn_fsm_stopped (&usock->fsm, NN_USOCK_STOPPED); +finish3: + return; + } + + nn_fsm_bad_state(usock->state, src, type); +} + +static void nn_usock_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_usock *usock; + + usock = nn_cont (self, struct nn_usock, fsm); + + switch (usock->state) { + +/*****************************************************************************/ +/* IDLE state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_IDLE: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + usock->state = NN_USOCK_STATE_STARTING; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* STARTING state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_STARTING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_LISTEN: + usock->state = NN_USOCK_STATE_LISTENING; + return; + case NN_USOCK_ACTION_CONNECT: + usock->state = NN_USOCK_STATE_CONNECTING; + return; + case NN_USOCK_ACTION_BEING_ACCEPTED: + usock->state = NN_USOCK_STATE_BEING_ACCEPTED; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* BEING_ACCEPTED state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_BEING_ACCEPTED: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_DONE: + usock->state = NN_USOCK_STATE_ACCEPTED; + nn_fsm_raise (&usock->fsm, &usock->event_established, + NN_USOCK_ACCEPTED); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* ACCEPTED state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_ACCEPTED: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ACTIVATE: + usock->state = NN_USOCK_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* CONNECTING state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_CONNECTING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_DONE: + usock->state = NN_USOCK_STATE_ACTIVE; + nn_fsm_raise (&usock->fsm, &usock->event_established, + NN_USOCK_CONNECTED); + return; + case NN_USOCK_ACTION_ERROR: + nn_usock_close(usock); + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, &usock->event_error, NN_USOCK_ERROR); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_USOCK_SRC_OUT: + switch (type) { + case NN_WORKER_OP_DONE: + usock->state = NN_USOCK_STATE_ACTIVE; + nn_fsm_raise (&usock->fsm, &usock->event_established, + NN_USOCK_CONNECTED); + return; + case NN_WORKER_OP_ERROR: + nn_usock_close(usock); + usock->state = NN_USOCK_STATE_DONE; + nn_fsm_raise (&usock->fsm, &usock->event_error, NN_USOCK_ERROR); + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* ACTIVE state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_ACTIVE: + switch (src) { + case NN_USOCK_SRC_IN: + switch (type) { + case NN_WORKER_OP_DONE: + nn_fsm_raise (&usock->fsm, &usock->event_received, + NN_USOCK_RECEIVED); + return; + case NN_WORKER_OP_ERROR: + if (nn_usock_cancel_io (usock) == 0) { + nn_fsm_raise(&usock->fsm, &usock->event_error, + NN_USOCK_ERROR); + nn_usock_close (usock); + usock->state = NN_USOCK_STATE_DONE; + return; + } + usock->state = NN_USOCK_STATE_CANCELLING_IO; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_USOCK_SRC_OUT: + switch (type) { + case NN_WORKER_OP_DONE: + if (usock->pipesendbuf) { + nn_free(usock->pipesendbuf); + usock->pipesendbuf = NULL; + } + nn_fsm_raise (&usock->fsm, &usock->event_sent, NN_USOCK_SENT); + return; + case NN_WORKER_OP_ERROR: + if (nn_usock_cancel_io (usock) == 0) { + nn_fsm_raise(&usock->fsm, &usock->event_error, + NN_USOCK_ERROR); + nn_usock_close(usock); + usock->state = NN_USOCK_STATE_DONE; + return; + } + usock->state = NN_USOCK_STATE_CANCELLING_IO; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ERROR: + if (nn_usock_cancel_io (usock) == 0) { + nn_fsm_raise(&usock->fsm, &usock->event_error, + NN_USOCK_SHUTDOWN); + nn_usock_close(usock); + usock->state = NN_USOCK_STATE_DONE; + return; + } + usock->state = NN_USOCK_STATE_CANCELLING_IO; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* CANCELLING_IO state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_CANCELLING_IO: + switch (src) { + case NN_USOCK_SRC_IN: + case NN_USOCK_SRC_OUT: + if (!nn_worker_op_isidle (&usock->in) || + !nn_worker_op_isidle (&usock->out)) + return; + nn_fsm_raise(&usock->fsm, &usock->event_error, NN_USOCK_SHUTDOWN); + nn_usock_close(usock); + usock->state = NN_USOCK_STATE_DONE; + return; + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* DONE state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_DONE: + nn_fsm_bad_source (usock->state, src, type); + +/*****************************************************************************/ +/* LISTENING state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_LISTENING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_ACCEPT: + usock->state = NN_USOCK_STATE_ACCEPTING; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* ACCEPTING state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_ACCEPTING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_USOCK_ACTION_DONE: + usock->state = NN_USOCK_STATE_LISTENING; + return; + case NN_USOCK_ACTION_CANCEL: + if (usock->p == INVALID_HANDLE_VALUE && usock->asock != NULL && usock->domain == AF_UNIX) { + usock->p = usock->asock->p; + nn_usock_cancel_io (usock); + usock->p = INVALID_HANDLE_VALUE; + } + else + { + nn_usock_cancel_io(usock); + } + usock->state = NN_USOCK_STATE_CANCELLING; + return; + default: + nn_fsm_bad_action (usock->state, src, type); + } + case NN_USOCK_SRC_IN: + switch (type) { + case NN_WORKER_OP_DONE: + + /* Adjust the new usock object. */ + usock->asock->state = NN_USOCK_STATE_ACCEPTED; + + /* Notify the user that connection was accepted. */ + nn_fsm_raise (&usock->asock->fsm, + &usock->asock->event_established, NN_USOCK_ACCEPTED); + + /* Disassociate the listener socket from the accepted + socket. */ + usock->asock->asock = NULL; + usock->asock = NULL; + + /* Wait till the user starts accepting once again. */ + usock->state = NN_USOCK_STATE_LISTENING; + + return; + + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* CANCELLING state. */ +/*****************************************************************************/ + case NN_USOCK_STATE_CANCELLING: + switch (src) { + case NN_USOCK_SRC_IN: + switch (type) { + case NN_WORKER_OP_DONE: + case NN_WORKER_OP_ERROR: + + /* TODO: The socket being accepted should be closed here. */ + + usock->state = NN_USOCK_STATE_LISTENING; + + /* Notify the accepted socket that it was stopped. */ + nn_fsm_action (&usock->asock->fsm, NN_USOCK_ACTION_DONE); + + return; + + default: + nn_fsm_bad_action (usock->state, src, type); + } + default: + nn_fsm_bad_source (usock->state, src, type); + } + +/*****************************************************************************/ +/* Invalid state. */ +/*****************************************************************************/ + default: + nn_fsm_bad_state (usock->state, src, type); + } +} + +/*****************************************************************************/ +/* State machine actions. */ +/*****************************************************************************/ + +/* Returns 0 if there's nothing to cancel or 1 otherwise. */ +static int nn_usock_cancel_io (struct nn_usock *self) +{ + int rc; + BOOL brc; + + /* For some reason simple CancelIo doesn't seem to work here. + We have to use CancelIoEx instead. */ + rc = 0; + if (!nn_worker_op_isidle (&self->in)) { + brc = CancelIoEx (self->p, &self->in.olpd); + win_assert (brc || GetLastError () == ERROR_NOT_FOUND); + rc = 1; + } + if (!nn_worker_op_isidle (&self->out)) { + brc = CancelIoEx (self->p, &self->out.olpd); + win_assert (brc || GetLastError () == ERROR_NOT_FOUND); + rc = 1; + } + + return rc; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker.c b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker.c new file mode 100644 index 0000000..1619657 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker.c @@ -0,0 +1,45 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "worker.h" + +#if defined NN_HAVE_WINDOWS +#include "worker_win.inc" +#else +#include "worker_posix.inc" +#endif + +void nn_worker_timer_init (struct nn_worker_timer *self, struct nn_fsm *owner) +{ + self->owner = owner; + nn_timerset_hndl_init (&self->hndl); +} + +void nn_worker_timer_term (struct nn_worker_timer *self) +{ + nn_timerset_hndl_term (&self->hndl); +} + +int nn_worker_timer_isactive (struct nn_worker_timer *self) +{ + return nn_timerset_hndl_isactive (&self->hndl); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker.h new file mode 100644 index 0000000..f49ec48 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker.h @@ -0,0 +1,69 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_WORKER_INCLUDED +#define NN_WORKER_INCLUDED + +#include "fsm.h" +#include "timerset.h" + +#if defined NN_HAVE_WINDOWS +#include "worker_win.h" +#else +#include "worker_posix.h" +#endif + +#define NN_WORKER_TIMER_TIMEOUT 1 + +struct nn_worker_timer { + struct nn_fsm *owner; + struct nn_timerset_hndl hndl; +}; + +void nn_worker_timer_init (struct nn_worker_timer *self, + struct nn_fsm *owner); +void nn_worker_timer_term (struct nn_worker_timer *self); +int nn_worker_timer_isactive (struct nn_worker_timer *self); + +#define NN_WORKER_TASK_EXECUTE 1 + +struct nn_worker_task; + +void nn_worker_task_init (struct nn_worker_task *self, int src, + struct nn_fsm *owner); +void nn_worker_task_term (struct nn_worker_task *self); + +struct nn_worker; + +int nn_worker_init (struct nn_worker *self); +void nn_worker_term (struct nn_worker *self); +void nn_worker_execute (struct nn_worker *self, struct nn_worker_task *task); +void nn_worker_cancel (struct nn_worker *self, struct nn_worker_task *task); + +void nn_worker_add_timer (struct nn_worker *self, int timeout, + struct nn_worker_timer *timer); +void nn_worker_rm_timer (struct nn_worker *self, + struct nn_worker_timer *timer); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_posix.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_posix.h new file mode 100644 index 0000000..4214abb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_posix.h @@ -0,0 +1,67 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../utils/queue.h" +#include "../utils/mutex.h" +#include "../utils/thread.h" +#include "../utils/efd.h" + +#include "poller.h" + +#define NN_WORKER_FD_IN NN_POLLER_IN +#define NN_WORKER_FD_OUT NN_POLLER_OUT +#define NN_WORKER_FD_ERR NN_POLLER_ERR + +struct nn_worker_fd { + int src; + struct nn_fsm *owner; + struct nn_poller_hndl hndl; +}; + +void nn_worker_fd_init (struct nn_worker_fd *self, int src, + struct nn_fsm *owner); +void nn_worker_fd_term (struct nn_worker_fd *self); + +struct nn_worker_task { + int src; + struct nn_fsm *owner; + struct nn_queue_item item; +}; + +struct nn_worker { + struct nn_mutex sync; + struct nn_queue tasks; + struct nn_queue_item stop; + struct nn_efd efd; + struct nn_poller poller; + struct nn_poller_hndl efd_hndl; + struct nn_timerset timerset; + struct nn_thread thread; +}; + +void nn_worker_add_fd (struct nn_worker *self, int s, struct nn_worker_fd *fd); +void nn_worker_rm_fd(struct nn_worker *self, struct nn_worker_fd *fd); +void nn_worker_set_in (struct nn_worker *self, struct nn_worker_fd *fd); +void nn_worker_reset_in (struct nn_worker *self, struct nn_worker_fd *fd); +void nn_worker_set_out (struct nn_worker *self, struct nn_worker_fd *fd); +void nn_worker_reset_out (struct nn_worker *self, struct nn_worker_fd *fd); diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_posix.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_posix.inc new file mode 100644 index 0000000..afdaa9e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_posix.inc @@ -0,0 +1,253 @@ +/* + Copyright (c) 2013-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ctx.h" + +#include "../utils/err.h" +#include "../utils/fast.h" +#include "../utils/cont.h" +#include "../utils/attr.h" +#include "../utils/queue.h" + +/* Private functions. */ +static void nn_worker_routine (void *arg); + +void nn_worker_fd_init (struct nn_worker_fd *self, int src, + struct nn_fsm *owner) +{ + self->src = src; + self->owner = owner; +} + +void nn_worker_fd_term (NN_UNUSED struct nn_worker_fd *self) +{ +} + +void nn_worker_add_fd (struct nn_worker *self, int s, struct nn_worker_fd *fd) +{ + nn_poller_add (&self->poller, s, &fd->hndl); +} + +void nn_worker_rm_fd (struct nn_worker *self, struct nn_worker_fd *fd) +{ + nn_poller_rm (&self->poller, &fd->hndl); +} + +void nn_worker_set_in (struct nn_worker *self, struct nn_worker_fd *fd) +{ + nn_poller_set_in (&self->poller, &fd->hndl); +} + +void nn_worker_reset_in (struct nn_worker *self, struct nn_worker_fd *fd) +{ + nn_poller_reset_in (&self->poller, &fd->hndl); +} + +void nn_worker_set_out (struct nn_worker *self, struct nn_worker_fd *fd) +{ + nn_poller_set_out (&self->poller, &fd->hndl); +} + +void nn_worker_reset_out (struct nn_worker *self, struct nn_worker_fd *fd) +{ + nn_poller_reset_out (&self->poller, &fd->hndl); +} + +void nn_worker_add_timer (struct nn_worker *self, int timeout, + struct nn_worker_timer *timer) +{ + nn_timerset_add (&self->timerset, timeout, &timer->hndl); +} + +void nn_worker_rm_timer (struct nn_worker *self, struct nn_worker_timer *timer) +{ + nn_timerset_rm (&self->timerset, &timer->hndl); +} + +void nn_worker_task_init (struct nn_worker_task *self, int src, + struct nn_fsm *owner) +{ + self->src = src; + self->owner = owner; + nn_queue_item_init (&self->item); +} + +void nn_worker_task_term (struct nn_worker_task *self) +{ + nn_queue_item_term (&self->item); +} + +int nn_worker_init (struct nn_worker *self) +{ + int rc; + + rc = nn_efd_init (&self->efd); + if (rc < 0) + return rc; + + nn_mutex_init (&self->sync); + nn_queue_init (&self->tasks); + nn_queue_item_init (&self->stop); + nn_poller_init (&self->poller); + nn_poller_add (&self->poller, nn_efd_getfd (&self->efd), &self->efd_hndl); + nn_poller_set_in (&self->poller, &self->efd_hndl); + nn_timerset_init (&self->timerset); + nn_thread_init (&self->thread, nn_worker_routine, self); + + return 0; +} + +void nn_worker_term (struct nn_worker *self) +{ + /* Ask worker thread to terminate. */ + nn_mutex_lock (&self->sync); + nn_queue_push (&self->tasks, &self->stop); + nn_efd_signal (&self->efd); + nn_mutex_unlock (&self->sync); + + /* Wait till worker thread terminates. */ + nn_thread_term (&self->thread); + + /* Clean up. */ + nn_timerset_term (&self->timerset); + nn_poller_term (&self->poller); + nn_efd_term (&self->efd); + nn_queue_item_term (&self->stop); + nn_queue_term (&self->tasks); + nn_mutex_term (&self->sync); +} + +void nn_worker_execute (struct nn_worker *self, struct nn_worker_task *task) +{ + nn_mutex_lock (&self->sync); + nn_queue_push (&self->tasks, &task->item); + nn_efd_signal (&self->efd); + nn_mutex_unlock (&self->sync); +} + +void nn_worker_cancel (struct nn_worker *self, struct nn_worker_task *task) +{ + nn_mutex_lock (&self->sync); + nn_queue_remove (&self->tasks, &task->item); + nn_mutex_unlock (&self->sync); +} + +static void nn_worker_routine (void *arg) +{ + int rc; + struct nn_worker *self; + int pevent; + struct nn_poller_hndl *phndl; + struct nn_timerset_hndl *thndl; + struct nn_queue tasks; + struct nn_queue_item *item; + struct nn_worker_task *task; + struct nn_worker_fd *fd; + struct nn_worker_timer *timer; + + self = (struct nn_worker*) arg; + + /* Infinite loop. It will be interrupted only when the object is + shut down. */ + while (1) { + + /* Wait for new events and/or timeouts. */ + rc = nn_poller_wait (&self->poller, + nn_timerset_timeout (&self->timerset)); + errnum_assert (rc == 0, -rc); + + /* Process all expired timers. */ + while (1) { + rc = nn_timerset_event (&self->timerset, &thndl); + if (rc == -EAGAIN) + break; + errnum_assert (rc == 0, -rc); + timer = nn_cont (thndl, struct nn_worker_timer, hndl); + nn_ctx_enter (timer->owner->ctx); + nn_fsm_feed (timer->owner, -1, NN_WORKER_TIMER_TIMEOUT, timer); + nn_ctx_leave (timer->owner->ctx); + } + + /* Process all events from the poller. */ + while (1) { + + /* Get next poller event, such as IN or OUT. */ + rc = nn_poller_event (&self->poller, &pevent, &phndl); + if (nn_slow (rc == -EAGAIN)) + break; + + /* If there are any new incoming worker tasks, process them. */ + if (phndl == &self->efd_hndl) { + nn_assert (pevent == NN_POLLER_IN); + + /* Make a local copy of the task queue. This way + the application threads are not blocked and can post new + tasks while the existing tasks are being processed. Also, + new tasks can be posted from within task handlers. */ + nn_mutex_lock (&self->sync); + nn_efd_unsignal (&self->efd); + memcpy (&tasks, &self->tasks, sizeof (tasks)); + nn_queue_init (&self->tasks); + nn_mutex_unlock (&self->sync); + + while (1) { + + /* Next worker task. */ + item = nn_queue_pop (&tasks); + if (nn_slow (!item)) + break; + + /* If the worker thread is asked to stop, do so. */ + if (nn_slow (item == &self->stop)) { + /* Make sure we remove all the other workers from + the queue, because we're not doing anything with + them. */ + while (nn_queue_pop (&tasks) != NULL) { + continue; + } + nn_queue_term (&tasks); + return; + } + + /* It's a user-defined task. Notify the user that it has + arrived in the worker thread. */ + task = nn_cont (item, struct nn_worker_task, item); + nn_ctx_enter (task->owner->ctx); + nn_fsm_feed (task->owner, task->src, + NN_WORKER_TASK_EXECUTE, task); + nn_ctx_leave (task->owner->ctx); + } + nn_queue_term (&tasks); + continue; + } + + /* It's a true I/O event. Invoke the handler. */ + fd = nn_cont (phndl, struct nn_worker_fd, hndl); + nn_ctx_enter (fd->owner->ctx); + nn_fsm_feed (fd->owner, fd->src, pevent, fd); + nn_ctx_leave (fd->owner->ctx); + } + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_win.h b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_win.h new file mode 100644 index 0000000..1b1dac0 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_win.h @@ -0,0 +1,64 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "fsm.h" +#include "timerset.h" + +#include "../utils/win.h" +#include "../utils/thread.h" + +struct nn_worker_task { + int src; + struct nn_fsm *owner; +}; + +#define NN_WORKER_OP_DONE 1 +#define NN_WORKER_OP_ERROR 2 + +struct nn_worker_op { + int src; + struct nn_fsm *owner; + int state; + + /* This structure is to be used by the user, not nn_worker_op itself. + Actual usage is specific to the asynchronous operation in question. */ + OVERLAPPED olpd; +}; + +void nn_worker_op_init (struct nn_worker_op *self, int src, + struct nn_fsm *owner); +void nn_worker_op_term (struct nn_worker_op *self); + +/* Call this function when asynchronous operation is started. + If 'zeroiserror' is set to 1, zero bytes transferred will be treated + as an error. */ +void nn_worker_op_start (struct nn_worker_op *self, int zeroiserror); + +int nn_worker_op_isidle (struct nn_worker_op *self); + +struct nn_worker { + HANDLE cp; + struct nn_timerset timerset; + struct nn_thread thread; +}; + +HANDLE nn_worker_getcp (struct nn_worker *self); diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_win.inc b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_win.inc new file mode 100644 index 0000000..d62028a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/aio/worker_win.inc @@ -0,0 +1,222 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ctx.h" +#include "usock.h" + +#include "../utils/err.h" +#include "../utils/cont.h" +#include "../utils/fast.h" + +#define NN_WORKER_MAX_EVENTS 32 + +#define NN_WORKER_OP_STATE_IDLE 1 +#define NN_WORKER_OP_STATE_ACTIVE 2 +#define NN_WORKER_OP_STATE_ACTIVE_ZEROISERROR 3 + +/* The value of this variable is irrelevant. It's used only as a placeholder + for the address that is used as the 'stop' event ID. */ +const int nn_worker_stop = 0; + +/* Private functions. */ +static void nn_worker_routine (void *arg); + +void nn_worker_task_init (struct nn_worker_task *self, int src, + struct nn_fsm *owner) +{ + self->src = src; + self->owner = owner; +} + +void nn_worker_task_term (struct nn_worker_task *self) +{ +} + +void nn_worker_op_init (struct nn_worker_op *self, int src, + struct nn_fsm *owner) +{ + self->src = src; + self->owner = owner; + self->state = NN_WORKER_OP_STATE_IDLE; +} + +void nn_worker_op_term (struct nn_worker_op *self) +{ + nn_assert_state (self, NN_WORKER_OP_STATE_IDLE); +} + +void nn_worker_op_start (struct nn_worker_op *self, int zeroiserror) +{ + nn_assert_state (self, NN_WORKER_OP_STATE_IDLE); + self->state = zeroiserror ? NN_WORKER_OP_STATE_ACTIVE_ZEROISERROR : + NN_WORKER_OP_STATE_ACTIVE; +} + +int nn_worker_op_isidle (struct nn_worker_op *self) +{ + return self->state == NN_WORKER_OP_STATE_IDLE ? 1 : 0; +} + +int nn_worker_init (struct nn_worker *self) +{ + self->cp = CreateIoCompletionPort (INVALID_HANDLE_VALUE, NULL, 0, 0); + win_assert (self->cp); + nn_timerset_init (&self->timerset); + nn_thread_init (&self->thread, nn_worker_routine, self); + + return 0; +} + +void nn_worker_term (struct nn_worker *self) +{ + BOOL brc; + + /* Ask worker thread to terminate. */ + brc = PostQueuedCompletionStatus (self->cp, 0, + (ULONG_PTR) &nn_worker_stop, NULL); + win_assert (brc); + + /* Wait till worker thread terminates. */ + nn_thread_term (&self->thread); + + nn_timerset_term (&self->timerset); + brc = CloseHandle (self->cp); + win_assert (brc); +} + +void nn_worker_execute (struct nn_worker *self, struct nn_worker_task *task) +{ + BOOL brc; + + brc = PostQueuedCompletionStatus (self->cp, 0, (ULONG_PTR) task, NULL); + win_assert (brc); +} + +void nn_worker_add_timer (struct nn_worker *self, int timeout, + struct nn_worker_timer *timer) +{ + nn_timerset_add (&((struct nn_worker*) self)->timerset, timeout, + &timer->hndl); +} + +void nn_worker_rm_timer (struct nn_worker *self, struct nn_worker_timer *timer) +{ + nn_timerset_rm (&((struct nn_worker*) self)->timerset, &timer->hndl); +} + +HANDLE nn_worker_getcp (struct nn_worker *self) +{ + return self->cp; +} + +static void nn_worker_routine (void *arg) +{ + int rc; + BOOL brc; + struct nn_worker *self; + int timeout; + ULONG count; + ULONG i; + struct nn_timerset_hndl *thndl; + struct nn_worker_timer *timer; + struct nn_worker_task *task; + struct nn_worker_op *op; + OVERLAPPED_ENTRY entries [NN_WORKER_MAX_EVENTS]; + + self = (struct nn_worker*) arg; + + while (1) { + + /* Process all expired timers. */ + while (1) { + rc = nn_timerset_event (&self->timerset, &thndl); + if (nn_fast (rc == -EAGAIN)) + break; + errnum_assert (rc == 0, -rc); + timer = nn_cont (thndl, struct nn_worker_timer, hndl); + nn_ctx_enter (timer->owner->ctx); + nn_fsm_feed (timer->owner, -1, NN_WORKER_TIMER_TIMEOUT, timer); + nn_ctx_leave (timer->owner->ctx); + } + + /* Compute the time interval till next timer expiration. */ + timeout = nn_timerset_timeout (&self->timerset); + + /* Wait for new events and/or timeouts. */ + brc = GetQueuedCompletionStatusEx (self->cp, entries, + NN_WORKER_MAX_EVENTS, &count, timeout < 0 ? INFINITE : timeout, + FALSE); + if (nn_slow (!brc && GetLastError () == WAIT_TIMEOUT)) + continue; + win_assert (brc); + + for (i = 0; i != count; ++i) { + + /* Process I/O completion events. */ + if (nn_fast (entries [i].lpOverlapped != NULL)) { + op = nn_cont (entries [i].lpOverlapped, + struct nn_worker_op, olpd); + + /* The 'Internal' field is actually an NTSTATUS. Report + success and error. Ignore warnings and informational + messages.*/ + rc = entries [i].Internal & 0xc0000000; + switch (rc) { + case 0x00000000: + rc = NN_WORKER_OP_DONE; + break; + case 0xc0000000: + rc = NN_WORKER_OP_ERROR; + break; + default: + continue; + } + + /* Raise the completion event. */ + nn_ctx_enter (op->owner->ctx); + nn_assert (op->state != NN_WORKER_OP_STATE_IDLE); + if (rc != NN_WORKER_OP_ERROR && + op->state == NN_WORKER_OP_STATE_ACTIVE_ZEROISERROR && + entries [i].dwNumberOfBytesTransferred == 0) + rc = NN_WORKER_OP_ERROR; + op->state = NN_WORKER_OP_STATE_IDLE; + nn_fsm_feed (op->owner, op->src, rc, op); + nn_ctx_leave (op->owner->ctx); + + continue; + } + + /* Worker thread shutdown is requested. */ + if (nn_slow (entries [i].lpCompletionKey == + (ULONG_PTR) &nn_worker_stop)) + return; + + /* Process tasks. */ + task = (struct nn_worker_task*) entries [i].lpCompletionKey; + nn_ctx_enter (task->owner->ctx); + nn_fsm_feed (task->owner, task->src, + NN_WORKER_TASK_EXECUTE, task); + nn_ctx_leave (task->owner->ctx); + } + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/bus.h b/node/node_modules/nanomsg/deps/nanomsg/src/bus.h new file mode 100644 index 0000000..7572903 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/bus.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef BUS_H_INCLUDED +#define BUS_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_PROTO_BUS 7 + +#define NN_BUS (NN_PROTO_BUS * 16 + 0) + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/README b/node/node_modules/nanomsg/deps/nanomsg/src/core/README new file mode 100644 index 0000000..b9c98a1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/README @@ -0,0 +1,3 @@ +In this directory all the generic code of the library resides. I.e. the code +that is not a transport, not a protocol, not a generic utility, rather a glue +between the pieces. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/ep.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/ep.c new file mode 100644 index 0000000..94b5f5e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/ep.c @@ -0,0 +1,230 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../transport.h" + +#include "ep.h" +#include "sock.h" + +#include "../utils/err.h" +#include "../utils/cont.h" +#include "../utils/fast.h" +#include "../utils/attr.h" + +#include + +#define NN_EP_STATE_IDLE 1 +#define NN_EP_STATE_ACTIVE 2 +#define NN_EP_STATE_STOPPING 3 + +#define NN_EP_ACTION_STOPPED 1 + +/* Private functions. */ +static void nn_ep_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_ep_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +int nn_ep_init (struct nn_ep *self, int src, struct nn_sock *sock, int eid, + struct nn_transport *transport, int bind, const char *addr) +{ + int rc; + + nn_fsm_init (&self->fsm, nn_ep_handler, nn_ep_shutdown, + src, self, &sock->fsm); + self->state = NN_EP_STATE_IDLE; + + self->epbase = NULL; + self->sock = sock; + self->eid = eid; + self->last_errno = 0; + nn_list_item_init (&self->item); + memcpy (&self->options, &sock->ep_template, sizeof(struct nn_ep_options)); + + /* Store the textual form of the address. */ + nn_assert (strlen (addr) <= NN_SOCKADDR_MAX); + strcpy (self->addr, addr); + + /* Create transport-specific part of the endpoint. */ + if (bind) + rc = transport->bind ((void*) self, &self->epbase); + else + rc = transport->connect ((void*) self, &self->epbase); + + /* Endpoint creation failed. */ + if (rc < 0) { + nn_list_item_term (&self->item); + nn_fsm_term (&self->fsm); + return rc; + } + + return 0; +} + +void nn_ep_term (struct nn_ep *self) +{ + nn_assert_state (self, NN_EP_STATE_IDLE); + + self->epbase->vfptr->destroy (self->epbase); + nn_list_item_term (&self->item); + nn_fsm_term (&self->fsm); +} + +void nn_ep_start (struct nn_ep *self) +{ + nn_fsm_start (&self->fsm); +} + +void nn_ep_stop (struct nn_ep *self) +{ + nn_fsm_stop (&self->fsm); +} + +void nn_ep_stopped (struct nn_ep *self) +{ + /* TODO: Do the following in a more sane way. */ + self->fsm.stopped.fsm = &self->fsm; + self->fsm.stopped.src = NN_FSM_ACTION; + self->fsm.stopped.srcptr = NULL; + self->fsm.stopped.type = NN_EP_ACTION_STOPPED; + nn_ctx_raise (self->fsm.ctx, &self->fsm.stopped); +} + +struct nn_ctx *nn_ep_getctx (struct nn_ep *self) +{ + return nn_sock_getctx (self->sock); +} + +const char *nn_ep_getaddr (struct nn_ep *self) +{ + return self->addr; +} + +void nn_ep_getopt (struct nn_ep *self, int level, int option, + void *optval, size_t *optvallen) +{ + int rc; + + rc = nn_sock_getopt_inner (self->sock, level, option, optval, optvallen); + errnum_assert (rc == 0, -rc); +} + +int nn_ep_ispeer (struct nn_ep *self, int socktype) +{ + return nn_sock_ispeer (self->sock, socktype); +} + + +static void nn_ep_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_ep *ep; + + ep = nn_cont (self, struct nn_ep, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + ep->epbase->vfptr->stop (ep->epbase); + ep->state = NN_EP_STATE_STOPPING; + return; + } + if (nn_slow (ep->state == NN_EP_STATE_STOPPING)) { + if (src != NN_FSM_ACTION || type != NN_EP_ACTION_STOPPED) + return; + ep->state = NN_EP_STATE_IDLE; + nn_fsm_stopped (&ep->fsm, NN_EP_STOPPED); + return; + } + + nn_fsm_bad_state (ep->state, src, type); +} + + +static void nn_ep_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_ep *ep; + + ep = nn_cont (self, struct nn_ep, fsm); + + switch (ep->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_EP_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + ep->state = NN_EP_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (ep->state, src, type); + } + + default: + nn_fsm_bad_source (ep->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* We don't expect any events in this state. The only thing that can be done */ +/* is closing the endpoint. */ +/******************************************************************************/ + case NN_EP_STATE_ACTIVE: + nn_fsm_bad_source (ep->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (ep->state, src, type); + } +} + +void nn_ep_set_error(struct nn_ep *self, int errnum) +{ + if (self->last_errno == errnum) + /* Error is still there, no need to report it again */ + return; + if (self->last_errno == 0) + nn_sock_stat_increment (self->sock, NN_STAT_CURRENT_EP_ERRORS, 1); + self->last_errno = errnum; + nn_sock_report_error (self->sock, self, errnum); +} + +void nn_ep_clear_error (struct nn_ep *self) +{ + if (self->last_errno == 0) + /* Error is already clear, no need to report it */ + return; + nn_sock_stat_increment (self->sock, NN_STAT_CURRENT_EP_ERRORS, -1); + self->last_errno = 0; + nn_sock_report_error (self->sock, self, 0); +} + +void nn_ep_stat_increment (struct nn_ep *self, int name, int increment) +{ + nn_sock_stat_increment (self->sock, name, increment); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/ep.h b/node/node_modules/nanomsg/deps/nanomsg/src/core/ep.h new file mode 100644 index 0000000..d32c23b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/ep.h @@ -0,0 +1,67 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_EP_INCLUDED +#define NN_EP_INCLUDED + +#include "../transport.h" + +#include "../aio/fsm.h" + +#include "../utils/list.h" + +/* Events generated by the nn_ep object. */ +#define NN_EP_STOPPED 1 + +struct nn_ep { + struct nn_fsm fsm; + int state; + struct nn_epbase *epbase; + struct nn_sock *sock; + struct nn_ep_options options; + int eid; + struct nn_list_item item; + char addr [NN_SOCKADDR_MAX + 1]; + + /* Error state for endpoint */ + int last_errno; +}; + +int nn_ep_init (struct nn_ep *self, int src, struct nn_sock *sock, int eid, + struct nn_transport *transport, int bind, const char *addr); +void nn_ep_term (struct nn_ep *self); + +void nn_ep_start (struct nn_ep *self); +void nn_ep_stop (struct nn_ep *self); + +void nn_ep_stopped (struct nn_ep *self); + +struct nn_ctx *nn_ep_getctx (struct nn_ep *self); +const char *nn_ep_getaddr (struct nn_ep *self); +void nn_ep_getopt (struct nn_ep *self, int level, int option, + void *optval, size_t *optvallen); +int nn_ep_ispeer (struct nn_ep *self, int socktype); +void nn_ep_set_error(struct nn_ep *self, int errnum); +void nn_ep_clear_error(struct nn_ep *self); +void nn_ep_stat_increment(struct nn_ep *self, int name, int increment); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/epbase.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/epbase.c new file mode 100644 index 0000000..28e0905 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/epbase.c @@ -0,0 +1,78 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../transport.h" + +#include "ep.h" +#include "sock.h" +#include "../utils/attr.h" + +void nn_epbase_init (struct nn_epbase *self, + const struct nn_epbase_vfptr *vfptr, void *hint) +{ + self->vfptr = vfptr; + self->ep = (struct nn_ep*) hint; +} + +void nn_epbase_term (NN_UNUSED struct nn_epbase *self) +{ +} + +void nn_epbase_stopped (struct nn_epbase *self) +{ + nn_ep_stopped (self->ep); +} + +struct nn_ctx *nn_epbase_getctx (struct nn_epbase *self) +{ + return nn_ep_getctx (self->ep); +} + +const char *nn_epbase_getaddr (struct nn_epbase *self) +{ + return nn_ep_getaddr (self->ep); +} + +void nn_epbase_getopt (struct nn_epbase *self, int level, int option, + void *optval, size_t *optvallen) +{ + nn_ep_getopt (self->ep, level, option, optval, optvallen); +} + +int nn_epbase_ispeer (struct nn_epbase *self, int socktype) +{ + return nn_ep_ispeer (self->ep, socktype); +} + +void nn_epbase_set_error (struct nn_epbase *self, int errnum) +{ + nn_ep_set_error (self->ep, errnum); +} + +void nn_epbase_clear_error (struct nn_epbase *self) +{ + nn_ep_clear_error (self->ep); +} + +void nn_epbase_stat_increment(struct nn_epbase *self, int name, int increment) { + nn_ep_stat_increment(self->ep, name, increment); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/global.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/global.c new file mode 100644 index 0000000..20dce1c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/global.c @@ -0,0 +1,1181 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../nn.h" +#include "../transport.h" +#include "../protocol.h" + +#include "global.h" +#include "sock.h" +#include "ep.h" + +#include "../aio/pool.h" +#include "../aio/timer.h" + +#include "../utils/err.h" +#include "../utils/alloc.h" +#include "../utils/mutex.h" +#include "../utils/condvar.h" +#include "../utils/once.h" +#include "../utils/list.h" +#include "../utils/cont.h" +#include "../utils/random.h" +#include "../utils/chunk.h" +#include "../utils/msg.h" +#include "../utils/attr.h" + +#include "../transports/inproc/inproc.h" +#include "../transports/ipc/ipc.h" +#include "../transports/tcp/tcp.h" +#include "../transports/ws/ws.h" + +#include "../protocols/pair/pair.h" +#include "../protocols/pair/xpair.h" +#include "../protocols/pubsub/pub.h" +#include "../protocols/pubsub/sub.h" +#include "../protocols/pubsub/xpub.h" +#include "../protocols/pubsub/xsub.h" +#include "../protocols/reqrep/rep.h" +#include "../protocols/reqrep/req.h" +#include "../protocols/reqrep/xrep.h" +#include "../protocols/reqrep/xreq.h" +#include "../protocols/pipeline/push.h" +#include "../protocols/pipeline/pull.h" +#include "../protocols/pipeline/xpush.h" +#include "../protocols/pipeline/xpull.h" +#include "../protocols/survey/respondent.h" +#include "../protocols/survey/surveyor.h" +#include "../protocols/survey/xrespondent.h" +#include "../protocols/survey/xsurveyor.h" +#include "../protocols/bus/bus.h" +#include "../protocols/bus/xbus.h" + +#include "../pubsub.h" +#include "../pipeline.h" + +#include +#include +#include +#include + +#if defined NN_HAVE_WINDOWS +#include "../utils/win.h" +#else +#include +#endif + +/* Max number of concurrent SP sockets. */ +#define NN_MAX_SOCKETS 512 + +/* To save some space, list of unused socket slots uses uint16_t integers to + refer to individual sockets. If there's a need to more that 0x10000 sockets, + the type should be changed to uint32_t or int. */ +CT_ASSERT (NN_MAX_SOCKETS <= 0x10000); + +#define NN_CTX_FLAG_TERMED 1 +#define NN_CTX_FLAG_TERMING 2 +#define NN_CTX_FLAG_TERM (NN_CTX_FLAG_TERMED | NN_CTX_FLAG_TERMING) + +#define NN_GLOBAL_SRC_STAT_TIMER 1 + +#define NN_GLOBAL_STATE_IDLE 1 +#define NN_GLOBAL_STATE_ACTIVE 2 +#define NN_GLOBAL_STATE_STOPPING_TIMER 3 + +struct nn_global { + + /* The global table of existing sockets. The descriptor representing + the socket is the index to this table. This pointer is also used to + find out whether context is initialised. If it is NULL, context is + uninitialised. */ + struct nn_sock **socks; + + /* Stack of unused file descriptors. */ + uint16_t *unused; + + /* Number of actual open sockets in the socket table. */ + size_t nsocks; + + /* Combination of the flags listed above. */ + int flags; + + /* List of all available transports. Note that this list is not + dynamic; i.e. it is created during global initialization and + is never modified. */ + struct nn_list transports; + + /* List of all available socket types. Again this list is not dynamic.*/ + struct nn_list socktypes; + + /* Pool of worker threads. */ + struct nn_pool pool; + + /* Timer and other machinery for submitting statistics */ + int state; + + int print_errors; + + nn_mutex_t lock; + nn_condvar_t cond; +}; + +/* Singleton object containing the global state of the library. */ +static struct nn_global self; +static nn_once_t once = NN_ONCE_INITIALIZER; + + +/* Context creation- and termination-related private functions. */ +static void nn_global_init (void); +static void nn_global_term (void); + +/* Transport-related private functions. */ +static void nn_global_add_transport (struct nn_transport *transport); +static void nn_global_add_socktype (struct nn_socktype *socktype); + +/* Private function that unifies nn_bind and nn_connect functionality. + It returns the ID of the newly created endpoint. */ +static int nn_global_create_ep (struct nn_sock *, const char *addr, int bind); + +/* Private socket creator which doesn't initialize global state and + does no locking by itself */ +static int nn_global_create_socket (int domain, int protocol); + +/* Socket holds. */ +static int nn_global_hold_socket (struct nn_sock **sockp, int s); +static int nn_global_hold_socket_locked (struct nn_sock **sockp, int s); +static void nn_global_rele_socket(struct nn_sock *); + +int nn_errno (void) +{ + return nn_err_errno (); +} + +const char *nn_strerror (int errnum) +{ + return nn_err_strerror (errnum); +} + +static void nn_global_init (void) +{ + int i; + char *envvar; + +#if defined NN_HAVE_WINDOWS + int rc; + WSADATA data; +#endif + + /* Check whether the library was already initialised. If so, do nothing. */ + if (self.socks) + return; + + /* On Windows, initialise the socket library. */ +#if defined NN_HAVE_WINDOWS + rc = WSAStartup (MAKEWORD (2, 2), &data); + nn_assert (rc == 0); + nn_assert (LOBYTE (data.wVersion) == 2 && + HIBYTE (data.wVersion) == 2); +#endif + + /* Initialise the memory allocation subsystem. */ + nn_alloc_init (); + + /* Seed the pseudo-random number generator. */ + nn_random_seed (); + + /* Allocate the global table of SP sockets. */ + self.socks = nn_alloc ((sizeof (struct nn_sock*) * NN_MAX_SOCKETS) + + (sizeof (uint16_t) * NN_MAX_SOCKETS), "socket table"); + alloc_assert (self.socks); + for (i = 0; i != NN_MAX_SOCKETS; ++i) + self.socks [i] = NULL; + self.nsocks = 0; + self.flags = 0; + + /* Print connection and accepting errors to the stderr */ + envvar = getenv("NN_PRINT_ERRORS"); + /* any non-empty string is true */ + self.print_errors = envvar && *envvar; + + /* Allocate the stack of unused file descriptors. */ + self.unused = (uint16_t*) (self.socks + NN_MAX_SOCKETS); + alloc_assert (self.unused); + for (i = 0; i != NN_MAX_SOCKETS; ++i) + self.unused [i] = NN_MAX_SOCKETS - i - 1; + + /* Initialise other parts of the global state. */ + nn_list_init (&self.transports); + nn_list_init (&self.socktypes); + + /* Plug in individual transports. */ + nn_global_add_transport (nn_inproc); + nn_global_add_transport (nn_ipc); + nn_global_add_transport (nn_tcp); + nn_global_add_transport (nn_ws); + + /* Plug in individual socktypes. */ + nn_global_add_socktype (nn_pair_socktype); + nn_global_add_socktype (nn_xpair_socktype); + nn_global_add_socktype (nn_pub_socktype); + nn_global_add_socktype (nn_sub_socktype); + nn_global_add_socktype (nn_xpub_socktype); + nn_global_add_socktype (nn_xsub_socktype); + nn_global_add_socktype (nn_rep_socktype); + nn_global_add_socktype (nn_req_socktype); + nn_global_add_socktype (nn_xrep_socktype); + nn_global_add_socktype (nn_xreq_socktype); + nn_global_add_socktype (nn_push_socktype); + nn_global_add_socktype (nn_xpush_socktype); + nn_global_add_socktype (nn_pull_socktype); + nn_global_add_socktype (nn_xpull_socktype); + nn_global_add_socktype (nn_respondent_socktype); + nn_global_add_socktype (nn_surveyor_socktype); + nn_global_add_socktype (nn_xrespondent_socktype); + nn_global_add_socktype (nn_xsurveyor_socktype); + nn_global_add_socktype (nn_bus_socktype); + nn_global_add_socktype (nn_xbus_socktype); + + /* Start the worker threads. */ + nn_pool_init (&self.pool); +} + +static void nn_global_term (void) +{ +#if defined NN_HAVE_WINDOWS + int rc; +#endif + struct nn_list_item *it; + struct nn_transport *tp; + + /* If there are no sockets remaining, uninitialise the global context. */ + nn_assert (self.socks); + if (self.nsocks > 0) + return; + + /* Shut down the worker threads. */ + nn_pool_term (&self.pool); + + /* Ask all the transport to deallocate their global resources. */ + while (!nn_list_empty (&self.transports)) { + it = nn_list_begin (&self.transports); + tp = nn_cont (it, struct nn_transport, item); + if (tp->term) + tp->term (); + nn_list_erase (&self.transports, it); + } + + /* For now there's nothing to deallocate about socket types, however, + let's remove them from the list anyway. */ + while (!nn_list_empty (&self.socktypes)) + nn_list_erase (&self.socktypes, nn_list_begin (&self.socktypes)); + + /* Final deallocation of the nn_global object itself. */ + nn_list_term (&self.socktypes); + nn_list_term (&self.transports); + nn_free (self.socks); + + /* This marks the global state as uninitialised. */ + self.socks = NULL; + + /* Shut down the memory allocation subsystem. */ + nn_alloc_term (); + + /* On Windows, uninitialise the socket library. */ +#if defined NN_HAVE_WINDOWS + rc = WSACleanup (); + nn_assert (rc == 0); +#endif +} + +void nn_term (void) +{ + int i; + + nn_mutex_lock (&self.lock); + self.flags |= NN_CTX_FLAG_TERMING; + nn_mutex_unlock (&self.lock); + + /* Make sure we really close resources, this will cause global + resources to be freed too when the last socket is closed. */ + for (i = 0; i < NN_MAX_SOCKETS; i++) { + (void) nn_close (i); + } + + nn_mutex_lock (&self.lock); + self.flags |= NN_CTX_FLAG_TERMED; + self.flags &= ~NN_CTX_FLAG_TERMING; + nn_condvar_broadcast(&self.cond); + nn_mutex_unlock (&self.lock); +} + +void nn_init (void) +{ + nn_mutex_lock (&self.lock); + /* Wait for any in progress term to complete. */ + while (self.flags & NN_CTX_FLAG_TERMING) { + nn_condvar_wait (&self.cond, &self.lock, -1); + } + self.flags &= ~NN_CTX_FLAG_TERMED; + nn_mutex_unlock (&self.lock); +} + +void *nn_allocmsg (size_t size, int type) +{ + int rc; + void *result; + + rc = nn_chunk_alloc (size, type, &result); + if (rc == 0) + return result; + errno = -rc; + return NULL; +} + +void *nn_reallocmsg (void *msg, size_t size) +{ + int rc; + + rc = nn_chunk_realloc (size, &msg); + if (rc == 0) + return msg; + errno = -rc; + return NULL; +} + +int nn_freemsg (void *msg) +{ + nn_chunk_free (msg); + return 0; +} + +struct nn_cmsghdr *nn_cmsg_nxthdr_ (const struct nn_msghdr *mhdr, + const struct nn_cmsghdr *cmsg) +{ + char *data; + size_t sz; + struct nn_cmsghdr *next; + size_t headsz; + + /* Early return if no message is provided. */ + if (nn_slow (mhdr == NULL)) + return NULL; + + /* Get the actual data. */ + if (mhdr->msg_controllen == NN_MSG) { + data = *((void**) mhdr->msg_control); + sz = nn_chunk_size (data); + } + else { + data = (char*) mhdr->msg_control; + sz = mhdr->msg_controllen; + } + + /* Ancillary data allocation was not even large enough for one element. */ + if (nn_slow (sz < NN_CMSG_SPACE (0))) + return NULL; + + /* If cmsg is set to NULL we are going to return first property. + Otherwise move to the next property. */ + if (!cmsg) + next = (struct nn_cmsghdr*) data; + else + next = (struct nn_cmsghdr*) + (((char*) cmsg) + NN_CMSG_ALIGN_ (cmsg->cmsg_len)); + + /* If there's no space for next property, treat it as the end + of the property list. */ + headsz = ((char*) next) - data; + if (headsz + NN_CMSG_SPACE (0) > sz || + headsz + NN_CMSG_ALIGN_ (next->cmsg_len) > sz) + return NULL; + + /* Success. */ + return next; +} + +int nn_global_create_socket (int domain, int protocol) +{ + int rc; + int s; + struct nn_list_item *it; + struct nn_socktype *socktype; + struct nn_sock *sock; + + /* The function is called with lock held */ + + /* Only AF_SP and AF_SP_RAW domains are supported. */ + if (nn_slow (domain != AF_SP && domain != AF_SP_RAW)) { + return -EAFNOSUPPORT; + } + + /* If socket limit was reached, report error. */ + if (nn_slow (self.nsocks >= NN_MAX_SOCKETS)) { + return -EMFILE; + } + + /* Find an empty socket slot. */ + s = self.unused [NN_MAX_SOCKETS - self.nsocks - 1]; + + /* Find the appropriate socket type. */ + for (it = nn_list_begin (&self.socktypes); + it != nn_list_end (&self.socktypes); + it = nn_list_next (&self.socktypes, it)) { + socktype = nn_cont (it, struct nn_socktype, item); + if (socktype->domain == domain && socktype->protocol == protocol) { + + /* Instantiate the socket. */ + sock = nn_alloc (sizeof (struct nn_sock), "sock"); + alloc_assert (sock); + rc = nn_sock_init (sock, socktype, s); + if (rc < 0) + return rc; + + /* Adjust the global socket table. */ + self.socks [s] = sock; + ++self.nsocks; + return s; + } + } + /* Specified socket type wasn't found. */ + return -EINVAL; +} + +static void nn_lib_init(void) +{ + /* This function is executed once to initialize global locks. */ + nn_mutex_init (&self.lock); + nn_condvar_init (&self.cond); +} + +int nn_socket (int domain, int protocol) +{ + int rc; + + nn_do_once (&once, nn_lib_init); + + nn_mutex_lock (&self.lock); + + /* If nn_term() was already called, return ETERM. */ + if (nn_slow (self.flags & NN_CTX_FLAG_TERM)) { + nn_mutex_unlock (&self.lock); + errno = ETERM; + return -1; + } + + /* Make sure that global state is initialised. */ + nn_global_init (); + + rc = nn_global_create_socket (domain, protocol); + + if (rc < 0) { + nn_global_term (); + nn_mutex_unlock (&self.lock); + errno = -rc; + return -1; + } + + nn_mutex_unlock (&self.lock); + + return rc; +} + +int nn_close (int s) +{ + int rc; + struct nn_sock *sock; + + nn_mutex_lock (&self.lock); + rc = nn_global_hold_socket_locked (&sock, s); + if (nn_slow (rc < 0)) { + nn_mutex_unlock (&self.lock); + errno = -rc; + return -1; + } + + /* Start the shutdown process on the socket. This will cause + all other socket users, as well as endpoints, to begin cleaning up. + This is done with the lock held to ensure that two instances + of nn_close can't access the same socket. */ + nn_sock_stop (sock); + + /* We have to drop both the hold we just acquired, as well as + the original hold, in order for nn_sock_term to complete. */ + nn_sock_rele (sock); + nn_sock_rele (sock); + nn_mutex_unlock (&self.lock); + + /* Now clean up. The termination routine below will block until + all other consumers of the socket have dropped their holds, and + all endpoints have cleanly exited. */ + rc = nn_sock_term (sock); + if (nn_slow (rc == -EINTR)) { + nn_global_rele_socket (sock); + errno = EINTR; + return -1; + } + + /* Remove the socket from the socket table, add it to unused socket + table. */ + nn_mutex_lock (&self.lock); + self.socks [s] = NULL; + self.unused [NN_MAX_SOCKETS - self.nsocks] = s; + --self.nsocks; + nn_free (sock); + + /* Destroy the global context if there's no socket remaining. */ + nn_global_term (); + + nn_mutex_unlock (&self.lock); + + return 0; +} + +int nn_setsockopt (int s, int level, int option, const void *optval, + size_t optvallen) +{ + int rc; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + + if (nn_slow (!optval && optvallen)) { + rc = -EFAULT; + goto fail; + } + + rc = nn_sock_setopt (sock, level, option, optval, optvallen); + if (nn_slow (rc < 0)) + goto fail; + errnum_assert (rc == 0, -rc); + nn_global_rele_socket (sock); + return 0; + +fail: + nn_global_rele_socket (sock); + errno = -rc; + return -1; +} + +int nn_getsockopt (int s, int level, int option, void *optval, + size_t *optvallen) +{ + int rc; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + + if (nn_slow (!optval && optvallen)) { + rc = -EFAULT; + goto fail; + } + + rc = nn_sock_getopt (sock, level, option, optval, optvallen); + if (nn_slow (rc < 0)) + goto fail; + errnum_assert (rc == 0, -rc); + nn_global_rele_socket (sock); + return 0; + +fail: + nn_global_rele_socket (sock); + errno = -rc; + return -1; +} + +int nn_bind (int s, const char *addr) +{ + int rc; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (rc < 0) { + errno = -rc; + return -1; + } + + rc = nn_global_create_ep (sock, addr, 1); + if (nn_slow (rc < 0)) { + nn_global_rele_socket (sock); + errno = -rc; + return -1; + } + + nn_global_rele_socket (sock); + return rc; +} + +int nn_connect (int s, const char *addr) +{ + int rc; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + + rc = nn_global_create_ep (sock, addr, 0); + if (rc < 0) { + nn_global_rele_socket (sock); + errno = -rc; + return -1; + } + + nn_global_rele_socket (sock); + return rc; +} + +int nn_shutdown (int s, int how) +{ + int rc; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + + rc = nn_sock_rm_ep (sock, how); + if (nn_slow (rc < 0)) { + nn_global_rele_socket (sock); + errno = -rc; + return -1; + } + nn_assert (rc == 0); + + nn_global_rele_socket (sock); + return 0; +} + +int nn_send (int s, const void *buf, size_t len, int flags) +{ + struct nn_iovec iov; + struct nn_msghdr hdr; + + iov.iov_base = (void*) buf; + iov.iov_len = len; + + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = NULL; + hdr.msg_controllen = 0; + + return nn_sendmsg (s, &hdr, flags); +} + +int nn_recv (int s, void *buf, size_t len, int flags) +{ + struct nn_iovec iov; + struct nn_msghdr hdr; + + iov.iov_base = buf; + iov.iov_len = len; + + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = NULL; + hdr.msg_controllen = 0; + + return nn_recvmsg (s, &hdr, flags); +} + +int nn_sendmsg (int s, const struct nn_msghdr *msghdr, int flags) +{ + int rc; + size_t sz; + size_t spsz; + int i; + struct nn_iovec *iov; + struct nn_msg msg; + void *chunk; + int nnmsg; + struct nn_cmsghdr *cmsg; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + + if (nn_slow (!msghdr)) { + rc = -EINVAL; + goto fail; + } + + if (nn_slow (msghdr->msg_iovlen < 0)) { + rc = -EMSGSIZE; + goto fail; + } + + if (msghdr->msg_iovlen == 1 && msghdr->msg_iov [0].iov_len == NN_MSG) { + chunk = *(void**) msghdr->msg_iov [0].iov_base; + if (nn_slow (chunk == NULL)) { + rc = -EFAULT; + goto fail; + } + sz = nn_chunk_size (chunk); + nn_msg_init_chunk (&msg, chunk); + nnmsg = 1; + } + else { + + /* Compute the total size of the message. */ + sz = 0; + for (i = 0; i != msghdr->msg_iovlen; ++i) { + iov = &msghdr->msg_iov [i]; + if (nn_slow (iov->iov_len == NN_MSG)) { + rc = -EINVAL; + goto fail; + } + if (nn_slow (!iov->iov_base && iov->iov_len)) { + rc = -EFAULT; + goto fail; + } + if (nn_slow (sz + iov->iov_len < sz)) { + rc = -EINVAL; + goto fail; + } + sz += iov->iov_len; + } + + /* Create a message object from the supplied scatter array. */ + nn_msg_init (&msg, sz); + sz = 0; + for (i = 0; i != msghdr->msg_iovlen; ++i) { + iov = &msghdr->msg_iov [i]; + memcpy (((uint8_t*) nn_chunkref_data (&msg.body)) + sz, + iov->iov_base, iov->iov_len); + sz += iov->iov_len; + } + + nnmsg = 0; + } + + /* Add ancillary data to the message. */ + if (msghdr->msg_control) { + + /* Copy all headers. */ + /* TODO: SP_HDR should not be copied here! */ + if (msghdr->msg_controllen == NN_MSG) { + chunk = *((void**) msghdr->msg_control); + nn_chunkref_term (&msg.hdrs); + nn_chunkref_init_chunk (&msg.hdrs, chunk); + } + else { + nn_chunkref_term (&msg.hdrs); + nn_chunkref_init (&msg.hdrs, msghdr->msg_controllen); + memcpy (nn_chunkref_data (&msg.hdrs), + msghdr->msg_control, msghdr->msg_controllen); + } + + /* Search for SP_HDR property. */ + cmsg = NN_CMSG_FIRSTHDR (msghdr); + while (cmsg) { + if (cmsg->cmsg_level == PROTO_SP && cmsg->cmsg_type == SP_HDR) { + unsigned char *ptr = NN_CMSG_DATA (cmsg); + size_t clen = cmsg->cmsg_len - NN_CMSG_SPACE (0); + if (clen > sizeof (size_t)) { + spsz = *(size_t *)(void *)ptr; + if (spsz <= (clen - sizeof (size_t))) { + /* Copy body of SP_HDR property into 'sphdr'. */ + nn_chunkref_term (&msg.sphdr); + nn_chunkref_init (&msg.sphdr, spsz); + memcpy (nn_chunkref_data (&msg.sphdr), + ptr + sizeof (size_t), spsz); + } + } + break; + } + cmsg = NN_CMSG_NXTHDR (msghdr, cmsg); + } + } + + /* Send it further down the stack. */ + rc = nn_sock_send (sock, &msg, flags); + if (nn_slow (rc < 0)) { + + /* If we are dealing with user-supplied buffer, detach it from + the message object. */ + if (nnmsg) + nn_chunkref_init (&msg.body, 0); + + nn_msg_term (&msg); + goto fail; + } + + /* Adjust the statistics. */ + nn_sock_stat_increment (sock, NN_STAT_MESSAGES_SENT, 1); + nn_sock_stat_increment (sock, NN_STAT_BYTES_SENT, sz); + + nn_global_rele_socket (sock); + + return (int) sz; + +fail: + nn_global_rele_socket (sock); + + errno = -rc; + return -1; +} + +int nn_recvmsg (int s, struct nn_msghdr *msghdr, int flags) +{ + int rc; + struct nn_msg msg; + uint8_t *data; + size_t sz; + int i; + struct nn_iovec *iov; + void *chunk; + size_t hdrssz; + void *ctrl; + size_t ctrlsz; + size_t spsz; + size_t sptotalsz; + struct nn_cmsghdr *chdr; + struct nn_sock *sock; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + + if (nn_slow (!msghdr)) { + rc = -EINVAL; + goto fail; + } + + if (nn_slow (msghdr->msg_iovlen < 0)) { + rc = -EMSGSIZE; + goto fail; + } + + /* Get a message. */ + rc = nn_sock_recv (sock, &msg, flags); + if (nn_slow (rc < 0)) { + goto fail; + } + + if (msghdr->msg_iovlen == 1 && msghdr->msg_iov [0].iov_len == NN_MSG) { + chunk = nn_chunkref_getchunk (&msg.body); + *(void**) (msghdr->msg_iov [0].iov_base) = chunk; + sz = nn_chunk_size (chunk); + } + else { + + /* Copy the message content into the supplied gather array. */ + data = nn_chunkref_data (&msg.body); + sz = nn_chunkref_size (&msg.body); + for (i = 0; i != msghdr->msg_iovlen; ++i) { + iov = &msghdr->msg_iov [i]; + if (nn_slow (iov->iov_len == NN_MSG)) { + nn_msg_term (&msg); + rc = -EINVAL; + goto fail; + } + if (iov->iov_len > sz) { + memcpy (iov->iov_base, data, sz); + break; + } + memcpy (iov->iov_base, data, iov->iov_len); + data += iov->iov_len; + sz -= iov->iov_len; + } + sz = nn_chunkref_size (&msg.body); + } + + /* Retrieve the ancillary data from the message. */ + if (msghdr->msg_control) { + + spsz = nn_chunkref_size (&msg.sphdr); + sptotalsz = NN_CMSG_SPACE (spsz+sizeof (size_t)); + ctrlsz = sptotalsz + nn_chunkref_size (&msg.hdrs); + + if (msghdr->msg_controllen == NN_MSG) { + + /* Allocate the buffer. */ + rc = nn_chunk_alloc (ctrlsz, 0, &ctrl); + errnum_assert (rc == 0, -rc); + + /* Set output parameters. */ + *((void**) msghdr->msg_control) = ctrl; + } + else { + + /* Just use the buffer supplied by the user. */ + ctrl = msghdr->msg_control; + ctrlsz = msghdr->msg_controllen; + } + + /* If SP header alone won't fit into the buffer, return no ancillary + properties. */ + if (ctrlsz >= sptotalsz) { + char *ptr; + + /* Fill in SP_HDR ancillary property. */ + chdr = (struct nn_cmsghdr*) ctrl; + chdr->cmsg_len = sptotalsz; + chdr->cmsg_level = PROTO_SP; + chdr->cmsg_type = SP_HDR; + ptr = (void *)chdr; + ptr += sizeof (*chdr); + *(size_t *)(void *)ptr = spsz; + ptr += sizeof (size_t); + memcpy (ptr, nn_chunkref_data (&msg.sphdr), spsz); + + /* Fill in as many remaining properties as possible. + Truncate the trailing properties if necessary. */ + hdrssz = nn_chunkref_size (&msg.hdrs); + if (hdrssz > ctrlsz - sptotalsz) + hdrssz = ctrlsz - sptotalsz; + memcpy (((char*) ctrl) + sptotalsz, + nn_chunkref_data (&msg.hdrs), hdrssz); + } + } + + nn_msg_term (&msg); + + /* Adjust the statistics. */ + nn_sock_stat_increment (sock, NN_STAT_MESSAGES_RECEIVED, 1); + nn_sock_stat_increment (sock, NN_STAT_BYTES_RECEIVED, sz); + + nn_global_rele_socket (sock); + + return (int) sz; + +fail: + nn_global_rele_socket (sock); + + errno = -rc; + return -1; +} + +uint64_t nn_get_statistic (int s, int statistic) +{ + int rc; + struct nn_sock *sock; + uint64_t val; + + rc = nn_global_hold_socket (&sock, s); + if (nn_slow (rc < 0)) { + errno = -rc; + return (uint64_t)-1; + } + + switch (statistic) { + case NN_STAT_ESTABLISHED_CONNECTIONS: + val = sock->statistics.established_connections; + break; + case NN_STAT_ACCEPTED_CONNECTIONS: + val = sock->statistics.accepted_connections; + break; + case NN_STAT_DROPPED_CONNECTIONS: + val = sock->statistics.dropped_connections; + break; + case NN_STAT_BROKEN_CONNECTIONS: + val = sock->statistics.broken_connections; + break; + case NN_STAT_CONNECT_ERRORS: + val = sock->statistics.connect_errors; + break; + case NN_STAT_BIND_ERRORS: + val = sock->statistics.bind_errors; + break; + case NN_STAT_ACCEPT_ERRORS: + val = sock->statistics.bind_errors; + break; + case NN_STAT_MESSAGES_SENT: + val = sock->statistics.messages_sent; + break; + case NN_STAT_MESSAGES_RECEIVED: + val = sock->statistics.messages_received; + break; + case NN_STAT_BYTES_SENT: + val = sock->statistics.bytes_sent; + break; + case NN_STAT_BYTES_RECEIVED: + val = sock->statistics.bytes_received; + break; + case NN_STAT_CURRENT_CONNECTIONS: + val = sock->statistics.current_connections; + break; + case NN_STAT_INPROGRESS_CONNECTIONS: + val = sock->statistics.inprogress_connections; + break; + case NN_STAT_CURRENT_SND_PRIORITY: + val = sock->statistics.current_snd_priority; + break; + case NN_STAT_CURRENT_EP_ERRORS: + val = sock->statistics.current_ep_errors; + break; + default: + val = (uint64_t)-1; + errno = EINVAL; + break; + } + + nn_global_rele_socket (sock); + return val; +} + +static void nn_global_add_transport (struct nn_transport *transport) +{ + if (transport->init) + transport->init (); + nn_list_insert (&self.transports, &transport->item, + nn_list_end (&self.transports)); +} + +static void nn_global_add_socktype (struct nn_socktype *socktype) +{ + nn_list_insert (&self.socktypes, &socktype->item, + nn_list_end (&self.socktypes)); +} + +static int nn_global_create_ep (struct nn_sock *sock, const char *addr, + int bind) +{ + int rc; + const char *proto; + const char *delim; + size_t protosz; + struct nn_transport *tp; + struct nn_list_item *it; + + /* Check whether address is valid. */ + if (!addr) + return -EINVAL; + if (strlen (addr) >= NN_SOCKADDR_MAX) + return -ENAMETOOLONG; + + /* Separate the protocol and the actual address. */ + proto = addr; + delim = strchr (addr, ':'); + if (!delim) + return -EINVAL; + if (delim [1] != '/' || delim [2] != '/') + return -EINVAL; + protosz = delim - addr; + addr += protosz + 3; + + /* Find the specified protocol. */ + tp = NULL; + for (it = nn_list_begin (&self.transports); + it != nn_list_end (&self.transports); + it = nn_list_next (&self.transports, it)) { + tp = nn_cont (it, struct nn_transport, item); + if (strlen (tp->name) == protosz && + memcmp (tp->name, proto, protosz) == 0) + break; + tp = NULL; + } + + /* The protocol specified doesn't match any known protocol. */ + if (!tp) { + return -EPROTONOSUPPORT; + } + + /* Ask the socket to create the endpoint. */ + rc = nn_sock_add_ep (sock, tp, bind, addr); + return rc; +} + +struct nn_transport *nn_global_transport (int id) +{ + struct nn_transport *tp; + struct nn_list_item *it; + + /* Find the specified protocol. */ + tp = NULL; + for (it = nn_list_begin (&self.transports); + it != nn_list_end (&self.transports); + it = nn_list_next (&self.transports, it)) { + tp = nn_cont (it, struct nn_transport, item); + if (tp->id == id) + break; + tp = NULL; + } + + return tp; +} + +struct nn_pool *nn_global_getpool () +{ + return &self.pool; +} + +int nn_global_print_errors () +{ + return self.print_errors; +} + +/* Get the socket structure for a socket id. This must be called under + the global lock (self.lock.) The socket itself will not be freed + while the hold is active. */ +int nn_global_hold_socket_locked(struct nn_sock **sockp, int s) +{ + struct nn_sock *sock; + + if (nn_slow (s < 0 || s >= NN_MAX_SOCKETS || self.socks == NULL)) + return -EBADF; + + sock = self.socks[s]; + if (nn_slow (sock == NULL)) { + return -EBADF; + } + + if (nn_slow (nn_sock_hold (sock) != 0)) { + return -EBADF; + } + *sockp = sock; + return 0; +} + +int nn_global_hold_socket(struct nn_sock **sockp, int s) +{ + int rc; + nn_mutex_lock(&self.lock); + rc = nn_global_hold_socket_locked(sockp, s); + nn_mutex_unlock(&self.lock); + return rc; +} + +void nn_global_rele_socket(struct nn_sock *sock) +{ + nn_mutex_lock(&self.lock); + nn_sock_rele(sock); + nn_mutex_unlock(&self.lock); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/global.h b/node/node_modules/nanomsg/deps/nanomsg/src/core/global.h new file mode 100644 index 0000000..53e9d25 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/global.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_GLOBAL_INCLUDED +#define NN_GLOBAL_INCLUDED + +/* Provides access to the list of available transports. */ +struct nn_transport *nn_global_transport (int id); + +/* Returns the global worker thread pool. */ +struct nn_pool *nn_global_getpool (); +int nn_global_print_errors(); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/pipe.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/pipe.c new file mode 100644 index 0000000..56d2d6e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/pipe.c @@ -0,0 +1,228 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../transport.h" +#include "../protocol.h" + +#include "sock.h" +#include "ep.h" + +#include "../utils/err.h" +#include "../utils/fast.h" + +/* Internal pipe states. */ +#define NN_PIPEBASE_STATE_IDLE 1 +#define NN_PIPEBASE_STATE_ACTIVE 2 +#define NN_PIPEBASE_STATE_FAILED 3 + +#define NN_PIPEBASE_INSTATE_DEACTIVATED 0 +#define NN_PIPEBASE_INSTATE_IDLE 1 +#define NN_PIPEBASE_INSTATE_RECEIVING 2 +#define NN_PIPEBASE_INSTATE_RECEIVED 3 +#define NN_PIPEBASE_INSTATE_ASYNC 4 + +#define NN_PIPEBASE_OUTSTATE_DEACTIVATED 0 +#define NN_PIPEBASE_OUTSTATE_IDLE 1 +#define NN_PIPEBASE_OUTSTATE_SENDING 2 +#define NN_PIPEBASE_OUTSTATE_SENT 3 +#define NN_PIPEBASE_OUTSTATE_ASYNC 4 + +void nn_pipebase_init (struct nn_pipebase *self, + const struct nn_pipebase_vfptr *vfptr, struct nn_epbase *epbase) +{ + nn_assert (epbase->ep->sock); + + nn_fsm_init (&self->fsm, NULL, NULL, 0, self, &epbase->ep->sock->fsm); + self->vfptr = vfptr; + self->state = NN_PIPEBASE_STATE_IDLE; + self->instate = NN_PIPEBASE_INSTATE_DEACTIVATED; + self->outstate = NN_PIPEBASE_OUTSTATE_DEACTIVATED; + self->sock = epbase->ep->sock; + memcpy (&self->options, &epbase->ep->options, + sizeof (struct nn_ep_options)); + nn_fsm_event_init (&self->in); + nn_fsm_event_init (&self->out); +} + +void nn_pipebase_term (struct nn_pipebase *self) +{ + nn_assert_state (self, NN_PIPEBASE_STATE_IDLE); + + nn_fsm_event_term (&self->out); + nn_fsm_event_term (&self->in); + nn_fsm_term (&self->fsm); +} + +int nn_pipebase_start (struct nn_pipebase *self) +{ + int rc; + + nn_assert_state (self, NN_PIPEBASE_STATE_IDLE); + + self->state = NN_PIPEBASE_STATE_ACTIVE; + self->instate = NN_PIPEBASE_INSTATE_ASYNC; + self->outstate = NN_PIPEBASE_OUTSTATE_IDLE; + rc = nn_sock_add (self->sock, (struct nn_pipe*) self); + if (nn_slow (rc < 0)) { + self->state = NN_PIPEBASE_STATE_FAILED; + return rc; + } + if (self->sock) + nn_fsm_raise (&self->fsm, &self->out, NN_PIPE_OUT); + + return 0; +} + +void nn_pipebase_stop (struct nn_pipebase *self) +{ + if (self->state == NN_PIPEBASE_STATE_ACTIVE) + nn_sock_rm (self->sock, (struct nn_pipe*) self); + self->state = NN_PIPEBASE_STATE_IDLE; +} + +void nn_pipebase_received (struct nn_pipebase *self) +{ + if (nn_fast (self->instate == NN_PIPEBASE_INSTATE_RECEIVING)) { + self->instate = NN_PIPEBASE_INSTATE_RECEIVED; + return; + } + nn_assert (self->instate == NN_PIPEBASE_INSTATE_ASYNC); + self->instate = NN_PIPEBASE_INSTATE_IDLE; + if (self->sock) + nn_fsm_raise (&self->fsm, &self->in, NN_PIPE_IN); +} + +void nn_pipebase_sent (struct nn_pipebase *self) +{ + if (nn_fast (self->outstate == NN_PIPEBASE_OUTSTATE_SENDING)) { + self->outstate = NN_PIPEBASE_OUTSTATE_SENT; + return; + } + nn_assert (self->outstate == NN_PIPEBASE_OUTSTATE_ASYNC); + self->outstate = NN_PIPEBASE_OUTSTATE_IDLE; + if (self->sock) + nn_fsm_raise (&self->fsm, &self->out, NN_PIPE_OUT); +} + +void nn_pipebase_getopt (struct nn_pipebase *self, int level, int option, + void *optval, size_t *optvallen) +{ + int rc; + int intval; + + if (level == NN_SOL_SOCKET) { + switch (option) { + + /* Endpoint options */ + case NN_SNDPRIO: + intval = self->options.sndprio; + break; + case NN_RCVPRIO: + intval = self->options.rcvprio; + break; + case NN_IPV4ONLY: + intval = self->options.ipv4only; + break; + + /* Fallback to socket options */ + default: + rc = nn_sock_getopt_inner (self->sock, level, + option, optval, optvallen); + errnum_assert (rc == 0, -rc); + return; + } + + memcpy (optval, &intval, + *optvallen < sizeof (int) ? *optvallen : sizeof (int)); + *optvallen = sizeof (int); + + return; + } + + rc = nn_sock_getopt_inner (self->sock, level, option, optval, optvallen); + errnum_assert (rc == 0, -rc); +} + +int nn_pipebase_ispeer (struct nn_pipebase *self, int socktype) +{ + return nn_sock_ispeer (self->sock, socktype); +} + +void nn_pipe_setdata (struct nn_pipe *self, void *data) +{ + ((struct nn_pipebase*) self)->data = data; +} + +void *nn_pipe_getdata (struct nn_pipe *self) +{ + return ((struct nn_pipebase*) self)->data; +} + +int nn_pipe_send (struct nn_pipe *self, struct nn_msg *msg) +{ + int rc; + struct nn_pipebase *pipebase; + + pipebase = (struct nn_pipebase*) self; + nn_assert (pipebase->outstate == NN_PIPEBASE_OUTSTATE_IDLE); + pipebase->outstate = NN_PIPEBASE_OUTSTATE_SENDING; + rc = pipebase->vfptr->send (pipebase, msg); + errnum_assert (rc >= 0, -rc); + if (nn_fast (pipebase->outstate == NN_PIPEBASE_OUTSTATE_SENT)) { + pipebase->outstate = NN_PIPEBASE_OUTSTATE_IDLE; + return rc; + } + nn_assert (pipebase->outstate == NN_PIPEBASE_OUTSTATE_SENDING); + pipebase->outstate = NN_PIPEBASE_OUTSTATE_ASYNC; + return rc | NN_PIPEBASE_RELEASE; +} + +int nn_pipe_recv (struct nn_pipe *self, struct nn_msg *msg) +{ + int rc; + struct nn_pipebase *pipebase; + + pipebase = (struct nn_pipebase*) self; + nn_assert (pipebase->instate == NN_PIPEBASE_INSTATE_IDLE); + pipebase->instate = NN_PIPEBASE_INSTATE_RECEIVING; + rc = pipebase->vfptr->recv (pipebase, msg); + errnum_assert (rc >= 0, -rc); + + if (nn_fast (pipebase->instate == NN_PIPEBASE_INSTATE_RECEIVED)) { + pipebase->instate = NN_PIPEBASE_INSTATE_IDLE; + return rc; + } + nn_assert (pipebase->instate == NN_PIPEBASE_INSTATE_RECEIVING); + pipebase->instate = NN_PIPEBASE_INSTATE_ASYNC; + return rc | NN_PIPEBASE_RELEASE; +} + +void nn_pipe_getopt (struct nn_pipe *self, int level, int option, + void *optval, size_t *optvallen) +{ + + struct nn_pipebase *pipebase; + + pipebase = (struct nn_pipebase*) self; + nn_pipebase_getopt (pipebase, level, option, optval, optvallen); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/poll.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/poll.c new file mode 100644 index 0000000..3a9a44e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/poll.c @@ -0,0 +1,205 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../nn.h" + +#if defined NN_HAVE_WINDOWS + +#include "../utils/win.h" +#include "../utils/fast.h" +#include "../utils/sleep.h" +#include "../utils/err.h" + +int nn_poll (struct nn_pollfd *fds, int nfds, int timeout) +{ + int rc; + int i; + fd_set fdset; + SOCKET fd; + int res; + size_t sz; + struct timeval tv; + + /* Fill in the fdset, as appropriate. */ + FD_ZERO (&fdset); + for (i = 0; i != nfds; ++i) { + if (fds [i].events & NN_POLLIN) { + sz = sizeof (fd); + rc = nn_getsockopt (fds [i].fd, NN_SOL_SOCKET, NN_RCVFD, &fd, &sz); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + nn_assert (sz == sizeof (fd)); + FD_SET (fd, &fdset); + } + if (fds [i].events & NN_POLLOUT) { + sz = sizeof (fd); + rc = nn_getsockopt (fds [i].fd, NN_SOL_SOCKET, NN_SNDFD, &fd, &sz); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + nn_assert (sz == sizeof (fd)); + FD_SET (fd, &fdset); + } + } + + /* Do the polling itself. */ + tv.tv_sec = timeout / 1000; + tv.tv_usec = timeout % 1000 * 1000; + if (nn_fast (nfds)) { + rc = select (-1, &fdset, NULL, NULL, &tv); + if (nn_slow (rc == 0)) + return 0; + if (nn_slow (rc == SOCKET_ERROR)) { + errno = nn_err_wsa_to_posix (WSAGetLastError ()); + return -1; + } + } + else { + + /* POSIX platforms will sleep until timeout is expired, + so let's do the same on Windows. */ + if (timeout > 0) + nn_sleep(timeout); + return 0; + } + + /* Move the results from fdset to the nanomsg pollset. */ + res = 0; + for (i = 0; i != nfds; ++i) { + fds [i].revents = 0; + if (fds [i].events & NN_POLLIN) { + sz = sizeof (fd); + rc = nn_getsockopt (fds [i].fd, NN_SOL_SOCKET, NN_RCVFD, &fd, &sz); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + nn_assert (sz == sizeof (fd)); + if (FD_ISSET (fd, &fdset)) + fds [i].revents |= NN_POLLIN; + } + if (fds [i].events & NN_POLLOUT) { + sz = sizeof (fd); + rc = nn_getsockopt (fds [i].fd, NN_SOL_SOCKET, NN_SNDFD, &fd, &sz); + if (nn_slow (rc < 0)) { + errno = -rc; + return -1; + } + nn_assert (sz == sizeof (fd)); + if (FD_ISSET (fd, &fdset)) + fds [i].revents |= NN_POLLOUT; + } + if (fds [i].revents) + ++res; + } + + return res; +} + +#else + +#include "../utils/alloc.h" +#include "../utils/fast.h" +#include "../utils/err.h" + +#include +#include + +int nn_poll (struct nn_pollfd *fds, int nfds, int timeout) +{ + int rc; + int i; + int pos; + int fd; + int res; + size_t sz; + struct pollfd *pfd; + + /* Construct a pollset to be used with OS-level 'poll' function. */ + pfd = nn_alloc (sizeof (struct pollfd) * nfds * 2, "pollset"); + alloc_assert (pfd); + pos = 0; + for (i = 0; i != nfds; ++i) { + if (fds [i].events & NN_POLLIN) { + sz = sizeof (fd); + rc = nn_getsockopt (fds [i].fd, NN_SOL_SOCKET, NN_RCVFD, &fd, &sz); + if (nn_slow (rc < 0)) { + nn_free (pfd); + errno = -rc; + return -1; + } + nn_assert (sz == sizeof (fd)); + pfd [pos].fd = fd; + pfd [pos].events = POLLIN; + ++pos; + } + if (fds [i].events & NN_POLLOUT) { + sz = sizeof (fd); + rc = nn_getsockopt (fds [i].fd, NN_SOL_SOCKET, NN_SNDFD, &fd, &sz); + if (nn_slow (rc < 0)) { + nn_free (pfd); + errno = -rc; + return -1; + } + nn_assert (sz == sizeof (fd)); + pfd [pos].fd = fd; + pfd [pos].events = POLLIN; + ++pos; + } + } + + /* Do the polling itself. */ + rc = poll (pfd, pos, timeout); + if (nn_slow (rc <= 0)) { + res = errno; + nn_free (pfd); + errno = res; + return rc; + } + + /* Move the results from OS-level poll to nn_poll's pollset. */ + res = 0; + pos = 0; + for (i = 0; i != nfds; ++i) { + fds [i].revents = 0; + if (fds [i].events & NN_POLLIN) { + if (pfd [pos].revents & POLLIN) + fds [i].revents |= NN_POLLIN; + ++pos; + } + if (fds [i].events & NN_POLLOUT) { + if (pfd [pos].revents & POLLIN) + fds [i].revents |= NN_POLLOUT; + ++pos; + } + if (fds [i].revents) + ++res; + } + + nn_free (pfd); + return res; +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/sock.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/sock.c new file mode 100644 index 0000000..4db7d49 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/sock.c @@ -0,0 +1,1132 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../protocol.h" +#include "../transport.h" + +#include "sock.h" +#include "global.h" +#include "ep.h" + +#include "../utils/err.h" +#include "../utils/cont.h" +#include "../utils/clock.h" +#include "../utils/fast.h" +#include "../utils/alloc.h" +#include "../utils/msg.h" + +#include + +/* These bits specify whether individual efds are signalled or not at + the moment. Storing this information allows us to avoid redundant signalling + and unsignalling of the efd objects. */ +#define NN_SOCK_FLAG_IN 1 +#define NN_SOCK_FLAG_OUT 2 + +/* Possible states of the socket. */ +#define NN_SOCK_STATE_INIT 1 +#define NN_SOCK_STATE_ACTIVE 2 +#define NN_SOCK_STATE_STOPPING_EPS 3 +#define NN_SOCK_STATE_STOPPING 4 +#define NN_SOCK_STATE_FINI 5 + +/* Events sent to the state machine. */ +#define NN_SOCK_ACTION_STOPPED 1 + +/* Subordinated source objects. */ +#define NN_SOCK_SRC_EP 1 + +/* Private functions. */ +static struct nn_optset *nn_sock_optset (struct nn_sock *self, int id); +static int nn_sock_setopt_inner (struct nn_sock *self, int level, + int option, const void *optval, size_t optvallen); +static void nn_sock_onleave (struct nn_ctx *self); +static void nn_sock_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_sock_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +/* Initialize a socket. A hold is placed on the initialized socket for + the caller as well. */ +int nn_sock_init (struct nn_sock *self, struct nn_socktype *socktype, int fd) +{ + int rc; + int i; + + /* Make sure that at least one message direction is supported. */ + nn_assert (!(socktype->flags & NN_SOCKTYPE_FLAG_NOSEND) || + !(socktype->flags & NN_SOCKTYPE_FLAG_NORECV)); + + /* Create the AIO context for the SP socket. */ + nn_ctx_init (&self->ctx, nn_global_getpool (), nn_sock_onleave); + + /* Initialise the state machine. */ + nn_fsm_init_root (&self->fsm, nn_sock_handler, + nn_sock_shutdown, &self->ctx); + self->state = NN_SOCK_STATE_INIT; + + /* Open the NN_SNDFD and NN_RCVFD efds. Do so, only if the socket type + supports send/recv, as appropriate. */ + if (socktype->flags & NN_SOCKTYPE_FLAG_NOSEND) + memset (&self->sndfd, 0xcd, sizeof (self->sndfd)); + else { + rc = nn_efd_init (&self->sndfd); + if (nn_slow (rc < 0)) + return rc; + } + if (socktype->flags & NN_SOCKTYPE_FLAG_NORECV) + memset (&self->rcvfd, 0xcd, sizeof (self->rcvfd)); + else { + rc = nn_efd_init (&self->rcvfd); + if (nn_slow (rc < 0)) { + if (!(socktype->flags & NN_SOCKTYPE_FLAG_NOSEND)) + nn_efd_term (&self->sndfd); + return rc; + } + } + nn_sem_init (&self->termsem); + nn_sem_init (&self->relesem); + if (nn_slow (rc < 0)) { + if (!(socktype->flags & NN_SOCKTYPE_FLAG_NORECV)) + nn_efd_term (&self->rcvfd); + if (!(socktype->flags & NN_SOCKTYPE_FLAG_NOSEND)) + nn_efd_term (&self->sndfd); + return rc; + } + + self->holds = 1; /* Callers hold. */ + self->flags = 0; + nn_list_init (&self->eps); + nn_list_init (&self->sdeps); + self->eid = 1; + + /* Default values for NN_SOL_SOCKET options. */ + self->linger = 1000; + self->sndbuf = 128 * 1024; + self->rcvbuf = 128 * 1024; + self->rcvmaxsize = 1024 * 1024; + self->sndtimeo = -1; + self->rcvtimeo = -1; + self->reconnect_ivl = 100; + self->reconnect_ivl_max = 0; + self->maxttl = 8; + self->ep_template.sndprio = 8; + self->ep_template.rcvprio = 8; + self->ep_template.ipv4only = 1; + + /* Initialize statistic entries */ + self->statistics.established_connections = 0; + self->statistics.accepted_connections = 0; + self->statistics.dropped_connections = 0; + self->statistics.broken_connections = 0; + self->statistics.connect_errors = 0; + self->statistics.bind_errors = 0; + self->statistics.accept_errors = 0; + + self->statistics.messages_sent = 0; + self->statistics.messages_received = 0; + self->statistics.bytes_sent = 0; + self->statistics.bytes_received = 0; + + self->statistics.current_connections = 0; + self->statistics.inprogress_connections = 0; + self->statistics.current_snd_priority = 0; + self->statistics.current_ep_errors = 0; + + /* Should be pretty much enough space for just the number */ + sprintf(self->socket_name, "%d", fd); + + /* Security attribute */ + self->sec_attr = NULL; + self->sec_attr_size = 0; + self->inbuffersz = 4096; + self->outbuffersz = 4096; + + /* The transport-specific options are not initialised immediately, + rather, they are allocated later on when needed. */ + for (i = 0; i != NN_MAX_TRANSPORT; ++i) + self->optsets [i] = NULL; + + /* Create the specific socket type itself. */ + rc = socktype->create ((void*) self, &self->sockbase); + errnum_assert (rc == 0, -rc); + self->socktype = socktype; + + /* Launch the state machine. */ + nn_ctx_enter (&self->ctx); + nn_fsm_start (&self->fsm); + nn_ctx_leave (&self->ctx); + + return 0; +} + +void nn_sock_stopped (struct nn_sock *self) +{ + /* TODO: Do the following in a more sane way. */ + self->fsm.stopped.fsm = &self->fsm; + self->fsm.stopped.src = NN_FSM_ACTION; + self->fsm.stopped.srcptr = NULL; + self->fsm.stopped.type = NN_SOCK_ACTION_STOPPED; + nn_ctx_raise (self->fsm.ctx, &self->fsm.stopped); +} + +/* Stop the socket. This will prevent new calls from aquiring a + hold on the socket, cause endpoints to shut down, and wake any + threads waiting to recv or send data. */ +void nn_sock_stop (struct nn_sock *self) +{ + nn_ctx_enter (&self->ctx); + nn_fsm_stop (&self->fsm); + nn_ctx_leave (&self->ctx); +} + +int nn_sock_term (struct nn_sock *self) +{ + int rc; + int i; + + /* NOTE: nn_sock_stop must have already been called. */ + + /* Some endpoints may still be alive. Here we are going to wait + till they are all closed. This loop is not interruptible, because + making it so would leave a partially cleaned up socket, and we don't + have a way to defer resource deallocation. */ + for (;;) { + rc = nn_sem_wait (&self->termsem); + if (nn_slow (rc == -EINTR)) + continue; + errnum_assert (rc == 0, -rc); + break; + } + + /* Also, wait for all holds on the socket to be released. */ + for (;;) { + rc = nn_sem_wait (&self->relesem); + if (nn_slow (rc == -EINTR)) + continue; + errnum_assert (rc == 0, -rc); + break; + } + + /* Threads that posted the semaphore(s) can still have the ctx locked + for a short while. By simply entering the context and exiting it + immediately we can be sure that any such threads have already + exited the context. */ + nn_ctx_enter (&self->ctx); + nn_ctx_leave (&self->ctx); + + /* At this point, we can be reasonably certain that no other thread + has any references to the socket. */ + + nn_fsm_stopped_noevent (&self->fsm); + nn_fsm_term (&self->fsm); + nn_sem_term (&self->termsem); + nn_list_term (&self->sdeps); + nn_list_term (&self->eps); + nn_ctx_term (&self->ctx); + + /* Destroy any optsets associated with the socket. */ + for (i = 0; i != NN_MAX_TRANSPORT; ++i) + if (self->optsets [i]) + self->optsets [i]->vfptr->destroy (self->optsets [i]); + + return 0; +} + +struct nn_ctx *nn_sock_getctx (struct nn_sock *self) +{ + return &self->ctx; +} + +int nn_sock_ispeer (struct nn_sock *self, int socktype) +{ + /* If the peer implements a different SP protocol it is not a valid peer. + Checking it here ensures that even if faulty protocol implementation + allows for cross-protocol communication, it will never happen + in practice. */ + if ((self->socktype->protocol & 0xfff0) != (socktype & 0xfff0)) + return 0; + + /* As long as the peer speaks the same protocol, socket type itself + decides which socket types are to be accepted. */ + return self->socktype->ispeer (socktype); +} + +int nn_sock_setopt (struct nn_sock *self, int level, int option, + const void *optval, size_t optvallen) +{ + int rc; + + nn_ctx_enter (&self->ctx); + rc = nn_sock_setopt_inner (self, level, option, optval, optvallen); + nn_ctx_leave (&self->ctx); + + return rc; +} + +static int nn_sock_setopt_inner (struct nn_sock *self, int level, + int option, const void *optval, size_t optvallen) +{ + struct nn_optset *optset; + int val; + + /* Protocol-specific socket options. */ + if (level > NN_SOL_SOCKET) + return self->sockbase->vfptr->setopt (self->sockbase, level, option, + optval, optvallen); + + /* Transport-specific options. */ + if (level < NN_SOL_SOCKET) { + optset = nn_sock_optset (self, level); + if (!optset) + return -ENOPROTOOPT; + return optset->vfptr->setopt (optset, option, optval, optvallen); + } + + nn_assert (level == NN_SOL_SOCKET); + + /* Special-casing socket name for now as it's the only string option */ + if (option == NN_SOCKET_NAME) { + if (optvallen > 63) + return -EINVAL; + memcpy (self->socket_name, optval, optvallen); + self->socket_name [optvallen] = 0; + return 0; + } + + /* At this point we assume that all options are of type int. */ + if (optvallen != sizeof (int)) + return -EINVAL; + val = *(int*) optval; + + /* Generic socket-level options. */ + switch (option) { + case NN_LINGER: + self->linger = val; + return 0; + case NN_SNDBUF: + if (val <= 0) + return -EINVAL; + self->sndbuf = val; + return 0; + case NN_RCVBUF: + if (val <= 0) + return -EINVAL; + self->rcvbuf = val; + return 0; + case NN_RCVMAXSIZE: + if (val < -1) + return -EINVAL; + self->rcvmaxsize = val; + return 0; + case NN_SNDTIMEO: + self->sndtimeo = val; + return 0; + case NN_RCVTIMEO: + self->rcvtimeo = val; + return 0; + case NN_RECONNECT_IVL: + if (val < 0) + return -EINVAL; + self->reconnect_ivl = val; + return 0; + case NN_RECONNECT_IVL_MAX: + if (val < 0) + return -EINVAL; + self->reconnect_ivl_max = val; + return 0; + case NN_SNDPRIO: + if (val < 1 || val > 16) + return -EINVAL; + self->ep_template.sndprio = val; + return 0; + case NN_RCVPRIO: + if (val < 1 || val > 16) + return -EINVAL; + self->ep_template.rcvprio = val; + return 0; + case NN_IPV4ONLY: + if (val != 0 && val != 1) + return -EINVAL; + self->ep_template.ipv4only = val; + return 0; + case NN_MAXTTL: + if (val < 1 || val > 255) + return -EINVAL; + self->maxttl = val; + return 0; + } + + return -ENOPROTOOPT; +} + +int nn_sock_getopt (struct nn_sock *self, int level, int option, + void *optval, size_t *optvallen) +{ + int rc; + + nn_ctx_enter (&self->ctx); + rc = nn_sock_getopt_inner (self, level, option, optval, optvallen); + nn_ctx_leave (&self->ctx); + + return rc; +} + +int nn_sock_getopt_inner (struct nn_sock *self, int level, + int option, void *optval, size_t *optvallen) +{ + int rc; + struct nn_optset *optset; + int intval; + nn_fd fd; + + /* Protocol-specific socket options. */ + if (level > NN_SOL_SOCKET) + return rc = self->sockbase->vfptr->getopt (self->sockbase, + level, option, optval, optvallen); + + /* Transport-specific options. */ + if (level < NN_SOL_SOCKET) { + optset = nn_sock_optset (self, level); + if (!optset) + return -ENOPROTOOPT; + return optset->vfptr->getopt (optset, option, optval, optvallen); + } + + nn_assert (level == NN_SOL_SOCKET); + + /* Generic socket-level options. */ + switch (option) { + case NN_DOMAIN: + intval = self->socktype->domain; + break; + case NN_PROTOCOL: + intval = self->socktype->protocol; + break; + case NN_LINGER: + intval = self->linger; + break; + case NN_SNDBUF: + intval = self->sndbuf; + break; + case NN_RCVBUF: + intval = self->rcvbuf; + break; + case NN_RCVMAXSIZE: + intval = self->rcvmaxsize; + break; + case NN_SNDTIMEO: + intval = self->sndtimeo; + break; + case NN_RCVTIMEO: + intval = self->rcvtimeo; + break; + case NN_RECONNECT_IVL: + intval = self->reconnect_ivl; + break; + case NN_RECONNECT_IVL_MAX: + intval = self->reconnect_ivl_max; + break; + case NN_SNDPRIO: + intval = self->ep_template.sndprio; + break; + case NN_RCVPRIO: + intval = self->ep_template.rcvprio; + break; + case NN_IPV4ONLY: + intval = self->ep_template.ipv4only; + break; + case NN_MAXTTL: + intval = self->maxttl; + break; + case NN_SNDFD: + if (self->socktype->flags & NN_SOCKTYPE_FLAG_NOSEND) + return -ENOPROTOOPT; + fd = nn_efd_getfd (&self->sndfd); + memcpy (optval, &fd, + *optvallen < sizeof (nn_fd) ? *optvallen : sizeof (nn_fd)); + *optvallen = sizeof (nn_fd); + return 0; + case NN_RCVFD: + if (self->socktype->flags & NN_SOCKTYPE_FLAG_NORECV) + return -ENOPROTOOPT; + fd = nn_efd_getfd (&self->rcvfd); + memcpy (optval, &fd, + *optvallen < sizeof (nn_fd) ? *optvallen : sizeof (nn_fd)); + *optvallen = sizeof (nn_fd); + return 0; + case NN_SOCKET_NAME: + strncpy (optval, self->socket_name, *optvallen); + *optvallen = strlen(self->socket_name); + return 0; + default: + return -ENOPROTOOPT; + } + + memcpy (optval, &intval, + *optvallen < sizeof (int) ? *optvallen : sizeof (int)); + *optvallen = sizeof (int); + + return 0; +} + +int nn_sock_add_ep (struct nn_sock *self, struct nn_transport *transport, + int bind, const char *addr) +{ + int rc; + struct nn_ep *ep; + int eid; + + nn_ctx_enter (&self->ctx); + + /* Instantiate the endpoint. */ + ep = nn_alloc (sizeof (struct nn_ep), "endpoint"); + rc = nn_ep_init (ep, NN_SOCK_SRC_EP, self, self->eid, transport, + bind, addr); + if (nn_slow (rc < 0)) { + nn_free (ep); + nn_ctx_leave (&self->ctx); + return rc; + } + nn_ep_start (ep); + + /* Increase the endpoint ID for the next endpoint. */ + eid = self->eid; + ++self->eid; + + /* Add it to the list of active endpoints. */ + nn_list_insert (&self->eps, &ep->item, nn_list_end (&self->eps)); + + nn_ctx_leave (&self->ctx); + + return eid; +} + +int nn_sock_rm_ep (struct nn_sock *self, int eid) +{ + struct nn_list_item *it; + struct nn_ep *ep; + + nn_ctx_enter (&self->ctx); + + /* Find the specified enpoint. */ + ep = NULL; + for (it = nn_list_begin (&self->eps); + it != nn_list_end (&self->eps); + it = nn_list_next (&self->eps, it)) { + ep = nn_cont (it, struct nn_ep, item); + if (ep->eid == eid) + break; + ep = NULL; + } + + /* The endpoint doesn't exist. */ + if (!ep) { + nn_ctx_leave (&self->ctx); + return -EINVAL; + } + + /* Move the endpoint from the list of active endpoints to the list + of shutting down endpoints. */ + nn_list_erase (&self->eps, &ep->item); + nn_list_insert (&self->sdeps, &ep->item, nn_list_end (&self->sdeps)); + + /* Ask the endpoint to stop. Actual terminatation may be delayed + by the transport. */ + nn_ep_stop (ep); + + nn_ctx_leave (&self->ctx); + + return 0; +} + +int nn_sock_send (struct nn_sock *self, struct nn_msg *msg, int flags) +{ + int rc; + uint64_t deadline; + uint64_t now; + int timeout; + + /* Some sockets types cannot be used for sending messages. */ + if (nn_slow (self->socktype->flags & NN_SOCKTYPE_FLAG_NOSEND)) + return -ENOTSUP; + + nn_ctx_enter (&self->ctx); + + /* Compute the deadline for SNDTIMEO timer. */ + if (self->sndtimeo < 0) { + deadline = -1; + timeout = -1; + } + else { + deadline = nn_clock_ms() + self->sndtimeo; + timeout = self->sndtimeo; + } + + while (1) { + + switch (self->state) { + case NN_SOCK_STATE_ACTIVE: + case NN_SOCK_STATE_INIT: + break; + + case NN_SOCK_STATE_STOPPING_EPS: + case NN_SOCK_STATE_STOPPING: + case NN_SOCK_STATE_FINI: + /* Socket closed or closing. Should we return something + else here; recvmsg(2) for example returns no data in + this case, like read(2). The use of indexed file + descriptors is further problematic, as an FD can be reused + leading to situations where technically the outstanding + operation should refer to some other socket entirely. */ + nn_ctx_leave (&self->ctx); + return -EBADF; + } + + /* Try to send the message in a non-blocking way. */ + rc = self->sockbase->vfptr->send (self->sockbase, msg); + if (nn_fast (rc == 0)) { + nn_ctx_leave (&self->ctx); + return 0; + } + nn_assert (rc < 0); + + /* Any unexpected error is forwarded to the caller. */ + if (nn_slow (rc != -EAGAIN)) { + nn_ctx_leave (&self->ctx); + return rc; + } + + /* If the message cannot be sent at the moment and the send call + is non-blocking, return immediately. */ + if (nn_fast (flags & NN_DONTWAIT)) { + nn_ctx_leave (&self->ctx); + return -EAGAIN; + } + + /* With blocking send, wait while there are new pipes available + for sending. */ + nn_ctx_leave (&self->ctx); + rc = nn_efd_wait (&self->sndfd, timeout); + if (nn_slow (rc == -ETIMEDOUT)) + return -ETIMEDOUT; + if (nn_slow (rc == -EINTR)) + return -EINTR; + if (nn_slow (rc == -EBADF)) + return -EBADF; + errnum_assert (rc == 0, rc); + nn_ctx_enter (&self->ctx); + /* + * Double check if pipes are still available for sending + */ + if (!nn_efd_wait (&self->sndfd, 0)) { + self->flags |= NN_SOCK_FLAG_OUT; + } + + /* If needed, re-compute the timeout to reflect the time that have + already elapsed. */ + if (self->sndtimeo >= 0) { + now = nn_clock_ms(); + timeout = (int) (now > deadline ? 0 : deadline - now); + } + } +} + +int nn_sock_recv (struct nn_sock *self, struct nn_msg *msg, int flags) +{ + int rc; + uint64_t deadline; + uint64_t now; + int timeout; + + /* Some sockets types cannot be used for receiving messages. */ + if (nn_slow (self->socktype->flags & NN_SOCKTYPE_FLAG_NORECV)) + return -ENOTSUP; + + nn_ctx_enter (&self->ctx); + + /* Compute the deadline for RCVTIMEO timer. */ + if (self->rcvtimeo < 0) { + deadline = -1; + timeout = -1; + } + else { + deadline = nn_clock_ms() + self->rcvtimeo; + timeout = self->rcvtimeo; + } + + while (1) { + + switch (self->state) { + case NN_SOCK_STATE_ACTIVE: + case NN_SOCK_STATE_INIT: + break; + + case NN_SOCK_STATE_STOPPING_EPS: + case NN_SOCK_STATE_STOPPING: + case NN_SOCK_STATE_FINI: + /* Socket closed or closing. Should we return something + else here; recvmsg(2) for example returns no data in + this case, like read(2). The use of indexed file + descriptors is further problematic, as an FD can be reused + leading to situations where technically the outstanding + operation should refer to some other socket entirely. */ + nn_ctx_leave (&self->ctx); + return -EBADF; + } + + /* Try to receive the message in a non-blocking way. */ + rc = self->sockbase->vfptr->recv (self->sockbase, msg); + if (nn_fast (rc == 0)) { + nn_ctx_leave (&self->ctx); + return 0; + } + nn_assert (rc < 0); + + /* Any unexpected error is forwarded to the caller. */ + if (nn_slow (rc != -EAGAIN)) { + nn_ctx_leave (&self->ctx); + return rc; + } + + /* If the message cannot be received at the moment and the recv call + is non-blocking, return immediately. */ + if (nn_fast (flags & NN_DONTWAIT)) { + nn_ctx_leave (&self->ctx); + return -EAGAIN; + } + + /* With blocking recv, wait while there are new pipes available + for receiving. */ + nn_ctx_leave (&self->ctx); + rc = nn_efd_wait (&self->rcvfd, timeout); + if (nn_slow (rc == -ETIMEDOUT)) + return -ETIMEDOUT; + if (nn_slow (rc == -EINTR)) + return -EINTR; + if (nn_slow (rc == -EBADF)) + return -EBADF; + errnum_assert (rc == 0, rc); + nn_ctx_enter (&self->ctx); + /* + * Double check if pipes are still available for receiving + */ + if (!nn_efd_wait (&self->rcvfd, 0)) { + self->flags |= NN_SOCK_FLAG_IN; + } + + /* If needed, re-compute the timeout to reflect the time that have + already elapsed. */ + if (self->rcvtimeo >= 0) { + now = nn_clock_ms(); + timeout = (int) (now > deadline ? 0 : deadline - now); + } + } +} + +int nn_sock_add (struct nn_sock *self, struct nn_pipe *pipe) +{ + int rc; + + rc = self->sockbase->vfptr->add (self->sockbase, pipe); + if (nn_slow (rc >= 0)) { + nn_sock_stat_increment (self, NN_STAT_CURRENT_CONNECTIONS, 1); + } + return rc; +} + +void nn_sock_rm (struct nn_sock *self, struct nn_pipe *pipe) +{ + self->sockbase->vfptr->rm (self->sockbase, pipe); + nn_sock_stat_increment (self, NN_STAT_CURRENT_CONNECTIONS, -1); +} + +static void nn_sock_onleave (struct nn_ctx *self) +{ + struct nn_sock *sock; + int events; + + sock = nn_cont (self, struct nn_sock, ctx); + + /* If nn_close() was already called there's no point in adjusting the + snd/rcv file descriptors. */ + if (nn_slow (sock->state != NN_SOCK_STATE_ACTIVE)) + return; + + /* Check whether socket is readable and/or writable at the moment. */ + events = sock->sockbase->vfptr->events (sock->sockbase); + errnum_assert (events >= 0, -events); + + /* Signal/unsignal IN as needed. */ + if (!(sock->socktype->flags & NN_SOCKTYPE_FLAG_NORECV)) { + if (events & NN_SOCKBASE_EVENT_IN) { + if (!(sock->flags & NN_SOCK_FLAG_IN)) { + sock->flags |= NN_SOCK_FLAG_IN; + nn_efd_signal (&sock->rcvfd); + } + } + else { + if (sock->flags & NN_SOCK_FLAG_IN) { + sock->flags &= ~NN_SOCK_FLAG_IN; + nn_efd_unsignal (&sock->rcvfd); + } + } + } + + /* Signal/unsignal OUT as needed. */ + if (!(sock->socktype->flags & NN_SOCKTYPE_FLAG_NOSEND)) { + if (events & NN_SOCKBASE_EVENT_OUT) { + if (!(sock->flags & NN_SOCK_FLAG_OUT)) { + sock->flags |= NN_SOCK_FLAG_OUT; + nn_efd_signal (&sock->sndfd); + } + } + else { + if (sock->flags & NN_SOCK_FLAG_OUT) { + sock->flags &= ~NN_SOCK_FLAG_OUT; + nn_efd_unsignal (&sock->sndfd); + } + } + } +} + +static struct nn_optset *nn_sock_optset (struct nn_sock *self, int id) +{ + int index; + struct nn_transport *tp; + + /* Transport IDs are negative and start from -1. */ + index = (-id) - 1; + + /* Check for invalid indices. */ + if (nn_slow (index < 0 || index >= NN_MAX_TRANSPORT)) + return NULL; + + /* If the option set already exists return it. */ + if (nn_fast (self->optsets [index] != NULL)) + return self->optsets [index]; + + /* If the option set doesn't exist yet, create it. */ + tp = nn_global_transport (id); + if (nn_slow (!tp)) + return NULL; + if (nn_slow (!tp->optset)) + return NULL; + self->optsets [index] = tp->optset (); + + return self->optsets [index]; +} + +static void nn_sock_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_sock *sock; + struct nn_list_item *it; + struct nn_ep *ep; + + sock = nn_cont (self, struct nn_sock, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_assert (sock->state == NN_SOCK_STATE_ACTIVE); + + /* Close sndfd and rcvfd. This should make any current + select/poll using SNDFD and/or RCVFD exit. */ + if (!(sock->socktype->flags & NN_SOCKTYPE_FLAG_NORECV)) { + nn_efd_stop (&sock->rcvfd); + } + if (!(sock->socktype->flags & NN_SOCKTYPE_FLAG_NOSEND)) { + nn_efd_stop (&sock->sndfd); + } + + /* Ask all the associated endpoints to stop. */ + it = nn_list_begin (&sock->eps); + while (it != nn_list_end (&sock->eps)) { + ep = nn_cont (it, struct nn_ep, item); + it = nn_list_next (&sock->eps, it); + nn_list_erase (&sock->eps, &ep->item); + nn_list_insert (&sock->sdeps, &ep->item, + nn_list_end (&sock->sdeps)); + nn_ep_stop (ep); + + } + sock->state = NN_SOCK_STATE_STOPPING_EPS; + goto finish2; + } + if (nn_slow (sock->state == NN_SOCK_STATE_STOPPING_EPS)) { + + if (!(src == NN_SOCK_SRC_EP && type == NN_EP_STOPPED)) { + /* If we got here waiting for EPs to teardown, but src is + not an EP, then it isn't safe for us to do anything, + because we just need to wait for the EPs to finish + up their thing. Just bail. */ + return; + } + /* Endpoint is stopped. Now we can safely deallocate it. */ + ep = (struct nn_ep*) srcptr; + nn_list_erase (&sock->sdeps, &ep->item); + nn_ep_term (ep); + nn_free (ep); + +finish2: + /* If all the endpoints are deallocated, we can start stopping + protocol-specific part of the socket. If there' no stop function + we can consider it stopped straight away. */ + if (!nn_list_empty (&sock->sdeps)) + return; + nn_assert (nn_list_empty (&sock->eps)); + sock->state = NN_SOCK_STATE_STOPPING; + if (!sock->sockbase->vfptr->stop) + goto finish1; + sock->sockbase->vfptr->stop (sock->sockbase); + return; + } + if (nn_slow (sock->state == NN_SOCK_STATE_STOPPING)) { + + /* We get here when the deallocation of the socket was delayed by the + specific socket type. */ + nn_assert (src == NN_FSM_ACTION && type == NN_SOCK_ACTION_STOPPED); + +finish1: + /* Protocol-specific part of the socket is stopped. + We can safely deallocate it. */ + sock->sockbase->vfptr->destroy (sock->sockbase); + sock->state = NN_SOCK_STATE_FINI; + + /* Close the event FDs entirely. */ + if (!(sock->socktype->flags & NN_SOCKTYPE_FLAG_NORECV)) { + nn_efd_term (&sock->rcvfd); + } + if (!(sock->socktype->flags & NN_SOCKTYPE_FLAG_NOSEND)) { + nn_efd_term (&sock->sndfd); + } + + /* Now we can unblock the application thread blocked in + the nn_close() call. */ + nn_sem_post (&sock->termsem); + + return; + } + + nn_fsm_bad_state(sock->state, src, type); +} + +static void nn_sock_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_sock *sock; + struct nn_ep *ep; + + sock = nn_cont (self, struct nn_sock, fsm); + + switch (sock->state) { + +/******************************************************************************/ +/* INIT state. */ +/******************************************************************************/ + case NN_SOCK_STATE_INIT: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + sock->state = NN_SOCK_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (sock->state, src, type); + } + + default: + nn_fsm_bad_source (sock->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_SOCK_STATE_ACTIVE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + default: + nn_fsm_bad_action (sock->state, src, type); + } + + case NN_SOCK_SRC_EP: + switch (type) { + case NN_EP_STOPPED: + + /* This happens when an endpoint is closed using + nn_shutdown() function. */ + ep = (struct nn_ep*) srcptr; + nn_list_erase (&sock->sdeps, &ep->item); + nn_ep_term (ep); + nn_free (ep); + return; + + default: + nn_fsm_bad_action (sock->state, src, type); + } + + default: + + /* The assumption is that all the other events come from pipes. */ + switch (type) { + case NN_PIPE_IN: + sock->sockbase->vfptr->in (sock->sockbase, + (struct nn_pipe*) srcptr); + return; + case NN_PIPE_OUT: + sock->sockbase->vfptr->out (sock->sockbase, + (struct nn_pipe*) srcptr); + return; + default: + nn_fsm_bad_action (sock->state, src, type); + } + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (sock->state, src, type); + } +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +void nn_sock_report_error (struct nn_sock *self, struct nn_ep *ep, int errnum) +{ + if (!nn_global_print_errors()) + return; + + if (errnum == 0) + return; + + if (ep) { + fprintf(stderr, "nanomsg: socket.%s[%s]: Error: %s\n", + self->socket_name, nn_ep_getaddr(ep), nn_strerror(errnum)); + } else { + fprintf(stderr, "nanomsg: socket.%s: Error: %s\n", + self->socket_name, nn_strerror(errnum)); + } +} + +void nn_sock_stat_increment (struct nn_sock *self, int name, int64_t increment) +{ + switch (name) { + case NN_STAT_ESTABLISHED_CONNECTIONS: + nn_assert (increment > 0); + self->statistics.established_connections += increment; + break; + case NN_STAT_ACCEPTED_CONNECTIONS: + nn_assert (increment > 0); + self->statistics.accepted_connections += increment; + break; + case NN_STAT_DROPPED_CONNECTIONS: + nn_assert (increment > 0); + self->statistics.dropped_connections += increment; + break; + case NN_STAT_BROKEN_CONNECTIONS: + nn_assert (increment > 0); + self->statistics.broken_connections += increment; + break; + case NN_STAT_CONNECT_ERRORS: + nn_assert (increment > 0); + self->statistics.connect_errors += increment; + break; + case NN_STAT_BIND_ERRORS: + nn_assert (increment > 0); + self->statistics.bind_errors += increment; + break; + case NN_STAT_ACCEPT_ERRORS: + nn_assert (increment > 0); + self->statistics.accept_errors += increment; + break; + case NN_STAT_MESSAGES_SENT: + nn_assert (increment > 0); + self->statistics.messages_sent += increment; + break; + case NN_STAT_MESSAGES_RECEIVED: + nn_assert (increment > 0); + self->statistics.messages_received += increment; + break; + case NN_STAT_BYTES_SENT: + nn_assert (increment >= 0); + self->statistics.bytes_sent += increment; + break; + case NN_STAT_BYTES_RECEIVED: + nn_assert (increment >= 0); + self->statistics.bytes_received += increment; + break; + + case NN_STAT_CURRENT_CONNECTIONS: + nn_assert (increment > 0 || + self->statistics.current_connections >= -increment); + nn_assert(increment < INT_MAX && increment > -INT_MAX); + self->statistics.current_connections += (int) increment; + break; + case NN_STAT_INPROGRESS_CONNECTIONS: + nn_assert (increment > 0 || + self->statistics.inprogress_connections >= -increment); + nn_assert(increment < INT_MAX && increment > -INT_MAX); + self->statistics.inprogress_connections += (int) increment; + break; + case NN_STAT_CURRENT_SND_PRIORITY: + /* This is an exception, we don't want to increment priority */ + nn_assert((increment > 0 && increment <= 16) || increment == -1); + self->statistics.current_snd_priority = (int) increment; + break; + case NN_STAT_CURRENT_EP_ERRORS: + nn_assert (increment > 0 || + self->statistics.current_ep_errors >= -increment); + nn_assert(increment < INT_MAX && increment > -INT_MAX); + self->statistics.current_ep_errors += (int) increment; + break; + } +} + +int nn_sock_hold (struct nn_sock *self) +{ + switch (self->state) { + case NN_SOCK_STATE_ACTIVE: + case NN_SOCK_STATE_INIT: + self->holds++; + return 0; + case NN_SOCK_STATE_STOPPING: + case NN_SOCK_STATE_STOPPING_EPS: + case NN_SOCK_STATE_FINI: + default: + return -EBADF; + } +} + +void nn_sock_rele (struct nn_sock *self) +{ + self->holds--; + if (self->holds == 0) { + nn_sem_post (&self->relesem); + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/sock.h b/node/node_modules/nanomsg/deps/nanomsg/src/core/sock.h new file mode 100644 index 0000000..f87e7e9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/sock.h @@ -0,0 +1,202 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SOCK_INCLUDED +#define NN_SOCK_INCLUDED + +#include "../protocol.h" +#include "../transport.h" + +#include "../aio/ctx.h" +#include "../aio/fsm.h" + +#include "../utils/efd.h" +#include "../utils/sem.h" +#include "../utils/list.h" + +struct nn_pipe; + +/* The maximum implemented transport ID. */ +#define NN_MAX_TRANSPORT 4 + +struct nn_sock +{ + /* Socket state machine. */ + struct nn_fsm fsm; + int state; + + /* Pointer to the instance of the specific socket type. */ + struct nn_sockbase *sockbase; + + /* Pointer to the socket type metadata. */ + struct nn_socktype *socktype; + + int flags; + + struct nn_ctx ctx; + struct nn_efd sndfd; + struct nn_efd rcvfd; + struct nn_sem termsem; + struct nn_sem relesem; + + /* List of all endpoints associated with the socket. */ + struct nn_list eps; + + /* List of all endpoint being in the process of shutting down. */ + struct nn_list sdeps; + + /* Next endpoint ID to assign to a new endpoint. */ + int eid; + + /* Count of active holds against the socket. */ + int holds; + + /* Socket-level socket options. */ + int linger; + int sndbuf; + int rcvbuf; + int rcvmaxsize; + int sndtimeo; + int rcvtimeo; + int reconnect_ivl; + int reconnect_ivl_max; + int maxttl; + + /* Endpoint-specific options. */ + struct nn_ep_options ep_template; + + /* Transport-specific socket options. */ + struct nn_optset *optsets [NN_MAX_TRANSPORT]; + + struct { + + /***** The ever-incrementing counters *****/ + + /* Successfully established nn_connect() connections */ + uint64_t established_connections; + /* Successfully accepted connections */ + uint64_t accepted_connections; + /* Forcedly closed connections */ + uint64_t dropped_connections; + /* Connections closed by peer */ + uint64_t broken_connections; + /* Errors trying to establish active connection */ + uint64_t connect_errors; + /* Errors binding to specified port */ + uint64_t bind_errors; + /* Errors accepting connections at nn_bind()'ed endpoint */ + uint64_t accept_errors; + + /* Messages sent */ + uint64_t messages_sent; + /* Messages received */ + uint64_t messages_received; + /* Bytes sent (sum length of data in messages sent) */ + uint64_t bytes_sent; + /* Bytes recevied (sum length of data in messages received) */ + uint64_t bytes_received; + + /***** Level-style values *****/ + + /* Number of currently established connections */ + int current_connections; + /* Number of connections currently in progress */ + int inprogress_connections; + /* The currently set priority for sending data */ + int current_snd_priority; + /* Number of endpoints having last_errno set to non-zero value */ + int current_ep_errors; + + } statistics; + + /* The socket name for statistics */ + char socket_name[64]; + + /* Win32 Security Attribute */ + void * sec_attr; + size_t sec_attr_size; + int outbuffersz; + int inbuffersz; + +}; + +/* Initialise the socket. */ +int nn_sock_init (struct nn_sock *self, struct nn_socktype *socktype, int fd); + +/* Called by nn_close() to stop activity on the socket. It doesn't block. */ +void nn_sock_stop (struct nn_sock *self); + +/* Called by nn_close() to deallocate the socket. It's a blocking function + and can return -EINTR. */ +int nn_sock_term (struct nn_sock *self); + +/* Called by sockbase when stopping is done. */ +void nn_sock_stopped (struct nn_sock *self); + +/* Returns the AIO context associated with the socket. */ +struct nn_ctx *nn_sock_getctx (struct nn_sock *self); + +/* Returns 1 if the specified socket type is a valid peer for this socket, + 0 otherwise. */ +int nn_sock_ispeer (struct nn_sock *self, int socktype); + +/* Add new endpoint to the socket. */ +int nn_sock_add_ep (struct nn_sock *self, struct nn_transport *transport, + int bind, const char *addr); + +/* Remove the endpoint with the specified ID from the socket. */ +int nn_sock_rm_ep (struct nn_sock *self, int eid); + +/* Send a message to the socket. */ +int nn_sock_send (struct nn_sock *self, struct nn_msg *msg, int flags); + +/* Receive a message from the socket. */ +int nn_sock_recv (struct nn_sock *self, struct nn_msg *msg, int flags); + +/* Set a socket option. */ +int nn_sock_setopt (struct nn_sock *self, int level, int option, + const void *optval, size_t optvallen); + +/* Retrieve a socket option. This function is to be called from the API. */ +int nn_sock_getopt (struct nn_sock *self, int level, int option, + void *optval, size_t *optvallen); + +/* Retrieve a socket option. This function is to be called from within + the socket. */ +int nn_sock_getopt_inner (struct nn_sock *self, int level, int option, + void *optval, size_t *optvallen); + +/* Used by pipes. */ +int nn_sock_add (struct nn_sock *self, struct nn_pipe *pipe); +void nn_sock_rm (struct nn_sock *self, struct nn_pipe *pipe); + +/* Monitoring callbacks */ +void nn_sock_report_error(struct nn_sock *self, struct nn_ep *ep, int errnum); +void nn_sock_stat_increment(struct nn_sock *self, int name, int64_t increment); + +/* Holds and releases. */ +int nn_sock_hold (struct nn_sock *self); +void nn_sock_rele (struct nn_sock *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/sockbase.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/sockbase.c new file mode 100644 index 0000000..ce179da --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/sockbase.c @@ -0,0 +1,62 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../protocol.h" + +#include "sock.h" + +#include "../utils/err.h" +#include "../utils/attr.h" + +void nn_sockbase_init (struct nn_sockbase *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + self->vfptr = vfptr; + self->sock = (struct nn_sock*) hint; +} + +void nn_sockbase_term (NN_UNUSED struct nn_sockbase *self) +{ +} + +void nn_sockbase_stopped (struct nn_sockbase *self) +{ + nn_sock_stopped (self->sock); +} + +struct nn_ctx *nn_sockbase_getctx (struct nn_sockbase *self) +{ + return nn_sock_getctx (self->sock); +} + +int nn_sockbase_getopt (struct nn_sockbase *self, int option, + void *optval, size_t *optvallen) +{ + return nn_sock_getopt_inner (self->sock, NN_SOL_SOCKET, option, + optval, optvallen); +} + +void nn_sockbase_stat_increment (struct nn_sockbase *self, int name, + int increment) +{ + nn_sock_stat_increment (self->sock, name, increment); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/core/symbol.c b/node/node_modules/nanomsg/deps/nanomsg/src/core/symbol.c new file mode 100644 index 0000000..32af085 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/core/symbol.c @@ -0,0 +1,211 @@ +/* + Copyright (c) 2013 Evan Wies + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright (c) 2016 Bent Cardan. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../nn.h" + +#include "../inproc.h" +#include "../ipc.h" +#include "../tcp.h" + +#include "../pair.h" +#include "../pubsub.h" +#include "../reqrep.h" +#include "../pipeline.h" +#include "../survey.h" +#include "../bus.h" +#include "../ws.h" + +#include + +#define NN_SYM(sym, namespace, typ, unit) \ + { sym, #sym, NN_NS_ ## namespace, NN_TYPE_ ## typ, NN_UNIT_ ## unit } + +static const struct nn_symbol_properties sym_value_names [] = { + NN_SYM(NN_NS_NAMESPACE, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_VERSION, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_DOMAIN, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_TRANSPORT, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_PROTOCOL, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_OPTION_LEVEL, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_SOCKET_OPTION, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_TRANSPORT_OPTION, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_OPTION_TYPE, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_OPTION_UNIT, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_FLAG, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_ERROR, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_LIMIT, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_EVENT, NAMESPACE, NONE, NONE), + NN_SYM(NN_NS_STATISTIC, NAMESPACE, NONE, NONE), + + NN_SYM(NN_TYPE_NONE, OPTION_TYPE, NONE, NONE), + NN_SYM(NN_TYPE_INT, OPTION_TYPE, NONE, NONE), + NN_SYM(NN_TYPE_STR, OPTION_TYPE, NONE, NONE), + + NN_SYM(NN_UNIT_NONE, OPTION_UNIT, NONE, NONE), + NN_SYM(NN_UNIT_BYTES, OPTION_UNIT, NONE, NONE), + NN_SYM(NN_UNIT_MILLISECONDS, OPTION_UNIT, NONE, NONE), + NN_SYM(NN_UNIT_PRIORITY, OPTION_UNIT, NONE, NONE), + NN_SYM(NN_UNIT_BOOLEAN, OPTION_UNIT, NONE, NONE), + NN_SYM(NN_UNIT_COUNTER, OPTION_UNIT, NONE, NONE), + NN_SYM(NN_UNIT_MESSAGES, OPTION_UNIT, NONE, NONE), + + NN_SYM(NN_VERSION_CURRENT, VERSION, NONE, NONE), + NN_SYM(NN_VERSION_REVISION, VERSION, NONE, NONE), + NN_SYM(NN_VERSION_AGE, VERSION, NONE, NONE), + + NN_SYM(AF_SP, DOMAIN, NONE, NONE), + NN_SYM(AF_SP_RAW, DOMAIN, NONE, NONE), + + NN_SYM(NN_INPROC, TRANSPORT, NONE, NONE), + NN_SYM(NN_IPC, TRANSPORT, NONE, NONE), + NN_SYM(NN_TCP, TRANSPORT, NONE, NONE), + NN_SYM(NN_WS, TRANSPORT, NONE, NONE), + + NN_SYM(NN_PAIR, PROTOCOL, NONE, NONE), + NN_SYM(NN_PUB, PROTOCOL, NONE, NONE), + NN_SYM(NN_SUB, PROTOCOL, NONE, NONE), + NN_SYM(NN_REP, PROTOCOL, NONE, NONE), + NN_SYM(NN_REQ, PROTOCOL, NONE, NONE), + NN_SYM(NN_PUSH, PROTOCOL, NONE, NONE), + NN_SYM(NN_PULL, PROTOCOL, NONE, NONE), + NN_SYM(NN_SURVEYOR, PROTOCOL, NONE, NONE), + NN_SYM(NN_RESPONDENT, PROTOCOL, NONE, NONE), + NN_SYM(NN_BUS, PROTOCOL, NONE, NONE), + + NN_SYM(NN_SOCKADDR_MAX, LIMIT, NONE, NONE), + + NN_SYM(NN_SOL_SOCKET, OPTION_LEVEL, NONE, NONE), + + NN_SYM(NN_LINGER, SOCKET_OPTION, INT, MILLISECONDS), + NN_SYM(NN_SNDBUF, SOCKET_OPTION, INT, BYTES), + NN_SYM(NN_RCVBUF, SOCKET_OPTION, INT, BYTES), + NN_SYM(NN_RCVMAXSIZE, SOCKET_OPTION, INT, BYTES), + NN_SYM(NN_SNDTIMEO, SOCKET_OPTION, INT, MILLISECONDS), + NN_SYM(NN_RCVTIMEO, SOCKET_OPTION, INT, MILLISECONDS), + NN_SYM(NN_RECONNECT_IVL, SOCKET_OPTION, INT, MILLISECONDS), + NN_SYM(NN_RECONNECT_IVL_MAX, SOCKET_OPTION, INT, MILLISECONDS), + NN_SYM(NN_SNDPRIO, SOCKET_OPTION, INT, PRIORITY), + NN_SYM(NN_RCVPRIO, SOCKET_OPTION, INT, PRIORITY), + NN_SYM(NN_SNDFD, SOCKET_OPTION, INT, NONE), + NN_SYM(NN_RCVFD, SOCKET_OPTION, INT, NONE), + NN_SYM(NN_DOMAIN, SOCKET_OPTION, INT, NONE), + NN_SYM(NN_PROTOCOL, SOCKET_OPTION, INT, NONE), + NN_SYM(NN_IPV4ONLY, SOCKET_OPTION, INT, BOOLEAN), + NN_SYM(NN_SOCKET_NAME, SOCKET_OPTION, STR, NONE), + + NN_SYM(NN_SUB_SUBSCRIBE, TRANSPORT_OPTION, STR, NONE), + NN_SYM(NN_SUB_UNSUBSCRIBE, TRANSPORT_OPTION, STR, NONE), + NN_SYM(NN_REQ_RESEND_IVL, TRANSPORT_OPTION, INT, MILLISECONDS), + NN_SYM(NN_SURVEYOR_DEADLINE, TRANSPORT_OPTION, INT, MILLISECONDS), + NN_SYM(NN_TCP_NODELAY, TRANSPORT_OPTION, INT, BOOLEAN), + NN_SYM(NN_WS_MSG_TYPE, TRANSPORT_OPTION, INT, NONE), + + NN_SYM(NN_DONTWAIT, FLAG, NONE, NONE), + NN_SYM(NN_WS_MSG_TYPE_TEXT, FLAG, NONE, NONE), + NN_SYM(NN_WS_MSG_TYPE_BINARY, FLAG, NONE, NONE), + + NN_SYM(NN_POLLIN, EVENT, NONE, NONE), + NN_SYM(NN_POLLOUT, EVENT, NONE, NONE), + + NN_SYM(EADDRINUSE, ERROR, NONE, NONE), + NN_SYM(EADDRNOTAVAIL, ERROR, NONE, NONE), + NN_SYM(EAFNOSUPPORT, ERROR, NONE, NONE), + NN_SYM(EAGAIN, ERROR, NONE, NONE), + NN_SYM(EBADF, ERROR, NONE, NONE), + NN_SYM(ECONNREFUSED, ERROR, NONE, NONE), + NN_SYM(EFAULT, ERROR, NONE, NONE), + NN_SYM(EFSM, ERROR, NONE, NONE), + NN_SYM(EINPROGRESS, ERROR, NONE, NONE), + NN_SYM(EINTR, ERROR, NONE, NONE), + NN_SYM(EINVAL, ERROR, NONE, NONE), + NN_SYM(EMFILE, ERROR, NONE, NONE), + NN_SYM(ENAMETOOLONG, ERROR, NONE, NONE), + NN_SYM(ENETDOWN, ERROR, NONE, NONE), + NN_SYM(ENOBUFS, ERROR, NONE, NONE), + NN_SYM(ENODEV, ERROR, NONE, NONE), + NN_SYM(ENOMEM, ERROR, NONE, NONE), + NN_SYM(ENOPROTOOPT, ERROR, NONE, NONE), + NN_SYM(ENOTSOCK, ERROR, NONE, NONE), + NN_SYM(ENOTSUP, ERROR, NONE, NONE), + NN_SYM(EPROTO, ERROR, NONE, NONE), + NN_SYM(EPROTONOSUPPORT, ERROR, NONE, NONE), + NN_SYM(ETERM, ERROR, NONE, NONE), + NN_SYM(ETIMEDOUT, ERROR, NONE, NONE), + NN_SYM(EACCES, ERROR, NONE, NONE), + NN_SYM(ECONNABORTED, ERROR, NONE, NONE), + NN_SYM(ECONNRESET, ERROR, NONE, NONE), + NN_SYM(EHOSTUNREACH, ERROR, NONE, NONE), + NN_SYM(EMSGSIZE, ERROR, NONE, NONE), + NN_SYM(ENETRESET, ERROR, NONE, NONE), + NN_SYM(ENETUNREACH, ERROR, NONE, NONE), + NN_SYM(ENOTCONN, ERROR, NONE, NONE), + + NN_SYM(NN_STAT_ESTABLISHED_CONNECTIONS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_ACCEPTED_CONNECTIONS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_DROPPED_CONNECTIONS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_BROKEN_CONNECTIONS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_CONNECT_ERRORS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_BIND_ERRORS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_ACCEPT_ERRORS, STATISTIC, INT, COUNTER), + NN_SYM(NN_STAT_MESSAGES_SENT, STATISTIC, INT, MESSAGES), + NN_SYM(NN_STAT_MESSAGES_RECEIVED, STATISTIC, INT, MESSAGES), + NN_SYM(NN_STAT_BYTES_SENT, STATISTIC, INT, BYTES), + NN_SYM(NN_STAT_BYTES_RECEIVED, STATISTIC, INT, BYTES), + NN_SYM(NN_STAT_CURRENT_CONNECTIONS, STATISTIC, INT, NONE), + NN_SYM(NN_STAT_INPROGRESS_CONNECTIONS, STATISTIC, INT, NONE), + NN_SYM(NN_STAT_CURRENT_SND_PRIORITY, STATISTIC, INT, PRIORITY), + NN_SYM(NN_STAT_CURRENT_EP_ERRORS, STATISTIC, INT, NONE) +}; + +const int SYM_VALUE_NAMES_LEN = (sizeof (sym_value_names) / + sizeof (sym_value_names [0])); + + +const char *nn_symbol (int i, int *value) +{ + const struct nn_symbol_properties *svn; + if (i < 0 || i >= SYM_VALUE_NAMES_LEN) { + errno = EINVAL; + return NULL; + } + + svn = &sym_value_names [i]; + if (value) + *value = svn->value; + return svn->name; +} + +int nn_symbol_info (int i, struct nn_symbol_properties *buf, int buflen) +{ + if (i < 0 || i >= SYM_VALUE_NAMES_LEN) { + return 0; + } + if (buflen > (int)sizeof (struct nn_symbol_properties)) { + buflen = (int)sizeof (struct nn_symbol_properties); + } + memcpy(buf, &sym_value_names [i], buflen); + return buflen; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/devices/device.c b/node/node_modules/nanomsg/deps/nanomsg/src/devices/device.c new file mode 100644 index 0000000..752cb40 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/devices/device.c @@ -0,0 +1,321 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../nn.h" + +#include "../utils/err.h" +#include "../utils/fast.h" +#include "../utils/fd.h" +#include "../utils/attr.h" +#include "../utils/thread.h" +#include "device.h" + +#include + +int nn_custom_device(struct nn_device_recipe *device, int s1, int s2, + int flags) +{ + return nn_device_entry (device, s1, s2, flags); +} + +int nn_device (int s1, int s2) +{ + return nn_custom_device (&nn_ordinary_device, s1, s2, 0); +} + +int nn_device_entry (struct nn_device_recipe *device, int s1, int s2, + NN_UNUSED int flags) +{ + int rc; + int op1; + int op2; + nn_fd s1rcv; + nn_fd s1snd; + nn_fd s2rcv; + nn_fd s2snd; + size_t opsz; + + /* At least one socket must be specified. */ + if (device->required_checks & NN_CHECK_AT_LEAST_ONE_SOCKET) { + if (s1 < 0 && s2 < 0) { + errno = EBADF; + return -1; + } + } + + /* Handle the case when there's only one socket in the device. */ + if (device->required_checks & NN_CHECK_ALLOW_LOOPBACK) { + if (s2 < 0) + return nn_device_loopback (device, s1); + if (s1 < 0) + return nn_device_loopback (device, s2); + } + + /* Check whether both sockets are "raw" sockets. */ + if (device->required_checks & NN_CHECK_REQUIRE_RAW_SOCKETS) { + opsz = sizeof (op1); + rc = nn_getsockopt (s1, NN_SOL_SOCKET, NN_DOMAIN, &op1, &opsz); + if (rc != 0) + return -1; + nn_assert (opsz == sizeof (op1)); + opsz = sizeof (op2); + rc = nn_getsockopt (s2, NN_SOL_SOCKET, NN_DOMAIN, &op2, &opsz); + if (rc != 0) + return -1; + nn_assert (opsz == sizeof (op2)); + if (op1 != AF_SP_RAW || op2 != AF_SP_RAW) { + errno = EINVAL; + return -1; + } + } + + /* Check whether both sockets are from the same protocol. */ + if (device->required_checks & NN_CHECK_SAME_PROTOCOL_FAMILY) { + opsz = sizeof (op1); + rc = nn_getsockopt (s1, NN_SOL_SOCKET, NN_PROTOCOL, &op1, &opsz); + if (rc != 0) + return -1; + nn_assert (opsz == sizeof (op1)); + opsz = sizeof (op2); + rc = nn_getsockopt (s2, NN_SOL_SOCKET, NN_PROTOCOL, &op2, &opsz); + if (rc != 0) + return -1; + nn_assert (opsz == sizeof (op2)); + if (op1 / 16 != op2 / 16) { + errno = EINVAL; + return -1; + } + } + + /* Get the file descriptors for polling. */ + opsz = sizeof (s1rcv); + rc = nn_getsockopt (s1, NN_SOL_SOCKET, NN_RCVFD, &s1rcv, &opsz); + if (rc < 0) { + if (nn_errno () != ENOPROTOOPT) + return -1; + s1rcv = -1; + } else { + nn_assert (rc == 0); + nn_assert (opsz == sizeof (s1rcv)); + nn_assert (s1rcv >= 0); + } + opsz = sizeof (s1snd); + rc = nn_getsockopt (s1, NN_SOL_SOCKET, NN_SNDFD, &s1snd, &opsz); + if (rc < 0) { + if (nn_errno () != ENOPROTOOPT) + return -1; + s1snd = -1; + } else { + nn_assert (rc == 0); + nn_assert (opsz == sizeof (s1snd)); + nn_assert (s1snd >= 0); + } + opsz = sizeof (s2rcv); + rc = nn_getsockopt (s2, NN_SOL_SOCKET, NN_RCVFD, &s2rcv, &opsz); + if (rc < 0) { + if (nn_errno () != ENOPROTOOPT) + return -1; + s2rcv = -1; + } else { + nn_assert (rc == 0); + nn_assert (opsz == sizeof (s2rcv)); + nn_assert (s2rcv >= 0); + } + opsz = sizeof (s2snd); + rc = nn_getsockopt (s2, NN_SOL_SOCKET, NN_SNDFD, &s2snd, &opsz); + if (rc < 0) { + if (nn_errno () != ENOPROTOOPT) + return -1; + s2snd = -1; + } else { + nn_assert (rc == 0); + nn_assert (opsz == sizeof (s2snd)); + nn_assert (s2snd >= 0); + } + if (device->required_checks & NN_CHECK_SOCKET_DIRECTIONALITY) { + /* Check the directionality of the sockets. */ + if (s1rcv != -1 && s2snd == -1) { + errno = EINVAL; + return -1; + } + if (s1snd != -1 && s2rcv == -1) { + errno = EINVAL; + return -1; + } + if (s2rcv != -1 && s1snd == -1) { + errno = EINVAL; + return -1; + } + if (s2snd != -1 && s1rcv == -1) { + errno = EINVAL; + return -1; + } + } + + /* Two-directional device. */ + if (device->required_checks & NN_CHECK_ALLOW_BIDIRECTIONAL) { + if (s1rcv != -1 && s1snd != -1 && s2rcv != -1 && s2snd != -1) + return nn_device_twoway (device, s1, s2); + } + + if (device->required_checks & NN_CHECK_ALLOW_UNIDIRECTIONAL) { + /* Single-directional device passing messages from s1 to s2. */ + if (s1rcv != -1 && s1snd == -1 && s2rcv == -1 && s2snd != -1) + return nn_device_oneway (device, s1, s2); + + /* Single-directional device passing messages from s2 to s1. */ + if (s1rcv == -1 && s1snd != -1 && s2rcv != -1 && s2snd == -1) + return nn_device_oneway (device, s2, s1); + } + + /* This should never happen. */ + nn_assert (0); +} + +int nn_device_loopback (struct nn_device_recipe *device, int s) +{ + int rc; + int op; + size_t opsz; + + /* Check whether the socket is a "raw" socket. */ + opsz = sizeof (op); + rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_DOMAIN, &op, &opsz); + if (nn_slow (rc != 0)) + return -1; + nn_assert (opsz == sizeof (op)); + if (op != AF_SP_RAW) { + errno = EINVAL; + return -1; + } + + for (;;) { + rc = nn_device_mvmsg (device, s, s, 0); + if (nn_slow (rc < 0)) + return -1; + } +} + +struct nn_device_forwarder_args { + struct nn_device_recipe *device; + int s1; + int s2; + int rc; + int err; +}; + +static void nn_device_forwarder (void *a) +{ + struct nn_device_forwarder_args *args = a; + for (;;) { + args->rc = nn_device_mvmsg (args->device, args->s1, args->s2, 0); + if (nn_slow (args->rc < 0)) { + args->err = nn_errno (); + return; + } + } +} + +int nn_device_twoway (struct nn_device_recipe *device, int s1, int s2) +{ + struct nn_thread t1; + struct nn_thread t2; + struct nn_device_forwarder_args a1; + struct nn_device_forwarder_args a2; + + a1.device = device; + a1.s1 = s1; + a1.s2 = s2; + + a2.device = device; + a2.s1 = s2; + a2.s2 = s1; + + nn_thread_init (&t1, nn_device_forwarder, &a1); + nn_thread_init (&t2, nn_device_forwarder, &a2); + + nn_thread_term (&t1); + nn_thread_term (&t2); + + if (a1.rc != 0) { + errno = a1.err; + return (a1.rc); + } + errno = a2.err; + return a2.rc; +} + +int nn_device_oneway (struct nn_device_recipe *device, int s1, int s2) +{ + int rc; + + while (1) { + rc = nn_device_mvmsg (device, s1, s2, 0); + if (nn_slow (rc < 0)) + return -1; + } +} + +int nn_device_mvmsg (struct nn_device_recipe *device, + int from, int to, int flags) +{ + int rc; + void *body; + void *control; + struct nn_iovec iov; + struct nn_msghdr hdr; + + iov.iov_base = &body; + iov.iov_len = NN_MSG; + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = &control; + hdr.msg_controllen = NN_MSG; + rc = nn_recvmsg (from, &hdr, flags); + if (nn_slow (rc < 0 && (nn_errno () == ETERM || nn_errno () == EBADF))) { + return -1; + } + errno_assert (rc >= 0); + + rc = device->nn_device_rewritemsg (device, from, to, flags, &hdr, rc); + if (nn_slow (rc == -1)) + return -1; + else if (rc == 0) + return 0; + nn_assert(rc == 1); + + rc = nn_sendmsg (to, &hdr, flags); + if (nn_slow (rc < 0 && (nn_errno () == ETERM || nn_errno () == EBADF))) { + return -1; + } + errno_assert (rc >= 0); + return 0; +} + +int nn_device_rewritemsg (NN_UNUSED struct nn_device_recipe *device, + NN_UNUSED int from, NN_UNUSED int to, NN_UNUSED int flags, + NN_UNUSED struct nn_msghdr *msghdr, NN_UNUSED int bytes) +{ + return 1; /* always forward */ +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/devices/device.h b/node/node_modules/nanomsg/deps/nanomsg/src/devices/device.h new file mode 100644 index 0000000..37fb2cb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/devices/device.h @@ -0,0 +1,111 @@ +/* + Copyright (c) 2014 Drew Crawford. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +/* Base class for device. */ +struct nn_device_recipe { + + /* NN_CHECK flags. */ + int required_checks; + + /* The entry function. This checks the inputs according to the + required_checks flag, chooses the polling function, and starts + the device. You can override this function to implement + additional checks.*/ + int(*nn_device_entry) (struct nn_device_recipe *device, + int s1, int s2, int flags); + + /* The two-way poll function. */ + int (*nn_device_twoway) (struct nn_device_recipe *device, int s1, int s2); + + /* The one-way poll function. */ + int (*nn_device_oneway) (struct nn_device_recipe *device, int s1, int s2); + + int (*nn_device_loopback) (struct nn_device_recipe *device, int s); + + /* The movemsg function. */ + int (*nn_device_mvmsg) (struct nn_device_recipe *device, + int from, int to, int flags); + + /* The message intercept function. This function gives you an opportunity + to modify or cancel an nn_msghdr as it passes from one socket + to the other. + + from - the socket that the msghdr was received from + to - the socket where it is going + flags - the flags that are being used for send and receive functions + msghdr - the nn_msghdr that was received from the from socket + bytes - the actual received length of the msg. + The nn_msghdr->msg_iov->iov_len is not valid because + it contains NN_MSG + + return values: + + 1 indicates that the msghdr should be forwarded. + 0 indicates that the msghdr should *not* be forwarded, + e.g. the message is dropped in the device + -1 indicates an error. Set errno. + */ + int (*nn_device_rewritemsg) (struct nn_device_recipe *device, + int from, int to, int flags, struct nn_msghdr *msghdr, int bytes); +}; + +/* Default implementations of the functions. */ +int nn_device_loopback (struct nn_device_recipe *device, int s); +int nn_device_twoway (struct nn_device_recipe *device, int s1, int s2); +int nn_device_oneway (struct nn_device_recipe *device, int s1, int s2); +int nn_device_mvmsg (struct nn_device_recipe *device, + int from, int to, int flags); +int nn_device_entry(struct nn_device_recipe *device, + int s1, int s2, int flags); +int nn_device_rewritemsg(struct nn_device_recipe *device, + int from, int to, int flags, struct nn_msghdr *msghdr, int bytes); + + +/* At least one socket must be passed to the device. */ +#define NN_CHECK_AT_LEAST_ONE_SOCKET (1 << 0) +/* Loopback devices are allowed. */ +#define NN_CHECK_ALLOW_LOOPBACK (1 << 1) +/* Bidirectional devices are allowed. */ +#define NN_CHECK_ALLOW_BIDIRECTIONAL (1 << 2) +/* Unidirectional devices are allowed. */ +#define NN_CHECK_ALLOW_UNIDIRECTIONAL (1<<3) +/* Both sockets must be raw. */ +#define NN_CHECK_REQUIRE_RAW_SOCKETS (1 << 4) +/* Both sockets must be same protocol family. */ +#define NN_CHECK_SAME_PROTOCOL_FAMILY (1 << 5) +/* Check socket directionality. */ +#define NN_CHECK_SOCKET_DIRECTIONALITY (1 << 6) + +/* Allows spawning a custom device from a recipe */ +int nn_custom_device(struct nn_device_recipe *device, + int s1, int s2, int flags); + +static struct nn_device_recipe nn_ordinary_device = { + NN_CHECK_AT_LEAST_ONE_SOCKET | NN_CHECK_ALLOW_LOOPBACK | NN_CHECK_ALLOW_BIDIRECTIONAL | NN_CHECK_REQUIRE_RAW_SOCKETS | NN_CHECK_SAME_PROTOCOL_FAMILY | NN_CHECK_SOCKET_DIRECTIONALITY | NN_CHECK_ALLOW_UNIDIRECTIONAL, + nn_device_entry, + nn_device_twoway, + nn_device_oneway, + nn_device_loopback, + nn_device_mvmsg, + nn_device_rewritemsg +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/inproc.h b/node/node_modules/nanomsg/deps/nanomsg/src/inproc.h new file mode 100644 index 0000000..ed38799 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/inproc.h @@ -0,0 +1,37 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef INPROC_H_INCLUDED +#define INPROC_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_INPROC -1 + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/ipc.h b/node/node_modules/nanomsg/deps/nanomsg/src/ipc.h new file mode 100644 index 0000000..a78bfb8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/ipc.h @@ -0,0 +1,42 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef IPC_H_INCLUDED +#define IPC_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_IPC -2 + +/* The object set here must be valid as long as you are using the socket */ +#define NN_IPC_SEC_ATTR 1 +#define NN_IPC_OUTBUFSZ 2 +#define NN_IPC_INBUFSZ 3 + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/nn.h b/node/node_modules/nanomsg/deps/nanomsg/src/nn.h new file mode 100644 index 0000000..ce5efe3 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/nn.h @@ -0,0 +1,412 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_H_INCLUDED +#define NN_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* Handle DSO symbol visibility. */ +#if !defined(NN_EXPORT) +# if defined(_WIN32) && !defined(NN_STATIC_LIB) +# if defined NN_SHARED_LIB +# define NN_EXPORT __declspec(dllexport) +# else +# define NN_EXPORT __declspec(dllimport) +# endif +# else +# define NN_EXPORT extern +# endif +#endif + +/******************************************************************************/ +/* ABI versioning support. */ +/******************************************************************************/ + +/* Don't change this unless you know exactly what you're doing and have */ +/* read and understand the following documents: */ +/* www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html */ +/* www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html */ + +/* The current interface version. */ +#define NN_VERSION_CURRENT 5 + +/* The latest revision of the current interface. */ +#define NN_VERSION_REVISION 0 + +/* How many past interface versions are still supported. */ +#define NN_VERSION_AGE 0 + +/******************************************************************************/ +/* Errors. */ +/******************************************************************************/ + +/* A number random enough not to collide with different errno ranges on */ +/* different OSes. The assumption is that error_t is at least 32-bit type. */ +#define NN_HAUSNUMERO 156384712 + +/* On some platforms some standard POSIX errnos are not defined. */ +#ifndef ENOTSUP +#define ENOTSUP (NN_HAUSNUMERO + 1) +#endif +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT (NN_HAUSNUMERO + 2) +#endif +#ifndef ENOBUFS +#define ENOBUFS (NN_HAUSNUMERO + 3) +#endif +#ifndef ENETDOWN +#define ENETDOWN (NN_HAUSNUMERO + 4) +#endif +#ifndef EADDRINUSE +#define EADDRINUSE (NN_HAUSNUMERO + 5) +#endif +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL (NN_HAUSNUMERO + 6) +#endif +#ifndef ECONNREFUSED +#define ECONNREFUSED (NN_HAUSNUMERO + 7) +#endif +#ifndef EINPROGRESS +#define EINPROGRESS (NN_HAUSNUMERO + 8) +#endif +#ifndef ENOTSOCK +#define ENOTSOCK (NN_HAUSNUMERO + 9) +#endif +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT (NN_HAUSNUMERO + 10) +#endif +#ifndef EPROTO +#define EPROTO (NN_HAUSNUMERO + 11) +#endif +#ifndef EAGAIN +#define EAGAIN (NN_HAUSNUMERO + 12) +#endif +#ifndef EBADF +#define EBADF (NN_HAUSNUMERO + 13) +#endif +#ifndef EINVAL +#define EINVAL (NN_HAUSNUMERO + 14) +#endif +#ifndef EMFILE +#define EMFILE (NN_HAUSNUMERO + 15) +#endif +#ifndef EFAULT +#define EFAULT (NN_HAUSNUMERO + 16) +#endif +#ifndef EACCES +#define EACCES (NN_HAUSNUMERO + 17) +#endif +#ifndef EACCESS +#define EACCESS (EACCES) +#endif +#ifndef ENETRESET +#define ENETRESET (NN_HAUSNUMERO + 18) +#endif +#ifndef ENETUNREACH +#define ENETUNREACH (NN_HAUSNUMERO + 19) +#endif +#ifndef EHOSTUNREACH +#define EHOSTUNREACH (NN_HAUSNUMERO + 20) +#endif +#ifndef ENOTCONN +#define ENOTCONN (NN_HAUSNUMERO + 21) +#endif +#ifndef EMSGSIZE +#define EMSGSIZE (NN_HAUSNUMERO + 22) +#endif +#ifndef ETIMEDOUT +#define ETIMEDOUT (NN_HAUSNUMERO + 23) +#endif +#ifndef ECONNABORTED +#define ECONNABORTED (NN_HAUSNUMERO + 24) +#endif +#ifndef ECONNRESET +#define ECONNRESET (NN_HAUSNUMERO + 25) +#endif +#ifndef ENOPROTOOPT +#define ENOPROTOOPT (NN_HAUSNUMERO + 26) +#endif +#ifndef EISCONN +#define EISCONN (NN_HAUSNUMERO + 27) +#define NN_EISCONN_DEFINED +#endif +#ifndef ESOCKTNOSUPPORT +#define ESOCKTNOSUPPORT (NN_HAUSNUMERO + 28) +#endif + +/* Native nanomsg error codes. */ +#ifndef ETERM +#define ETERM (NN_HAUSNUMERO + 53) +#endif +#ifndef EFSM +#define EFSM (NN_HAUSNUMERO + 54) +#endif + +/* This function retrieves the errno as it is known to the library. */ +/* The goal of this function is to make the code 100% portable, including */ +/* where the library is compiled with certain CRT library (on Windows) and */ +/* linked to an application that uses different CRT library. */ +NN_EXPORT int nn_errno (void); + +/* Resolves system errors and native errors to human-readable string. */ +NN_EXPORT const char *nn_strerror (int errnum); + + +/* Returns the symbol name (e.g. "NN_REQ") and value at a specified index. */ +/* If the index is out-of-range, returns NULL and sets errno to EINVAL */ +/* General usage is to start at i=0 and iterate until NULL is returned. */ +NN_EXPORT const char *nn_symbol (int i, int *value); + +/* Constants that are returned in `ns` member of nn_symbol_properties */ +#define NN_NS_NAMESPACE 0 +#define NN_NS_VERSION 1 +#define NN_NS_DOMAIN 2 +#define NN_NS_TRANSPORT 3 +#define NN_NS_PROTOCOL 4 +#define NN_NS_OPTION_LEVEL 5 +#define NN_NS_SOCKET_OPTION 6 +#define NN_NS_TRANSPORT_OPTION 7 +#define NN_NS_OPTION_TYPE 8 +#define NN_NS_OPTION_UNIT 9 +#define NN_NS_FLAG 10 +#define NN_NS_ERROR 11 +#define NN_NS_LIMIT 12 +#define NN_NS_EVENT 13 +#define NN_NS_STATISTIC 14 + +/* Constants that are returned in `type` member of nn_symbol_properties */ +#define NN_TYPE_NONE 0 +#define NN_TYPE_INT 1 +#define NN_TYPE_STR 2 + +/* Constants that are returned in the `unit` member of nn_symbol_properties */ +#define NN_UNIT_NONE 0 +#define NN_UNIT_BYTES 1 +#define NN_UNIT_MILLISECONDS 2 +#define NN_UNIT_PRIORITY 3 +#define NN_UNIT_BOOLEAN 4 +#define NN_UNIT_MESSAGES 5 +#define NN_UNIT_COUNTER 6 + +/* Structure that is returned from nn_symbol */ +struct nn_symbol_properties { + + /* The constant value */ + int value; + + /* The constant name */ + const char* name; + + /* The constant namespace, or zero for namespaces themselves */ + int ns; + + /* The option type for socket option constants */ + int type; + + /* The unit for the option value for socket option constants */ + int unit; +}; + +/* Fills in nn_symbol_properties structure and returns it's length */ +/* If the index is out-of-range, returns 0 */ +/* General usage is to start at i=0 and iterate until zero is returned. */ +NN_EXPORT int nn_symbol_info (int i, + struct nn_symbol_properties *buf, int buflen); + +/******************************************************************************/ +/* Helper function for shutting down multi-threaded applications. */ +/******************************************************************************/ + +NN_EXPORT void nn_term (void); + +/******************************************************************************/ +/* Zero-copy support. */ +/******************************************************************************/ + +#define NN_MSG ((size_t) -1) + +NN_EXPORT void *nn_allocmsg (size_t size, int type); +NN_EXPORT void *nn_reallocmsg (void *msg, size_t size); +NN_EXPORT int nn_freemsg (void *msg); + +/******************************************************************************/ +/* Socket definition. */ +/******************************************************************************/ + +struct nn_iovec { + void *iov_base; + size_t iov_len; +}; + +struct nn_msghdr { + struct nn_iovec *msg_iov; + int msg_iovlen; + void *msg_control; + size_t msg_controllen; +}; + +struct nn_cmsghdr { + size_t cmsg_len; + int cmsg_level; + int cmsg_type; +}; + +/* Internal stuff. Not to be used directly. */ +NN_EXPORT struct nn_cmsghdr *nn_cmsg_nxthdr_ ( + const struct nn_msghdr *mhdr, + const struct nn_cmsghdr *cmsg); +#define NN_CMSG_ALIGN_(len) \ + (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + +/* POSIX-defined msghdr manipulation. */ + +#define NN_CMSG_FIRSTHDR(mhdr) \ + nn_cmsg_nxthdr_ ((struct nn_msghdr*) (mhdr), NULL) + +#define NN_CMSG_NXTHDR(mhdr, cmsg) \ + nn_cmsg_nxthdr_ ((struct nn_msghdr*) (mhdr), (struct nn_cmsghdr*) (cmsg)) + +#define NN_CMSG_DATA(cmsg) \ + ((unsigned char*) (((struct nn_cmsghdr*) (cmsg)) + 1)) + +/* Extensions to POSIX defined by RFC 3542. */ + +#define NN_CMSG_SPACE(len) \ + (NN_CMSG_ALIGN_ (len) + NN_CMSG_ALIGN_ (sizeof (struct nn_cmsghdr))) + +#define NN_CMSG_LEN(len) \ + (NN_CMSG_ALIGN_ (sizeof (struct nn_cmsghdr)) + (len)) + +/* SP address families. */ +#define AF_SP 1 +#define AF_SP_RAW 2 + +/* Max size of an SP address. */ +#define NN_SOCKADDR_MAX 128 + +/* Socket option levels: Negative numbers are reserved for transports, + positive for socket types. */ +#define NN_SOL_SOCKET 0 + +/* Generic socket options (NN_SOL_SOCKET level). */ +#define NN_LINGER 1 +#define NN_SNDBUF 2 +#define NN_RCVBUF 3 +#define NN_SNDTIMEO 4 +#define NN_RCVTIMEO 5 +#define NN_RECONNECT_IVL 6 +#define NN_RECONNECT_IVL_MAX 7 +#define NN_SNDPRIO 8 +#define NN_RCVPRIO 9 +#define NN_SNDFD 10 +#define NN_RCVFD 11 +#define NN_DOMAIN 12 +#define NN_PROTOCOL 13 +#define NN_IPV4ONLY 14 +#define NN_SOCKET_NAME 15 +#define NN_RCVMAXSIZE 16 +#define NN_MAXTTL 17 + +/* Send/recv options. */ +#define NN_DONTWAIT 1 + +/* Ancillary data. */ +#define PROTO_SP 1 +#define SP_HDR 1 + +NN_EXPORT int nn_socket (int domain, int protocol); +NN_EXPORT int nn_close (int s); +NN_EXPORT int nn_setsockopt (int s, int level, int option, const void *optval, + size_t optvallen); +NN_EXPORT int nn_getsockopt (int s, int level, int option, void *optval, + size_t *optvallen); +NN_EXPORT int nn_bind (int s, const char *addr); +NN_EXPORT int nn_connect (int s, const char *addr); +NN_EXPORT int nn_shutdown (int s, int how); +NN_EXPORT int nn_send (int s, const void *buf, size_t len, int flags); +NN_EXPORT int nn_recv (int s, void *buf, size_t len, int flags); +NN_EXPORT int nn_sendmsg (int s, const struct nn_msghdr *msghdr, int flags); +NN_EXPORT int nn_recvmsg (int s, struct nn_msghdr *msghdr, int flags); + +/******************************************************************************/ +/* Socket mutliplexing support. */ +/******************************************************************************/ + +#define NN_POLLIN 1 +#define NN_POLLOUT 2 + +struct nn_pollfd { + int fd; + short events; + short revents; +}; + +NN_EXPORT int nn_poll (struct nn_pollfd *fds, int nfds, int timeout); + +/******************************************************************************/ +/* Built-in support for devices. */ +/******************************************************************************/ + +NN_EXPORT int nn_device (int s1, int s2); + +/******************************************************************************/ +/* Statistics. */ +/******************************************************************************/ + +/* Transport statistics */ +#define NN_STAT_ESTABLISHED_CONNECTIONS 101 +#define NN_STAT_ACCEPTED_CONNECTIONS 102 +#define NN_STAT_DROPPED_CONNECTIONS 103 +#define NN_STAT_BROKEN_CONNECTIONS 104 +#define NN_STAT_CONNECT_ERRORS 105 +#define NN_STAT_BIND_ERRORS 106 +#define NN_STAT_ACCEPT_ERRORS 107 + +#define NN_STAT_CURRENT_CONNECTIONS 201 +#define NN_STAT_INPROGRESS_CONNECTIONS 202 +#define NN_STAT_CURRENT_EP_ERRORS 203 + +/* The socket-internal statistics */ +#define NN_STAT_MESSAGES_SENT 301 +#define NN_STAT_MESSAGES_RECEIVED 302 +#define NN_STAT_BYTES_SENT 303 +#define NN_STAT_BYTES_RECEIVED 304 +/* Protocol statistics */ +#define NN_STAT_CURRENT_SND_PRIORITY 401 + +NN_EXPORT uint64_t nn_get_statistic (int s, int stat); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/pair.h b/node/node_modules/nanomsg/deps/nanomsg/src/pair.h new file mode 100644 index 0000000..3409418 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/pair.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef PAIR_H_INCLUDED +#define PAIR_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_PROTO_PAIR 1 + +#define NN_PAIR (NN_PROTO_PAIR * 16 + 0) + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/pipeline.h b/node/node_modules/nanomsg/deps/nanomsg/src/pipeline.h new file mode 100644 index 0000000..db9b7d7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/pipeline.h @@ -0,0 +1,41 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef PIPELINE_H_INCLUDED +#define PIPELINE_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_PROTO_PIPELINE 5 + +#define NN_PUSH (NN_PROTO_PIPELINE * 16 + 0) +#define NN_PULL (NN_PROTO_PIPELINE * 16 + 1) + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/pkgconfig.in b/node/node_modules/nanomsg/deps/nanomsg/src/pkgconfig.in new file mode 100644 index 0000000..1e2e6cd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/pkgconfig.in @@ -0,0 +1,13 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=${prefix}/include +libdir=${prefix}/lib + +Name: @CMAKE_PROJECT_NAME@ +Description: @NN_DESCRIPTION@ +URL: http://nanomsg.org/ +Version: @NN_PACKAGE_VERSION@ +Requires: +Libs: -L${libdir} -l@CMAKE_PROJECT_NAME@ +Libs.private:@NN_REQUIRED_LFLAGS@ +Cflags: -I${includedir} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocol.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocol.h new file mode 100644 index 0000000..476185f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocol.h @@ -0,0 +1,197 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PROTOCOL_INCLUDED +#define NN_PROTOCOL_INCLUDED + +#include "utils/msg.h" +#include "utils/list.h" + +#include +#include + +struct nn_ctx; + +/******************************************************************************/ +/* Pipe class. */ +/******************************************************************************/ + +/* Any combination of following flags can be returned from successful call + to nn_pipe_send or nn_pipe_recv. */ + +/* This flag means that the pipe can't be used for receiving (when returned + from nn_pipe_recv()) or sending (when returned from nn_pipe_send()). + Protocol implementation should not send/recv messages from the pipe until + the pipe is revived by in()/out() function. */ +#define NN_PIPE_RELEASE 1 + +/* Specifies that received message is already split into header and body. + This flag is used only by inproc transport to avoid merging and re-splitting + the messages passed with a single process. */ +#define NN_PIPE_PARSED 2 + +/* Events generated by the pipe. */ +#define NN_PIPE_IN 33987 +#define NN_PIPE_OUT 33988 + +struct nn_pipe; + +/* Associates opaque pointer to protocol-specific data with the pipe. */ +void nn_pipe_setdata (struct nn_pipe *self, void *data); + +/* Retrieves the opaque pointer associated with the pipe. */ +void *nn_pipe_getdata (struct nn_pipe *self); + +/* Send the message to the pipe. If successful, pipe takes ownership of the + messages. */ +int nn_pipe_send (struct nn_pipe *self, struct nn_msg *msg); + +/* Receive a message from a pipe. 'msg' should not be initialised prior to + the call. It will be initialised when the call succeeds. */ +int nn_pipe_recv (struct nn_pipe *self, struct nn_msg *msg); + +/* Get option for pipe. Mostly useful for endpoint-specific options */ +void nn_pipe_getopt (struct nn_pipe *self, int level, int option, + void *optval, size_t *optvallen); + + +/******************************************************************************/ +/* Base class for all socket types. */ +/******************************************************************************/ + +struct nn_sockbase; + +/* Any combination of these events can be returned from 'events' virtual + function. */ +#define NN_SOCKBASE_EVENT_IN 1 +#define NN_SOCKBASE_EVENT_OUT 2 + +/* To be implemented by individual socket types. */ +struct nn_sockbase_vfptr { + + /* Ask socket to stop. */ + void (*stop) (struct nn_sockbase *self); + + /* Deallocate the socket. */ + void (*destroy) (struct nn_sockbase *self); + + /* Management of pipes. 'add' registers a new pipe. The pipe cannot be used + to send to or to be received from at the moment. 'rm' unregisters the + pipe. The pipe should not be used after this call as it may already be + deallocated. 'in' informs the socket that pipe is readable. 'out' + informs it that it is writable. */ + int (*add) (struct nn_sockbase *self, struct nn_pipe *pipe); + void (*rm) (struct nn_sockbase *self, struct nn_pipe *pipe); + void (*in) (struct nn_sockbase *self, struct nn_pipe *pipe); + void (*out) (struct nn_sockbase *self, struct nn_pipe *pipe); + + /* Return any combination of event flags defined above, thus specifying + whether the socket should be readable, writable, both or none. */ + int (*events) (struct nn_sockbase *self); + + /* Send a message to the socket. Returns -EAGAIN if it cannot be done at + the moment or zero in case of success. */ + int (*send) (struct nn_sockbase *self, struct nn_msg *msg); + + /* Receive a message from the socket. Returns -EAGAIN if it cannot be done + at the moment or zero in case of success. */ + int (*recv) (struct nn_sockbase *self, struct nn_msg *msg); + + /* Set a protocol specific option. */ + int (*setopt) (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); + + /* Retrieve a protocol specific option. */ + int (*getopt) (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +}; + +struct nn_sockbase { + const struct nn_sockbase_vfptr *vfptr; + struct nn_sock *sock; +}; + +/* Initialise the socket base class. 'hint' is the opaque value passed to the + nn_transport's 'create' function. */ +void nn_sockbase_init (struct nn_sockbase *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); + +/* Terminate the socket base class. */ +void nn_sockbase_term (struct nn_sockbase *self); + +/* Call this function when stopping is done. */ +void nn_sockbase_stopped (struct nn_sockbase *self); + +/* Returns the AIO context associated with the socket. This function is + useful when socket type implementation needs to create async objects, + such as timers. */ +struct nn_ctx *nn_sockbase_getctx (struct nn_sockbase *self); + +/* Retrieve a NN_SOL_SOCKET-level option. */ +int nn_sockbase_getopt (struct nn_sockbase *self, int option, + void *optval, size_t *optvallen); + +/* Add some statistics for socket */ +void nn_sockbase_stat_increment (struct nn_sockbase *self, int name, + int increment); + +/******************************************************************************/ +/* The socktype class. */ +/******************************************************************************/ + +/* This structure defines a class factory for individual socket types. */ + +/* Specifies that the socket type can be never used to receive messages. */ +#define NN_SOCKTYPE_FLAG_NORECV 1 + +/* Specifies that the socket type can be never used to send messages. */ +#define NN_SOCKTYPE_FLAG_NOSEND 2 + +struct nn_socktype { + + /* Domain and protocol IDs as specified in nn_socket() function. */ + int domain; + int protocol; + + /* Any combination of the flags defined above. */ + int flags; + + /* Function to create specific socket type. 'sockbase' is the output + parameter to return reference to newly created socket. This function + is called under global lock, so it is not possible that two sockets are + being created in parallel. */ + int (*create) (void *hint, struct nn_sockbase **sockbase); + + /* Returns 1 if the supplied socket type is a valid peer for this socket, + 0 otherwise. Note that the validation is done only within a single + SP protocol. Peers speaking other SP protocols are discarded by the + core and socket is not even asked to validate them. */ + int (*ispeer) (int socktype); + + /* This member is owned by the core. Never touch it directly from inside + the protocol implementation. */ + struct nn_list_item item; +}; + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/README b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/README new file mode 100644 index 0000000..cb3e874 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/README @@ -0,0 +1,2 @@ +This directory contains all the available scalability protocol implementations, +such as publish/subscribe, request/reply etc. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/bus.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/bus.c new file mode 100644 index 0000000..3064fa8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/bus.c @@ -0,0 +1,143 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "bus.h" +#include "xbus.h" + +#include "../../nn.h" +#include "../../bus.h" + +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/err.h" +#include "../../utils/list.h" + +struct nn_bus { + struct nn_xbus xbus; +}; + +/* Private functions. */ +static void nn_bus_init (struct nn_bus *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_bus_term (struct nn_bus *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_bus_destroy (struct nn_sockbase *self); +static int nn_bus_send (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_bus_recv (struct nn_sockbase *self, struct nn_msg *msg); +static const struct nn_sockbase_vfptr nn_bus_sockbase_vfptr = { + NULL, + nn_bus_destroy, + nn_xbus_add, + nn_xbus_rm, + nn_xbus_in, + nn_xbus_out, + nn_xbus_events, + nn_bus_send, + nn_bus_recv, + nn_xbus_setopt, + nn_xbus_getopt +}; + +static void nn_bus_init (struct nn_bus *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_xbus_init (&self->xbus, vfptr, hint); +} + +static void nn_bus_term (struct nn_bus *self) +{ + nn_xbus_term (&self->xbus); +} + +static void nn_bus_destroy (struct nn_sockbase *self) +{ + struct nn_bus *bus; + + bus = nn_cont (self, struct nn_bus, xbus.sockbase); + + nn_bus_term (bus); + nn_free (bus); +} + +static int nn_bus_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_bus *bus; + + bus = nn_cont (self, struct nn_bus, xbus.sockbase); + + /* Check for malformed messages. */ + if (nn_chunkref_size (&msg->sphdr)) + return -EINVAL; + + /* Send the message. */ + rc = nn_xbus_send (&bus->xbus.sockbase, msg); + errnum_assert (rc == 0, -rc); + + return 0; +} + +static int nn_bus_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_bus *bus; + + bus = nn_cont (self, struct nn_bus, xbus.sockbase); + + /* Get next message. */ + rc = nn_xbus_recv (&bus->xbus.sockbase, msg); + if (nn_slow (rc == -EAGAIN)) + return -EAGAIN; + errnum_assert (rc == 0, -rc); + nn_assert (nn_chunkref_size (&msg->sphdr) == sizeof (uint64_t)); + + /* Discard the header. */ + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, 0); + + return 0; +} + +static int nn_bus_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_bus *self; + + self = nn_alloc (sizeof (struct nn_bus), "socket (bus)"); + alloc_assert (self); + nn_bus_init (self, &nn_bus_sockbase_vfptr, hint); + *sockbase = &self->xbus.sockbase; + + return 0; +} + +static struct nn_socktype nn_bus_socktype_struct = { + AF_SP, + NN_BUS, + 0, + nn_bus_create, + nn_xbus_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_bus_socktype = &nn_bus_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/bus.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/bus.h new file mode 100644 index 0000000..4390ace --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/bus.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BUS_INCLUDED +#define NN_BUS_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_bus_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/xbus.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/xbus.c new file mode 100644 index 0000000..50e89e9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/xbus.c @@ -0,0 +1,240 @@ +/* + Copyright (c) 2013-2014 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xbus.h" + +#include "../../nn.h" +#include "../../bus.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +#include +#include + +/* To make the algorithm super efficient we directly cast pipe pointers to + pipe IDs (rather than maintaining a hash table). For this to work, it is + neccessary for the pointer to fit in 64-bit ID. */ +CT_ASSERT (sizeof (uint64_t) >= sizeof (struct nn_pipe*)); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_xbus_destroy (struct nn_sockbase *self); +static const struct nn_sockbase_vfptr nn_xbus_sockbase_vfptr = { + NULL, + nn_xbus_destroy, + nn_xbus_add, + nn_xbus_rm, + nn_xbus_in, + nn_xbus_out, + nn_xbus_events, + nn_xbus_send, + nn_xbus_recv, + nn_xbus_setopt, + nn_xbus_getopt +}; + +void nn_xbus_init (struct nn_xbus *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_dist_init (&self->outpipes); + nn_fq_init (&self->inpipes); +} + +void nn_xbus_term (struct nn_xbus *self) +{ + nn_fq_term (&self->inpipes); + nn_dist_term (&self->outpipes); + nn_sockbase_term (&self->sockbase); +} + +static void nn_xbus_destroy (struct nn_sockbase *self) +{ + struct nn_xbus *xbus; + + xbus = nn_cont (self, struct nn_xbus, sockbase); + + nn_xbus_term (xbus); + nn_free (xbus); +} + +int nn_xbus_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xbus *xbus; + struct nn_xbus_data *data; + int rcvprio; + size_t sz; + + xbus = nn_cont (self, struct nn_xbus, sockbase); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (struct nn_xbus_data), "pipe data (xbus)"); + alloc_assert (data); + nn_fq_add (&xbus->inpipes, &data->initem, pipe, rcvprio); + nn_dist_add (&xbus->outpipes, &data->outitem, pipe); + nn_pipe_setdata (pipe, data); + + return 0; +} + +void nn_xbus_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xbus *xbus; + struct nn_xbus_data *data; + + xbus = nn_cont (self, struct nn_xbus, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_rm (&xbus->inpipes, &data->initem); + nn_dist_rm (&xbus->outpipes, &data->outitem); + + nn_free (data); +} + +void nn_xbus_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xbus *xbus; + struct nn_xbus_data *data; + + xbus = nn_cont (self, struct nn_xbus, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_in (&xbus->inpipes, &data->initem); +} + +void nn_xbus_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xbus *xbus; + struct nn_xbus_data *data; + + xbus = nn_cont (self, struct nn_xbus, sockbase); + data = nn_pipe_getdata (pipe); + + nn_dist_out (&xbus->outpipes, &data->outitem); +} + +int nn_xbus_events (struct nn_sockbase *self) +{ + return (nn_fq_can_recv (&nn_cont (self, struct nn_xbus, + sockbase)->inpipes) ? NN_SOCKBASE_EVENT_IN : 0) | NN_SOCKBASE_EVENT_OUT; +} + +int nn_xbus_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + size_t hdrsz; + struct nn_pipe *exclude; + + hdrsz = nn_chunkref_size (&msg->sphdr); + if (hdrsz == 0) + exclude = NULL; + else if (hdrsz == sizeof (uint64_t)) { + memcpy (&exclude, nn_chunkref_data (&msg->sphdr), sizeof (exclude)); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, 0); + } + else + return -EINVAL; + + return nn_dist_send (&nn_cont (self, struct nn_xbus, sockbase)->outpipes, + msg, exclude); +} + +int nn_xbus_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_xbus *xbus; + struct nn_pipe *pipe; + + xbus = nn_cont (self, struct nn_xbus, sockbase); + + while (1) { + + /* Get next message in fair-queued manner. */ + rc = nn_fq_recv (&xbus->inpipes, msg, &pipe); + if (nn_slow (rc < 0)) + return rc; + + /* The message should have no header. Drop malformed messages. */ + if (nn_chunkref_size (&msg->sphdr) == 0) + break; + nn_msg_term (msg); + } + + /* Add pipe ID to the message header. */ + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, sizeof (uint64_t)); + memset (nn_chunkref_data (&msg->sphdr), 0, sizeof (uint64_t)); + memcpy (nn_chunkref_data (&msg->sphdr), &pipe, sizeof (pipe)); + + return 0; +} + +int nn_xbus_setopt (NN_UNUSED struct nn_sockbase *self, NN_UNUSED int level, + NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xbus_getopt (NN_UNUSED struct nn_sockbase *self, NN_UNUSED int level, + NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xbus_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xbus *self; + + self = nn_alloc (sizeof (struct nn_xbus), "socket (bus)"); + alloc_assert (self); + nn_xbus_init (self, &nn_xbus_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xbus_ispeer (int socktype) +{ + return socktype == NN_BUS ? 1 : 0; +} + +static struct nn_socktype nn_xbus_socktype_struct = { + AF_SP_RAW, + NN_BUS, + 0, + nn_xbus_create, + nn_xbus_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xbus_socktype = &nn_xbus_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/xbus.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/xbus.h new file mode 100644 index 0000000..bdf04f8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/bus/xbus.h @@ -0,0 +1,62 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XBUS_INCLUDED +#define NN_XBUS_INCLUDED + +#include "../../protocol.h" + +#include "../utils/dist.h" +#include "../utils/fq.h" + +extern struct nn_socktype *nn_xbus_socktype; + +struct nn_xbus_data { + struct nn_dist_data outitem; + struct nn_fq_data initem; +}; + +struct nn_xbus { + struct nn_sockbase sockbase; + struct nn_dist outpipes; + struct nn_fq inpipes; +}; + +void nn_xbus_init (struct nn_xbus *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +void nn_xbus_term (struct nn_xbus *self); + +int nn_xbus_add (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xbus_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xbus_in (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xbus_out (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_xbus_events (struct nn_sockbase *self); +int nn_xbus_send (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xbus_recv (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xbus_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +int nn_xbus_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); + +int nn_xbus_ispeer (int socktype); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/pair.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/pair.c new file mode 100644 index 0000000..4cbb3fb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/pair.c @@ -0,0 +1,40 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "pair.h" +#include "xpair.h" + +#include "../../nn.h" +#include "../../pair.h" +#include "../../utils/list.h" + +static struct nn_socktype nn_pair_socktype_struct = { + AF_SP, + NN_PAIR, + 0, + nn_xpair_create, + nn_xpair_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_pair_socktype = &nn_pair_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/pair.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/pair.h new file mode 100644 index 0000000..b33ab48 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/pair.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PAIR_INCLUDED +#define NN_PAIR_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_pair_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/xpair.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/xpair.c new file mode 100644 index 0000000..ab925a1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/xpair.c @@ -0,0 +1,190 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xpair.h" + +#include "../../nn.h" +#include "../../pair.h" + +#include "../utils/excl.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +struct nn_xpair { + struct nn_sockbase sockbase; + struct nn_excl excl; +}; + +/* Private functions. */ +static void nn_xpair_init (struct nn_xpair *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_xpair_term (struct nn_xpair *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_xpair_destroy (struct nn_sockbase *self); +static int nn_xpair_add (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpair_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpair_in (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpair_out (struct nn_sockbase *self, struct nn_pipe *pipe); +static int nn_xpair_events (struct nn_sockbase *self); +static int nn_xpair_send (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_xpair_recv (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_xpair_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +static int nn_xpair_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +static const struct nn_sockbase_vfptr nn_xpair_sockbase_vfptr = { + NULL, + nn_xpair_destroy, + nn_xpair_add, + nn_xpair_rm, + nn_xpair_in, + nn_xpair_out, + nn_xpair_events, + nn_xpair_send, + nn_xpair_recv, + nn_xpair_setopt, + nn_xpair_getopt +}; + +static void nn_xpair_init (struct nn_xpair *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_excl_init (&self->excl); +} + +static void nn_xpair_term (struct nn_xpair *self) +{ + nn_excl_term (&self->excl); + nn_sockbase_term (&self->sockbase); +} + +void nn_xpair_destroy (struct nn_sockbase *self) +{ + struct nn_xpair *xpair; + + xpair = nn_cont (self, struct nn_xpair, sockbase); + + nn_xpair_term (xpair); + nn_free (xpair); +} + +static int nn_xpair_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + return nn_excl_add (&nn_cont (self, struct nn_xpair, sockbase)->excl, + pipe); +} + +static void nn_xpair_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + nn_excl_rm (&nn_cont (self, struct nn_xpair, sockbase)->excl, pipe); +} + +static void nn_xpair_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + nn_excl_in (&nn_cont (self, struct nn_xpair, sockbase)->excl, pipe); +} + +static void nn_xpair_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + nn_excl_out (&nn_cont (self, struct nn_xpair, sockbase)->excl, pipe); +} + +static int nn_xpair_events (struct nn_sockbase *self) +{ + struct nn_xpair *xpair; + int events; + + xpair = nn_cont (self, struct nn_xpair, sockbase); + + events = 0; + if (nn_excl_can_recv (&xpair->excl)) + events |= NN_SOCKBASE_EVENT_IN; + if (nn_excl_can_send (&xpair->excl)) + events |= NN_SOCKBASE_EVENT_OUT; + return events; +} + +static int nn_xpair_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + return nn_excl_send (&nn_cont (self, struct nn_xpair, sockbase)->excl, + msg); +} + +static int nn_xpair_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + + rc = nn_excl_recv (&nn_cont (self, struct nn_xpair, sockbase)->excl, msg); + + /* Discard NN_PIPEBASE_PARSED flag. */ + return rc < 0 ? rc : 0; +} + +static int nn_xpair_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xpair_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xpair_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xpair *self; + + self = nn_alloc (sizeof (struct nn_xpair), "socket (pair)"); + alloc_assert (self); + nn_xpair_init (self, &nn_xpair_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xpair_ispeer (int socktype) +{ + return socktype == NN_PAIR ? 1 : 0; +} + +static struct nn_socktype nn_xpair_socktype_struct = { + AF_SP_RAW, + NN_PAIR, + 0, + nn_xpair_create, + nn_xpair_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xpair_socktype = &nn_xpair_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/xpair.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/xpair.h new file mode 100644 index 0000000..a0738b3 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pair/xpair.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XPAIR_INCLUDED +#define NN_XPAIR_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_xpair_socktype; + +int nn_xpair_create (void *hint, struct nn_sockbase **sockbase); +int nn_xpair_ispeer (int socktype); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.c new file mode 100644 index 0000000..ec9f1d6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.c @@ -0,0 +1,40 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "pull.h" +#include "xpull.h" + +#include "../../nn.h" +#include "../../pipeline.h" +#include "../../utils/list.h" + +static struct nn_socktype nn_pull_socktype_struct = { + AF_SP, + NN_PULL, + NN_SOCKTYPE_FLAG_NOSEND, + nn_xpull_create, + nn_xpull_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_pull_socktype = &nn_pull_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.h new file mode 100644 index 0000000..592e6cf --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/pull.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PULL_INCLUDED +#define NN_PULL_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_pull_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/push.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/push.c new file mode 100644 index 0000000..061f07e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/push.c @@ -0,0 +1,40 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "push.h" +#include "xpush.h" + +#include "../../nn.h" +#include "../../pipeline.h" +#include "../../utils/list.h" + +static struct nn_socktype nn_push_socktype_struct = { + AF_SP, + NN_PUSH, + NN_SOCKTYPE_FLAG_NORECV, + nn_xpush_create, + nn_xpush_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_push_socktype = &nn_push_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/push.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/push.h new file mode 100644 index 0000000..e0bb6a5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/push.h @@ -0,0 +1,31 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PUSH_INCLUDED +#define NN_PUSH_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_push_socktype; + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.c new file mode 100644 index 0000000..673accd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.c @@ -0,0 +1,210 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xpull.h" + +#include "../../nn.h" +#include "../../pipeline.h" + +#include "../utils/fq.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +struct nn_xpull_data { + struct nn_fq_data fq; +}; + +struct nn_xpull { + struct nn_sockbase sockbase; + struct nn_fq fq; +}; + +/* Private functions. */ +static void nn_xpull_init (struct nn_xpull *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_xpull_term (struct nn_xpull *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_xpull_destroy (struct nn_sockbase *self); +static int nn_xpull_add (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpull_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpull_in (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpull_out (struct nn_sockbase *self, struct nn_pipe *pipe); +static int nn_xpull_events (struct nn_sockbase *self); +static int nn_xpull_recv (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_xpull_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +static int nn_xpull_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +static const struct nn_sockbase_vfptr nn_xpull_sockbase_vfptr = { + NULL, + nn_xpull_destroy, + nn_xpull_add, + nn_xpull_rm, + nn_xpull_in, + nn_xpull_out, + nn_xpull_events, + NULL, + nn_xpull_recv, + nn_xpull_setopt, + nn_xpull_getopt +}; + +static void nn_xpull_init (struct nn_xpull *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_fq_init (&self->fq); +} + +static void nn_xpull_term (struct nn_xpull *self) +{ + nn_fq_term (&self->fq); + nn_sockbase_term (&self->sockbase); +} + +void nn_xpull_destroy (struct nn_sockbase *self) +{ + struct nn_xpull *xpull; + + xpull = nn_cont (self, struct nn_xpull, sockbase); + + nn_xpull_term (xpull); + nn_free (xpull); +} + +static int nn_xpull_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpull *xpull; + struct nn_xpull_data *data; + int rcvprio; + size_t sz; + + xpull = nn_cont (self, struct nn_xpull, sockbase); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (struct nn_xpull_data), "pipe data (pull)"); + alloc_assert (data); + nn_pipe_setdata (pipe, data); + nn_fq_add (&xpull->fq, &data->fq, pipe, rcvprio); + + return 0; +} + +static void nn_xpull_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpull *xpull; + struct nn_xpull_data *data; + + xpull = nn_cont (self, struct nn_xpull, sockbase); + data = nn_pipe_getdata (pipe); + nn_fq_rm (&xpull->fq, &data->fq); + nn_free (data); +} + +static void nn_xpull_in (NN_UNUSED struct nn_sockbase *self, + struct nn_pipe *pipe) +{ + struct nn_xpull *xpull; + struct nn_xpull_data *data; + + xpull = nn_cont (self, struct nn_xpull, sockbase); + data = nn_pipe_getdata (pipe); + nn_fq_in (&xpull->fq, &data->fq); +} + +static void nn_xpull_out (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED struct nn_pipe *pipe) +{ + /* We are not going to send any messages, so there's no point is + maintaining a list of pipes ready for sending. */ +} + +static int nn_xpull_events (struct nn_sockbase *self) +{ + return nn_fq_can_recv (&nn_cont (self, struct nn_xpull, sockbase)->fq) ? + NN_SOCKBASE_EVENT_IN : 0; +} + +static int nn_xpull_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + + rc = nn_fq_recv (&nn_cont (self, struct nn_xpull, sockbase)->fq, + msg, NULL); + + /* Discard NN_PIPEBASE_PARSED flag. */ + return rc < 0 ? rc : 0; +} + +static int nn_xpull_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xpull_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xpull_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xpull *self; + + self = nn_alloc (sizeof (struct nn_xpull), "socket (pull)"); + alloc_assert (self); + nn_xpull_init (self, &nn_xpull_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xpull_ispeer (int socktype) +{ + return socktype == NN_PUSH ? 1 : 0; +} + +static struct nn_socktype nn_xpull_socktype_struct = { + AF_SP_RAW, + NN_PULL, + NN_SOCKTYPE_FLAG_NOSEND, + nn_xpull_create, + nn_xpull_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xpull_socktype = &nn_xpull_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.h new file mode 100644 index 0000000..37ef9a4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpull.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XPULL_INCLUDED +#define NN_XPULL_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_xpull_socktype; + +int nn_xpull_create (void *hint, struct nn_sockbase **sockbase); +int nn_xpull_ispeer (int socktype); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.c new file mode 100644 index 0000000..2d938bd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.c @@ -0,0 +1,208 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xpush.h" + +#include "../../nn.h" +#include "../../pipeline.h" + +#include "../utils/lb.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +struct nn_xpush_data { + struct nn_lb_data lb; +}; + +struct nn_xpush { + struct nn_sockbase sockbase; + struct nn_lb lb; +}; + +/* Private functions. */ +static void nn_xpush_init (struct nn_xpush *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_xpush_term (struct nn_xpush *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_xpush_destroy (struct nn_sockbase *self); +static int nn_xpush_add (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpush_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpush_in (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpush_out (struct nn_sockbase *self, struct nn_pipe *pipe); +static int nn_xpush_events (struct nn_sockbase *self); +static int nn_xpush_send (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_xpush_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +static int nn_xpush_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +static const struct nn_sockbase_vfptr nn_xpush_sockbase_vfptr = { + NULL, + nn_xpush_destroy, + nn_xpush_add, + nn_xpush_rm, + nn_xpush_in, + nn_xpush_out, + nn_xpush_events, + nn_xpush_send, + NULL, + nn_xpush_setopt, + nn_xpush_getopt +}; + +static void nn_xpush_init (struct nn_xpush *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_lb_init (&self->lb); +} + +static void nn_xpush_term (struct nn_xpush *self) +{ + nn_lb_term (&self->lb); + nn_sockbase_term (&self->sockbase); +} + +void nn_xpush_destroy (struct nn_sockbase *self) +{ + struct nn_xpush *xpush; + + xpush = nn_cont (self, struct nn_xpush, sockbase); + + nn_xpush_term (xpush); + nn_free (xpush); +} + +static int nn_xpush_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpush *xpush; + struct nn_xpush_data *data; + int sndprio; + size_t sz; + + xpush = nn_cont (self, struct nn_xpush, sockbase); + + sz = sizeof (sndprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_SNDPRIO, &sndprio, &sz); + nn_assert (sz == sizeof (sndprio)); + nn_assert (sndprio >= 1 && sndprio <= 16); + + data = nn_alloc (sizeof (struct nn_xpush_data), "pipe data (push)"); + alloc_assert (data); + nn_pipe_setdata (pipe, data); + nn_lb_add (&xpush->lb, &data->lb, pipe, sndprio); + + return 0; +} + +static void nn_xpush_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpush *xpush; + struct nn_xpush_data *data; + + xpush = nn_cont (self, struct nn_xpush, sockbase); + data = nn_pipe_getdata (pipe); + nn_lb_rm (&xpush->lb, &data->lb); + nn_free (data); + + nn_sockbase_stat_increment (self, NN_STAT_CURRENT_SND_PRIORITY, + nn_lb_get_priority (&xpush->lb)); +} + +static void nn_xpush_in (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED struct nn_pipe *pipe) +{ + /* We are not going to receive any messages, so there's no need to store + the list of inbound pipes. */ +} + +static void nn_xpush_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpush *xpush; + struct nn_xpush_data *data; + + xpush = nn_cont (self, struct nn_xpush, sockbase); + data = nn_pipe_getdata (pipe); + nn_lb_out (&xpush->lb, &data->lb); + nn_sockbase_stat_increment (self, NN_STAT_CURRENT_SND_PRIORITY, + nn_lb_get_priority (&xpush->lb)); +} + +static int nn_xpush_events (struct nn_sockbase *self) +{ + return nn_lb_can_send (&nn_cont (self, struct nn_xpush, sockbase)->lb) ? + NN_SOCKBASE_EVENT_OUT : 0; +} + +static int nn_xpush_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + return nn_lb_send (&nn_cont (self, struct nn_xpush, sockbase)->lb, + msg, NULL); +} + +static int nn_xpush_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xpush_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xpush_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xpush *self; + + self = nn_alloc (sizeof (struct nn_xpush), "socket (push)"); + alloc_assert (self); + nn_xpush_init (self, &nn_xpush_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xpush_ispeer (int socktype) +{ + return socktype == NN_PULL ? 1 : 0; +} + +static struct nn_socktype nn_xpush_socktype_struct = { + AF_SP_RAW, + NN_PUSH, + NN_SOCKTYPE_FLAG_NORECV, + nn_xpush_create, + nn_xpush_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xpush_socktype = &nn_xpush_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.h new file mode 100644 index 0000000..f7c7e60 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pipeline/xpush.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XPUSH_INCLUDED +#define NN_XPUSH_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_xpush_socktype; + +int nn_xpush_create (void *hint, struct nn_sockbase **sockbase); +int nn_xpush_ispeer (int socktype); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.c new file mode 100644 index 0000000..44f9899 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.c @@ -0,0 +1,40 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "pub.h" +#include "xpub.h" + +#include "../../nn.h" +#include "../../pubsub.h" +#include "../../utils/list.h" + +static struct nn_socktype nn_pub_socktype_struct = { + AF_SP, + NN_PUB, + NN_SOCKTYPE_FLAG_NORECV, + nn_xpub_create, + nn_xpub_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_pub_socktype = &nn_pub_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.h new file mode 100644 index 0000000..366ada8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/pub.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PUB_INCLUDED +#define NN_PUB_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_pub_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.c new file mode 100644 index 0000000..789dc76 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.c @@ -0,0 +1,40 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sub.h" +#include "xsub.h" + +#include "../../nn.h" +#include "../../pubsub.h" +#include "../../utils/list.h" + +static struct nn_socktype nn_sub_socktype_struct = { + AF_SP, + NN_SUB, + NN_SOCKTYPE_FLAG_NOSEND, + nn_xsub_create, + nn_xsub_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_sub_socktype = &nn_sub_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.h new file mode 100644 index 0000000..300c0ab --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/sub.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SUB_INCLUDED +#define NN_SUB_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_sub_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.c new file mode 100644 index 0000000..1d3d0ee --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.c @@ -0,0 +1,662 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include +#include +#include + +#include "trie.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/err.h" + +/* Double check that the size of node structure is as small as + we believe it to be. */ +CT_ASSERT (sizeof (struct nn_trie_node) == 24); + +/* Forward declarations. */ +static struct nn_trie_node *nn_node_compact (struct nn_trie_node *self); +static int nn_node_check_prefix (struct nn_trie_node *self, + const uint8_t *data, size_t size); +static struct nn_trie_node **nn_node_child (struct nn_trie_node *self, + int index); +static struct nn_trie_node **nn_node_next (struct nn_trie_node *self, + uint8_t c); +static int nn_node_unsubscribe (struct nn_trie_node **self, + const uint8_t *data, size_t size); +static void nn_node_term (struct nn_trie_node *self); +static int nn_node_has_subscribers (struct nn_trie_node *self); +static void nn_node_dump (struct nn_trie_node *self, int indent); +static void nn_node_indent (int indent); +static void nn_node_putchar (uint8_t c); + +void nn_trie_init (struct nn_trie *self) +{ + self->root = NULL; +} + +void nn_trie_term (struct nn_trie *self) +{ + nn_node_term (self->root); +} + +void nn_trie_dump (struct nn_trie *self) +{ + nn_node_dump (self->root, 0); +} + +void nn_node_dump (struct nn_trie_node *self, int indent) +{ + int i; + int children; + + if (!self) { + nn_node_indent (indent); + printf ("NULL\n"); + return; + } + + nn_node_indent (indent); + printf ("===================\n"); + nn_node_indent (indent); + printf ("refcount=%d\n", (int) self->refcount); + nn_node_indent (indent); + printf ("prefix_len=%d\n", (int) self->prefix_len); + nn_node_indent (indent); + if (self->type == NN_TRIE_DENSE_TYPE) + printf ("type=dense\n"); + else + printf ("type=sparse\n"); + nn_node_indent (indent); + printf ("prefix=\""); + for (i = 0; i != self->prefix_len; ++i) + nn_node_putchar (self->prefix [i]); + printf ("\"\n"); + if (self->type <= 8) { + nn_node_indent (indent); + printf ("sparse.children=\""); + for (i = 0; i != self->type; ++i) + nn_node_putchar (self->u.sparse.children [i]); + printf ("\"\n"); + children = self->type; + } + else { + nn_node_indent (indent); + printf ("dense.min='%c' (%d)\n", (char) self->u.dense.min, + (int) self->u.dense.min); + nn_node_indent (indent); + printf ("dense.max='%c' (%d)\n", (char) self->u.dense.max, + (int) self->u.dense.max); + nn_node_indent (indent); + printf ("dense.nbr=%d\n", (int) self->u.dense.nbr); + children = self->u.dense.max - self->u.dense.min + 1; + } + + for (i = 0; i != children; ++i) + nn_node_dump (((struct nn_trie_node**) (self + 1)) [i], indent + 1); + + nn_node_indent (indent); + printf ("===================\n"); +} + +void nn_node_indent (int indent) +{ + int i; + + for (i = 0; i != indent * 4; ++i) + nn_node_putchar (' '); +} + +void nn_node_putchar (uint8_t c) +{ + if (c < 32 || c > 127) + putchar ('?'); + else + putchar (c); +} + +void nn_node_term (struct nn_trie_node *self) +{ + int children; + int i; + + /* Trivial case of the recursive algorithm. */ + if (!self) + return; + + /* Recursively destroy the child nodes. */ + children = self->type <= NN_TRIE_SPARSE_MAX ? + self->type : (self->u.dense.max - self->u.dense.min + 1); + for (i = 0; i != children; ++i) + nn_node_term (*nn_node_child (self, i)); + + /* Deallocate this node. */ + nn_free (self); +} + +int nn_node_check_prefix (struct nn_trie_node *self, + const uint8_t *data, size_t size) +{ + /* Check how many characters from the data match the prefix. */ + + int i; + + for (i = 0; i != self->prefix_len; ++i) { + if (!size || self->prefix [i] != *data) + return i; + ++data; + --size; + } + return self->prefix_len; +} + +struct nn_trie_node **nn_node_child (struct nn_trie_node *self, int index) +{ + /* Finds pointer to the n-th child of the node. */ + + return ((struct nn_trie_node**) (self + 1)) + index; +} + +struct nn_trie_node **nn_node_next (struct nn_trie_node *self, uint8_t c) +{ + /* Finds the pointer to the next node based on the supplied character. + If there is no such pointer, it returns NULL. */ + + int i; + + if (self->type == 0) + return NULL; + + /* Sparse mode. */ + if (self->type <= 8) { + for (i = 0; i != self->type; ++i) + if (self->u.sparse.children [i] == c) + return nn_node_child (self, i); + return NULL; + } + + /* Dense mode. */ + if (c < self->u.dense.min || c > self->u.dense.max) + return NULL; + return nn_node_child (self, c - self->u.dense.min); +} + +struct nn_trie_node *nn_node_compact (struct nn_trie_node *self) +{ + /* Tries to merge the node with the child node. Returns pointer to + the compacted node. */ + + struct nn_trie_node *ch; + + /* Node that is a subscription cannot be compacted. */ + if (nn_node_has_subscribers (self)) + return self; + + /* Only a node with a single child can be compacted. */ + if (self->type != 1) + return self; + + /* Check whether combined prefixes would fix into a single node. */ + ch = *nn_node_child (self, 0); + if (self->prefix_len + ch->prefix_len + 1 > NN_TRIE_PREFIX_MAX) + return self; + + /* Concatenate the prefixes. */ + memmove (ch->prefix + self->prefix_len + 1, ch->prefix, ch->prefix_len); + memcpy (ch->prefix, self->prefix, self->prefix_len); + ch->prefix [self->prefix_len] = self->u.sparse.children [0]; + ch->prefix_len += self->prefix_len + 1; + + /* Get rid of the obsolete parent node. */ + nn_free (self); + + /* Return the new compacted node. */ + return ch; +} + +int nn_trie_subscribe (struct nn_trie *self, const uint8_t *data, size_t size) +{ + int i; + struct nn_trie_node **node; + struct nn_trie_node **n; + struct nn_trie_node *ch; + struct nn_trie_node *old_node; + int pos; + uint8_t c; + uint8_t c2; + uint8_t new_min; + uint8_t new_max; + int old_children; + int new_children; + int inserted; + int more_nodes; + + /* Step 1 -- Traverse the trie. */ + + node = &self->root; + while (1) { + + /* If there are no more nodes on the path, go to step 4. */ + if (!*node) + goto step4; + + /* Check whether prefix matches the new subscription. */ + pos = nn_node_check_prefix (*node, data, size); + data += pos; + size -= pos; + + /* If only part of the prefix matches, go to step 2. */ + if (pos < (*node)->prefix_len) + goto step2; + + /* Even if whole prefix matches and there's no more data to match, + go directly to step 5. */ + if (!size) + goto step5; + + /* Move to the next node. If it is not present, go to step 3. */ + n = nn_node_next (*node, *data); + if (!n || !*n) + goto step3; + node = n; + ++data; + --size; + } + + /* Step 2 -- Split the prefix into two parts if required. */ +step2: + + ch = *node; + *node = nn_alloc (sizeof (struct nn_trie_node) + + sizeof (struct nn_trie_node*), "trie node"); + assert (*node); + (*node)->refcount = 0; + (*node)->prefix_len = pos; + (*node)->type = 1; + memcpy ((*node)->prefix, ch->prefix, pos); + (*node)->u.sparse.children [0] = ch->prefix [pos]; + ch->prefix_len -= (pos + 1); + memmove (ch->prefix, ch->prefix + pos + 1, ch->prefix_len); + ch = nn_node_compact (ch); + *nn_node_child (*node, 0) = ch; + + /* Step 3 -- Adjust the child array to accommodate the new character. */ +step3: + + /* If there are no more data in the subscription, there's nothing to + adjust in the child array. Proceed directly to the step 5. */ + if (!size) + goto step5; + + /* If the new branch fits into sparse array... */ + if ((*node)->type < NN_TRIE_SPARSE_MAX) { + *node = nn_realloc (*node, sizeof (struct nn_trie_node) + + ((*node)->type + 1) * sizeof (struct nn_trie_node*)); + assert (*node); + (*node)->u.sparse.children [(*node)->type] = *data; + ++(*node)->type; + node = nn_node_child (*node, (*node)->type - 1); + *node = NULL; + ++data; + --size; + goto step4; + } + + /* If the node is already a dense array, resize it to fit the next + character. */ + if ((*node)->type == NN_TRIE_DENSE_TYPE) { + c = *data; + if (c < (*node)->u.dense.min || c > (*node)->u.dense.max) { + new_min = (*node)->u.dense.min < c ? (*node)->u.dense.min : c; + new_max = (*node)->u.dense.max > c ? (*node)->u.dense.max : c; + *node = nn_realloc (*node, sizeof (struct nn_trie_node) + + (new_max - new_min + 1) * sizeof (struct nn_trie_node*)); + assert (*node); + old_children = (*node)->u.dense.max - (*node)->u.dense.min + 1; + new_children = new_max - new_min + 1; + if ((*node)->u.dense.min != new_min) { + inserted = (*node)->u.dense.min - new_min; + memmove (nn_node_child (*node, inserted), + nn_node_child (*node, 0), + old_children * sizeof (struct nn_trie_node*)); + memset (nn_node_child (*node, 0), 0, + inserted * sizeof (struct nn_trie_node*)); + } + else { + memset (nn_node_child (*node, old_children), 0, + (new_children - old_children) * + sizeof (struct nn_trie_node*)); + } + (*node)->u.dense.min = new_min; + (*node)->u.dense.max = new_max; + } + ++(*node)->u.dense.nbr; + + node = nn_node_child (*node, c - (*node)->u.dense.min); + ++data; + --size; + goto step4; + } + + /* This is a sparse array, but no more children can be added to it. + We have to convert it into a dense array. */ + { + /* First, determine the range of children. */ + new_min = 255; + new_max = 0; + for (i = 0; i != (*node)->type; ++i) { + c2 = (*node)->u.sparse.children [i]; + new_min = new_min < c2 ? new_min : c2; + new_max = new_max > c2 ? new_max : c2; + } + new_min = new_min < *data ? new_min : *data; + new_max = new_max > *data ? new_max : *data; + + /* Create a new mode, while keeping the old one for a while. */ + old_node = *node; + *node = (struct nn_trie_node*) nn_alloc (sizeof (struct nn_trie_node) + + (new_max - new_min + 1) * sizeof (struct nn_trie_node*), + "trie node"); + assert (*node); + + /* Fill in the new node. */ + (*node)->refcount = 0; + (*node)->prefix_len = old_node->prefix_len; + (*node)->type = NN_TRIE_DENSE_TYPE; + memcpy ((*node)->prefix, old_node->prefix, old_node->prefix_len); + (*node)->u.dense.min = new_min; + (*node)->u.dense.max = new_max; + (*node)->u.dense.nbr = old_node->type + 1; + memset (*node + 1, 0, (new_max - new_min + 1) * + sizeof (struct nn_trie_node*)); + for (i = 0; i != old_node->type; ++i) + *nn_node_child (*node, old_node->u.sparse.children [i] - new_min) = + *nn_node_child (old_node, i); + node = nn_node_next (*node, *data); + ++data; + --size; + + /* Get rid of the obsolete old node. */ + nn_free (old_node); + } + + /* Step 4 -- Create new nodes for remaining part of the subscription. */ +step4: + + assert (!*node); + while (1) { + + /* Create a new node to hold the next part of the subscription. */ + more_nodes = size > NN_TRIE_PREFIX_MAX; + *node = nn_alloc (sizeof (struct nn_trie_node) + + (more_nodes ? sizeof (struct nn_trie_node*) : 0), "trie node"); + assert (*node); + + /* Fill in the new node. */ + (*node)->refcount = 0; + (*node)->type = more_nodes ? 1 : 0; + (*node)->prefix_len = size < (uint8_t) NN_TRIE_PREFIX_MAX ? + (uint8_t) size : (uint8_t) NN_TRIE_PREFIX_MAX; + memcpy ((*node)->prefix, data, (*node)->prefix_len); + data += (*node)->prefix_len; + size -= (*node)->prefix_len; + if (!more_nodes) + break; + (*node)->u.sparse.children [0] = *data; + node = nn_node_child (*node, 0); + ++data; + --size; + } + + /* Step 5 -- Create the subscription as such. */ +step5: + + ++(*node)->refcount; + + /* Return 1 in case of a fresh subscription. */ + return (*node)->refcount == 1 ? 1 : 0; +} + +int nn_trie_match (struct nn_trie *self, const uint8_t *data, size_t size) +{ + struct nn_trie_node *node; + struct nn_trie_node **tmp; + + node = self->root; + while (1) { + + /* If we are at the end of the trie, return. */ + if (!node) + return 0; + + /* Check whether whole prefix matches the data. If not so, + the whole string won't match. */ + if (nn_node_check_prefix (node, data, size) != node->prefix_len) + return 0; + + /* Skip the prefix. */ + data += node->prefix_len; + size -= node->prefix_len; + + /* If all the data are matched, return. */ + if (nn_node_has_subscribers (node)) + return 1; + + /* Move to the next node. */ + tmp = nn_node_next (node, *data); + node = tmp ? *tmp : NULL; + ++data; + --size; + } +} + +int nn_trie_unsubscribe (struct nn_trie *self, const uint8_t *data, size_t size) +{ + return nn_node_unsubscribe (&self->root, data, size); +} + +static int nn_node_unsubscribe (struct nn_trie_node **self, + const uint8_t *data, size_t size) +{ + int i; + int j; + int index; + int new_min; + struct nn_trie_node **ch; + struct nn_trie_node *new_node; + struct nn_trie_node *ch2; + + if (!size) + goto found; + + /* If prefix does not match the data, return. */ + if (nn_node_check_prefix (*self, data, size) != (*self)->prefix_len) + return 0; + + /* Skip the prefix. */ + data += (*self)->prefix_len; + size -= (*self)->prefix_len; + + if (!size) + goto found; + + /* Move to the next node. */ + ch = nn_node_next (*self, *data); + if (!ch) + return 0; /* TODO: This should be an error. */ + + /* Recursive traversal of the trie happens here. If the subscription + wasn't really removed, nothing have changed in the trie and + no additional pruning is needed. */ + if (nn_node_unsubscribe (ch, data + 1, size - 1) == 0) + return 0; + + /* Subscription removal is already done. Now we are going to compact + the trie. However, if the following node remains in place, there's + nothing to compact here. */ + if (*ch) + return 1; + + /* Sparse array. */ + if ((*self)->type < NN_TRIE_DENSE_TYPE) { + + /* Get the indices of the removed child. */ + for (index = 0; index != (*self)->type; ++index) + if ((*self)->u.sparse.children [index] == *data) + break; + assert (index != (*self)->type); + + /* Remove the destroyed child from both lists of children. */ + memmove ( + (*self)->u.sparse.children + index, + (*self)->u.sparse.children + index + 1, + (*self)->type - index - 1); + memmove ( + nn_node_child (*self, index), + nn_node_child (*self, index + 1), + ((*self)->type - index - 1) * sizeof (struct nn_trie_node*)); + --(*self)->type; + *self = nn_realloc (*self, sizeof (struct nn_trie_node) + + ((*self)->type * sizeof (struct nn_trie_node*))); + assert (*self); + + /* If there are no more children and no refcount, we can delete + the node altogether. */ + if (!(*self)->type && !nn_node_has_subscribers (*self)) { + nn_free (*self); + *self = NULL; + return 1; + } + + /* Try to merge the node with the following node. */ + *self = nn_node_compact (*self); + + return 1; + } + + /* Dense array. */ + + /* In this case the array stays dense. We have to adjust the limits of + the array, if appropriate. */ + if ((*self)->u.dense.nbr > NN_TRIE_SPARSE_MAX + 1) { + + /* If the removed item is the leftmost one, trim the array from + the left side. */ + if (*data == (*self)->u.dense.min) { + for (i = 0; i != (*self)->u.dense.max - (*self)->u.dense.min + 1; + ++i) + if (*nn_node_child (*self, i)) + break; + new_min = i + (*self)->u.dense.min; + memmove (nn_node_child (*self, 0), nn_node_child (*self, i), + ((*self)->u.dense.max - new_min + 1) * + sizeof (struct nn_trie_node*)); + (*self)->u.dense.min = new_min; + --(*self)->u.dense.nbr; + *self = nn_realloc (*self, sizeof (struct nn_trie_node) + + ((*self)->u.dense.max - new_min + 1) * + sizeof (struct nn_trie_node*)); + assert (*self); + return 1; + } + + /* If the removed item is the rightmost one, trim the array from + the right side. */ + if (*data == (*self)->u.dense.max) { + for (i = (*self)->u.dense.max - (*self)->u.dense.min; i != 0; --i) + if (*nn_node_child (*self, i)) + break; + (*self)->u.dense.max = i + (*self)->u.dense.min; + --(*self)->u.dense.nbr; + *self = nn_realloc (*self, sizeof (struct nn_trie_node) + + ((*self)->u.dense.max - (*self)->u.dense.min + 1) * + sizeof (struct nn_trie_node*)); + assert (*self); + return 1; + } + + /* If the item is removed from the middle of the array, do nothing. */ + --(*self)->u.dense.nbr; + return 1; + } + + /* Convert dense array into sparse array. */ + { + new_node = nn_alloc (sizeof (struct nn_trie_node) + + NN_TRIE_SPARSE_MAX * sizeof (struct nn_trie_node*), "trie node"); + assert (new_node); + new_node->refcount = 0; + new_node->prefix_len = (*self)->prefix_len; + memcpy (new_node->prefix, (*self)->prefix, new_node->prefix_len); + new_node->type = NN_TRIE_SPARSE_MAX; + j = 0; + for (i = 0; i != (*self)->u.dense.max - (*self)->u.dense.min + 1; + ++i) { + ch2 = *nn_node_child (*self, i); + if (ch2) { + new_node->u.sparse.children [j] = i + (*self)->u.dense.min; + *nn_node_child (new_node, j) = ch2; + ++j; + } + } + assert (j == NN_TRIE_SPARSE_MAX); + nn_free (*self); + *self = new_node; + return 1; + } + +found: + + /* We are at the end of the subscription here. */ + + /* Subscription doesn't exist. */ + if (nn_slow (!*self || !nn_node_has_subscribers (*self))) + return -EINVAL; + + /* Subscription exists. Unsubscribe. */ + --(*self)->refcount; + + /* If reference count has dropped to zero we can try to compact + the node. */ + if (!(*self)->refcount) { + + /* If there are no children, we can delete the node altogether. */ + if (!(*self)->type) { + nn_free (*self); + *self = NULL; + return 1; + } + + /* Try to merge the node with the following node. */ + *self = nn_node_compact (*self); + return 1; + } + + return 0; +} + +int nn_node_has_subscribers (struct nn_trie_node *node) +{ + /* Returns 1 when there are no subscribers associated with the node. */ + return node->refcount ? 1 : 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.h new file mode 100644 index 0000000..56c790c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/trie.h @@ -0,0 +1,119 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_TRIE_INCLUDED +#define NN_TRIE_INCLUDED + +#include +#include + +/* This class implements highly memory-efficient patricia trie. */ + +/* Maximum length of the prefix. */ +#define NN_TRIE_PREFIX_MAX 10 + +/* Maximum number of children in the sparse mode. */ +#define NN_TRIE_SPARSE_MAX 8 + +/* 'type' is set to this value when in the dense mode. */ +#define NN_TRIE_DENSE_TYPE (NN_TRIE_SPARSE_MAX + 1) + +/* This structure represents a node in patricia trie. It's a header to be + followed by the array of pointers to child nodes. Each node represents + the string composed of all the prefixes on the way from the trie root, + including the prefix in that node. */ +struct nn_trie_node +{ + /* Number of subscriptions to the given string. */ + uint32_t refcount; + + /* Number of elements is a sparse array, or NN_TRIE_DENSE_TYPE in case + the array of children is dense. */ + uint8_t type; + + /* The node adds more characters to the string, compared to the parent + node. If there is only a single character added, it's represented + directly in the child array. If there's more than one character added, + all but the last one are stored as a 'prefix'. */ + uint8_t prefix_len; + uint8_t prefix [NN_TRIE_PREFIX_MAX]; + + /* The array of characters pointing to individual children of the node. + Actual pointers to child nodes are stored in the memory following + nn_trie_node structure. */ + union { + + /* Sparse array means that individual children are identified by + characters stored in 'children' array. The number of characters + in the array is specified in the 'type' field. */ + struct { + uint8_t children [NN_TRIE_SPARSE_MAX]; + } sparse; + + /* Dense array means that the array of node pointers following the + structure corresponds to a continuous list of characters starting + by 'min' character and ending by 'max' character. The characters + in the range that have no corresponding child node are represented + by NULL pointers. 'nbr' is the count of child nodes. */ + struct { + uint8_t min; + uint8_t max; + uint16_t nbr; + /* There are 4 bytes of padding here. */ + } dense; + } u; +}; +/* The structure is followed by the array of pointers to children. */ + +struct nn_trie { + + /* The root node of the trie (representing the empty subscription). */ + struct nn_trie_node *root; + +}; + +/* Initialise an empty trie. */ +void nn_trie_init (struct nn_trie *self); + +/* Release all the resources associated with the trie. */ +void nn_trie_term (struct nn_trie *self); + +/* Add the string to the trie. If the string is not yet there, 1 is returned. + If it already exists in the trie, its reference count is incremented and + 0 is returned. */ +int nn_trie_subscribe (struct nn_trie *self, const uint8_t *data, size_t size); + +/* Remove the string from the trie. If the string was actually removed, + 1 is returned. If reference count was decremented without falling to zero, + 0 is returned. */ +int nn_trie_unsubscribe (struct nn_trie *self, const uint8_t *data, + size_t size); + +/* Checks the supplied string. If it matches it returns 1, if it does not + it returns 0. */ +int nn_trie_match (struct nn_trie *self, const uint8_t *data, size_t size); + +/* Debugging interface. */ +void nn_trie_dump (struct nn_trie *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.c new file mode 100644 index 0000000..de108ea --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.c @@ -0,0 +1,204 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xpub.h" + +#include "../../nn.h" +#include "../../pubsub.h" + +#include "../utils/dist.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +#include + +struct nn_xpub_data { + struct nn_dist_data item; +}; + +struct nn_xpub { + + /* The generic socket base class. */ + struct nn_sockbase sockbase; + + /* Distributor. */ + struct nn_dist outpipes; +}; + +/* Private functions. */ +static void nn_xpub_init (struct nn_xpub *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_xpub_term (struct nn_xpub *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_xpub_destroy (struct nn_sockbase *self); +static int nn_xpub_add (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpub_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpub_in (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xpub_out (struct nn_sockbase *self, struct nn_pipe *pipe); +static int nn_xpub_events (struct nn_sockbase *self); +static int nn_xpub_send (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_xpub_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +static int nn_xpub_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +static const struct nn_sockbase_vfptr nn_xpub_sockbase_vfptr = { + NULL, + nn_xpub_destroy, + nn_xpub_add, + nn_xpub_rm, + nn_xpub_in, + nn_xpub_out, + nn_xpub_events, + nn_xpub_send, + NULL, + nn_xpub_setopt, + nn_xpub_getopt +}; + +static void nn_xpub_init (struct nn_xpub *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_dist_init (&self->outpipes); +} + +static void nn_xpub_term (struct nn_xpub *self) +{ + nn_dist_term (&self->outpipes); + nn_sockbase_term (&self->sockbase); +} + +void nn_xpub_destroy (struct nn_sockbase *self) +{ + struct nn_xpub *xpub; + + xpub = nn_cont (self, struct nn_xpub, sockbase); + + nn_xpub_term (xpub); + nn_free (xpub); +} + +static int nn_xpub_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpub *xpub; + struct nn_xpub_data *data; + + xpub = nn_cont (self, struct nn_xpub, sockbase); + + data = nn_alloc (sizeof (struct nn_xpub_data), "pipe data (pub)"); + alloc_assert (data); + nn_dist_add (&xpub->outpipes, &data->item, pipe); + nn_pipe_setdata (pipe, data); + + return 0; +} + +static void nn_xpub_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpub *xpub; + struct nn_xpub_data *data; + + xpub = nn_cont (self, struct nn_xpub, sockbase); + data = nn_pipe_getdata (pipe); + + nn_dist_rm (&xpub->outpipes, &data->item); + + nn_free (data); +} + +static void nn_xpub_in (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED struct nn_pipe *pipe) +{ + /* We shouldn't get any messages from subscribers. */ + nn_assert (0); +} + +static void nn_xpub_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xpub *xpub; + struct nn_xpub_data *data; + + xpub = nn_cont (self, struct nn_xpub, sockbase); + data = nn_pipe_getdata (pipe); + + nn_dist_out (&xpub->outpipes, &data->item); +} + +static int nn_xpub_events (NN_UNUSED struct nn_sockbase *self) +{ + return NN_SOCKBASE_EVENT_OUT; +} + +static int nn_xpub_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + return nn_dist_send (&nn_cont (self, struct nn_xpub, sockbase)->outpipes, + msg, NULL); +} + +static int nn_xpub_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xpub_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xpub_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xpub *self; + + self = nn_alloc (sizeof (struct nn_xpub), "socket (xpub)"); + alloc_assert (self); + nn_xpub_init (self, &nn_xpub_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xpub_ispeer (int socktype) +{ + return socktype == NN_SUB ? 1 : 0; +} + +static struct nn_socktype nn_xpub_socktype_struct = { + AF_SP_RAW, + NN_PUB, + NN_SOCKTYPE_FLAG_NORECV, + nn_xpub_create, + nn_xpub_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xpub_socktype = &nn_xpub_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.h new file mode 100644 index 0000000..59009a3 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xpub.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XPUB_INCLUDED +#define NN_XPUB_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_xpub_socktype; + +int nn_xpub_create (void *hint, struct nn_sockbase **sockbase); +int nn_xpub_ispeer (int socktype); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.c new file mode 100644 index 0000000..e7b2646 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.c @@ -0,0 +1,250 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xsub.h" +#include "trie.h" + +#include "../../nn.h" +#include "../../pubsub.h" + +#include "../utils/fq.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +struct nn_xsub_data { + struct nn_fq_data fq; +}; + +struct nn_xsub { + struct nn_sockbase sockbase; + struct nn_fq fq; + struct nn_trie trie; +}; + +/* Private functions. */ +static void nn_xsub_init (struct nn_xsub *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_xsub_term (struct nn_xsub *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_xsub_destroy (struct nn_sockbase *self); +static int nn_xsub_add (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xsub_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xsub_in (struct nn_sockbase *self, struct nn_pipe *pipe); +static void nn_xsub_out (struct nn_sockbase *self, struct nn_pipe *pipe); +static int nn_xsub_events (struct nn_sockbase *self); +static int nn_xsub_recv (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_xsub_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +static int nn_xsub_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +static const struct nn_sockbase_vfptr nn_xsub_sockbase_vfptr = { + NULL, + nn_xsub_destroy, + nn_xsub_add, + nn_xsub_rm, + nn_xsub_in, + nn_xsub_out, + nn_xsub_events, + NULL, + nn_xsub_recv, + nn_xsub_setopt, + nn_xsub_getopt +}; + +static void nn_xsub_init (struct nn_xsub *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_fq_init (&self->fq); + nn_trie_init (&self->trie); +} + +static void nn_xsub_term (struct nn_xsub *self) +{ + nn_trie_term (&self->trie); + nn_fq_term (&self->fq); + nn_sockbase_term (&self->sockbase); +} + +void nn_xsub_destroy (struct nn_sockbase *self) +{ + struct nn_xsub *xsub; + + xsub = nn_cont (self, struct nn_xsub, sockbase); + + nn_xsub_term (xsub); + nn_free (xsub); +} + +static int nn_xsub_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsub *xsub; + struct nn_xsub_data *data; + int rcvprio; + size_t sz; + + xsub = nn_cont (self, struct nn_xsub, sockbase); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (struct nn_xsub_data), "pipe data (sub)"); + alloc_assert (data); + nn_pipe_setdata (pipe, data); + nn_fq_add (&xsub->fq, &data->fq, pipe, rcvprio); + + return 0; +} + +static void nn_xsub_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsub *xsub; + struct nn_xsub_data *data; + + xsub = nn_cont (self, struct nn_xsub, sockbase); + data = nn_pipe_getdata (pipe); + nn_fq_rm (&xsub->fq, &data->fq); + nn_free (data); +} + +static void nn_xsub_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsub *xsub; + struct nn_xsub_data *data; + + xsub = nn_cont (self, struct nn_xsub, sockbase); + data = nn_pipe_getdata (pipe); + nn_fq_in (&xsub->fq, &data->fq); +} + +static void nn_xsub_out (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED struct nn_pipe *pipe) +{ + /* We are not going to send any messages until subscription forwarding + is implemented, so there's no point is maintaining a list of pipes + ready for sending. */ +} + +static int nn_xsub_events (struct nn_sockbase *self) +{ + return nn_fq_can_recv (&nn_cont (self, struct nn_xsub, sockbase)->fq) ? + NN_SOCKBASE_EVENT_IN : 0; +} + +static int nn_xsub_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_xsub *xsub; + + xsub = nn_cont (self, struct nn_xsub, sockbase); + + /* Loop while a matching message is found or when there are no more + messages to receive. */ + while (1) { + rc = nn_fq_recv (&xsub->fq, msg, NULL); + if (nn_slow (rc == -EAGAIN)) + return -EAGAIN; + errnum_assert (rc >= 0, -rc); + rc = nn_trie_match (&xsub->trie, nn_chunkref_data (&msg->body), + nn_chunkref_size (&msg->body)); + if (rc == 0) { + nn_msg_term (msg); + continue; + } + if (rc == 1) + return 0; + errnum_assert (0, -rc); + } +} + +static int nn_xsub_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen) +{ + int rc; + struct nn_xsub *xsub; + + xsub = nn_cont (self, struct nn_xsub, sockbase); + + if (level != NN_SUB) + return -ENOPROTOOPT; + + if (option == NN_SUB_SUBSCRIBE) { + rc = nn_trie_subscribe (&xsub->trie, optval, optvallen); + if (rc >= 0) + return 0; + return rc; + } + + if (option == NN_SUB_UNSUBSCRIBE) { + rc = nn_trie_unsubscribe (&xsub->trie, optval, optvallen); + if (rc >= 0) + return 0; + return rc; + } + + return -ENOPROTOOPT; +} + +static int nn_xsub_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xsub_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xsub *self; + + self = nn_alloc (sizeof (struct nn_xsub), "socket (xsub)"); + alloc_assert (self); + nn_xsub_init (self, &nn_xsub_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xsub_ispeer (int socktype) +{ + return socktype == NN_PUB ? 1 : 0; +} + +static struct nn_socktype nn_xsub_socktype_struct = { + AF_SP_RAW, + NN_SUB, + NN_SOCKTYPE_FLAG_NOSEND, + nn_xsub_create, + nn_xsub_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xsub_socktype = &nn_xsub_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.h new file mode 100644 index 0000000..1d42692 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/pubsub/xsub.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XSUB_INCLUDED +#define NN_XSUB_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_xsub_socktype; + +int nn_xsub_create (void *hint, struct nn_sockbase **sockbase); +int nn_xsub_ispeer (int socktype); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.c new file mode 100644 index 0000000..6886041 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.c @@ -0,0 +1,165 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "rep.h" +#include "xrep.h" + +#include "../../nn.h" +#include "../../reqrep.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/chunkref.h" +#include "../../utils/wire.h" +#include "../../utils/list.h" + +#include +#include + +#define NN_REP_INPROGRESS 1 + +static const struct nn_sockbase_vfptr nn_rep_sockbase_vfptr = { + NULL, + nn_rep_destroy, + nn_xrep_add, + nn_xrep_rm, + nn_xrep_in, + nn_xrep_out, + nn_rep_events, + nn_rep_send, + nn_rep_recv, + nn_xrep_setopt, + nn_xrep_getopt +}; + +void nn_rep_init (struct nn_rep *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_xrep_init (&self->xrep, vfptr, hint); + self->flags = 0; +} + +void nn_rep_term (struct nn_rep *self) +{ + if (self->flags & NN_REP_INPROGRESS) + nn_chunkref_term (&self->backtrace); + nn_xrep_term (&self->xrep); +} + +void nn_rep_destroy (struct nn_sockbase *self) +{ + struct nn_rep *rep; + + rep = nn_cont (self, struct nn_rep, xrep.sockbase); + + nn_rep_term (rep); + nn_free (rep); +} + +int nn_rep_events (struct nn_sockbase *self) +{ + struct nn_rep *rep; + int events; + + rep = nn_cont (self, struct nn_rep, xrep.sockbase); + events = nn_xrep_events (&rep->xrep.sockbase); + if (!(rep->flags & NN_REP_INPROGRESS)) + events &= ~NN_SOCKBASE_EVENT_OUT; + return events; +} + +int nn_rep_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_rep *rep; + + rep = nn_cont (self, struct nn_rep, xrep.sockbase); + + /* If no request was received, there's nowhere to send the reply to. */ + if (nn_slow (!(rep->flags & NN_REP_INPROGRESS))) + return -EFSM; + + /* Move the stored backtrace into the message header. */ + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_mv (&msg->sphdr, &rep->backtrace); + rep->flags &= ~NN_REP_INPROGRESS; + + /* Send the reply. If it cannot be sent because of pushback, + drop it silently. */ + rc = nn_xrep_send (&rep->xrep.sockbase, msg); + errnum_assert (rc == 0 || rc == -EAGAIN, -rc); + + return 0; +} + +int nn_rep_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_rep *rep; + + rep = nn_cont (self, struct nn_rep, xrep.sockbase); + + /* If a request is already being processed, cancel it. */ + if (nn_slow (rep->flags & NN_REP_INPROGRESS)) { + nn_chunkref_term (&rep->backtrace); + rep->flags &= ~NN_REP_INPROGRESS; + } + + /* Receive the request. */ + rc = nn_xrep_recv (&rep->xrep.sockbase, msg); + if (nn_slow (rc == -EAGAIN)) + return -EAGAIN; + errnum_assert (rc == 0, -rc); + + /* Store the backtrace. */ + nn_chunkref_mv (&rep->backtrace, &msg->sphdr); + nn_chunkref_init (&msg->sphdr, 0); + rep->flags |= NN_REP_INPROGRESS; + + return 0; +} + +static int nn_rep_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_rep *self; + + self = nn_alloc (sizeof (struct nn_rep), "socket (rep)"); + alloc_assert (self); + nn_rep_init (self, &nn_rep_sockbase_vfptr, hint); + *sockbase = &self->xrep.sockbase; + + return 0; +} + +static struct nn_socktype nn_rep_socktype_struct = { + AF_SP, + NN_REP, + 0, + nn_rep_create, + nn_xrep_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_rep_socktype = &nn_rep_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.h new file mode 100644 index 0000000..0f78b39 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/rep.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_REP_INCLUDED +#define NN_REP_INCLUDED + +#include "../../protocol.h" +#include "xrep.h" + +extern struct nn_socktype *nn_rep_socktype; + + +struct nn_rep { + struct nn_xrep xrep; + uint32_t flags; + struct nn_chunkref backtrace; +}; + +/* Some users may want to extend the REP protocol similar to how REP extends XREP. + Expose these methods to improve extensibility. */ +void nn_rep_init (struct nn_rep *self, +const struct nn_sockbase_vfptr *vfptr, void *hint); +void nn_rep_term (struct nn_rep *self); + +/* Implementation of nn_sockbase's virtual functions. */ +void nn_rep_destroy (struct nn_sockbase *self); +int nn_rep_events (struct nn_sockbase *self); +int nn_rep_send (struct nn_sockbase *self, struct nn_msg *msg); +int nn_rep_recv (struct nn_sockbase *self, struct nn_msg *msg); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/req.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/req.c new file mode 100644 index 0000000..9d0d8d5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/req.c @@ -0,0 +1,671 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "req.h" +#include "xreq.h" + +#include "../../nn.h" +#include "../../reqrep.h" + +#include "../../aio/fsm.h" +#include "../../aio/timer.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/random.h" +#include "../../utils/wire.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +#include +#include + +/* Default re-send interval is 1 minute. */ +#define NN_REQ_DEFAULT_RESEND_IVL 60000 + +#define NN_REQ_STATE_IDLE 1 +#define NN_REQ_STATE_PASSIVE 2 +#define NN_REQ_STATE_DELAYED 3 +#define NN_REQ_STATE_ACTIVE 4 +#define NN_REQ_STATE_TIMED_OUT 5 +#define NN_REQ_STATE_CANCELLING 6 +#define NN_REQ_STATE_STOPPING_TIMER 7 +#define NN_REQ_STATE_DONE 8 +#define NN_REQ_STATE_STOPPING 9 + +#define NN_REQ_ACTION_START 1 +#define NN_REQ_ACTION_IN 2 +#define NN_REQ_ACTION_OUT 3 +#define NN_REQ_ACTION_SENT 4 +#define NN_REQ_ACTION_RECEIVED 5 +#define NN_REQ_ACTION_PIPE_RM 6 + +#define NN_REQ_SRC_RESEND_TIMER 1 + +static const struct nn_sockbase_vfptr nn_req_sockbase_vfptr = { + nn_req_stop, + nn_req_destroy, + nn_xreq_add, + nn_req_rm, + nn_req_in, + nn_req_out, + nn_req_events, + nn_req_csend, + nn_req_crecv, + nn_req_setopt, + nn_req_getopt +}; + +void nn_req_init (struct nn_req *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_xreq_init (&self->xreq, vfptr, hint); + nn_fsm_init_root (&self->fsm, nn_req_handler, nn_req_shutdown, + nn_sockbase_getctx (&self->xreq.sockbase)); + self->state = NN_REQ_STATE_IDLE; + + /* Start assigning request IDs beginning with a random number. This way + there should be no key clashes even if the executable is re-started. */ + nn_random_generate (&self->lastid, sizeof (self->lastid)); + + self->task.sent_to = NULL; + + nn_msg_init (&self->task.request, 0); + nn_msg_init (&self->task.reply, 0); + nn_timer_init (&self->task.timer, NN_REQ_SRC_RESEND_TIMER, &self->fsm); + self->resend_ivl = NN_REQ_DEFAULT_RESEND_IVL; + + nn_task_init (&self->task, self->lastid); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_req_term (struct nn_req *self) +{ + nn_timer_term (&self->task.timer); + nn_task_term (&self->task); + nn_msg_term (&self->task.reply); + nn_msg_term (&self->task.request); + nn_fsm_term (&self->fsm); + nn_xreq_term (&self->xreq); +} + +void nn_req_stop (struct nn_sockbase *self) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + nn_fsm_stop (&req->fsm); +} + +void nn_req_destroy (struct nn_sockbase *self) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + nn_req_term (req); + nn_free (req); +} + +int nn_req_inprogress (struct nn_req *self) +{ + /* Return 1 if there's a request submitted. 0 otherwise. */ + return self->state == NN_REQ_STATE_IDLE || + self->state == NN_REQ_STATE_PASSIVE || + self->state == NN_REQ_STATE_STOPPING ? 0 : 1; +} + +void nn_req_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + int rc; + struct nn_req *req; + uint32_t reqid; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + /* Pass the pipe to the raw REQ socket. */ + nn_xreq_in (&req->xreq.sockbase, pipe); + + while (1) { + + /* Get new reply. */ + rc = nn_xreq_recv (&req->xreq.sockbase, &req->task.reply); + if (nn_slow (rc == -EAGAIN)) + return; + errnum_assert (rc == 0, -rc); + + /* No request was sent. Getting a reply doesn't make sense. */ + if (nn_slow (!nn_req_inprogress (req))) { + nn_msg_term (&req->task.reply); + continue; + } + + /* Ignore malformed replies. */ + if (nn_slow (nn_chunkref_size (&req->task.reply.sphdr) != + sizeof (uint32_t))) { + nn_msg_term (&req->task.reply); + continue; + } + + /* Ignore replies with incorrect request IDs. */ + reqid = nn_getl (nn_chunkref_data (&req->task.reply.sphdr)); + if (nn_slow (!(reqid & 0x80000000))) { + nn_msg_term (&req->task.reply); + continue; + } + if (nn_slow (reqid != (req->task.id | 0x80000000))) { + nn_msg_term (&req->task.reply); + continue; + } + + /* Trim the request ID. */ + nn_chunkref_term (&req->task.reply.sphdr); + nn_chunkref_init (&req->task.reply.sphdr, 0); + + /* TODO: Deallocate the request here? */ + + /* Notify the state machine. */ + if (req->state == NN_REQ_STATE_ACTIVE) + nn_fsm_action (&req->fsm, NN_REQ_ACTION_IN); + + return; + } +} + +void nn_req_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + /* Add the pipe to the underlying raw socket. */ + nn_xreq_out (&req->xreq.sockbase, pipe); + + /* Notify the state machine. */ + if (req->state == NN_REQ_STATE_DELAYED) + nn_fsm_action (&req->fsm, NN_REQ_ACTION_OUT); +} + +int nn_req_events (struct nn_sockbase *self) +{ + int rc; + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + /* OUT is signalled all the time because sending a request while + another one is being processed cancels the old one. */ + rc = NN_SOCKBASE_EVENT_OUT; + + /* In DONE state the reply is stored in 'reply' field. */ + if (req->state == NN_REQ_STATE_DONE) + rc |= NN_SOCKBASE_EVENT_IN; + + return rc; +} + +int nn_req_csend (struct nn_sockbase *self, struct nn_msg *msg) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + /* Generate new request ID for the new request and put it into message + header. The most important bit is set to 1 to indicate that this is + the bottom of the backtrace stack. */ + ++req->task.id; + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, 4); + nn_putl (nn_chunkref_data (&msg->sphdr), req->task.id | 0x80000000); + + /* Store the message so that it can be re-sent if there's no reply. */ + nn_msg_term (&req->task.request); + nn_msg_mv (&req->task.request, msg); + + /* Notify the state machine. */ + nn_fsm_action (&req->fsm, NN_REQ_ACTION_SENT); + + return 0; +} + +int nn_req_crecv (struct nn_sockbase *self, struct nn_msg *msg) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + /* No request was sent. Waiting for a reply doesn't make sense. */ + if (nn_slow (!nn_req_inprogress (req))) + return -EFSM; + + /* If reply was not yet recieved, wait further. */ + if (nn_slow (req->state != NN_REQ_STATE_DONE)) + return -EAGAIN; + + /* If the reply was already received, just pass it to the caller. */ + nn_msg_mv (msg, &req->task.reply); + nn_msg_init (&req->task.reply, 0); + + /* Notify the state machine. */ + nn_fsm_action (&req->fsm, NN_REQ_ACTION_RECEIVED); + + return 0; +} + +int nn_req_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + if (level != NN_REQ) + return -ENOPROTOOPT; + + if (option == NN_REQ_RESEND_IVL) { + if (nn_slow (optvallen != sizeof (int))) + return -EINVAL; + req->resend_ivl = *(int*) optval; + return 0; + } + + return -ENOPROTOOPT; +} + +int nn_req_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + if (level != NN_REQ) + return -ENOPROTOOPT; + + if (option == NN_REQ_RESEND_IVL) { + if (nn_slow (*optvallen < sizeof (int))) + return -EINVAL; + *(int*) optval = req->resend_ivl; + *optvallen = sizeof (int); + return 0; + } + + return -ENOPROTOOPT; +} + +void nn_req_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_timer_stop (&req->task.timer); + req->state = NN_REQ_STATE_STOPPING; + } + if (nn_slow (req->state == NN_REQ_STATE_STOPPING)) { + if (!nn_timer_isidle (&req->task.timer)) + return; + req->state = NN_REQ_STATE_IDLE; + nn_fsm_stopped_noevent (&req->fsm); + nn_sockbase_stopped (&req->xreq.sockbase); + return; + } + + nn_fsm_bad_state(req->state, src, type); +} + +void nn_req_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_req *req; + + req = nn_cont (self, struct nn_req, fsm); + + switch (req->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The socket was created recently. Intermediate state. */ +/* Pass straight to the PASSIVE state. */ +/******************************************************************************/ + case NN_REQ_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + req->state = NN_REQ_STATE_PASSIVE; + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* PASSIVE state. */ +/* No request is submitted. */ +/******************************************************************************/ + case NN_REQ_STATE_PASSIVE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_SENT: + nn_req_action_send (req, 1); + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* DELAYED state. */ +/* Request was submitted but it could not be sent to the network because */ +/* there was no peer available at the moment. Now we are waiting for the */ +/* peer to arrive to send the request to it. */ +/******************************************************************************/ + case NN_REQ_STATE_DELAYED: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_OUT: + nn_req_action_send (req, 0); + return; + case NN_REQ_ACTION_SENT: + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* Request was submitted. Waiting for reply. */ +/******************************************************************************/ + case NN_REQ_STATE_ACTIVE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_IN: + + /* Reply arrived. */ + nn_timer_stop (&req->task.timer); + req->task.sent_to = NULL; + req->state = NN_REQ_STATE_STOPPING_TIMER; + return; + + case NN_REQ_ACTION_SENT: + + /* New request was sent while the old one was still being + processed. Cancel the old request first. */ + nn_timer_stop (&req->task.timer); + req->task.sent_to = NULL; + req->state = NN_REQ_STATE_CANCELLING; + return; + + case NN_REQ_ACTION_PIPE_RM: + /* Pipe that we sent request to is removed */ + nn_timer_stop (&req->task.timer); + req->task.sent_to = NULL; + /* Pretend we timed out so request resent immediately */ + req->state = NN_REQ_STATE_TIMED_OUT; + return; + + default: + nn_fsm_bad_action (req->state, src, type); + } + + case NN_REQ_SRC_RESEND_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&req->task.timer); + req->task.sent_to = NULL; + req->state = NN_REQ_STATE_TIMED_OUT; + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* TIMED_OUT state. */ +/* Waiting for reply has timed out. Stopping the timer. Afterwards, we'll */ +/* re-send the request. */ +/******************************************************************************/ + case NN_REQ_STATE_TIMED_OUT: + switch (src) { + + case NN_REQ_SRC_RESEND_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + nn_req_action_send (req, 1); + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_SENT: + req->state = NN_REQ_STATE_CANCELLING; + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* CANCELLING state. */ +/* Request was canceled. Waiting till the timer is stopped. Note that */ +/* cancelling is done by sending a new request. Thus there's already */ +/* a request waiting to be sent in this state. */ +/******************************************************************************/ + case NN_REQ_STATE_CANCELLING: + switch (src) { + + case NN_REQ_SRC_RESEND_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + + /* Timer is stopped. Now we can send the delayed request. */ + nn_req_action_send (req, 1); + return; + + default: + nn_fsm_bad_action (req->state, src, type); + } + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_SENT: + + /* No need to do anything here. Old delayed request is just + replaced by the new one that will be sent once the timer + is closed. */ + return; + + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_TIMER state. */ +/* Reply was delivered. Waiting till the timer is stopped. */ +/******************************************************************************/ + case NN_REQ_STATE_STOPPING_TIMER: + switch (src) { + + case NN_REQ_SRC_RESEND_TIMER: + + switch (type) { + case NN_TIMER_STOPPED: + req->state = NN_REQ_STATE_DONE; + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_SENT: + req->state = NN_REQ_STATE_CANCELLING; + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/* Reply was received but not yet retrieved by the user. */ +/******************************************************************************/ + case NN_REQ_STATE_DONE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_REQ_ACTION_RECEIVED: + req->state = NN_REQ_STATE_PASSIVE; + return; + case NN_REQ_ACTION_SENT: + nn_req_action_send (req, 1); + return; + default: + nn_fsm_bad_action (req->state, src, type); + } + + default: + nn_fsm_bad_source (req->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (req->state, src, type); + } +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +void nn_req_action_send (struct nn_req *self, int allow_delay) +{ + int rc; + struct nn_msg msg; + struct nn_pipe *to; + + /* Send the request. */ + nn_msg_cp (&msg, &self->task.request); + rc = nn_xreq_send_to (&self->xreq.sockbase, &msg, &to); + + /* If the request cannot be sent at the moment wait till + new outbound pipe arrives. */ + if (nn_slow (rc == -EAGAIN)) { + nn_assert (allow_delay == 1); + nn_msg_term (&msg); + self->state = NN_REQ_STATE_DELAYED; + return; + } + + /* Request was successfully sent. Set up the re-send timer + in case the request gets lost somewhere further out + in the topology. */ + if (nn_fast (rc == 0)) { + nn_timer_start (&self->task.timer, self->resend_ivl); + nn_assert (to); + self->task.sent_to = to; + self->state = NN_REQ_STATE_ACTIVE; + return; + } + + /* Unexpected error. */ + errnum_assert (0, -rc); +} + +static int nn_req_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_req *self; + + self = nn_alloc (sizeof (struct nn_req), "socket (req)"); + alloc_assert (self); + nn_req_init (self, &nn_req_sockbase_vfptr, hint); + *sockbase = &self->xreq.sockbase; + + return 0; +} + +void nn_req_rm (struct nn_sockbase *self, struct nn_pipe *pipe) { + struct nn_req *req; + + req = nn_cont (self, struct nn_req, xreq.sockbase); + + nn_xreq_rm (self, pipe); + if (nn_slow (pipe == req->task.sent_to)) { + nn_fsm_action (&req->fsm, NN_REQ_ACTION_PIPE_RM); + } +} + +static struct nn_socktype nn_req_socktype_struct = { + AF_SP, + NN_REQ, + 0, + nn_req_create, + nn_xreq_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_req_socktype = &nn_req_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/req.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/req.h new file mode 100644 index 0000000..6669244 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/req.h @@ -0,0 +1,81 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_REQ_INCLUDED +#define NN_REQ_INCLUDED + +#include "xreq.h" +#include "task.h" + +#include "../../protocol.h" +#include "../../aio/fsm.h" + +struct nn_req { + + /* The base class. Raw REQ socket. */ + struct nn_xreq xreq; + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Last request ID assigned. */ + uint32_t lastid; + + /* Protocol-specific socket options. */ + int resend_ivl; + + /* The request being processed. */ + struct nn_task task; +}; + +extern struct nn_socktype *nn_req_socktype; + +/* Some users may want to extend the REQ protocol similar to how REQ extends XREQ. + Expose these methods to improve extensibility. */ +void nn_req_init (struct nn_req *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +void nn_req_term (struct nn_req *self); +int nn_req_inprogress (struct nn_req *self); +void nn_req_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +void nn_req_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +void nn_req_action_send (struct nn_req *self, int allow_delay); + +/* Implementation of nn_sockbase's virtual functions. */ +void nn_req_stop (struct nn_sockbase *self); +void nn_req_destroy (struct nn_sockbase *self); +void nn_req_in (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_req_out (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_req_events (struct nn_sockbase *self); +int nn_req_csend (struct nn_sockbase *self, struct nn_msg *msg); +void nn_req_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_req_crecv (struct nn_sockbase *self, struct nn_msg *msg); +int nn_req_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +int nn_req_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +int nn_req_csend (struct nn_sockbase *self, struct nn_msg *msg); +int nn_req_crecv (struct nn_sockbase *self, struct nn_msg *msg); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/task.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/task.c new file mode 100644 index 0000000..98b00bf --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/task.c @@ -0,0 +1,35 @@ +/* + Copyright (c) 2014 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "task.h" +#include "../../utils/attr.h" + +void nn_task_init (struct nn_task *self, uint32_t id) +{ + self->id = id; +} + +void nn_task_term (NN_UNUSED struct nn_task *self) +{ +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/task.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/task.h new file mode 100644 index 0000000..eacb87d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/task.h @@ -0,0 +1,57 @@ +/* + Copyright (c) 2014 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_TASK_INCLUDED +#define NN_TASK_INCLUDED + +#include "../../reqrep.h" + +#include "../../aio/fsm.h" +#include "../../aio/timer.h" +#include "../../utils/msg.h" + +struct nn_task { + + /* ID of the request being currently processed. Replies for different + requests are considered stale and simply dropped. */ + uint32_t id; + + /* Stored request, so that it can be re-sent if needed. */ + struct nn_msg request; + + /* Stored reply, so that user can retrieve it later on. */ + struct nn_msg reply; + + /* Timer used to wait while request should be re-sent. */ + struct nn_timer timer; + + /* Pipe the current request has been sent to. This is an optimisation so + that request can be re-sent immediately if the pipe disappears. */ + struct nn_pipe *sent_to; +}; + +void nn_task_init (struct nn_task *self, uint32_t id); +void nn_task_term (struct nn_task *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.c new file mode 100644 index 0000000..dcd8fbf --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.c @@ -0,0 +1,304 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xrep.h" + +#include "../../nn.h" +#include "../../reqrep.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/random.h" +#include "../../utils/wire.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +#include + +/* Private functions. */ +static void nn_xrep_destroy (struct nn_sockbase *self); + +static const struct nn_sockbase_vfptr nn_xrep_sockbase_vfptr = { + NULL, + nn_xrep_destroy, + nn_xrep_add, + nn_xrep_rm, + nn_xrep_in, + nn_xrep_out, + nn_xrep_events, + nn_xrep_send, + nn_xrep_recv, + nn_xrep_setopt, + nn_xrep_getopt +}; + +void nn_xrep_init (struct nn_xrep *self, const struct nn_sockbase_vfptr *vfptr, + void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + + /* Start assigning keys beginning with a random number. This way there + are no key clashes even if the executable is re-started. */ + nn_random_generate (&self->next_key, sizeof (self->next_key)); + + nn_hash_init (&self->outpipes); + nn_fq_init (&self->inpipes); +} + +void nn_xrep_term (struct nn_xrep *self) +{ + nn_fq_term (&self->inpipes); + nn_hash_term (&self->outpipes); + nn_sockbase_term (&self->sockbase); +} + +static void nn_xrep_destroy (struct nn_sockbase *self) +{ + struct nn_xrep *xrep; + + xrep = nn_cont (self, struct nn_xrep, sockbase); + + nn_xrep_term (xrep); + nn_free (xrep); +} + +int nn_xrep_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrep *xrep; + struct nn_xrep_data *data; + int rcvprio; + size_t sz; + + xrep = nn_cont (self, struct nn_xrep, sockbase); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (struct nn_xrep_data), "pipe data (xrep)"); + alloc_assert (data); + data->pipe = pipe; + nn_hash_item_init (&data->outitem); + data->flags = 0; + nn_hash_insert (&xrep->outpipes, xrep->next_key & 0x7fffffff, + &data->outitem); + ++xrep->next_key; + nn_fq_add (&xrep->inpipes, &data->initem, pipe, rcvprio); + nn_pipe_setdata (pipe, data); + + return 0; +} + +void nn_xrep_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrep *xrep; + struct nn_xrep_data *data; + + xrep = nn_cont (self, struct nn_xrep, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_rm (&xrep->inpipes, &data->initem); + nn_hash_erase (&xrep->outpipes, &data->outitem); + nn_hash_item_term (&data->outitem); + + nn_free (data); +} + +void nn_xrep_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrep *xrep; + struct nn_xrep_data *data; + + xrep = nn_cont (self, struct nn_xrep, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_in (&xrep->inpipes, &data->initem); +} + +void nn_xrep_out (NN_UNUSED struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrep_data *data; + + data = nn_pipe_getdata (pipe); + data->flags |= NN_XREP_OUT; +} + +int nn_xrep_events (struct nn_sockbase *self) +{ + return (nn_fq_can_recv (&nn_cont (self, struct nn_xrep, + sockbase)->inpipes) ? NN_SOCKBASE_EVENT_IN : 0) | NN_SOCKBASE_EVENT_OUT; +} + +int nn_xrep_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + uint32_t key; + struct nn_xrep *xrep; + struct nn_xrep_data *data; + + xrep = nn_cont (self, struct nn_xrep, sockbase); + + /* We treat invalid peer ID as if the peer was non-existent. */ + if (nn_slow (nn_chunkref_size (&msg->sphdr) < sizeof (uint32_t))) { + nn_msg_term (msg); + return 0; + } + + /* Retrieve the destination peer ID. Trim it from the header. */ + key = nn_getl (nn_chunkref_data (&msg->sphdr)); + nn_chunkref_trim (&msg->sphdr, 4); + + /* Find the appropriate pipe to send the message to. If there's none, + or if it's not ready for sending, silently drop the message. */ + data = nn_cont (nn_hash_get (&xrep->outpipes, key), struct nn_xrep_data, + outitem); + if (!data || !(data->flags & NN_XREP_OUT)) { + nn_msg_term (msg); + return 0; + } + + /* Send the message. */ + rc = nn_pipe_send (data->pipe, msg); + errnum_assert (rc >= 0, -rc); + if (rc & NN_PIPE_RELEASE) + data->flags &= ~NN_XREP_OUT; + + return 0; +} + +int nn_xrep_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_xrep *xrep; + struct nn_pipe *pipe; + int i; + int maxttl; + void *data; + size_t sz; + struct nn_chunkref ref; + struct nn_xrep_data *pipedata; + + xrep = nn_cont (self, struct nn_xrep, sockbase); + + rc = nn_fq_recv (&xrep->inpipes, msg, &pipe); + if (nn_slow (rc < 0)) + return rc; + + if (!(rc & NN_PIPE_PARSED)) { + + sz = sizeof (maxttl); + rc = nn_sockbase_getopt (self, NN_MAXTTL, &maxttl, &sz); + errnum_assert (rc == 0, -rc); + + /* Determine the size of the message header. */ + data = nn_chunkref_data (&msg->body); + sz = nn_chunkref_size (&msg->body); + i = 0; + while (1) { + + /* Ignore the malformed requests without the bottom of the stack. */ + if (nn_slow ((i + 1) * sizeof (uint32_t) > sz)) { + nn_msg_term (msg); + return -EAGAIN; + } + + /* If the bottom of the backtrace stack is reached, proceed. */ + if (nn_getl ((uint8_t*)(((uint32_t*) data) + i)) & 0x80000000) + break; + + ++i; + } + ++i; + + /* If we encountered too many hops, just toss the message */ + if (i > maxttl) { + nn_msg_term (msg); + return -EAGAIN; + } + + /* Split the header and the body. */ + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, i * sizeof (uint32_t)); + memcpy (nn_chunkref_data (&msg->sphdr), data, i * sizeof (uint32_t)); + nn_chunkref_trim (&msg->body, i * sizeof (uint32_t)); + } + + /* Prepend the header by the pipe key. */ + pipedata = nn_pipe_getdata (pipe); + nn_chunkref_init (&ref, + nn_chunkref_size (&msg->sphdr) + sizeof (uint32_t)); + nn_putl (nn_chunkref_data (&ref), pipedata->outitem.key); + memcpy (((uint8_t*) nn_chunkref_data (&ref)) + sizeof (uint32_t), + nn_chunkref_data (&msg->sphdr), nn_chunkref_size (&msg->sphdr)); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_mv (&msg->sphdr, &ref); + + return 0; +} + +int nn_xrep_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xrep_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xrep_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xrep *self; + + self = nn_alloc (sizeof (struct nn_xrep), "socket (xrep)"); + alloc_assert (self); + nn_xrep_init (self, &nn_xrep_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xrep_ispeer (int socktype) +{ + return socktype == NN_REQ ? 1 : 0; +} + +static struct nn_socktype nn_xrep_socktype_struct = { + AF_SP_RAW, + NN_REP, + 0, + nn_xrep_create, + nn_xrep_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xrep_socktype = &nn_xrep_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.h new file mode 100644 index 0000000..a3b3ff3 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xrep.h @@ -0,0 +1,77 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XREP_INCLUDED +#define NN_XREP_INCLUDED + +#include "../../protocol.h" + +#include "../../utils/hash.h" + +#include "../utils/fq.h" + +#include + +#define NN_XREP_OUT 1 + +struct nn_xrep_data { + struct nn_pipe *pipe; + struct nn_hash_item outitem; + struct nn_fq_data initem; + uint32_t flags; +}; + +struct nn_xrep { + + struct nn_sockbase sockbase; + + /* Key to be assigned to the next added pipe. */ + uint32_t next_key; + + /* Map of all registered pipes indexed by the peer ID. */ + struct nn_hash outpipes; + + /* Fair-queuer to get messages from. */ + struct nn_fq inpipes; +}; + +void nn_xrep_init (struct nn_xrep *self, const struct nn_sockbase_vfptr *vfptr, + void *hint); +void nn_xrep_term (struct nn_xrep *self); + +int nn_xrep_add (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xrep_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xrep_in (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xrep_out (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_xrep_events (struct nn_sockbase *self); +int nn_xrep_send (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xrep_recv (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xrep_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +int nn_xrep_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); + +int nn_xrep_ispeer (int socktype); + +extern struct nn_socktype *nn_xrep_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.c new file mode 100644 index 0000000..392382f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.c @@ -0,0 +1,248 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xreq.h" + +#include "../../nn.h" +#include "../../reqrep.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +struct nn_xreq_data { + struct nn_lb_data lb; + struct nn_fq_data fq; +}; + +/* Private functions. */ +static void nn_xreq_destroy (struct nn_sockbase *self); + +static const struct nn_sockbase_vfptr nn_xreq_sockbase_vfptr = { + NULL, + nn_xreq_destroy, + nn_xreq_add, + nn_xreq_rm, + nn_xreq_in, + nn_xreq_out, + nn_xreq_events, + nn_xreq_send, + nn_xreq_recv, + nn_xreq_setopt, + nn_xreq_getopt +}; + +void nn_xreq_init (struct nn_xreq *self, const struct nn_sockbase_vfptr *vfptr, + void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_lb_init (&self->lb); + nn_fq_init (&self->fq); +} + +void nn_xreq_term (struct nn_xreq *self) +{ + nn_fq_term (&self->fq); + nn_lb_term (&self->lb); + nn_sockbase_term (&self->sockbase); +} + +static void nn_xreq_destroy (struct nn_sockbase *self) +{ + struct nn_xreq *xreq; + + xreq = nn_cont (self, struct nn_xreq, sockbase); + + nn_xreq_term (xreq); + nn_free (xreq); +} + +int nn_xreq_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xreq *xreq; + struct nn_xreq_data *data; + int sndprio; + int rcvprio; + size_t sz; + + xreq = nn_cont (self, struct nn_xreq, sockbase); + + sz = sizeof (sndprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_SNDPRIO, &sndprio, &sz); + nn_assert (sz == sizeof (sndprio)); + nn_assert (sndprio >= 1 && sndprio <= 16); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (struct nn_xreq_data), "pipe data (req)"); + alloc_assert (data); + nn_pipe_setdata (pipe, data); + nn_lb_add (&xreq->lb, &data->lb, pipe, sndprio); + nn_fq_add (&xreq->fq, &data->fq, pipe, rcvprio); + + return 0; +} + +void nn_xreq_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xreq *xreq; + struct nn_xreq_data *data; + + xreq = nn_cont (self, struct nn_xreq, sockbase); + data = nn_pipe_getdata (pipe); + nn_lb_rm (&xreq->lb, &data->lb); + nn_fq_rm (&xreq->fq, &data->fq); + nn_free (data); + + nn_sockbase_stat_increment (self, NN_STAT_CURRENT_SND_PRIORITY, + nn_lb_get_priority (&xreq->lb)); +} + +void nn_xreq_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xreq *xreq; + struct nn_xreq_data *data; + + xreq = nn_cont (self, struct nn_xreq, sockbase); + data = nn_pipe_getdata (pipe); + nn_fq_in (&xreq->fq, &data->fq); +} + +void nn_xreq_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xreq *xreq; + struct nn_xreq_data *data; + + xreq = nn_cont (self, struct nn_xreq, sockbase); + data = nn_pipe_getdata (pipe); + nn_lb_out (&xreq->lb, &data->lb); + + nn_sockbase_stat_increment (self, NN_STAT_CURRENT_SND_PRIORITY, + nn_lb_get_priority (&xreq->lb)); +} + +int nn_xreq_events (struct nn_sockbase *self) +{ + struct nn_xreq *xreq; + + xreq = nn_cont (self, struct nn_xreq, sockbase); + + return (nn_fq_can_recv (&xreq->fq) ? NN_SOCKBASE_EVENT_IN : 0) | + (nn_lb_can_send (&xreq->lb) ? NN_SOCKBASE_EVENT_OUT : 0); +} + +int nn_xreq_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + return nn_xreq_send_to (self, msg, NULL); +} + +int nn_xreq_send_to (struct nn_sockbase *self, struct nn_msg *msg, + struct nn_pipe **to) +{ + int rc; + + /* If request cannot be sent due to the pushback, drop it silenly. */ + rc = nn_lb_send (&nn_cont (self, struct nn_xreq, sockbase)->lb, msg, to); + if (nn_slow (rc == -EAGAIN)) + return -EAGAIN; + errnum_assert (rc >= 0, -rc); + + return 0; +} + +int nn_xreq_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + + rc = nn_fq_recv (&nn_cont (self, struct nn_xreq, sockbase)->fq, msg, NULL); + if (rc == -EAGAIN) + return -EAGAIN; + errnum_assert (rc >= 0, -rc); + + if (!(rc & NN_PIPE_PARSED)) { + + /* Ignore malformed replies. */ + if (nn_slow (nn_chunkref_size (&msg->body) < sizeof (uint32_t))) { + nn_msg_term (msg); + return -EAGAIN; + } + + /* Split the message into the header and the body. */ + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, sizeof (uint32_t)); + memcpy (nn_chunkref_data (&msg->sphdr), nn_chunkref_data (&msg->body), + sizeof (uint32_t)); + nn_chunkref_trim (&msg->body, sizeof (uint32_t)); + } + + return 0; +} + +int nn_xreq_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xreq_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xreq_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xreq *self; + + self = nn_alloc (sizeof (struct nn_xreq), "socket (xreq)"); + alloc_assert (self); + nn_xreq_init (self, &nn_xreq_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xreq_ispeer (int socktype) +{ + return socktype == NN_REP ? 1 : 0; +} + +static struct nn_socktype nn_xreq_socktype_struct = { + AF_SP_RAW, + NN_REQ, + 0, + nn_xreq_create, + nn_xreq_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xreq_socktype = &nn_xreq_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.h new file mode 100644 index 0000000..56497dc --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/reqrep/xreq.h @@ -0,0 +1,59 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XREQ_INCLUDED +#define NN_XREQ_INCLUDED + +#include "../../protocol.h" + +#include "../utils/lb.h" +#include "../utils/fq.h" + +struct nn_xreq { + struct nn_sockbase sockbase; + struct nn_lb lb; + struct nn_fq fq; +}; + +void nn_xreq_init (struct nn_xreq *self, const struct nn_sockbase_vfptr *vfptr, + void *hint); +void nn_xreq_term (struct nn_xreq *self); + +int nn_xreq_add (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xreq_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xreq_in (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xreq_out (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_xreq_events (struct nn_sockbase *self); +int nn_xreq_send (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xreq_send_to (struct nn_sockbase *self, struct nn_msg *msg, + struct nn_pipe **to); +int nn_xreq_recv (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xreq_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +int nn_xreq_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); + +int nn_xreq_ispeer (int socktype); + +extern struct nn_socktype *nn_xreq_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/respondent.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/respondent.c new file mode 100644 index 0000000..e43f059 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/respondent.c @@ -0,0 +1,186 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "respondent.h" +#include "xrespondent.h" + +#include "../../nn.h" +#include "../../survey.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/wire.h" +#include "../../utils/list.h" + +#include + +#define NN_RESPONDENT_INPROGRESS 1 + +struct nn_respondent { + struct nn_xrespondent xrespondent; + uint32_t flags; + struct nn_chunkref backtrace; +}; + +/* Private functions. */ +static void nn_respondent_init (struct nn_respondent *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_respondent_term (struct nn_respondent *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_respondent_destroy (struct nn_sockbase *self); +static int nn_respondent_events (struct nn_sockbase *self); +static int nn_respondent_send (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_respondent_recv (struct nn_sockbase *self, struct nn_msg *msg); +static const struct nn_sockbase_vfptr nn_respondent_sockbase_vfptr = { + NULL, + nn_respondent_destroy, + nn_xrespondent_add, + nn_xrespondent_rm, + nn_xrespondent_in, + nn_xrespondent_out, + nn_respondent_events, + nn_respondent_send, + nn_respondent_recv, + nn_xrespondent_setopt, + nn_xrespondent_getopt +}; + +static void nn_respondent_init (struct nn_respondent *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_xrespondent_init (&self->xrespondent, vfptr, hint); + self->flags = 0; +} + +static void nn_respondent_term (struct nn_respondent *self) +{ + if (self->flags & NN_RESPONDENT_INPROGRESS) + nn_chunkref_term (&self->backtrace); + nn_xrespondent_term (&self->xrespondent); +} + +void nn_respondent_destroy (struct nn_sockbase *self) +{ + struct nn_respondent *respondent; + + respondent = nn_cont (self, struct nn_respondent, xrespondent.sockbase); + + nn_respondent_term (respondent); + nn_free (respondent); +} + +static int nn_respondent_events (struct nn_sockbase *self) +{ + int events; + struct nn_respondent *respondent; + + respondent = nn_cont (self, struct nn_respondent, xrespondent.sockbase); + + events = nn_xrespondent_events (&respondent->xrespondent.sockbase); + if (!(respondent->flags & NN_RESPONDENT_INPROGRESS)) + events &= ~NN_SOCKBASE_EVENT_OUT; + return events; +} + +static int nn_respondent_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_respondent *respondent; + + respondent = nn_cont (self, struct nn_respondent, xrespondent.sockbase); + + /* If there's no survey going on, report EFSM error. */ + if (nn_slow (!(respondent->flags & NN_RESPONDENT_INPROGRESS))) + return -EFSM; + + /* Tag the message with survey ID. */ + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_mv (&msg->sphdr, &respondent->backtrace); + + /* Remember that no survey is being processed. */ + respondent->flags &= ~NN_RESPONDENT_INPROGRESS; + + /* Try to send the message. If it cannot be sent due to pushback, drop it + silently. */ + rc = nn_xrespondent_send (&respondent->xrespondent.sockbase, msg); + errnum_assert (rc == 0 || rc == -EAGAIN, -rc); + + return 0; +} + +static int nn_respondent_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_respondent *respondent; + + respondent = nn_cont (self, struct nn_respondent, xrespondent.sockbase); + + /* Cancel current survey and clean up backtrace, if it exists. */ + if (nn_slow (respondent->flags & NN_RESPONDENT_INPROGRESS)) { + nn_chunkref_term (&respondent->backtrace); + respondent->flags &= ~NN_RESPONDENT_INPROGRESS; + } + + /* Get next survey. */ + rc = nn_xrespondent_recv (&respondent->xrespondent.sockbase, msg); + if (nn_slow (rc == -EAGAIN)) + return -EAGAIN; + errnum_assert (rc == 0, -rc); + + /* Store the backtrace. */ + nn_chunkref_mv (&respondent->backtrace, &msg->sphdr); + nn_chunkref_init (&msg->sphdr, 0); + + /* Remember that survey is being processed. */ + respondent->flags |= NN_RESPONDENT_INPROGRESS; + + return 0; +} + +static int nn_respondent_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_respondent *self; + + self = nn_alloc (sizeof (struct nn_respondent), "socket (respondent)"); + alloc_assert (self); + nn_respondent_init (self, &nn_respondent_sockbase_vfptr, hint); + *sockbase = &self->xrespondent.sockbase; + + return 0; +} + +static struct nn_socktype nn_respondent_socktype_struct = { + AF_SP, + NN_RESPONDENT, + 0, + nn_respondent_create, + nn_xrespondent_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_respondent_socktype = &nn_respondent_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/respondent.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/respondent.h new file mode 100644 index 0000000..aabf72f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/respondent.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_RESPONDENT_INCLUDED +#define NN_RESPONDENT_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_respondent_socktype; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.c new file mode 100644 index 0000000..703cf30 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.c @@ -0,0 +1,525 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "surveyor.h" +#include "xsurveyor.h" + +#include "../../nn.h" +#include "../../survey.h" + +#include "../../aio/fsm.h" +#include "../../aio/timer.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/wire.h" +#include "../../utils/alloc.h" +#include "../../utils/random.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +#include + +#define NN_SURVEYOR_DEFAULT_DEADLINE 1000 + +#define NN_SURVEYOR_STATE_IDLE 1 +#define NN_SURVEYOR_STATE_PASSIVE 2 +#define NN_SURVEYOR_STATE_ACTIVE 3 +#define NN_SURVEYOR_STATE_CANCELLING 4 +#define NN_SURVEYOR_STATE_STOPPING_TIMER 5 +#define NN_SURVEYOR_STATE_STOPPING 6 + +#define NN_SURVEYOR_ACTION_START 1 +#define NN_SURVEYOR_ACTION_CANCEL 2 + +#define NN_SURVEYOR_SRC_DEADLINE_TIMER 1 + +#define NN_SURVEYOR_TIMEDOUT 1 + +struct nn_surveyor { + + /* The underlying raw SP socket. */ + struct nn_xsurveyor xsurveyor; + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Survey ID of the current survey. */ + uint32_t surveyid; + + /* Timer for timing out the survey. */ + struct nn_timer timer; + + /* When starting the survey, the message is temporarily stored here. */ + struct nn_msg tosend; + + /* Protocol-specific socket options. */ + int deadline; + + /* Flag if surveyor has timed out */ + int timedout; +}; + +/* Private functions. */ +static void nn_surveyor_init (struct nn_surveyor *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +static void nn_surveyor_term (struct nn_surveyor *self); +static void nn_surveyor_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_surveyor_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static int nn_surveyor_inprogress (struct nn_surveyor *self); +static void nn_surveyor_resend (struct nn_surveyor *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static void nn_surveyor_stop (struct nn_sockbase *self); +static void nn_surveyor_destroy (struct nn_sockbase *self); +static int nn_surveyor_events (struct nn_sockbase *self); +static int nn_surveyor_send (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_surveyor_recv (struct nn_sockbase *self, struct nn_msg *msg); +static int nn_surveyor_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +static int nn_surveyor_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); +static const struct nn_sockbase_vfptr nn_surveyor_sockbase_vfptr = { + nn_surveyor_stop, + nn_surveyor_destroy, + nn_xsurveyor_add, + nn_xsurveyor_rm, + nn_xsurveyor_in, + nn_xsurveyor_out, + nn_surveyor_events, + nn_surveyor_send, + nn_surveyor_recv, + nn_surveyor_setopt, + nn_surveyor_getopt +}; + +static void nn_surveyor_init (struct nn_surveyor *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_xsurveyor_init (&self->xsurveyor, vfptr, hint); + nn_fsm_init_root (&self->fsm, nn_surveyor_handler, nn_surveyor_shutdown, + nn_sockbase_getctx (&self->xsurveyor.sockbase)); + self->state = NN_SURVEYOR_STATE_IDLE; + + /* Start assigning survey IDs beginning with a random number. This way + there should be no key clashes even if the executable is re-started. */ + nn_random_generate (&self->surveyid, sizeof (self->surveyid)); + + nn_timer_init (&self->timer, NN_SURVEYOR_SRC_DEADLINE_TIMER, &self->fsm); + nn_msg_init (&self->tosend, 0); + self->deadline = NN_SURVEYOR_DEFAULT_DEADLINE; + self->timedout = 0; + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); +} + +static void nn_surveyor_term (struct nn_surveyor *self) +{ + nn_msg_term (&self->tosend); + nn_timer_term (&self->timer); + nn_fsm_term (&self->fsm); + nn_xsurveyor_term (&self->xsurveyor); +} + +void nn_surveyor_stop (struct nn_sockbase *self) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + nn_fsm_stop (&surveyor->fsm); +} + +void nn_surveyor_destroy (struct nn_sockbase *self) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + nn_surveyor_term (surveyor); + nn_free (surveyor); +} + +static int nn_surveyor_inprogress (struct nn_surveyor *self) +{ + /* Return 1 if there's a survey going on. 0 otherwise. */ + return self->state == NN_SURVEYOR_STATE_IDLE || + self->state == NN_SURVEYOR_STATE_PASSIVE || + self->state == NN_SURVEYOR_STATE_STOPPING ? 0 : 1; +} + +static int nn_surveyor_events (struct nn_sockbase *self) +{ + int rc; + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + /* Determine the actual readability/writability of the socket. */ + rc = nn_xsurveyor_events (&surveyor->xsurveyor.sockbase); + + /* If there's no survey going on we'll signal IN to interrupt polling + when the survey expires. nn_recv() will return -EFSM afterwards. */ + if (!nn_surveyor_inprogress (surveyor)) + rc |= NN_SOCKBASE_EVENT_IN; + + return rc; +} + +static int nn_surveyor_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + /* Generate new survey ID. */ + ++surveyor->surveyid; + surveyor->surveyid |= 0x80000000; + + /* Tag the survey body with survey ID. */ + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, 4); + nn_putl (nn_chunkref_data (&msg->sphdr), surveyor->surveyid); + + /* Store the survey, so that it can be sent later on. */ + nn_msg_term (&surveyor->tosend); + nn_msg_mv (&surveyor->tosend, msg); + nn_msg_init (msg, 0); + + /* Cancel any ongoing survey, if any. */ + if (nn_slow (nn_surveyor_inprogress (surveyor))) { + + /* First check whether the survey can be sent at all. */ + if (!(nn_xsurveyor_events (&surveyor->xsurveyor.sockbase) & + NN_SOCKBASE_EVENT_OUT)) + return -EAGAIN; + + /* Cancel the current survey. */ + nn_fsm_action (&surveyor->fsm, NN_SURVEYOR_ACTION_CANCEL); + + return 0; + } + + /* Notify the state machine that the survey was started. */ + nn_fsm_action (&surveyor->fsm, NN_SURVEYOR_ACTION_START); + + return 0; +} + +static int nn_surveyor_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_surveyor *surveyor; + uint32_t surveyid; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + /* If no survey is going on return EFSM error. */ + if (nn_slow (!nn_surveyor_inprogress (surveyor))) { + if (surveyor->timedout == NN_SURVEYOR_TIMEDOUT) { + surveyor->timedout = 0; + return -ETIMEDOUT; + } else + return -EFSM; + } + + while (1) { + + /* Get next response. */ + rc = nn_xsurveyor_recv (&surveyor->xsurveyor.sockbase, msg); + if (nn_slow (rc == -EAGAIN)) + return -EAGAIN; + errnum_assert (rc == 0, -rc); + + /* Get the survey ID. Ignore any stale responses. */ + /* TODO: This should be done asynchronously! */ + if (nn_slow (nn_chunkref_size (&msg->sphdr) != sizeof (uint32_t))) + continue; + surveyid = nn_getl (nn_chunkref_data (&msg->sphdr)); + if (nn_slow (surveyid != surveyor->surveyid)) + continue; + + /* Discard the header and return the message to the user. */ + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, 0); + break; + } + + return 0; +} + +static int nn_surveyor_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + if (level != NN_SURVEYOR) + return -ENOPROTOOPT; + + if (option == NN_SURVEYOR_DEADLINE) { + if (nn_slow (optvallen != sizeof (int))) + return -EINVAL; + surveyor->deadline = *(int*) optval; + return 0; + } + + return -ENOPROTOOPT; +} + +static int nn_surveyor_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, xsurveyor.sockbase); + + if (level != NN_SURVEYOR) + return -ENOPROTOOPT; + + if (option == NN_SURVEYOR_DEADLINE) { + if (nn_slow (*optvallen < sizeof (int))) + return -EINVAL; + *(int*) optval = surveyor->deadline; + *optvallen = sizeof (int); + return 0; + } + + return -ENOPROTOOPT; +} + +static void nn_surveyor_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, fsm); + + if (nn_slow (src== NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_timer_stop (&surveyor->timer); + surveyor->state = NN_SURVEYOR_STATE_STOPPING; + } + if (nn_slow (surveyor->state == NN_SURVEYOR_STATE_STOPPING)) { + if (!nn_timer_isidle (&surveyor->timer)) + return; + surveyor->state = NN_SURVEYOR_STATE_IDLE; + nn_fsm_stopped_noevent (&surveyor->fsm); + nn_sockbase_stopped (&surveyor->xsurveyor.sockbase); + return; + } + + nn_fsm_bad_state(surveyor->state, src, type); +} + +static void nn_surveyor_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_surveyor *surveyor; + + surveyor = nn_cont (self, struct nn_surveyor, fsm); + + switch (surveyor->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The socket was created recently. */ +/******************************************************************************/ + case NN_SURVEYOR_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + surveyor->state = NN_SURVEYOR_STATE_PASSIVE; + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + default: + nn_fsm_bad_source (surveyor->state, src, type); + } + +/******************************************************************************/ +/* PASSIVE state. */ +/* There's no survey going on. */ +/******************************************************************************/ + case NN_SURVEYOR_STATE_PASSIVE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_SURVEYOR_ACTION_START: + nn_surveyor_resend (surveyor); + nn_timer_start (&surveyor->timer, surveyor->deadline); + surveyor->state = NN_SURVEYOR_STATE_ACTIVE; + return; + + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + default: + nn_fsm_bad_source (surveyor->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* Survey was sent, waiting for responses. */ +/******************************************************************************/ + case NN_SURVEYOR_STATE_ACTIVE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_SURVEYOR_ACTION_CANCEL: + nn_timer_stop (&surveyor->timer); + surveyor->state = NN_SURVEYOR_STATE_CANCELLING; + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + case NN_SURVEYOR_SRC_DEADLINE_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&surveyor->timer); + surveyor->state = NN_SURVEYOR_STATE_STOPPING_TIMER; + surveyor->timedout = NN_SURVEYOR_TIMEDOUT; + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + default: + nn_fsm_bad_source (surveyor->state, src, type); + } + +/******************************************************************************/ +/* CANCELLING state. */ +/* Survey was cancelled, but the old timer haven't stopped yet. The new */ +/* survey thus haven't been sent and is stored in 'tosend'. */ +/******************************************************************************/ + case NN_SURVEYOR_STATE_CANCELLING: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_SURVEYOR_ACTION_CANCEL: + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + case NN_SURVEYOR_SRC_DEADLINE_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + nn_surveyor_resend (surveyor); + nn_timer_start (&surveyor->timer, surveyor->deadline); + surveyor->state = NN_SURVEYOR_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + default: + nn_fsm_bad_source (surveyor->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_TIMER state. */ +/* Survey timeout expired. Now we are stopping the timer. */ +/******************************************************************************/ + case NN_SURVEYOR_STATE_STOPPING_TIMER: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_SURVEYOR_ACTION_CANCEL: + surveyor->state = NN_SURVEYOR_STATE_CANCELLING; + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + case NN_SURVEYOR_SRC_DEADLINE_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + surveyor->state = NN_SURVEYOR_STATE_PASSIVE; + return; + default: + nn_fsm_bad_action (surveyor->state, src, type); + } + + default: + nn_fsm_bad_source (surveyor->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (surveyor->state, src, type); + } +} + +static void nn_surveyor_resend (struct nn_surveyor *self) +{ + int rc; + struct nn_msg msg; + + nn_msg_cp (&msg, &self->tosend); + rc = nn_xsurveyor_send (&self->xsurveyor.sockbase, &msg); + errnum_assert (rc == 0, -rc); +} + +static int nn_surveyor_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_surveyor *self; + + self = nn_alloc (sizeof (struct nn_surveyor), "socket (surveyor)"); + alloc_assert (self); + nn_surveyor_init (self, &nn_surveyor_sockbase_vfptr, hint); + *sockbase = &self->xsurveyor.sockbase; + + return 0; +} + +static struct nn_socktype nn_surveyor_socktype_struct = { + AF_SP, + NN_SURVEYOR, + 0, + nn_surveyor_create, + nn_xsurveyor_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_surveyor_socktype = &nn_surveyor_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.h new file mode 100644 index 0000000..b4bf514 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/surveyor.h @@ -0,0 +1,31 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SURVEYOR_INCLUDED +#define NN_SURVEYOR_INCLUDED + +#include "../../protocol.h" + +extern struct nn_socktype *nn_surveyor_socktype; + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.c new file mode 100644 index 0000000..6e628d2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.c @@ -0,0 +1,302 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xrespondent.h" + +#include "../../nn.h" +#include "../../survey.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" +#include "../../utils/random.h" +#include "../../utils/wire.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +/* Private functions. */ +static void nn_xrespondent_destroy (struct nn_sockbase *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static const struct nn_sockbase_vfptr nn_xrespondent_sockbase_vfptr = { + NULL, + nn_xrespondent_destroy, + nn_xrespondent_add, + nn_xrespondent_rm, + nn_xrespondent_in, + nn_xrespondent_out, + nn_xrespondent_events, + nn_xrespondent_send, + nn_xrespondent_recv, + nn_xrespondent_setopt, + nn_xrespondent_getopt +}; + +void nn_xrespondent_init (struct nn_xrespondent *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + + /* Pipes IDs should be random. See RFC for info. */ + nn_random_generate (&self->next_key, sizeof (self->next_key)); + nn_hash_init (&self->outpipes); + nn_fq_init (&self->inpipes); +} + +void nn_xrespondent_term (struct nn_xrespondent *self) +{ + nn_fq_term (&self->inpipes); + nn_hash_term (&self->outpipes); + nn_sockbase_term (&self->sockbase); +} + +static void nn_xrespondent_destroy (struct nn_sockbase *self) +{ + struct nn_xrespondent *xrespondent; + + xrespondent = nn_cont (self, struct nn_xrespondent, sockbase); + + nn_xrespondent_term (xrespondent); + nn_free (xrespondent); +} + +int nn_xrespondent_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrespondent *xrespondent; + struct nn_xrespondent_data *data; + int rcvprio; + size_t sz; + + xrespondent = nn_cont (self, struct nn_xrespondent, sockbase); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (*data), "pipe data (xrespondent)"); + alloc_assert (data); + + data->pipe = pipe; + nn_hash_item_init (&data->outitem); + data->flags = 0; + nn_hash_insert (&xrespondent->outpipes, xrespondent->next_key & 0x7fffffff, + &data->outitem); + xrespondent->next_key++; + nn_fq_add (&xrespondent->inpipes, &data->initem, pipe, rcvprio); + nn_pipe_setdata (pipe, data); + + return 0; +} + +void nn_xrespondent_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrespondent *xrespondent; + struct nn_xrespondent_data *data; + + xrespondent = nn_cont (self, struct nn_xrespondent, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_rm (&xrespondent->inpipes, &data->initem); + nn_hash_erase (&xrespondent->outpipes, &data->outitem); + nn_hash_item_term (&data->outitem); + + nn_free (data); +} + +void nn_xrespondent_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xrespondent *xrespondent; + struct nn_xrespondent_data *data; + + xrespondent = nn_cont (self, struct nn_xrespondent, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_in (&xrespondent->inpipes, &data->initem); +} + +void nn_xrespondent_out (NN_UNUSED struct nn_sockbase *self, + struct nn_pipe *pipe) +{ + struct nn_xrespondent_data *data; + + data = nn_pipe_getdata (pipe); + data->flags |= NN_XRESPONDENT_OUT; +} + +int nn_xrespondent_events (struct nn_sockbase *self) +{ + return (nn_fq_can_recv (&nn_cont (self, struct nn_xrespondent, + sockbase)->inpipes) ? NN_SOCKBASE_EVENT_IN : 0) | NN_SOCKBASE_EVENT_OUT; +} + +int nn_xrespondent_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + uint32_t key; + struct nn_xrespondent *xrespondent; + struct nn_xrespondent_data *data; + + xrespondent = nn_cont (self, struct nn_xrespondent, sockbase); + + /* We treat invalid peer ID as if the peer was non-existent. */ + if (nn_slow (nn_chunkref_size (&msg->sphdr) < sizeof (uint32_t))) { + nn_msg_term (msg); + return 0; + } + + /* Retrieve destination peer ID. Trim it from the header. */ + key = nn_getl (nn_chunkref_data (&msg->sphdr)); + nn_chunkref_trim (&msg->sphdr, 4); + + /* Find the appropriate pipe to send the message to. If there's none, + or if it's not ready for sending, silently drop the message. */ + data = nn_cont (nn_hash_get (&xrespondent->outpipes, key), + struct nn_xrespondent_data, outitem); + if (!data || !(data->flags & NN_XRESPONDENT_OUT)) { + nn_msg_term (msg); + return 0; + } + + /* Send the message. */ + rc = nn_pipe_send (data->pipe, msg); + errnum_assert (rc >= 0, -rc); + if (rc & NN_PIPE_RELEASE) + data->flags &= ~NN_XRESPONDENT_OUT; + + return 0; +} + +int nn_xrespondent_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_xrespondent *xrespondent; + struct nn_pipe *pipe; + int i; + size_t sz; + void *data; + struct nn_chunkref ref; + struct nn_xrespondent_data *pipedata; + int maxttl; + + xrespondent = nn_cont (self, struct nn_xrespondent, sockbase); + + rc = nn_fq_recv (&xrespondent->inpipes, msg, &pipe); + if (nn_slow (rc < 0)) + return rc; + + /* Split the header (including survey ID) from the body, if needed. */ + if (!(rc & NN_PIPE_PARSED)) { + + sz = sizeof (maxttl); + rc = nn_sockbase_getopt (self, NN_MAXTTL, &maxttl, &sz); + errnum_assert (rc == 0, -rc); + + /* Determine the size of the message header. */ + data = nn_chunkref_data (&msg->body); + sz = nn_chunkref_size (&msg->body); + i = 0; + + while (1) { + /* Ignore the malformed surveys without the bottom of the stack. */ + if (nn_slow ((i + 1) * sizeof (uint32_t) > sz)) { + nn_msg_term (msg); + return -EAGAIN; + } + + /* If the bottom of the backtrace stack is reached, proceed. */ + if (nn_getl ((uint8_t*)(((uint32_t*) data) + i)) & 0x80000000) + break; + + ++i; + } + ++i; + + /* Ignore messages with too many hops. */ + if (i > maxttl) { + nn_msg_term (msg); + return -EAGAIN; + } + + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, i * sizeof (uint32_t)); + memcpy (nn_chunkref_data (&msg->sphdr), data, i * sizeof (uint32_t)); + nn_chunkref_trim (&msg->body, i * sizeof (uint32_t)); + } + + /* Prepend the header by the pipe key. */ + pipedata = nn_pipe_getdata (pipe); + nn_chunkref_init (&ref, nn_chunkref_size (&msg->sphdr) + sizeof (uint32_t)); + nn_putl (nn_chunkref_data (&ref), pipedata->outitem.key); + memcpy (((uint8_t *) nn_chunkref_data (&ref)) + sizeof (uint32_t), + nn_chunkref_data (&msg->sphdr), nn_chunkref_size (&msg->sphdr)); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_mv (&msg->sphdr, &ref); + + return 0; +} + +int nn_xrespondent_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xrespondent_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xrespondent_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xrespondent *self; + + self = nn_alloc (sizeof (struct nn_xrespondent), "socket (xrespondent)"); + alloc_assert (self); + nn_xrespondent_init (self, &nn_xrespondent_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xrespondent_ispeer (int socktype) +{ + return socktype == NN_SURVEYOR ? 1 : 0; +} + +static struct nn_socktype nn_xrespondent_socktype_struct = { + AF_SP_RAW, + NN_RESPONDENT, + 0, + nn_xrespondent_create, + nn_xrespondent_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xrespondent_socktype = &nn_xrespondent_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.h new file mode 100644 index 0000000..322a7a8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xrespondent.h @@ -0,0 +1,74 @@ +/* + Copyright (c) 201-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XRESPONDENT_INCLUDED +#define NN_XRESPONDENT_INCLUDED + +#include "../../protocol.h" + +#include "../../utils/hash.h" +#include "../utils/fq.h" + +extern struct nn_socktype *nn_xrespondent_socktype; + +#define NN_XRESPONDENT_OUT 1 + +struct nn_xrespondent_data { + struct nn_pipe *pipe; + struct nn_hash_item outitem; + struct nn_fq_data initem; + uint32_t flags; +}; + +struct nn_xrespondent { + struct nn_sockbase sockbase; + + /* Key to be assigned to the next added pipe. */ + uint32_t next_key; + + /* Map of all registered pipes indexed by the peer ID. */ + struct nn_hash outpipes; + + /* Fair-queuer to get surveys from. */ + struct nn_fq inpipes; +}; + +void nn_xrespondent_init (struct nn_xrespondent *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +void nn_xrespondent_term (struct nn_xrespondent *self); + +int nn_xrespondent_add (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xrespondent_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xrespondent_in (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xrespondent_out (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_xrespondent_events (struct nn_sockbase *self); +int nn_xrespondent_send (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xrespondent_recv (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xrespondent_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +int nn_xrespondent_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); + +int nn_xrespondent_ispeer (int socktype); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.c new file mode 100644 index 0000000..c2e5c9c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.c @@ -0,0 +1,230 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "xsurveyor.h" + +#include "../../nn.h" +#include "../../survey.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/list.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/attr.h" + +#include + +/* Private functions. */ +static void nn_xsurveyor_destroy (struct nn_sockbase *self); + +/* Implementation of nn_sockbase's virtual functions. */ +static const struct nn_sockbase_vfptr nn_xsurveyor_sockbase_vfptr = { + NULL, + nn_xsurveyor_destroy, + nn_xsurveyor_add, + nn_xsurveyor_rm, + nn_xsurveyor_in, + nn_xsurveyor_out, + nn_xsurveyor_events, + nn_xsurveyor_send, + nn_xsurveyor_recv, + nn_xsurveyor_setopt, + nn_xsurveyor_getopt +}; + +void nn_xsurveyor_init (struct nn_xsurveyor *self, + const struct nn_sockbase_vfptr *vfptr, void *hint) +{ + nn_sockbase_init (&self->sockbase, vfptr, hint); + nn_dist_init (&self->outpipes); + nn_fq_init (&self->inpipes); +} + +void nn_xsurveyor_term (struct nn_xsurveyor *self) +{ + nn_fq_term (&self->inpipes); + nn_dist_term (&self->outpipes); + nn_sockbase_term (&self->sockbase); +} + +static void nn_xsurveyor_destroy (struct nn_sockbase *self) +{ + struct nn_xsurveyor *xsurveyor; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + + nn_xsurveyor_term (xsurveyor); + nn_free (xsurveyor); +} + +int nn_xsurveyor_add (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsurveyor *xsurveyor; + struct nn_xsurveyor_data *data; + int rcvprio; + size_t sz; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + + sz = sizeof (rcvprio); + nn_pipe_getopt (pipe, NN_SOL_SOCKET, NN_RCVPRIO, &rcvprio, &sz); + nn_assert (sz == sizeof (rcvprio)); + nn_assert (rcvprio >= 1 && rcvprio <= 16); + + data = nn_alloc (sizeof (struct nn_xsurveyor_data), + "pipe data (xsurveyor)"); + alloc_assert (data); + data->pipe = pipe; + nn_fq_add (&xsurveyor->inpipes, &data->initem, pipe, rcvprio); + nn_dist_add (&xsurveyor->outpipes, &data->outitem, pipe); + nn_pipe_setdata (pipe, data); + + return 0; +} + +void nn_xsurveyor_rm (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsurveyor *xsurveyor; + struct nn_xsurveyor_data *data; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_rm (&xsurveyor->inpipes, &data->initem); + nn_dist_rm (&xsurveyor->outpipes, &data->outitem); + + nn_free (data); +} + +void nn_xsurveyor_in (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsurveyor *xsurveyor; + struct nn_xsurveyor_data *data; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + data = nn_pipe_getdata (pipe); + + nn_fq_in (&xsurveyor->inpipes, &data->initem); +} + +void nn_xsurveyor_out (struct nn_sockbase *self, struct nn_pipe *pipe) +{ + struct nn_xsurveyor *xsurveyor; + struct nn_xsurveyor_data *data; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + data = nn_pipe_getdata (pipe); + + nn_dist_out (&xsurveyor->outpipes, &data->outitem); +} + +int nn_xsurveyor_events (struct nn_sockbase *self) +{ + struct nn_xsurveyor *xsurveyor; + int events; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + + events = NN_SOCKBASE_EVENT_OUT; + if (nn_fq_can_recv (&xsurveyor->inpipes)) + events |= NN_SOCKBASE_EVENT_IN; + return events; +} + +int nn_xsurveyor_send (struct nn_sockbase *self, struct nn_msg *msg) +{ + return nn_dist_send ( + &nn_cont (self, struct nn_xsurveyor, sockbase)->outpipes, msg, NULL); +} + +int nn_xsurveyor_recv (struct nn_sockbase *self, struct nn_msg *msg) +{ + int rc; + struct nn_xsurveyor *xsurveyor; + + xsurveyor = nn_cont (self, struct nn_xsurveyor, sockbase); + + rc = nn_fq_recv (&xsurveyor->inpipes, msg, NULL); + if (nn_slow (rc < 0)) + return rc; + + /* Split the header from the body, if needed. */ + if (!(rc & NN_PIPE_PARSED)) { + if (nn_slow (nn_chunkref_size (&msg->body) < sizeof (uint32_t))) { + nn_msg_term (msg); + return -EAGAIN; + } + nn_assert (nn_chunkref_size (&msg->sphdr) == 0); + nn_chunkref_term (&msg->sphdr); + nn_chunkref_init (&msg->sphdr, sizeof (uint32_t)); + memcpy (nn_chunkref_data (&msg->sphdr), nn_chunkref_data (&msg->body), + sizeof (uint32_t)); + nn_chunkref_trim (&msg->body, sizeof (uint32_t)); + } + + return 0; +} + +int nn_xsurveyor_setopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED const void *optval, NN_UNUSED size_t optvallen) +{ + return -ENOPROTOOPT; +} + +int nn_xsurveyor_getopt (NN_UNUSED struct nn_sockbase *self, + NN_UNUSED int level, NN_UNUSED int option, + NN_UNUSED void *optval, NN_UNUSED size_t *optvallen) +{ + return -ENOPROTOOPT; +} + +static int nn_xsurveyor_create (void *hint, struct nn_sockbase **sockbase) +{ + struct nn_xsurveyor *self; + + self = nn_alloc (sizeof (struct nn_xsurveyor), "socket (xsurveyor)"); + alloc_assert (self); + nn_xsurveyor_init (self, &nn_xsurveyor_sockbase_vfptr, hint); + *sockbase = &self->sockbase; + + return 0; +} + +int nn_xsurveyor_ispeer (int socktype) +{ + return socktype == NN_RESPONDENT ? 1 : 0; +} + +static struct nn_socktype nn_xsurveyor_socktype_struct = { + AF_SP_RAW, + NN_SURVEYOR, + 0, + nn_xsurveyor_create, + nn_xsurveyor_ispeer, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_socktype *nn_xsurveyor_socktype = &nn_xsurveyor_socktype_struct; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.h new file mode 100644 index 0000000..fe7f8b4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/survey/xsurveyor.h @@ -0,0 +1,70 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_XSURVEYOR_INCLUDED +#define NN_XSURVEYOR_INCLUDED + +#include "../../protocol.h" + +#include "../utils/dist.h" +#include "../utils/fq.h" + +extern struct nn_socktype *nn_xsurveyor_socktype; + +struct nn_xsurveyor_data { + struct nn_pipe *pipe; + struct nn_dist_data outitem; + struct nn_fq_data initem; +}; + +struct nn_xsurveyor { + + /* The generic socket base class. */ + struct nn_sockbase sockbase; + + /* Distributor to send messages. */ + struct nn_dist outpipes; + + /* Fair-queuer to receive messages. */ + struct nn_fq inpipes; +}; + +void nn_xsurveyor_init (struct nn_xsurveyor *self, + const struct nn_sockbase_vfptr *vfptr, void *hint); +void nn_xsurveyor_term (struct nn_xsurveyor *self); + +int nn_xsurveyor_add (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xsurveyor_rm (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xsurveyor_in (struct nn_sockbase *self, struct nn_pipe *pipe); +void nn_xsurveyor_out (struct nn_sockbase *self, struct nn_pipe *pipe); +int nn_xsurveyor_events (struct nn_sockbase *self); +int nn_xsurveyor_send (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xsurveyor_recv (struct nn_sockbase *self, struct nn_msg *msg); +int nn_xsurveyor_setopt (struct nn_sockbase *self, int level, int option, + const void *optval, size_t optvallen); +int nn_xsurveyor_getopt (struct nn_sockbase *self, int level, int option, + void *optval, size_t *optvallen); + +int nn_xsurveyor_ispeer (int socktype); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/README b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/README new file mode 100644 index 0000000..621d8db --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/README @@ -0,0 +1,2 @@ +This directory contains the utilities that can be used when creating new +protocols. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/dist.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/dist.c new file mode 100644 index 0000000..51ebe11 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/dist.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "dist.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/attr.h" + +#include + +void nn_dist_init (struct nn_dist *self) +{ + self->count = 0; + nn_list_init (&self->pipes); +} + +void nn_dist_term (struct nn_dist *self) +{ + nn_assert (self->count == 0); + nn_list_term (&self->pipes); +} + +void nn_dist_add (NN_UNUSED struct nn_dist *self, + struct nn_dist_data *data, struct nn_pipe *pipe) +{ + data->pipe = pipe; + nn_list_item_init (&data->item); +} + +void nn_dist_rm (struct nn_dist *self, struct nn_dist_data *data) +{ + if (nn_list_item_isinlist (&data->item)) { + --self->count; + nn_list_erase (&self->pipes, &data->item); + } + nn_list_item_term (&data->item); +} + +void nn_dist_out (struct nn_dist *self, struct nn_dist_data *data) +{ + ++self->count; + nn_list_insert (&self->pipes, &data->item, nn_list_end (&self->pipes)); +} + +int nn_dist_send (struct nn_dist *self, struct nn_msg *msg, + struct nn_pipe *exclude) +{ + int rc; + struct nn_list_item *it; + struct nn_dist_data *data; + struct nn_msg copy; + + /* TODO: We can optimise for the case when there's only one outbound + pipe here. No message copying is needed in such case. */ + + /* In the specific case when there are no outbound pipes. There's nowhere + to send the message to. Deallocate it. */ + if (nn_slow (self->count) == 0) { + nn_msg_term (msg); + return 0; + } + + /* Send the message to all the subscribers. */ + nn_msg_bulkcopy_start (msg, self->count); + it = nn_list_begin (&self->pipes); + while (it != nn_list_end (&self->pipes)) { + data = nn_cont (it, struct nn_dist_data, item); + nn_msg_bulkcopy_cp (©, msg); + if (nn_fast (data->pipe == exclude)) { + nn_msg_term (©); + } + else { + rc = nn_pipe_send (data->pipe, ©); + errnum_assert (rc >= 0, -rc); + if (rc & NN_PIPE_RELEASE) { + --self->count; + it = nn_list_erase (&self->pipes, it); + continue; + } + } + it = nn_list_next (&self->pipes, it); + } + nn_msg_term (msg); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/dist.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/dist.h new file mode 100644 index 0000000..403a915 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/dist.h @@ -0,0 +1,55 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_DIST_INCLUDED +#define NN_DIST_INCLUDED + +#include "../../protocol.h" + +#include "../../utils/list.h" + +/* Distributor. Sends messages to all the pipes. */ + +struct nn_dist_data { + struct nn_list_item item; + struct nn_pipe *pipe; +}; + +struct nn_dist { + uint32_t count; + struct nn_list pipes; +}; + +void nn_dist_init (struct nn_dist *self); +void nn_dist_term (struct nn_dist *self); +void nn_dist_add (struct nn_dist *self, + struct nn_dist_data *data, struct nn_pipe *pipe); +void nn_dist_rm (struct nn_dist *self, struct nn_dist_data *data); +void nn_dist_out (struct nn_dist *self, struct nn_dist_data *data); + +/* Sends the message to all the attached pipes except the one specified + by 'exclude' parameter. If 'exclude' is NULL, message is sent to all + attached pipes. */ +int nn_dist_send (struct nn_dist *self, struct nn_msg *msg, + struct nn_pipe *exclude); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/excl.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/excl.c new file mode 100644 index 0000000..73886a1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/excl.c @@ -0,0 +1,118 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "excl.h" + +#include "../../utils/fast.h" +#include "../../utils/err.h" +#include "../../utils/attr.h" + +void nn_excl_init (struct nn_excl *self) +{ + self->pipe = NULL; + self->inpipe = NULL; + self->outpipe = NULL; +} + +void nn_excl_term (struct nn_excl *self) +{ + nn_assert (!self->pipe); + nn_assert (!self->inpipe); + nn_assert (!self->outpipe); +} + +int nn_excl_add (struct nn_excl *self, struct nn_pipe *pipe) +{ + /* If there's a connection being used, reject any new connection. */ + if (self->pipe) + return -EISCONN; + + /* Remember that this pipe is the active one. */ + self->pipe = pipe; + + return 0; +} + +void nn_excl_rm (struct nn_excl *self, NN_UNUSED struct nn_pipe *pipe) +{ + nn_assert (self->pipe); + self->pipe = NULL; + self->inpipe = NULL; + self->outpipe = NULL; +} + +void nn_excl_in (struct nn_excl *self, struct nn_pipe *pipe) +{ + nn_assert (!self->inpipe); + nn_assert (pipe == self->pipe); + self->inpipe = pipe; +} + +void nn_excl_out (struct nn_excl *self, struct nn_pipe *pipe) +{ + nn_assert (!self->outpipe); + nn_assert (pipe == self->pipe); + self->outpipe = pipe; +} + +int nn_excl_send (struct nn_excl *self, struct nn_msg *msg) +{ + int rc; + + if (nn_slow (!self->outpipe)) + return -EAGAIN; + + rc = nn_pipe_send (self->outpipe, msg); + errnum_assert (rc >= 0, -rc); + + if (rc & NN_PIPE_RELEASE) + self->outpipe = NULL; + + return rc & ~NN_PIPE_RELEASE; +} + +int nn_excl_recv (struct nn_excl *self, struct nn_msg *msg) +{ + int rc; + + if (nn_slow (!self->inpipe)) + return -EAGAIN; + + rc = nn_pipe_recv (self->inpipe, msg); + errnum_assert (rc >= 0, -rc); + + if (rc & NN_PIPE_RELEASE) + self->inpipe = NULL; + + return rc & ~NN_PIPE_RELEASE; +} + +int nn_excl_can_send (struct nn_excl *self) +{ + return self->outpipe ? 1 : 0; +} + +int nn_excl_can_recv (struct nn_excl *self) +{ + return self->inpipe ? 1 : 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/excl.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/excl.h new file mode 100644 index 0000000..f2d15cd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/excl.h @@ -0,0 +1,58 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_EXCL_INCLUDED +#define NN_EXCL_INCLUDED + +#include "../../protocol.h" + +#include + +/* This is an object to handle a single pipe. To be used by socket types that + can work with precisely one connection, e.g. PAIR. */ + +struct nn_excl { + + /* The pipe being used at the moment. All other pipes will be rejected + until this one terminates. NULL if there is no connected pipe. */ + struct nn_pipe *pipe; + + /* Pipe ready for receiving. It's either equal to 'pipe' or NULL. */ + struct nn_pipe *inpipe; + + /* Pipe ready for sending. It's either equal to 'pipe' or NULL. */ + struct nn_pipe *outpipe; + +}; + +void nn_excl_init (struct nn_excl *self); +void nn_excl_term (struct nn_excl *self); +int nn_excl_add (struct nn_excl *self, struct nn_pipe *pipe); +void nn_excl_rm (struct nn_excl *self, struct nn_pipe *pipe); +void nn_excl_in (struct nn_excl *self, struct nn_pipe *pipe); +void nn_excl_out (struct nn_excl *self, struct nn_pipe *pipe); +int nn_excl_send (struct nn_excl *self, struct nn_msg *msg); +int nn_excl_recv (struct nn_excl *self, struct nn_msg *msg); +int nn_excl_can_send (struct nn_excl *self); +int nn_excl_can_recv (struct nn_excl *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/fq.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/fq.c new file mode 100644 index 0000000..3e91c32 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/fq.c @@ -0,0 +1,84 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "fq.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" + +#include + +void nn_fq_init (struct nn_fq *self) +{ + nn_priolist_init (&self->priolist); +} + +void nn_fq_term (struct nn_fq *self) +{ + nn_priolist_term (&self->priolist); +} + +void nn_fq_add (struct nn_fq *self, struct nn_fq_data *data, + struct nn_pipe *pipe, int priority) +{ + nn_priolist_add (&self->priolist, &data->priodata, pipe, priority); +} + +void nn_fq_rm (struct nn_fq *self, struct nn_fq_data *data) +{ + nn_priolist_rm (&self->priolist, &data->priodata); +} + +void nn_fq_in (struct nn_fq *self, struct nn_fq_data *data) +{ + nn_priolist_activate (&self->priolist, &data->priodata); +} + +int nn_fq_can_recv (struct nn_fq *self) +{ + return nn_priolist_is_active (&self->priolist); +} + +int nn_fq_recv (struct nn_fq *self, struct nn_msg *msg, struct nn_pipe **pipe) +{ + int rc; + struct nn_pipe *p; + + /* Pipe is NULL only when there are no avialable pipes. */ + p = nn_priolist_getpipe (&self->priolist); + if (nn_slow (!p)) + return -EAGAIN; + + /* Receive the messsage. */ + rc = nn_pipe_recv (p, msg); + errnum_assert (rc >= 0, -rc); + + /* Return the pipe data to the user, if required. */ + if (pipe) + *pipe = p; + + /* Move to the next pipe. */ + nn_priolist_advance (&self->priolist, rc & NN_PIPE_RELEASE); + + return rc & ~NN_PIPE_RELEASE; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/fq.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/fq.h new file mode 100644 index 0000000..fd9305b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/fq.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_FQ_INCLUDED +#define NN_FQ_INCLUDED + +#include "../../protocol.h" + +#include "priolist.h" + +/* Fair-queuer. Retrieves messages from a set of pipes in round-robin + manner. */ + +struct nn_fq_data { + struct nn_priolist_data priodata; +}; + +struct nn_fq { + struct nn_priolist priolist; +}; + +void nn_fq_init (struct nn_fq *self); +void nn_fq_term (struct nn_fq *self); +void nn_fq_add (struct nn_fq *self, struct nn_fq_data *data, + struct nn_pipe *pipe, int priority); +void nn_fq_rm (struct nn_fq *self, struct nn_fq_data *data); +void nn_fq_in (struct nn_fq *self, struct nn_fq_data *data); +int nn_fq_can_recv (struct nn_fq *self); +int nn_fq_recv (struct nn_fq *self, struct nn_msg *msg, struct nn_pipe **pipe); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/lb.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/lb.c new file mode 100644 index 0000000..5b68dc9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/lb.c @@ -0,0 +1,88 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "lb.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" + +#include + +void nn_lb_init (struct nn_lb *self) +{ + nn_priolist_init (&self->priolist); +} + +void nn_lb_term (struct nn_lb *self) +{ + nn_priolist_term (&self->priolist); +} + +void nn_lb_add (struct nn_lb *self, struct nn_lb_data *data, + struct nn_pipe *pipe, int priority) +{ + nn_priolist_add (&self->priolist, &data->priodata, pipe, priority); +} + +void nn_lb_rm (struct nn_lb *self, struct nn_lb_data *data) +{ + nn_priolist_rm (&self->priolist, &data->priodata); +} + +void nn_lb_out (struct nn_lb *self, struct nn_lb_data *data) +{ + nn_priolist_activate (&self->priolist, &data->priodata); +} + +int nn_lb_can_send (struct nn_lb *self) +{ + return nn_priolist_is_active (&self->priolist); +} + +int nn_lb_get_priority (struct nn_lb *self) +{ + return nn_priolist_get_priority (&self->priolist); +} + +int nn_lb_send (struct nn_lb *self, struct nn_msg *msg, struct nn_pipe **to) +{ + int rc; + struct nn_pipe *pipe; + + /* Pipe is NULL only when there are no avialable pipes. */ + pipe = nn_priolist_getpipe (&self->priolist); + if (nn_slow (!pipe)) + return -EAGAIN; + + /* Send the messsage. */ + rc = nn_pipe_send (pipe, msg); + errnum_assert (rc >= 0, -rc); + + /* Move to the next pipe. */ + nn_priolist_advance (&self->priolist, rc & NN_PIPE_RELEASE); + + if (to != NULL) + *to = pipe; + + return rc & ~NN_PIPE_RELEASE; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/lb.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/lb.h new file mode 100644 index 0000000..1fc018a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/lb.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_LB_INCLUDED +#define NN_LB_INCLUDED + +#include "../../protocol.h" + +#include "priolist.h" + +/* A load balancer. Round-robins messages to a set of pipes. */ + +struct nn_lb_data { + struct nn_priolist_data priodata; +}; + +struct nn_lb { + struct nn_priolist priolist; +}; + +void nn_lb_init (struct nn_lb *self); +void nn_lb_term (struct nn_lb *self); +void nn_lb_add (struct nn_lb *self, struct nn_lb_data *data, + struct nn_pipe *pipe, int priority); +void nn_lb_rm (struct nn_lb *self, struct nn_lb_data *data); +void nn_lb_out (struct nn_lb *self, struct nn_lb_data *data); +int nn_lb_can_send (struct nn_lb *self); +int nn_lb_get_priority (struct nn_lb *self); +int nn_lb_send (struct nn_lb *self, struct nn_msg *msg, struct nn_pipe **to); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/priolist.c b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/priolist.c new file mode 100644 index 0000000..8d89658 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/priolist.c @@ -0,0 +1,180 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "priolist.h" + +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/err.h" +#include "../../utils/attr.h" + +#include + +void nn_priolist_init (struct nn_priolist *self) +{ + int i; + + for (i = 0; i != NN_PRIOLIST_SLOTS; ++i) { + nn_list_init (&self->slots [i].pipes); + self->slots [i].current = NULL; + } + self->current = -1; +} + +void nn_priolist_term (struct nn_priolist *self) +{ + int i; + + for (i = 0; i != NN_PRIOLIST_SLOTS; ++i) + nn_list_term (&self->slots [i].pipes); +} + +void nn_priolist_add (NN_UNUSED struct nn_priolist *self, + struct nn_priolist_data *data, struct nn_pipe *pipe, int priority) +{ + data->pipe = pipe; + data->priority = priority; + nn_list_item_init (&data->item); +} + +void nn_priolist_rm (struct nn_priolist *self, struct nn_priolist_data *data) +{ + struct nn_priolist_slot *slot; + struct nn_list_item *it; + + /* Non-active pipes don't need any special processing. */ + if (!nn_list_item_isinlist (&data->item)) { + nn_list_item_term (&data->item); + return; + } + + /* If the pipe being removed is not current, we can simply erase it + from the list. */ + slot = &self->slots [data->priority - 1]; + if (slot->current != data) { + nn_list_erase (&slot->pipes, &data->item); + nn_list_item_term (&data->item); + return; + } + + /* Advance the current pointer (with wrap-over). */ + it = nn_list_erase (&slot->pipes, &data->item); + slot->current = nn_cont (it, struct nn_priolist_data, item); + nn_list_item_term (&data->item); + if (!slot->current) { + it = nn_list_begin (&slot->pipes); + slot->current = nn_cont (it, struct nn_priolist_data, item); + } + + /* If we are not messing with the current slot, we are done. */ + if (self->current != data->priority) + return; + + /* Otherwise, the current slot may have become empty and we have switch + to lower priority slots. */ + while (nn_list_empty (&self->slots [self->current - 1].pipes)) { + ++self->current; + if (self->current > NN_PRIOLIST_SLOTS) { + self->current = -1; + return; + } + } +} + +void nn_priolist_activate (struct nn_priolist *self, + struct nn_priolist_data *data) +{ + struct nn_priolist_slot *slot; + + slot = &self->slots [data->priority - 1]; + + /* If there are already some elements in this slot, current pipe is not + going to change. */ + if (!nn_list_empty (&slot->pipes)) { + nn_list_insert (&slot->pipes, &data->item, nn_list_end (&slot->pipes)); + return; + } + + /* Add first pipe into the slot. If there are no pipes in priolist at all + this slot becomes current. */ + nn_list_insert (&slot->pipes, &data->item, nn_list_end (&slot->pipes)); + slot->current = data; + if (self->current == -1) { + self->current = data->priority; + return; + } + + /* If the current priority is lower than the one of the newly activated + pipe, this slot becomes current. */ + if (self->current > data->priority) { + self->current = data->priority; + return; + } + + /* Current doesn't change otherwise. */ +} + +int nn_priolist_is_active (struct nn_priolist *self) +{ + return self->current == -1 ? 0 : 1; +} + +struct nn_pipe *nn_priolist_getpipe (struct nn_priolist *self) +{ + if (nn_slow (self->current == -1)) + return NULL; + return self->slots [self->current - 1].current->pipe; +} + +void nn_priolist_advance (struct nn_priolist *self, int release) +{ + struct nn_priolist_slot *slot; + struct nn_list_item *it; + + nn_assert (self->current > 0); + slot = &self->slots [self->current - 1]; + + /* Move slot's current pointer to the next pipe. */ + if (release) + it = nn_list_erase (&slot->pipes, &slot->current->item); + else + it = nn_list_next (&slot->pipes, &slot->current->item); + if (!it) + it = nn_list_begin (&slot->pipes); + slot->current = nn_cont (it, struct nn_priolist_data, item); + + /* If there are no more pipes in this slot, find a non-empty slot with + lower priority. */ + while (nn_list_empty (&slot->pipes)) { + ++self->current; + if (self->current > NN_PRIOLIST_SLOTS) { + self->current = -1; + return; + } + slot = &self->slots [self->current - 1]; + } +} + +int nn_priolist_get_priority (struct nn_priolist *self) { + return self->current; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/priolist.h b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/priolist.h new file mode 100644 index 0000000..a68491c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/protocols/utils/priolist.h @@ -0,0 +1,102 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PRIOLIST_INCLUDED +#define NN_PRIOLIST_INCLUDED + +#include "../../protocol.h" + +#include "../../utils/list.h" + +/* Prioritised list of pipes. */ + +#define NN_PRIOLIST_SLOTS 16 + +struct nn_priolist_data { + + /* The underlying pipe itself. */ + struct nn_pipe *pipe; + + /* Priority the pipe is assigned. Using this value we can find the + nn_priolist_slot object that owns this pipe. */ + int priority; + + /* The structure is a member in nn_priolist_slot's 'pipes' list. */ + struct nn_list_item item; +}; + +struct nn_priolist_slot { + + /* The list of pipes on particular priority level. */ + struct nn_list pipes; + + /* Pointer to the current pipe within the priority level. If there's no + pipe available, the field is set to NULL. */ + struct nn_priolist_data *current; +}; + +struct nn_priolist { + + /* Each slot holds pipes for a particular priority level. */ + struct nn_priolist_slot slots [NN_PRIOLIST_SLOTS]; + + /* The index of the slot holding the current pipe. It should be the + highest-priority non-empty slot available. If there's no available + pipe, this field is set to -1. */ + int current; +}; + +/* Initialise the list. */ +void nn_priolist_init (struct nn_priolist *self); + +/* Terminate the list. The list must be empty before it's terminated. */ +void nn_priolist_term (struct nn_priolist *self); + +/* Add a new pipe to the list with a particular priority level. The pipe + is not active at this point. Use nn_priolist_activate to activate it. */ +void nn_priolist_add (struct nn_priolist *self, struct nn_priolist_data *data, + struct nn_pipe *pipe, int priority); + +/* Remove the pipe from the list. */ +void nn_priolist_rm (struct nn_priolist *self, struct nn_priolist_data *data); + +/* Activates a non-active pipe. The pipe must be added to the list prior to + calling this function. */ +void nn_priolist_activate (struct nn_priolist *self, struct nn_priolist_data *data); + +/* Returns 1 if there's at least a single active pipe in the list, + 0 otherwise. */ +int nn_priolist_is_active (struct nn_priolist *self); + +/* Get the pointer to the current pipe. If there's no pipe in the list, + NULL is returned. */ +struct nn_pipe *nn_priolist_getpipe (struct nn_priolist *self); + +/* Moves to the next pipe in the list. If 'release' is set to 1, the current + pipe is removed from the list. To re-insert it into the list use + nn_priolist_activate function. */ +void nn_priolist_advance (struct nn_priolist *self, int release); + +/* Returns current priority. Used for statistics only */ +int nn_priolist_get_priority (struct nn_priolist *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/pubsub.h b/node/node_modules/nanomsg/deps/nanomsg/src/pubsub.h new file mode 100644 index 0000000..04abb4f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/pubsub.h @@ -0,0 +1,43 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef PUBSUB_H_INCLUDED +#define PUBSUB_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_PROTO_PUBSUB 2 + +#define NN_PUB (NN_PROTO_PUBSUB * 16 + 0) +#define NN_SUB (NN_PROTO_PUBSUB * 16 + 1) + +#define NN_SUB_SUBSCRIBE 1 +#define NN_SUB_UNSUBSCRIBE 2 + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/reqrep.h b/node/node_modules/nanomsg/deps/nanomsg/src/reqrep.h new file mode 100644 index 0000000..fea7a7e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/reqrep.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef REQREP_H_INCLUDED +#define REQREP_H_INCLUDED + +#include "nn.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_PROTO_REQREP 3 + +#define NN_REQ (NN_PROTO_REQREP * 16 + 0) +#define NN_REP (NN_PROTO_REQREP * 16 + 1) + +#define NN_REQ_RESEND_IVL 1 + +typedef union nn_req_handle { + int i; + void *ptr; +} nn_req_handle; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/survey.h b/node/node_modules/nanomsg/deps/nanomsg/src/survey.h new file mode 100644 index 0000000..ad594aa --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/survey.h @@ -0,0 +1,46 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef SURVEY_H_INCLUDED +#define SURVEY_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_PROTO_SURVEY 6 + +/* NB: Version 0 used 16 + 0/1. That version lacked backtraces, and so + is wire-incompatible with this version. */ + +#define NN_SURVEYOR (NN_PROTO_SURVEY * 16 + 2) +#define NN_RESPONDENT (NN_PROTO_SURVEY * 16 + 3) + +#define NN_SURVEYOR_DEADLINE 1 + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/tcp.h b/node/node_modules/nanomsg/deps/nanomsg/src/tcp.h new file mode 100644 index 0000000..1d90776 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/tcp.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef TCP_H_INCLUDED +#define TCP_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_TCP -3 + +#define NN_TCP_NODELAY 1 + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transport.h b/node/node_modules/nanomsg/deps/nanomsg/src/transport.h new file mode 100644 index 0000000..d56a77a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transport.h @@ -0,0 +1,244 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_TRANSPORT_INCLUDED +#define NN_TRANSPORT_INCLUDED + +#include "nn.h" + +#include "aio/fsm.h" + +#include "utils/list.h" +#include "utils/msg.h" + +#include + +/* This is the API between the nanomsg core and individual transports. */ + +struct nn_sock; +struct nn_cp; + +/******************************************************************************/ +/* Container for transport-specific socket options. */ +/******************************************************************************/ + +struct nn_optset; + +struct nn_optset_vfptr { + void (*destroy) (struct nn_optset *self); + int (*setopt) (struct nn_optset *self, int option, const void *optval, + size_t optvallen); + int (*getopt) (struct nn_optset *self, int option, void *optval, + size_t *optvallen); +}; + +struct nn_optset { + const struct nn_optset_vfptr *vfptr; +}; + +/******************************************************************************/ +/* The base class for endpoints. */ +/******************************************************************************/ + +/* The best way to think about endpoints is that endpoint is an object created + by each nn_bind() or nn_connect() call. Each endpoint is associated with + exactly one address string (e.g. "tcp://127.0.0.1:5555"). */ + +struct nn_epbase; + +struct nn_epbase_vfptr { + + /* Ask the endpoint to stop itself. The endpoint is allowed to linger + to send the pending outbound data. When done, it reports the fact by + invoking nn_epbase_stopped() function. */ + void (*stop) (struct nn_epbase *self); + + /* Deallocate the endpoint object. */ + void (*destroy) (struct nn_epbase *self); +}; + +struct nn_epbase { + const struct nn_epbase_vfptr *vfptr; + struct nn_ep *ep; +}; + +/* Creates a new endpoint. 'hint' parameter is an opaque value that + was passed to transport's bind or connect function. */ +void nn_epbase_init (struct nn_epbase *self, + const struct nn_epbase_vfptr *vfptr, void *hint); + +/* Notify the user that stopping is done. */ +void nn_epbase_stopped (struct nn_epbase *self); + +/* Terminate the epbase object. */ +void nn_epbase_term (struct nn_epbase *self); + +/* Returns the AIO context associated with the endpoint. */ +struct nn_ctx *nn_epbase_getctx (struct nn_epbase *self); + +/* Returns the address string associated with this endpoint. */ +const char *nn_epbase_getaddr (struct nn_epbase *self); + +/* Retrieve value of a socket option. */ +void nn_epbase_getopt (struct nn_epbase *self, int level, int option, + void *optval, size_t *optvallen); + +/* Returns 1 is the specified socket type is a valid peer for this socket, + or 0 otherwise. */ +int nn_epbase_ispeer (struct nn_epbase *self, int socktype); + +/* Notifies a monitoring system the error on this endpoint */ +void nn_epbase_set_error(struct nn_epbase *self, int errnum); + +/* Notifies a monitoring system that error is gone */ +void nn_epbase_clear_error(struct nn_epbase *self); + +/* Increments statistics counters in the socket structure */ +void nn_epbase_stat_increment(struct nn_epbase *self, int name, int increment); + + +/******************************************************************************/ +/* The base class for pipes. */ +/******************************************************************************/ + +/* Pipe represents one "connection", i.e. perfectly ordered uni- or + bi-directional stream of messages. One endpoint can create multiple pipes + (for example, bound TCP socket is an endpoint, individual accepted TCP + connections are represented by pipes. */ + +struct nn_pipebase; + +/* This value is returned by pipe's send and recv functions to signalise that + more sends/recvs are not possible at the moment. From that moment on, + the core will stop invoking the function. To re-establish the message + flow nn_pipebase_received (respectively nn_pipebase_sent) should + be called. */ +#define NN_PIPEBASE_RELEASE 1 + +/* Specifies that received message is already split into header and body. + This flag is used only by inproc transport to avoid merging and re-splitting + the messages passed with a single process. */ +#define NN_PIPEBASE_PARSED 2 + +struct nn_pipebase_vfptr { + + /* Send a message to the network. The function can return either error + (negative number) or any combination of the flags defined above. */ + int (*send) (struct nn_pipebase *self, struct nn_msg *msg); + + /* Receive a message from the network. The function can return either error + (negative number) or any combination of the flags defined above. */ + int (*recv) (struct nn_pipebase *self, struct nn_msg *msg); +}; + +/* Endpoint specific options. Same restrictions as for nn_pipebase apply */ +struct nn_ep_options +{ + int sndprio; + int rcvprio; + int ipv4only; +}; + +/* The member of this structure are used internally by the core. Never use + or modify them directly from the transport. */ +struct nn_pipebase { + struct nn_fsm fsm; + const struct nn_pipebase_vfptr *vfptr; + uint8_t state; + uint8_t instate; + uint8_t outstate; + struct nn_sock *sock; + void *data; + struct nn_fsm_event in; + struct nn_fsm_event out; + struct nn_ep_options options; +}; + +/* Initialise the pipe. */ +void nn_pipebase_init (struct nn_pipebase *self, + const struct nn_pipebase_vfptr *vfptr, struct nn_epbase *epbase); + +/* Terminate the pipe. */ +void nn_pipebase_term (struct nn_pipebase *self); + +/* Call this function once the connection is established. */ +int nn_pipebase_start (struct nn_pipebase *self); + +/* Call this function once the connection is broken. */ +void nn_pipebase_stop (struct nn_pipebase *self); + +/* Call this function when new message was fully received. */ +void nn_pipebase_received (struct nn_pipebase *self); + +/* Call this function when current outgoing message was fully sent. */ +void nn_pipebase_sent (struct nn_pipebase *self); + +/* Retrieve value of a socket option. */ +void nn_pipebase_getopt (struct nn_pipebase *self, int level, int option, + void *optval, size_t *optvallen); + +/* Returns 1 is the specified socket type is a valid peer for this socket, + or 0 otherwise. */ +int nn_pipebase_ispeer (struct nn_pipebase *self, int socktype); + +/******************************************************************************/ +/* The transport class. */ +/******************************************************************************/ + +struct nn_transport { + + /* Name of the transport as it appears in the connection strings ("tcp", + "ipc", "inproc" etc. */ + const char *name; + + /* ID of the transport. */ + int id; + + /* Following methods are guarded by a global critical section. Two of these + function will never be invoked in parallel. The first is called when + the library is initialised, the second one when it is terminated, i.e. + when there are no more open sockets. Either of them can be set to NULL + if no specific initialisation/termination is needed. */ + void (*init) (void); + void (*term) (void); + + /* Each of these functions creates an endpoint and returns the newly + created endpoint in 'epbase' parameter. 'hint' is in opaque pointer + to be passed to nn_epbase_init(). The epbase object can then be used + to retrieve the address to bind/connect to. These functions are guarded + by a socket-wide critical section. Two of these function will never be + invoked in parallel on the same socket. */ + int (*bind) (void *hint, struct nn_epbase **epbase); + int (*connect) (void *hint, struct nn_epbase **epbase); + + /* Create an object to hold transport-specific socket options. + Set this member to NULL in case there are no transport-specific + socket options available. */ + struct nn_optset *(*optset) (void); + + /* This member is used exclusively by the core. Never touch it directly + from the transport. */ + struct nn_list_item item; +}; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/README b/node/node_modules/nanomsg/deps/nanomsg/src/transports/README new file mode 100644 index 0000000..06230bb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/README @@ -0,0 +1,2 @@ +This directory contains all the available transport mechanisms such as +in-process message transfer, IPC or TCP. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/binproc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/binproc.c new file mode 100644 index 0000000..af96045 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/binproc.c @@ -0,0 +1,249 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "binproc.h" +#include "sinproc.h" +#include "cinproc.h" +#include "ins.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/alloc.h" + +#define NN_BINPROC_STATE_IDLE 1 +#define NN_BINPROC_STATE_ACTIVE 2 +#define NN_BINPROC_STATE_STOPPING 3 + +#define NN_BINPROC_SRC_SINPROC 1 + +/* Implementation of nn_epbase interface. */ +static void nn_binproc_stop (struct nn_epbase *self); +static void nn_binproc_destroy (struct nn_epbase *self); +static const struct nn_epbase_vfptr nn_binproc_vfptr = { + nn_binproc_stop, + nn_binproc_destroy +}; + +/* Private functions. */ +static void nn_binproc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_binproc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_binproc_connect (struct nn_ins_item *self, + struct nn_ins_item *peer); + + +int nn_binproc_create (void *hint, struct nn_epbase **epbase) +{ + int rc; + struct nn_binproc *self; + + self = nn_alloc (sizeof (struct nn_binproc), "binproc"); + alloc_assert (self); + + nn_ins_item_init (&self->item, &nn_binproc_vfptr, hint); + nn_fsm_init_root (&self->fsm, nn_binproc_handler, nn_binproc_shutdown, + nn_epbase_getctx (&self->item.epbase)); + self->state = NN_BINPROC_STATE_IDLE; + nn_list_init (&self->sinprocs); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + /* Register the inproc endpoint into a global repository. */ + rc = nn_ins_bind (&self->item, nn_binproc_connect); + if (nn_slow (rc < 0)) { + nn_list_term (&self->sinprocs); + + /* TODO: Now, this is ugly! We are getting the state machine into + the idle state manually. How should it be done correctly? */ + self->fsm.state = 1; + nn_fsm_term (&self->fsm); + + nn_ins_item_term (&self->item); + nn_free (self); + return rc; + } + + *epbase = &self->item.epbase; + return 0; +} + +static void nn_binproc_stop (struct nn_epbase *self) +{ + struct nn_binproc *binproc; + + binproc = nn_cont (self, struct nn_binproc, item.epbase); + + nn_fsm_stop (&binproc->fsm); +} + +static void nn_binproc_destroy (struct nn_epbase *self) +{ + struct nn_binproc *binproc; + + binproc = nn_cont (self, struct nn_binproc, item.epbase); + + nn_list_term (&binproc->sinprocs); + nn_fsm_term (&binproc->fsm); + nn_ins_item_term (&binproc->item); + + nn_free (binproc); +} + +static void nn_binproc_connect (struct nn_ins_item *self, + struct nn_ins_item *peer) +{ + struct nn_binproc *binproc; + struct nn_cinproc *cinproc; + struct nn_sinproc *sinproc; + + binproc = nn_cont (self, struct nn_binproc, item); + cinproc = nn_cont (peer, struct nn_cinproc, item); + + nn_assert_state (binproc, NN_BINPROC_STATE_ACTIVE); + + sinproc = nn_alloc (sizeof (struct nn_sinproc), "sinproc"); + alloc_assert (sinproc); + nn_sinproc_init (sinproc, NN_BINPROC_SRC_SINPROC, + &binproc->item.epbase, &binproc->fsm); + nn_list_insert (&binproc->sinprocs, &sinproc->item, + nn_list_end (&binproc->sinprocs)); + nn_sinproc_connect (sinproc, &cinproc->fsm); + + nn_epbase_stat_increment (&binproc->item.epbase, + NN_STAT_ACCEPTED_CONNECTIONS, 1); +} + +static void nn_binproc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_binproc *binproc; + struct nn_list_item *it; + struct nn_sinproc *sinproc; + + binproc = nn_cont (self, struct nn_binproc, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + + /* First, unregister the endpoint from the global repository of inproc + endpoints. This way, new connections cannot be created anymore. */ + nn_ins_unbind (&binproc->item); + + /* Stop the existing connections. */ + for (it = nn_list_begin (&binproc->sinprocs); + it != nn_list_end (&binproc->sinprocs); + it = nn_list_next (&binproc->sinprocs, it)) { + sinproc = nn_cont (it, struct nn_sinproc, item); + nn_sinproc_stop (sinproc); + } + + binproc->state = NN_BINPROC_STATE_STOPPING; + goto finish; + } + if (nn_slow (binproc->state == NN_BINPROC_STATE_STOPPING)) { + nn_assert (src == NN_BINPROC_SRC_SINPROC && type == NN_SINPROC_STOPPED); + sinproc = (struct nn_sinproc*) srcptr; + nn_list_erase (&binproc->sinprocs, &sinproc->item); + nn_sinproc_term (sinproc); + nn_free (sinproc); +finish: + if (!nn_list_empty (&binproc->sinprocs)) + return; + binproc->state = NN_BINPROC_STATE_IDLE; + nn_fsm_stopped_noevent (&binproc->fsm); + nn_epbase_stopped (&binproc->item.epbase); + return; + } + + nn_fsm_bad_state(binproc->state, src, type); +} + +static void nn_binproc_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_binproc *binproc; + struct nn_sinproc *peer; + struct nn_sinproc *sinproc; + + binproc = nn_cont (self, struct nn_binproc, fsm); + + switch (binproc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_BINPROC_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + binproc->state = NN_BINPROC_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (binproc->state, src, type); + } + + default: + nn_fsm_bad_source (binproc->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_BINPROC_STATE_ACTIVE: + switch (src) { + + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_CONNECT: + peer = (struct nn_sinproc*) srcptr; + sinproc = nn_alloc (sizeof (struct nn_sinproc), "sinproc"); + alloc_assert (sinproc); + nn_sinproc_init (sinproc, NN_BINPROC_SRC_SINPROC, + &binproc->item.epbase, &binproc->fsm); + nn_list_insert (&binproc->sinprocs, &sinproc->item, + nn_list_end (&binproc->sinprocs)); + nn_sinproc_accept (sinproc, peer); + return; + default: + nn_fsm_bad_action (binproc->state, src, type); + } + + case NN_BINPROC_SRC_SINPROC: + return; + + default: + nn_fsm_bad_source (binproc->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (binproc->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/binproc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/binproc.h new file mode 100644 index 0000000..4516bfa --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/binproc.h @@ -0,0 +1,51 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BINPROC_INCLUDED +#define NN_BINPROC_INCLUDED + +#include "ins.h" + +#include "../../transport.h" + +#include "../../aio/fsm.h" + +#include "../../utils/list.h" + +struct nn_cinproc; + +struct nn_binproc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is registered with nn_ins. */ + struct nn_ins_item item; + + /* The list of inproc sessions owned by this object. */ + struct nn_list sinprocs; +}; + +int nn_binproc_create (void *hint, struct nn_epbase **epbase); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.c new file mode 100644 index 0000000..997588b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.c @@ -0,0 +1,250 @@ + /* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "cinproc.h" +#include "binproc.h" +#include "ins.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/attr.h" + +#include + +#define NN_CINPROC_STATE_IDLE 1 +#define NN_CINPROC_STATE_DISCONNECTED 2 +#define NN_CINPROC_STATE_ACTIVE 3 +#define NN_CINPROC_STATE_STOPPING 4 + +#define NN_CINPROC_ACTION_CONNECT 1 + +#define NN_CINPROC_SRC_SINPROC 1 + +/* Implementation of nn_epbase callback interface. */ +static void nn_cinproc_stop (struct nn_epbase *self); +static void nn_cinproc_destroy (struct nn_epbase *self); +static const struct nn_epbase_vfptr nn_cinproc_vfptr = { + nn_cinproc_stop, + nn_cinproc_destroy +}; + +/* Private functions. */ +static void nn_cinproc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_cinproc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_cinproc_connect (struct nn_ins_item *self, + struct nn_ins_item *peer); + +int nn_cinproc_create (void *hint, struct nn_epbase **epbase) +{ + struct nn_cinproc *self; + + self = nn_alloc (sizeof (struct nn_cinproc), "cinproc"); + alloc_assert (self); + + nn_ins_item_init (&self->item, &nn_cinproc_vfptr, hint); + nn_fsm_init_root (&self->fsm, nn_cinproc_handler, nn_cinproc_shutdown, + nn_epbase_getctx (&self->item.epbase)); + self->state = NN_CINPROC_STATE_IDLE; + nn_sinproc_init (&self->sinproc, NN_CINPROC_SRC_SINPROC, + &self->item.epbase, &self->fsm); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + /* Register the inproc endpoint into a global repository. */ + nn_ins_connect (&self->item, nn_cinproc_connect); + + *epbase = &self->item.epbase; + return 0; +} + +static void nn_cinproc_stop (struct nn_epbase *self) +{ + struct nn_cinproc *cinproc; + + cinproc = nn_cont (self, struct nn_cinproc, item.epbase); + + nn_fsm_stop (&cinproc->fsm); +} + +static void nn_cinproc_destroy (struct nn_epbase *self) +{ + struct nn_cinproc *cinproc; + + cinproc = nn_cont (self, struct nn_cinproc, item.epbase); + + nn_sinproc_term (&cinproc->sinproc); + nn_fsm_term (&cinproc->fsm); + nn_ins_item_term (&cinproc->item); + + nn_free (cinproc); +} + +static void nn_cinproc_connect (struct nn_ins_item *self, + struct nn_ins_item *peer) +{ + struct nn_cinproc *cinproc; + struct nn_binproc *binproc; + + cinproc = nn_cont (self, struct nn_cinproc, item); + binproc = nn_cont (peer, struct nn_binproc, item); + + nn_assert_state (cinproc, NN_CINPROC_STATE_DISCONNECTED); + nn_sinproc_connect (&cinproc->sinproc, &binproc->fsm); + nn_fsm_action (&cinproc->fsm, NN_CINPROC_ACTION_CONNECT); +} + +static void nn_cinproc_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_cinproc *cinproc; + + cinproc = nn_cont (self, struct nn_cinproc, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + + /* First, unregister the endpoint from the global repository of inproc + endpoints. This way, new connections cannot be created anymore. */ + nn_ins_disconnect (&cinproc->item); + + /* Stop the existing connection. */ + nn_sinproc_stop (&cinproc->sinproc); + cinproc->state = NN_CINPROC_STATE_STOPPING; + } + if (nn_slow (cinproc->state == NN_CINPROC_STATE_STOPPING)) { + if (!nn_sinproc_isidle (&cinproc->sinproc)) + return; + cinproc->state = NN_CINPROC_STATE_IDLE; + nn_fsm_stopped_noevent (&cinproc->fsm); + nn_epbase_stopped (&cinproc->item.epbase); + return; + } + + nn_fsm_bad_state(cinproc->state, src, type); +} + +static void nn_cinproc_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_cinproc *cinproc; + struct nn_sinproc *sinproc; + + cinproc = nn_cont (self, struct nn_cinproc, fsm); + + + switch (cinproc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_CINPROC_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + cinproc->state = NN_CINPROC_STATE_DISCONNECTED; + nn_epbase_stat_increment (&cinproc->item.epbase, + NN_STAT_INPROGRESS_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (cinproc->state, src, type); + } + + default: + nn_fsm_bad_source (cinproc->state, src, type); + } + +/******************************************************************************/ +/* DISCONNECTED state. */ +/******************************************************************************/ + case NN_CINPROC_STATE_DISCONNECTED: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_CINPROC_ACTION_CONNECT: + cinproc->state = NN_CINPROC_STATE_ACTIVE; + nn_epbase_stat_increment (&cinproc->item.epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&cinproc->item.epbase, + NN_STAT_ESTABLISHED_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (cinproc->state, src, type); + } + + case NN_SINPROC_SRC_PEER: + sinproc = (struct nn_sinproc*) srcptr; + switch (type) { + case NN_SINPROC_CONNECT: + nn_sinproc_accept (&cinproc->sinproc, sinproc); + cinproc->state = NN_CINPROC_STATE_ACTIVE; + nn_epbase_stat_increment (&cinproc->item.epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&cinproc->item.epbase, + NN_STAT_ESTABLISHED_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (cinproc->state, src, type); + } + + default: + nn_fsm_bad_source (cinproc->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_CINPROC_STATE_ACTIVE: + switch (src) { + case NN_CINPROC_SRC_SINPROC: + switch (type) { + case NN_SINPROC_DISCONNECT: + cinproc->state = NN_CINPROC_STATE_DISCONNECTED; + nn_epbase_stat_increment (&cinproc->item.epbase, + NN_STAT_INPROGRESS_CONNECTIONS, 1); + + nn_sinproc_init (&cinproc->sinproc, NN_CINPROC_SRC_SINPROC, + &cinproc->item.epbase, &cinproc->fsm); + return; + + default: + nn_fsm_bad_action (cinproc->state, src, type); + } + + default: + nn_fsm_bad_source (cinproc->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (cinproc->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.h new file mode 100644 index 0000000..bccaed0 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/cinproc.h @@ -0,0 +1,49 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CINPROC_INCLUDED +#define NN_CINPROC_INCLUDED + +#include "ins.h" +#include "sinproc.h" + +#include "../../transport.h" + +#include "../../aio/fsm.h" + +struct nn_cinproc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is registered with nn_ins. */ + struct nn_ins_item item; + + /* The actual inproc session. */ + struct nn_sinproc sinproc; +}; + +int nn_cinproc_create (void *hint, struct nn_epbase **epbase); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/inproc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/inproc.c new file mode 100644 index 0000000..9f994f5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/inproc.c @@ -0,0 +1,71 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "inproc.h" +#include "ins.h" +#include "binproc.h" +#include "cinproc.h" + +#include "../../inproc.h" + +#include + +/* nn_transport interface. */ +static void nn_inproc_init (void); +static void nn_inproc_term (void); +static int nn_inproc_bind (void *hint, struct nn_epbase **epbase); +static int nn_inproc_connect (void *hint, struct nn_epbase **epbase); + +static struct nn_transport nn_inproc_vfptr = { + "inproc", + NN_INPROC, + nn_inproc_init, + nn_inproc_term, + nn_inproc_bind, + nn_inproc_connect, + NULL, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_transport *nn_inproc = &nn_inproc_vfptr; + +static void nn_inproc_init (void) +{ + nn_ins_init (); +} + +static void nn_inproc_term (void) +{ + nn_ins_term (); +} + +static int nn_inproc_bind (void *hint, struct nn_epbase **epbase) +{ + return nn_binproc_create (hint, epbase); +} + +static int nn_inproc_connect (void *hint, struct nn_epbase **epbase) +{ + return nn_cinproc_create (hint, epbase); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/inproc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/inproc.h new file mode 100644 index 0000000..0486dff --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/inproc.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_INPROC_INCLUDED +#define NN_INPROC_INCLUDED + +#include "../../transport.h" + +extern struct nn_transport *nn_inproc; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/ins.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/ins.c new file mode 100644 index 0000000..b8e08eb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/ins.c @@ -0,0 +1,174 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ins.h" + +#include "../../utils/mutex.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/err.h" + +struct nn_ins { + + /* Synchronises access to this object. */ + struct nn_mutex sync; + + /* List of all bound inproc endpoints. */ + /* TODO: O(n) lookup, shouldn't we do better? Hash? */ + struct nn_list bound; + + /* List of all connected inproc endpoints. */ + /* TODO: O(n) lookup, shouldn't we do better? Hash? */ + struct nn_list connected; +}; + +/* Global instance of the nn_ins object. It contains the lists of all + inproc endpoints in the current process. */ +static struct nn_ins self; + +void nn_ins_item_init (struct nn_ins_item *self, + const struct nn_epbase_vfptr *vfptr, void *hint) +{ + size_t sz; + + nn_epbase_init (&self->epbase, vfptr, hint); + nn_list_item_init (&self->item); + sz = sizeof (self->protocol); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_PROTOCOL, + &self->protocol, &sz); + nn_assert (sz == sizeof (self->protocol)); +} + +void nn_ins_item_term (struct nn_ins_item *self) +{ + nn_list_item_term (&self->item); + nn_epbase_term (&self->epbase); +} + +void nn_ins_init (void) +{ + nn_mutex_init (&self.sync); + nn_list_init (&self.bound); + nn_list_init (&self.connected); +} +void nn_ins_term (void) +{ + nn_list_term (&self.connected); + nn_list_term (&self.bound); + nn_mutex_term (&self.sync); +} + +int nn_ins_bind (struct nn_ins_item *item, nn_ins_fn fn) +{ + struct nn_list_item *it; + struct nn_ins_item *bitem; + struct nn_ins_item *citem; + + nn_mutex_lock (&self.sync); + + /* Check whether the endpoint isn't already bound. */ + /* TODO: This is an O(n) algorithm! */ + for (it = nn_list_begin (&self.bound); it != nn_list_end (&self.bound); + it = nn_list_next (&self.bound, it)) { + bitem = nn_cont (it, struct nn_ins_item, item); + if (strncmp (nn_epbase_getaddr (&item->epbase), + nn_epbase_getaddr (&bitem->epbase), NN_SOCKADDR_MAX) == 0) { + nn_mutex_unlock (&self.sync); + return -EADDRINUSE; + } + } + + /* Insert the entry into the endpoint repository. */ + nn_list_insert (&self.bound, &item->item, + nn_list_end (&self.bound)); + + /* During this process new pipes may be created. */ + for (it = nn_list_begin (&self.connected); + it != nn_list_end (&self.connected); + it = nn_list_next (&self.connected, it)) { + citem = nn_cont (it, struct nn_ins_item, item); + if (strncmp (nn_epbase_getaddr (&item->epbase), + nn_epbase_getaddr (&citem->epbase), NN_SOCKADDR_MAX) == 0) { + + /* Check whether the two sockets are compatible. */ + if (!nn_epbase_ispeer (&item->epbase, citem->protocol)) + continue; + + fn (item, citem); + } + } + + nn_mutex_unlock (&self.sync); + + return 0; +} + +void nn_ins_connect (struct nn_ins_item *item, nn_ins_fn fn) +{ + struct nn_list_item *it; + struct nn_ins_item *bitem; + + nn_mutex_lock (&self.sync); + + /* Insert the entry into the endpoint repository. */ + nn_list_insert (&self.connected, &item->item, + nn_list_end (&self.connected)); + + /* During this process a pipe may be created. */ + for (it = nn_list_begin (&self.bound); + it != nn_list_end (&self.bound); + it = nn_list_next (&self.bound, it)) { + bitem = nn_cont (it, struct nn_ins_item, item); + if (strncmp (nn_epbase_getaddr (&item->epbase), + nn_epbase_getaddr (&bitem->epbase), NN_SOCKADDR_MAX) == 0) { + + /* Check whether the two sockets are compatible. */ + if (!nn_epbase_ispeer (&item->epbase, bitem->protocol)) + break; + + /* Call back to cinproc to create actual connection. */ + fn (item, bitem); + + break; + } + } + + nn_mutex_unlock (&self.sync); +} + +void nn_ins_disconnect (struct nn_ins_item *item) +{ + nn_mutex_lock (&self.sync); + nn_list_erase (&self.connected, &item->item); + nn_mutex_unlock (&self.sync); +} + +void nn_ins_unbind (struct nn_ins_item *item) +{ + nn_mutex_lock (&self.sync); + nn_list_erase (&self.bound, &item->item); + nn_mutex_unlock (&self.sync); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/ins.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/ins.h new file mode 100644 index 0000000..04034fb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/ins.h @@ -0,0 +1,60 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_INS_INCLUDED +#define NN_INS_INCLUDED + +#include "../../transport.h" + +#include "../../utils/list.h" + +/* Inproc naming system. A global repository of inproc endpoints. */ + +struct nn_ins_item { + + /* Every ins_item is an endpoint. */ + struct nn_epbase epbase; + + /* Every ins_item is either in the list of bound or connected endpoints. */ + struct nn_list_item item; + + /* This is the local cache of the endpoint's protocol ID. This way we can + check the value without actually locking the object. */ + int protocol; +}; + +void nn_ins_item_init (struct nn_ins_item *self, + const struct nn_epbase_vfptr *vfptr, void *hint); +void nn_ins_item_term (struct nn_ins_item *self); + +void nn_ins_init (void); +void nn_ins_term (void); + +typedef void (*nn_ins_fn) (struct nn_ins_item *self, struct nn_ins_item *peer); + +int nn_ins_bind (struct nn_ins_item *item, nn_ins_fn fn); +void nn_ins_connect (struct nn_ins_item *item, nn_ins_fn fn); +void nn_ins_disconnect (struct nn_ins_item *item); +void nn_ins_unbind (struct nn_ins_item *item); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.c new file mode 100644 index 0000000..a55c8ef --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.c @@ -0,0 +1,147 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "msgqueue.h" + +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/err.h" + +#include + +void nn_msgqueue_init (struct nn_msgqueue *self, size_t maxmem) +{ + struct nn_msgqueue_chunk *chunk; + + self->count = 0; + self->mem = 0; + self->maxmem = maxmem; + + chunk = nn_alloc (sizeof (struct nn_msgqueue_chunk), "msgqueue chunk"); + alloc_assert (chunk); + chunk->next = NULL; + + self->out.chunk = chunk; + self->out.pos = 0; + self->in.chunk = chunk; + self->in.pos = 0; + + self->cache = NULL; +} + +void nn_msgqueue_term (struct nn_msgqueue *self) +{ + int rc; + struct nn_msg msg; + + /* Deallocate messages in the pipe. */ + while (1) { + rc = nn_msgqueue_recv (self, &msg); + if (rc == -EAGAIN) + break; + errnum_assert (rc >= 0, -rc); + nn_msg_term (&msg); + } + + /* There are no more messages in the pipe so there's at most one chunk + in the queue. Deallocate it. */ + nn_assert (self->in.chunk == self->out.chunk); + nn_free (self->in.chunk); + + /* Deallocate the cached chunk, if any. */ + if (self->cache) + nn_free (self->cache); +} + +int nn_msgqueue_empty (struct nn_msgqueue *self) +{ + return self->count == 0 ? 1 : 0; +} + +int nn_msgqueue_send (struct nn_msgqueue *self, struct nn_msg *msg) +{ + size_t msgsz; + + /* By allowing one message of arbitrary size to be written to the queue, + we allow even messages that exceed max buffer size to pass through. + Beyond that we'll apply the buffer limit as specified by the user. */ + msgsz = nn_chunkref_size (&msg->sphdr) + nn_chunkref_size (&msg->body); + if (nn_slow (self->count > 0 && self->mem + msgsz >= self->maxmem)) + return -EAGAIN; + + /* Adjust the statistics. */ + ++self->count; + self->mem += msgsz; + + /* Move the content of the message to the pipe. */ + nn_msg_mv (&self->out.chunk->msgs [self->out.pos], msg); + ++self->out.pos; + + /* If there's no space for a new message in the pipe, either re-use + the cache chunk or allocate a new chunk if it does not exist. */ + if (nn_slow (self->out.pos == NN_MSGQUEUE_GRANULARITY)) { + if (nn_slow (!self->cache)) { + self->cache = nn_alloc (sizeof (struct nn_msgqueue_chunk), + "msgqueue chunk"); + alloc_assert (self->cache); + self->cache->next = NULL; + } + self->out.chunk->next = self->cache; + self->out.chunk = self->cache; + self->cache = NULL; + self->out.pos = 0; + } + + return 0; +} + +int nn_msgqueue_recv (struct nn_msgqueue *self, struct nn_msg *msg) +{ + struct nn_msgqueue_chunk *o; + + /* If there is no message in the queue. */ + if (nn_slow (!self->count)) + return -EAGAIN; + + /* Move the message from the pipe to the user. */ + nn_msg_mv (msg, &self->in.chunk->msgs [self->in.pos]); + + /* Move to the next position. */ + ++self->in.pos; + if (nn_slow (self->in.pos == NN_MSGQUEUE_GRANULARITY)) { + o = self->in.chunk; + self->in.chunk = self->in.chunk->next; + self->in.pos = 0; + if (nn_fast (!self->cache)) + self->cache = o; + else + nn_free (o); + } + + /* Adjust the statistics. */ + --self->count; + self->mem -= (nn_chunkref_size (&msg->sphdr) + + nn_chunkref_size (&msg->body)); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.h new file mode 100644 index 0000000..9b2d9ca --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/msgqueue.h @@ -0,0 +1,86 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_MSGQUEUE_INCLUDED +#define NN_MSGQUEUE_INCLUDED + +#include "../../utils/msg.h" + +#include + +/* This class is a simple uni-directional message queue. */ + +/* It's not 128 so that chunk including its footer fits into a memory page. */ +#define NN_MSGQUEUE_GRANULARITY 126 + +struct nn_msgqueue_chunk { + struct nn_msg msgs [NN_MSGQUEUE_GRANULARITY]; + struct nn_msgqueue_chunk *next; +}; + +struct nn_msgqueue { + + /* Pointer to the position where next message should be written into + the message queue. */ + struct { + struct nn_msgqueue_chunk *chunk; + int pos; + } out; + + /* Pointer to the first unread message in the message queue. */ + struct { + struct nn_msgqueue_chunk *chunk; + int pos; + } in; + + /* Number of messages in the queue. */ + size_t count; + + /* Amount of memory used by messages in the queue. */ + size_t mem; + + /* Maximal queue size (in bytes). */ + size_t maxmem; + + /* One empty chunk is always cached so that in case of steady stream + of messages through the pipe there are no memory allocations. */ + struct nn_msgqueue_chunk *cache; +}; + +/* Initialise the message pipe. maxmem is the maximal queue size in bytes. */ +void nn_msgqueue_init (struct nn_msgqueue *self, size_t maxmem); + +/* Terminate the message pipe. */ +void nn_msgqueue_term (struct nn_msgqueue *self); + +/* Returns 1 if there are no messages in the queue, 0 otherwise. */ +int nn_msgqueue_empty (struct nn_msgqueue *self); + +/* Writes a message to the pipe. -EAGAIN is returned if the message cannot + be sent because the queue is full. */ +int nn_msgqueue_send (struct nn_msgqueue *self, struct nn_msg *msg); + +/* Reads a message from the pipe. -EAGAIN is returned if there's no message + to receive. */ +int nn_msgqueue_recv (struct nn_msgqueue *self, struct nn_msg *msg); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.c new file mode 100644 index 0000000..6e64395 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.c @@ -0,0 +1,489 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sinproc.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/attr.h" + +#include + +#define NN_SINPROC_STATE_IDLE 1 +#define NN_SINPROC_STATE_CONNECTING 2 +#define NN_SINPROC_STATE_READY 3 +#define NN_SINPROC_STATE_ACTIVE 4 +#define NN_SINPROC_STATE_DISCONNECTED 5 +#define NN_SINPROC_STATE_STOPPING_PEER 6 +#define NN_SINPROC_STATE_STOPPING 7 + +#define NN_SINPROC_ACTION_READY 1 +#define NN_SINPROC_ACTION_ACCEPTED 2 + +/* Set when SENT event was sent to the peer but RECEIVED haven't been + passed back yet. */ +#define NN_SINPROC_FLAG_SENDING 1 + +/* Set when SENT event was received, but the new message cannot be written + to the queue yet, i.e. RECEIVED event haven't been returned + to the peer yet. */ +#define NN_SINPROC_FLAG_RECEIVING 2 + +/* Private functions. */ +static void nn_sinproc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_sinproc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +static int nn_sinproc_send (struct nn_pipebase *self, struct nn_msg *msg); +static int nn_sinproc_recv (struct nn_pipebase *self, struct nn_msg *msg); +const struct nn_pipebase_vfptr nn_sinproc_pipebase_vfptr = { + nn_sinproc_send, + nn_sinproc_recv +}; + +void nn_sinproc_init (struct nn_sinproc *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + int rcvbuf; + size_t sz; + + nn_fsm_init (&self->fsm, nn_sinproc_handler, nn_sinproc_shutdown, + src, self, owner); + self->state = NN_SINPROC_STATE_IDLE; + self->flags = 0; + self->peer = NULL; + nn_pipebase_init (&self->pipebase, &nn_sinproc_pipebase_vfptr, epbase); + sz = sizeof (rcvbuf); + nn_epbase_getopt (epbase, NN_SOL_SOCKET, NN_RCVBUF, &rcvbuf, &sz); + nn_assert (sz == sizeof (rcvbuf)); + nn_msgqueue_init (&self->msgqueue, rcvbuf); + nn_msg_init (&self->msg, 0); + nn_fsm_event_init (&self->event_connect); + nn_fsm_event_init (&self->event_sent); + nn_fsm_event_init (&self->event_received); + nn_fsm_event_init (&self->event_disconnect); + nn_list_item_init (&self->item); +} + +void nn_sinproc_term (struct nn_sinproc *self) +{ + nn_list_item_term (&self->item); + nn_fsm_event_term (&self->event_disconnect); + nn_fsm_event_term (&self->event_received); + nn_fsm_event_term (&self->event_sent); + nn_fsm_event_term (&self->event_connect); + nn_msg_term (&self->msg); + nn_msgqueue_term (&self->msgqueue); + nn_pipebase_term (&self->pipebase); + nn_fsm_term (&self->fsm); +} + +int nn_sinproc_isidle (struct nn_sinproc *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_sinproc_connect (struct nn_sinproc *self, struct nn_fsm *peer) +{ + nn_fsm_start (&self->fsm); + + /* Start the connecting handshake with the peer. */ + nn_fsm_raiseto (&self->fsm, peer, &self->event_connect, + NN_SINPROC_SRC_PEER, NN_SINPROC_CONNECT, self); +} + +void nn_sinproc_accept (struct nn_sinproc *self, struct nn_sinproc *peer) +{ + nn_assert (!self->peer); + self->peer = peer; + + /* Start the connecting handshake with the peer. */ + nn_fsm_raiseto (&self->fsm, &peer->fsm, &self->event_connect, + NN_SINPROC_SRC_PEER, NN_SINPROC_READY, self); + + /* Notify the state machine. */ + nn_fsm_start (&self->fsm); + nn_fsm_action (&self->fsm, NN_SINPROC_ACTION_READY); +} + +void nn_sinproc_stop (struct nn_sinproc *self) +{ + nn_fsm_stop (&self->fsm); +} + + + +static int nn_sinproc_send (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_sinproc *sinproc; + struct nn_msg nmsg; + + sinproc = nn_cont (self, struct nn_sinproc, pipebase); + + /* If the peer have already closed the connection, we cannot send + anymore. */ + if (sinproc->state == NN_SINPROC_STATE_DISCONNECTED) + return -ECONNRESET; + + /* Sanity checks. */ + nn_assert_state (sinproc, NN_SINPROC_STATE_ACTIVE); + nn_assert (!(sinproc->flags & NN_SINPROC_FLAG_SENDING)); + + nn_msg_init (&nmsg, + nn_chunkref_size (&msg->sphdr) + + nn_chunkref_size (&msg->body)); + memcpy (nn_chunkref_data (&nmsg.body), + nn_chunkref_data (&msg->sphdr), + nn_chunkref_size (&msg->sphdr)); + memcpy ((char *)nn_chunkref_data (&nmsg.body) + + nn_chunkref_size (&msg->sphdr), + nn_chunkref_data (&msg->body), + nn_chunkref_size (&msg->body)); + nn_msg_term (msg); + + /* Expose the message to the peer. */ + nn_msg_term (&sinproc->msg); + nn_msg_mv (&sinproc->msg, &nmsg); + + /* Notify the peer that there's a message to get. */ + sinproc->flags |= NN_SINPROC_FLAG_SENDING; + nn_fsm_raiseto (&sinproc->fsm, &sinproc->peer->fsm, + &sinproc->peer->event_sent, NN_SINPROC_SRC_PEER, + NN_SINPROC_SENT, sinproc); + + return 0; +} + +static int nn_sinproc_recv (struct nn_pipebase *self, struct nn_msg *msg) +{ + int rc; + struct nn_sinproc *sinproc; + + sinproc = nn_cont (self, struct nn_sinproc, pipebase); + + /* Sanity check. */ + nn_assert (sinproc->state == NN_SINPROC_STATE_ACTIVE || + sinproc->state == NN_SINPROC_STATE_DISCONNECTED); + + /* Move the message to the caller. */ + rc = nn_msgqueue_recv (&sinproc->msgqueue, msg); + errnum_assert (rc == 0, -rc); + + /* If there was a message from peer lingering because of the exceeded + buffer limit, try to enqueue it once again. */ + if (sinproc->state != NN_SINPROC_STATE_DISCONNECTED) { + if (nn_slow (sinproc->flags & NN_SINPROC_FLAG_RECEIVING)) { + rc = nn_msgqueue_send (&sinproc->msgqueue, &sinproc->peer->msg); + nn_assert (rc == 0 || rc == -EAGAIN); + if (rc == 0) { + errnum_assert (rc == 0, -rc); + nn_msg_init (&sinproc->peer->msg, 0); + nn_fsm_raiseto (&sinproc->fsm, &sinproc->peer->fsm, + &sinproc->peer->event_received, NN_SINPROC_SRC_PEER, + NN_SINPROC_RECEIVED, sinproc); + sinproc->flags &= ~NN_SINPROC_FLAG_RECEIVING; + } + } + } + + if (!nn_msgqueue_empty (&sinproc->msgqueue)) + nn_pipebase_received (&sinproc->pipebase); + + return 0; +} + +static void nn_sinproc_shutdown_events (struct nn_sinproc *self, int src, + int type, NN_UNUSED void *srcptr) +{ + /* ******************************* */ + /* Any-state events */ + /* ******************************* */ + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_STOP: + if (self->state != NN_SINPROC_STATE_IDLE && + self->state != NN_SINPROC_STATE_DISCONNECTED) { + nn_pipebase_stop (&self->pipebase); + nn_assert (self->fsm.state == 2 || self->fsm.state == 3); + nn_fsm_raiseto (&self->fsm, &self->peer->fsm, + &self->peer->event_disconnect, NN_SINPROC_SRC_PEER, + NN_SINPROC_DISCONNECT, self); + + self->state = NN_SINPROC_STATE_STOPPING_PEER; + } else { + self->state = NN_SINPROC_STATE_STOPPING; + } + return; + } + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_RECEIVED: + return; + } + } + + /* ******************************* */ + /* Regular events */ + /* ******************************* */ + switch (self->state) { + case NN_SINPROC_STATE_STOPPING_PEER: + switch (src) { + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_DISCONNECT: + self->state = NN_SINPROC_STATE_STOPPING; + return; + default: + nn_fsm_bad_action (self->state, src, type); + } + default: + nn_fsm_bad_source (self->state, src, type); + } + default: + nn_fsm_bad_state (self->state, src, type); + } + + nn_fsm_bad_action (self->state, src, type); +} + +static void nn_sinproc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_sinproc *sinproc; + + sinproc = nn_cont (self, struct nn_sinproc, fsm); + nn_assert (sinproc->fsm.state == 3); + + nn_sinproc_shutdown_events (sinproc, src, type, srcptr); + + /* *************** */ + /* States to check */ + /* *************** */ + + /* Have we got notification that peer is stopped */ + if (nn_slow (sinproc->state != NN_SINPROC_STATE_STOPPING)) { + return; + } + + /* Are all events processed? We can't cancel them unfortunately */ + if (nn_fsm_event_active (&sinproc->event_received) + || nn_fsm_event_active (&sinproc->event_disconnect)) + { + return; + } + /* These events are deemed to be impossible here */ + nn_assert (!nn_fsm_event_active (&sinproc->event_connect)); + nn_assert (!nn_fsm_event_active (&sinproc->event_sent)); + + /* ********************************************** */ + /* All checks are successful. Just stop right now */ + /* ********************************************** */ + + nn_fsm_stopped (&sinproc->fsm, NN_SINPROC_STOPPED); + return; +} + +static void nn_sinproc_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + int rc; + struct nn_sinproc *sinproc; + int empty; + + sinproc = nn_cont (self, struct nn_sinproc, fsm); + + switch (sinproc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_SINPROC_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + sinproc->state = NN_SINPROC_STATE_CONNECTING; + return; + default: + nn_fsm_bad_action (sinproc->state, src, type); + } + + default: + nn_fsm_bad_source (sinproc->state, src, type); + } + +/******************************************************************************/ +/* CONNECTING state. */ +/* CONNECT request was sent to the peer. Now we are waiting for the */ +/* acknowledgement. */ +/******************************************************************************/ + case NN_SINPROC_STATE_CONNECTING: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_SINPROC_ACTION_READY: + sinproc->state = NN_SINPROC_STATE_READY; + return; + default: + nn_fsm_bad_action (sinproc->state, src, type); + } + + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_READY: + sinproc->peer = (struct nn_sinproc*) srcptr; + rc = nn_pipebase_start (&sinproc->pipebase); + errnum_assert (rc == 0, -rc); + sinproc->state = NN_SINPROC_STATE_ACTIVE; + nn_fsm_raiseto (&sinproc->fsm, &sinproc->peer->fsm, + &sinproc->event_connect, + NN_SINPROC_SRC_PEER, NN_SINPROC_ACCEPTED, self); + return; + default: + nn_fsm_bad_action (sinproc->state, src, type); + } + + default: + nn_fsm_bad_source (sinproc->state, src, type); + } + +/******************************************************************************/ +/* READY state. */ +/* */ +/******************************************************************************/ + case NN_SINPROC_STATE_READY: + switch (src) { + + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_READY: + /* This means both peers sent READY so they are both + ready for receiving messages */ + rc = nn_pipebase_start (&sinproc->pipebase); + errnum_assert (rc == 0, -rc); + sinproc->state = NN_SINPROC_STATE_ACTIVE; + return; + case NN_SINPROC_ACCEPTED: + rc = nn_pipebase_start (&sinproc->pipebase); + errnum_assert (rc == 0, -rc); + sinproc->state = NN_SINPROC_STATE_ACTIVE; + return; + default: + nn_fsm_bad_action (sinproc->state, src, type); + } + + default: + nn_fsm_bad_source (sinproc->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_SINPROC_STATE_ACTIVE: + switch (src) { + + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_SENT: + + empty = nn_msgqueue_empty (&sinproc->msgqueue); + + /* Push the message to the inbound message queue. */ + rc = nn_msgqueue_send (&sinproc->msgqueue, + &sinproc->peer->msg); + if (rc == -EAGAIN) { + sinproc->flags |= NN_SINPROC_FLAG_RECEIVING; + return; + } + errnum_assert (rc == 0, -rc); + nn_msg_init (&sinproc->peer->msg, 0); + + /* Notify the user that there's a message to receive. */ + if (empty) + nn_pipebase_received (&sinproc->pipebase); + + /* Notify the peer that the message was received. */ + nn_fsm_raiseto (&sinproc->fsm, &sinproc->peer->fsm, + &sinproc->peer->event_received, NN_SINPROC_SRC_PEER, + NN_SINPROC_RECEIVED, sinproc); + + return; + + case NN_SINPROC_RECEIVED: + nn_assert (sinproc->flags & NN_SINPROC_FLAG_SENDING); + nn_pipebase_sent (&sinproc->pipebase); + sinproc->flags &= ~NN_SINPROC_FLAG_SENDING; + return; + + case NN_SINPROC_DISCONNECT: + nn_pipebase_stop (&sinproc->pipebase); + nn_fsm_raiseto (&sinproc->fsm, &sinproc->peer->fsm, + &sinproc->peer->event_disconnect, NN_SINPROC_SRC_PEER, + NN_SINPROC_DISCONNECT, sinproc); + sinproc->state = NN_SINPROC_STATE_DISCONNECTED; + sinproc->peer = NULL; + nn_fsm_raise (&sinproc->fsm, &sinproc->event_disconnect, + NN_SINPROC_DISCONNECT); + return; + + default: + nn_fsm_bad_action (sinproc->state, src, type); + } + + default: + nn_fsm_bad_source (sinproc->state, src, type); + } + +/******************************************************************************/ +/* DISCONNECTED state. */ +/* The peer have already closed the connection, but the object was not yet */ +/* asked to stop. */ +/******************************************************************************/ + case NN_SINPROC_STATE_DISCONNECTED: + switch (src) { + case NN_SINPROC_SRC_PEER: + switch (type) { + case NN_SINPROC_RECEIVED: + /* This case can safely be ignored. It may happen when + nn_close() comes before the already enqueued + NN_SINPROC_RECEIVED has been delivered. */ + return; + default: + nn_fsm_bad_action (sinproc->state, src, type); + }; + default: + nn_fsm_bad_source (sinproc->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (sinproc->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.h new file mode 100644 index 0000000..07b51ad --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/inproc/sinproc.h @@ -0,0 +1,94 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SINPROC_INCLUDED +#define NN_SINPROC_INCLUDED + +#include "msgqueue.h" + +#include "../../transport.h" + +#include "../../aio/fsm.h" + +#include "../../utils/msg.h" +#include "../../utils/list.h" + +#define NN_SINPROC_CONNECT 1 +#define NN_SINPROC_READY 2 +#define NN_SINPROC_ACCEPTED 3 +#define NN_SINPROC_SENT 4 +#define NN_SINPROC_RECEIVED 5 +#define NN_SINPROC_DISCONNECT 6 +#define NN_SINPROC_STOPPED 7 + +/* We use a random value here to prevent accidental clashes with the peer's + internal source IDs. */ +#define NN_SINPROC_SRC_PEER 27713 + +struct nn_sinproc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Any combination of the flags defined in the .c file. */ + int flags; + + /* Pointer to the peer inproc session, if connected. NULL otherwise. */ + struct nn_sinproc *peer; + + /* Pipe connecting this inproc connection to the nanomsg core. */ + struct nn_pipebase pipebase; + + /* Inbound message queue. The messages contained are meant to be received + by the user later on. */ + struct nn_msgqueue msgqueue; + + /* This message is the one being sent from this session to the peer + session. It holds the data only temporarily, until the peer moves + it to its msgqueue. */ + struct nn_msg msg; + + /* Outbound events. I.e. event sent by this sinproc to the peer sinproc. */ + struct nn_fsm_event event_connect; + + /* Inbound events. I.e. events sent by the peer sinproc to this inproc. */ + struct nn_fsm_event event_sent; + struct nn_fsm_event event_received; + struct nn_fsm_event event_disconnect; + + /* This member is used only if we are on the bound side. binproc object + has a list of sinprocs it handles. */ + struct nn_list_item item; +}; + +void nn_sinproc_init (struct nn_sinproc *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_sinproc_term (struct nn_sinproc *self); +int nn_sinproc_isidle (struct nn_sinproc *self); + +/* Connect and accept are two different ways to start the state machine. */ +void nn_sinproc_connect (struct nn_sinproc *self, struct nn_fsm *peer); +void nn_sinproc_accept (struct nn_sinproc *self, struct nn_sinproc *peer); +void nn_sinproc_stop (struct nn_sinproc *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/aipc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/aipc.c new file mode 100644 index 0000000..bc64a4e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/aipc.c @@ -0,0 +1,320 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "aipc.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/attr.h" + +#define NN_AIPC_STATE_IDLE 1 +#define NN_AIPC_STATE_ACCEPTING 2 +#define NN_AIPC_STATE_ACTIVE 3 +#define NN_AIPC_STATE_STOPPING_SIPC 4 +#define NN_AIPC_STATE_STOPPING_USOCK 5 +#define NN_AIPC_STATE_DONE 6 +#define NN_AIPC_STATE_STOPPING_SIPC_FINAL 7 +#define NN_AIPC_STATE_STOPPING 8 + +#define NN_AIPC_SRC_USOCK 1 +#define NN_AIPC_SRC_SIPC 2 +#define NN_AIPC_SRC_LISTENER 3 + +/* Private functions. */ +static void nn_aipc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_aipc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_aipc_init (struct nn_aipc *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_aipc_handler, nn_aipc_shutdown, + src, self, owner); + self->state = NN_AIPC_STATE_IDLE; + self->epbase = epbase; + nn_usock_init (&self->usock, NN_AIPC_SRC_USOCK, &self->fsm); + self->listener = NULL; + self->listener_owner.src = -1; + self->listener_owner.fsm = NULL; + nn_sipc_init (&self->sipc, NN_AIPC_SRC_SIPC, epbase, &self->fsm); + nn_fsm_event_init (&self->accepted); + nn_fsm_event_init (&self->done); + nn_list_item_init (&self->item); +} + +void nn_aipc_term (struct nn_aipc *self) +{ + nn_assert_state (self, NN_AIPC_STATE_IDLE); + + nn_list_item_term (&self->item); + nn_fsm_event_term (&self->done); + nn_fsm_event_term (&self->accepted); + nn_sipc_term (&self->sipc); + nn_usock_term (&self->usock); + nn_fsm_term (&self->fsm); +} + +int nn_aipc_isidle (struct nn_aipc *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_aipc_start (struct nn_aipc *self, struct nn_usock *listener) +{ +#if defined NN_HAVE_WINDOWS + size_t sz; +#endif + nn_assert_state (self, NN_AIPC_STATE_IDLE); + + /* Take ownership of the listener socket. */ + self->listener = listener; + self->listener_owner.src = NN_AIPC_SRC_LISTENER; + self->listener_owner.fsm = &self->fsm; + nn_usock_swap_owner (listener, &self->listener_owner); + +#if defined NN_HAVE_WINDOWS + /* Get/Set security attribute pointer*/ + nn_epbase_getopt (self->epbase, NN_IPC, NN_IPC_SEC_ATTR, &self->usock.sec_attr, &sz); + nn_epbase_getopt (self->epbase, NN_IPC, NN_IPC_OUTBUFSZ, &self->usock.outbuffersz, &sz); + nn_epbase_getopt (self->epbase, NN_IPC, NN_IPC_INBUFSZ, &self->usock.inbuffersz, &sz); +#endif + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_aipc_stop (struct nn_aipc *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_aipc_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_aipc *aipc; + + aipc = nn_cont (self, struct nn_aipc, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (!nn_sipc_isidle (&aipc->sipc)) { + nn_epbase_stat_increment (aipc->epbase, + NN_STAT_DROPPED_CONNECTIONS, 1); + nn_sipc_stop (&aipc->sipc); + } + aipc->state = NN_AIPC_STATE_STOPPING_SIPC_FINAL; + } + if (nn_slow (aipc->state == NN_AIPC_STATE_STOPPING_SIPC_FINAL)) { + if (!nn_sipc_isidle (&aipc->sipc)) + return; + nn_usock_stop (&aipc->usock); + aipc->state = NN_AIPC_STATE_STOPPING; + } + if (nn_slow (aipc->state == NN_AIPC_STATE_STOPPING)) { + if (!nn_usock_isidle (&aipc->usock)) + return; + if (aipc->listener) { + nn_assert (aipc->listener_owner.fsm); + nn_usock_swap_owner (aipc->listener, &aipc->listener_owner); + aipc->listener = NULL; + aipc->listener_owner.src = -1; + aipc->listener_owner.fsm = NULL; + } + aipc->state = NN_AIPC_STATE_IDLE; + nn_fsm_stopped (&aipc->fsm, NN_AIPC_STOPPED); + return; + } + + nn_fsm_bad_state(aipc->state, src, type); +} + +static void nn_aipc_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_aipc *aipc; + int val; + size_t sz; + + aipc = nn_cont (self, struct nn_aipc, fsm); + + switch (aipc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The state machine wasn't yet started. */ +/******************************************************************************/ + case NN_AIPC_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_usock_accept (&aipc->usock, aipc->listener); + aipc->state = NN_AIPC_STATE_ACCEPTING; + return; + default: + nn_fsm_bad_action (aipc->state, src, type); + } + + default: + nn_fsm_bad_source (aipc->state, src, type); + } + +/******************************************************************************/ +/* ACCEPTING state. */ +/* Waiting for incoming connection. */ +/******************************************************************************/ + case NN_AIPC_STATE_ACCEPTING: + switch (src) { + + case NN_AIPC_SRC_USOCK: + switch (type) { + case NN_USOCK_ACCEPTED: + nn_epbase_clear_error (aipc->epbase); + + /* Set the relevant socket options. */ + sz = sizeof (val); + nn_epbase_getopt (aipc->epbase, NN_SOL_SOCKET, NN_SNDBUF, + &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&aipc->usock, SOL_SOCKET, SO_SNDBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (aipc->epbase, NN_SOL_SOCKET, NN_RCVBUF, + &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&aipc->usock, SOL_SOCKET, SO_RCVBUF, + &val, sizeof (val)); + + /* Return ownership of the listening socket to the parent. */ + nn_usock_swap_owner (aipc->listener, &aipc->listener_owner); + aipc->listener = NULL; + aipc->listener_owner.src = -1; + aipc->listener_owner.fsm = NULL; + nn_fsm_raise (&aipc->fsm, &aipc->accepted, NN_AIPC_ACCEPTED); + + /* Start the sipc state machine. */ + nn_usock_activate (&aipc->usock); + nn_sipc_start (&aipc->sipc, &aipc->usock); + aipc->state = NN_AIPC_STATE_ACTIVE; + + nn_epbase_stat_increment (aipc->epbase, + NN_STAT_ACCEPTED_CONNECTIONS, 1); + + return; + + default: + nn_fsm_bad_action (aipc->state, src, type); + } + + case NN_AIPC_SRC_LISTENER: + switch (type) { + case NN_USOCK_ACCEPT_ERROR: + nn_epbase_set_error (aipc->epbase, + nn_usock_geterrno (aipc->listener)); + nn_epbase_stat_increment (aipc->epbase, + NN_STAT_ACCEPT_ERRORS, 1); + nn_usock_accept (&aipc->usock, aipc->listener); + + return; + + default: + nn_fsm_bad_action (aipc->state, src, type); + } + + default: + nn_fsm_bad_source (aipc->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_AIPC_STATE_ACTIVE: + switch (src) { + + case NN_AIPC_SRC_SIPC: + switch (type) { + case NN_SIPC_ERROR: + nn_sipc_stop (&aipc->sipc); + aipc->state = NN_AIPC_STATE_STOPPING_SIPC; + nn_epbase_stat_increment (aipc->epbase, + NN_STAT_BROKEN_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (aipc->state, src, type); + } + + default: + nn_fsm_bad_source (aipc->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_SIPC state. */ +/******************************************************************************/ + case NN_AIPC_STATE_STOPPING_SIPC: + switch (src) { + + case NN_AIPC_SRC_SIPC: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_SIPC_STOPPED: + nn_usock_stop (&aipc->usock); + aipc->state = NN_AIPC_STATE_STOPPING_USOCK; + return; + default: + nn_fsm_bad_action (aipc->state, src, type); + } + + default: + nn_fsm_bad_source (aipc->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_USOCK state. */ +/******************************************************************************/ + case NN_AIPC_STATE_STOPPING_USOCK: + switch (src) { + + case NN_AIPC_SRC_USOCK: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_STOPPED: + nn_fsm_raise (&aipc->fsm, &aipc->done, NN_AIPC_ERROR); + aipc->state = NN_AIPC_STATE_DONE; + return; + default: + nn_fsm_bad_action (aipc->state, src, type); + } + + default: + nn_fsm_bad_source (aipc->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (aipc->state, src, type); + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/aipc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/aipc.h new file mode 100644 index 0000000..2c95a7f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/aipc.h @@ -0,0 +1,81 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_AIPC_INCLUDED +#define NN_AIPC_INCLUDED + +#include "sipc.h" + +#include "../../transport.h" +#include "../../ipc.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/list.h" + +/* State machine handling accepted IPC sockets. */ + +/* In bipc, some events are just *assumed* to come from a child aipc object. + By using non-trivial event codes, we can do more reliable sanity checking + in such scenarios. */ +#define NN_AIPC_ACCEPTED 34231 +#define NN_AIPC_ERROR 34232 +#define NN_AIPC_STOPPED 34233 + +struct nn_aipc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Pointer to the associated endpoint. */ + struct nn_epbase *epbase; + + /* Underlying socket. */ + struct nn_usock usock; + + /* Listening socket. Valid only while accepting new connection. */ + struct nn_usock *listener; + struct nn_fsm_owner listener_owner; + + /* State machine that takes care of the connection in the active state. */ + struct nn_sipc sipc; + + /* Events generated by aipc state machine. */ + struct nn_fsm_event accepted; + struct nn_fsm_event done; + + /* This member can be used by owner to keep individual aipcs in a list. */ + struct nn_list_item item; +}; + +void nn_aipc_init (struct nn_aipc *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_aipc_term (struct nn_aipc *self); + +int nn_aipc_isidle (struct nn_aipc *self); +void nn_aipc_start (struct nn_aipc *self, struct nn_usock *listener); +void nn_aipc_stop (struct nn_aipc *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/bipc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/bipc.c new file mode 100644 index 0000000..f1b3a2a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/bipc.c @@ -0,0 +1,364 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "bipc.h" +#include "aipc.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/fast.h" + +#include +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#include +#endif + +#define NN_BIPC_BACKLOG 10 + +#define NN_BIPC_STATE_IDLE 1 +#define NN_BIPC_STATE_ACTIVE 2 +#define NN_BIPC_STATE_STOPPING_AIPC 3 +#define NN_BIPC_STATE_STOPPING_USOCK 4 +#define NN_BIPC_STATE_STOPPING_AIPCS 5 + +#define NN_BIPC_SRC_USOCK 1 +#define NN_BIPC_SRC_AIPC 2 + +struct nn_bipc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is a specific type of endpoint. + Thus it is derived from epbase. */ + struct nn_epbase epbase; + + /* The underlying listening IPC socket. */ + struct nn_usock usock; + + /* The connection being accepted at the moment. */ + struct nn_aipc *aipc; + + /* List of accepted connections. */ + struct nn_list aipcs; +}; + +/* nn_epbase virtual interface implementation. */ +static void nn_bipc_stop (struct nn_epbase *self); +static void nn_bipc_destroy (struct nn_epbase *self); +const struct nn_epbase_vfptr nn_bipc_epbase_vfptr = { + nn_bipc_stop, + nn_bipc_destroy +}; + +/* Private functions. */ +static void nn_bipc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_bipc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static int nn_bipc_listen (struct nn_bipc *self); +static void nn_bipc_start_accepting (struct nn_bipc *self); + +int nn_bipc_create (void *hint, struct nn_epbase **epbase) +{ + struct nn_bipc *self; + int rc; + + /* Allocate the new endpoint object. */ + self = nn_alloc (sizeof (struct nn_bipc), "bipc"); + alloc_assert (self); + + + /* Initialise the structure. */ + nn_epbase_init (&self->epbase, &nn_bipc_epbase_vfptr, hint); + nn_fsm_init_root (&self->fsm, nn_bipc_handler, nn_bipc_shutdown, + nn_epbase_getctx (&self->epbase)); + self->state = NN_BIPC_STATE_IDLE; + self->aipc = NULL; + nn_list_init (&self->aipcs); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + nn_usock_init (&self->usock, NN_BIPC_SRC_USOCK, &self->fsm); + + rc = nn_bipc_listen (self); + if (rc != 0) { + nn_epbase_term (&self->epbase); + return rc; + } + + /* Return the base class as an out parameter. */ + *epbase = &self->epbase; + + return 0; +} + +static void nn_bipc_stop (struct nn_epbase *self) +{ + struct nn_bipc *bipc; + + bipc = nn_cont (self, struct nn_bipc, epbase); + + nn_fsm_stop (&bipc->fsm); +} + +static void nn_bipc_destroy (struct nn_epbase *self) +{ + struct nn_bipc *bipc; + + bipc = nn_cont (self, struct nn_bipc, epbase); + + nn_assert_state (bipc, NN_BIPC_STATE_IDLE); + nn_list_term (&bipc->aipcs); + nn_assert (bipc->aipc == NULL); + nn_usock_term (&bipc->usock); + nn_epbase_term (&bipc->epbase); + nn_fsm_term (&bipc->fsm); + + nn_free (bipc); +} + +static void nn_bipc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ +#if defined NN_HAVE_UNIX_SOCKETS + const char *addr; + int rc; +#endif + + struct nn_bipc *bipc; + struct nn_list_item *it; + struct nn_aipc *aipc; + + bipc = nn_cont (self, struct nn_bipc, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (bipc->aipc) { + nn_aipc_stop (bipc->aipc); + bipc->state = NN_BIPC_STATE_STOPPING_AIPC; + } + else { + bipc->state = NN_BIPC_STATE_STOPPING_USOCK; + } + } + if (nn_slow (bipc->state == NN_BIPC_STATE_STOPPING_AIPC)) { + if (!nn_aipc_isidle (bipc->aipc)) + return; + nn_aipc_term (bipc->aipc); + nn_free (bipc->aipc); + bipc->aipc = NULL; + + /* On *nixes, unlink the domain socket file */ +#if defined NN_HAVE_UNIX_SOCKETS + addr = nn_epbase_getaddr (&bipc->epbase); + rc = unlink(addr); + errno_assert (rc == 0 || errno == ENOENT); +#endif + + nn_usock_stop (&bipc->usock); + bipc->state = NN_BIPC_STATE_STOPPING_USOCK; + } + if (nn_slow (bipc->state == NN_BIPC_STATE_STOPPING_USOCK)) { + if (!nn_usock_isidle (&bipc->usock)) + return; + for (it = nn_list_begin (&bipc->aipcs); + it != nn_list_end (&bipc->aipcs); + it = nn_list_next (&bipc->aipcs, it)) { + aipc = nn_cont (it, struct nn_aipc, item); + nn_aipc_stop (aipc); + } + bipc->state = NN_BIPC_STATE_STOPPING_AIPCS; + goto aipcs_stopping; + } + if (nn_slow (bipc->state == NN_BIPC_STATE_STOPPING_AIPCS)) { + nn_assert (src == NN_BIPC_SRC_AIPC && type == NN_AIPC_STOPPED); + aipc = (struct nn_aipc *) srcptr; + nn_list_erase (&bipc->aipcs, &aipc->item); + nn_aipc_term (aipc); + nn_free (aipc); + + /* If there are no more aipc state machines, we can stop the whole + bipc object. */ +aipcs_stopping: + if (nn_list_empty (&bipc->aipcs)) { + bipc->state = NN_BIPC_STATE_IDLE; + nn_fsm_stopped_noevent (&bipc->fsm); + nn_epbase_stopped (&bipc->epbase); + return; + } + + return; + } + + nn_fsm_bad_state(bipc->state, src, type); +} + +static void nn_bipc_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_bipc *bipc; + struct nn_aipc *aipc; + + bipc = nn_cont (self, struct nn_bipc, fsm); + + switch (bipc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_BIPC_STATE_IDLE: + nn_assert (src == NN_FSM_ACTION); + nn_assert (type == NN_FSM_START); + bipc->state = NN_BIPC_STATE_ACTIVE; + return; + +/******************************************************************************/ +/* ACTIVE state. */ +/* The execution is yielded to the aipc state machine in this state. */ +/******************************************************************************/ + case NN_BIPC_STATE_ACTIVE: + if (src == NN_BIPC_SRC_USOCK) { + nn_assert (type == NN_USOCK_SHUTDOWN || type == NN_USOCK_STOPPED); + return; + } + + /* All other events come from child aipc objects. */ + nn_assert (src == NN_BIPC_SRC_AIPC); + aipc = (struct nn_aipc*) srcptr; + switch (type) { + case NN_AIPC_ACCEPTED: + + nn_list_insert (&bipc->aipcs, &aipc->item, + nn_list_end (&bipc->aipcs)); + bipc->aipc = NULL; + nn_bipc_start_accepting (bipc); + return; + case NN_AIPC_ERROR: + nn_aipc_stop (aipc); + return; + case NN_AIPC_STOPPED: + nn_list_erase (&bipc->aipcs, &aipc->item); + nn_aipc_term (aipc); + nn_free (aipc); + return; + default: + nn_fsm_bad_action (bipc->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (bipc->state, src, type); + } +} + +static int nn_bipc_listen (struct nn_bipc *self) +{ + int rc; + struct sockaddr_storage ss; + struct sockaddr_un *un; + const char *addr; +#if defined NN_HAVE_UNIX_SOCKETS + int fd; +#endif + + /* First, create the AF_UNIX address. */ + addr = nn_epbase_getaddr (&self->epbase); + memset (&ss, 0, sizeof (ss)); + un = (struct sockaddr_un*) &ss; + nn_assert (strlen (addr) < sizeof (un->sun_path)); + ss.ss_family = AF_UNIX; + strncpy (un->sun_path, addr, sizeof (un->sun_path)); + + /* Delete the IPC file left over by eventual previous runs of + the application. We'll check whether the file is still in use by + connecting to the endpoint. On Windows plaform, NamedPipe is used + which does not have an underlying file. */ +#if defined NN_HAVE_UNIX_SOCKETS + fd = socket (AF_UNIX, SOCK_STREAM, 0); + if (fd >= 0) { + rc = fcntl (fd, F_SETFL, O_NONBLOCK); + errno_assert (rc != -1 || errno == EINVAL); + rc = connect (fd, (struct sockaddr*) &ss, + sizeof (struct sockaddr_un)); + if (rc == -1 && errno == ECONNREFUSED) { + rc = unlink (addr); + errno_assert (rc == 0 || errno == ENOENT); + } + rc = close (fd); + errno_assert (rc == 0); + } +#endif + + /* Start listening for incoming connections. */ + rc = nn_usock_start (&self->usock, AF_UNIX, SOCK_STREAM, 0); + if (rc < 0) { + return rc; + } + + rc = nn_usock_bind (&self->usock, + (struct sockaddr*) &ss, sizeof (struct sockaddr_un)); + if (rc < 0) { + nn_usock_stop (&self->usock); + return rc; + } + + rc = nn_usock_listen (&self->usock, NN_BIPC_BACKLOG); + if (rc < 0) { + nn_usock_stop (&self->usock); + return rc; + } + nn_bipc_start_accepting (self); + + return 0; +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_bipc_start_accepting (struct nn_bipc *self) +{ + nn_assert (self->aipc == NULL); + + /* Allocate new aipc state machine. */ + self->aipc = nn_alloc (sizeof (struct nn_aipc), "aipc"); + alloc_assert (self->aipc); + nn_aipc_init (self->aipc, NN_BIPC_SRC_AIPC, &self->epbase, &self->fsm); + + /* Start waiting for a new incoming connection. */ + nn_aipc_start (self->aipc, &self->usock); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/bipc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/bipc.h new file mode 100644 index 0000000..ca43bd5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/bipc.h @@ -0,0 +1,32 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BIPC_INCLUDED +#define NN_BIPC_INCLUDED + +#include "../../transport.h" + +/* State machine managing bound IPC socket. */ + +int nn_bipc_create (void *hint, struct nn_epbase **epbase); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/cipc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/cipc.c new file mode 100644 index 0000000..1f6adad --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/cipc.c @@ -0,0 +1,435 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "cipc.h" +#include "sipc.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../utils/backoff.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/attr.h" + +#include +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#endif + +#define NN_CIPC_STATE_IDLE 1 +#define NN_CIPC_STATE_CONNECTING 2 +#define NN_CIPC_STATE_ACTIVE 3 +#define NN_CIPC_STATE_STOPPING_SIPC 4 +#define NN_CIPC_STATE_STOPPING_USOCK 5 +#define NN_CIPC_STATE_WAITING 6 +#define NN_CIPC_STATE_STOPPING_BACKOFF 7 +#define NN_CIPC_STATE_STOPPING_SIPC_FINAL 8 +#define NN_CIPC_STATE_STOPPING 9 + +#define NN_CIPC_SRC_USOCK 1 +#define NN_CIPC_SRC_RECONNECT_TIMER 2 +#define NN_CIPC_SRC_SIPC 3 + +struct nn_cipc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is a specific type of endpoint. + Thus it is derived from epbase. */ + struct nn_epbase epbase; + + /* The underlying IPC socket. */ + struct nn_usock usock; + + /* Used to wait before retrying to connect. */ + struct nn_backoff retry; + + /* State machine that handles the active part of the connection + lifetime. */ + struct nn_sipc sipc; +}; + +/* nn_epbase virtual interface implementation. */ +static void nn_cipc_stop (struct nn_epbase *self); +static void nn_cipc_destroy (struct nn_epbase *self); +const struct nn_epbase_vfptr nn_cipc_epbase_vfptr = { + nn_cipc_stop, + nn_cipc_destroy +}; + +/* Private functions. */ +static void nn_cipc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_cipc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_cipc_start_connecting (struct nn_cipc *self); + +int nn_cipc_create (void *hint, struct nn_epbase **epbase) +{ + struct nn_cipc *self; + int reconnect_ivl; + int reconnect_ivl_max; + size_t sz; + + /* Allocate the new endpoint object. */ + self = nn_alloc (sizeof (struct nn_cipc), "cipc"); + alloc_assert (self); + + /* Initialise the structure. */ + nn_epbase_init (&self->epbase, &nn_cipc_epbase_vfptr, hint); + nn_fsm_init_root (&self->fsm, nn_cipc_handler, nn_cipc_shutdown, + nn_epbase_getctx (&self->epbase)); + self->state = NN_CIPC_STATE_IDLE; + nn_usock_init (&self->usock, NN_CIPC_SRC_USOCK, &self->fsm); + sz = sizeof (reconnect_ivl); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL, + &reconnect_ivl, &sz); + nn_assert (sz == sizeof (reconnect_ivl)); + sz = sizeof (reconnect_ivl_max); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL_MAX, + &reconnect_ivl_max, &sz); + nn_assert (sz == sizeof (reconnect_ivl_max)); + if (reconnect_ivl_max == 0) + reconnect_ivl_max = reconnect_ivl; + nn_backoff_init (&self->retry, NN_CIPC_SRC_RECONNECT_TIMER, + reconnect_ivl, reconnect_ivl_max, &self->fsm); + nn_sipc_init (&self->sipc, NN_CIPC_SRC_SIPC, &self->epbase, &self->fsm); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + /* Return the base class as an out parameter. */ + *epbase = &self->epbase; + + return 0; +} + +static void nn_cipc_stop (struct nn_epbase *self) +{ + struct nn_cipc *cipc; + + cipc = nn_cont (self, struct nn_cipc, epbase); + + nn_fsm_stop (&cipc->fsm); +} + +static void nn_cipc_destroy (struct nn_epbase *self) +{ + struct nn_cipc *cipc; + + cipc = nn_cont (self, struct nn_cipc, epbase); + + nn_sipc_term (&cipc->sipc); + nn_backoff_term (&cipc->retry); + nn_usock_term (&cipc->usock); + nn_fsm_term (&cipc->fsm); + nn_epbase_term (&cipc->epbase); + + nn_free (cipc); +} + +static void nn_cipc_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_cipc *cipc; + + cipc = nn_cont (self, struct nn_cipc, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (!nn_sipc_isidle (&cipc->sipc)) { + nn_epbase_stat_increment (&cipc->epbase, + NN_STAT_DROPPED_CONNECTIONS, 1); + nn_sipc_stop (&cipc->sipc); + } + cipc->state = NN_CIPC_STATE_STOPPING_SIPC_FINAL; + } + if (nn_slow (cipc->state == NN_CIPC_STATE_STOPPING_SIPC_FINAL)) { + if (!nn_sipc_isidle (&cipc->sipc)) + return; + nn_backoff_stop (&cipc->retry); + nn_usock_stop (&cipc->usock); + cipc->state = NN_CIPC_STATE_STOPPING; + } + if (nn_slow (cipc->state == NN_CIPC_STATE_STOPPING)) { + if (!nn_backoff_isidle (&cipc->retry) || + !nn_usock_isidle (&cipc->usock)) + return; + cipc->state = NN_CIPC_STATE_IDLE; + nn_fsm_stopped_noevent (&cipc->fsm); + nn_epbase_stopped (&cipc->epbase); + return; + } + + nn_fsm_bad_state(cipc->state, src, type); +} + +static void nn_cipc_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_cipc *cipc; + + cipc = nn_cont (self, struct nn_cipc, fsm); + + switch (cipc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The state machine wasn't yet started. */ +/******************************************************************************/ + case NN_CIPC_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_cipc_start_connecting (cipc); + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* CONNECTING state. */ +/* Non-blocking connect is under way. */ +/******************************************************************************/ + case NN_CIPC_STATE_CONNECTING: + switch (src) { + + case NN_CIPC_SRC_USOCK: + switch (type) { + case NN_USOCK_CONNECTED: + nn_sipc_start (&cipc->sipc, &cipc->usock); + cipc->state = NN_CIPC_STATE_ACTIVE; + nn_epbase_stat_increment (&cipc->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&cipc->epbase, + NN_STAT_ESTABLISHED_CONNECTIONS, 1); + nn_epbase_clear_error (&cipc->epbase); + return; + case NN_USOCK_ERROR: + nn_epbase_set_error (&cipc->epbase, + nn_usock_geterrno (&cipc->usock)); + nn_usock_stop (&cipc->usock); + cipc->state = NN_CIPC_STATE_STOPPING_USOCK; + nn_epbase_stat_increment (&cipc->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&cipc->epbase, + NN_STAT_CONNECT_ERRORS, 1); + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* Connection is established and handled by the sipc state machine. */ +/******************************************************************************/ + case NN_CIPC_STATE_ACTIVE: + switch (src) { + + case NN_CIPC_SRC_SIPC: + switch (type) { + case NN_SIPC_ERROR: + nn_sipc_stop (&cipc->sipc); + cipc->state = NN_CIPC_STATE_STOPPING_SIPC; + nn_epbase_stat_increment (&cipc->epbase, + NN_STAT_BROKEN_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_SIPC state. */ +/* sipc object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CIPC_STATE_STOPPING_SIPC: + switch (src) { + + case NN_CIPC_SRC_SIPC: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_SIPC_STOPPED: + nn_usock_stop (&cipc->usock); + cipc->state = NN_CIPC_STATE_STOPPING_USOCK; + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_USOCK state. */ +/* usock object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CIPC_STATE_STOPPING_USOCK: + switch (src) { + + case NN_CIPC_SRC_USOCK: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_STOPPED: + nn_backoff_start (&cipc->retry); + cipc->state = NN_CIPC_STATE_WAITING; + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* WAITING state. */ +/* Waiting before re-connection is attempted. This way we won't overload */ +/* the system by continuous re-connection attemps. */ +/******************************************************************************/ + case NN_CIPC_STATE_WAITING: + switch (src) { + + case NN_CIPC_SRC_RECONNECT_TIMER: + switch (type) { + case NN_BACKOFF_TIMEOUT: + nn_backoff_stop (&cipc->retry); + cipc->state = NN_CIPC_STATE_STOPPING_BACKOFF; + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_BACKOFF state. */ +/* backoff object was asked to stop, but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CIPC_STATE_STOPPING_BACKOFF: + switch (src) { + + case NN_CIPC_SRC_RECONNECT_TIMER: + switch (type) { + case NN_BACKOFF_STOPPED: + nn_cipc_start_connecting (cipc); + return; + default: + nn_fsm_bad_action (cipc->state, src, type); + } + + default: + nn_fsm_bad_source (cipc->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (cipc->state, src, type); + } +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_cipc_start_connecting (struct nn_cipc *self) +{ + int rc; + struct sockaddr_storage ss; + struct sockaddr_un *un; + const char *addr; + int val; + size_t sz; + + /* Try to start the underlying socket. */ + rc = nn_usock_start (&self->usock, AF_UNIX, SOCK_STREAM, 0); + if (nn_slow (rc < 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CIPC_STATE_WAITING; + return; + } + + /* Set the relevant socket options. */ + sz = sizeof (val); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_SNDBUF, &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&self->usock, SOL_SOCKET, SO_SNDBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RCVBUF, &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&self->usock, SOL_SOCKET, SO_RCVBUF, + &val, sizeof (val)); + + /* Create the IPC address from the address string. */ + addr = nn_epbase_getaddr (&self->epbase); + memset (&ss, 0, sizeof (ss)); + un = (struct sockaddr_un*) &ss; + nn_assert (strlen (addr) < sizeof (un->sun_path)); + ss.ss_family = AF_UNIX; + strncpy (un->sun_path, addr, sizeof (un->sun_path)); + +#if defined NN_HAVE_WINDOWS + /* Get/Set security attribute pointer*/ + nn_epbase_getopt (&self->epbase, NN_IPC, NN_IPC_SEC_ATTR, &self->usock.sec_attr, &sz); + + nn_epbase_getopt (&self->epbase, NN_IPC, NN_IPC_OUTBUFSZ, &self->usock.outbuffersz, &sz); + nn_epbase_getopt (&self->epbase, NN_IPC, NN_IPC_INBUFSZ, &self->usock.inbuffersz, &sz); +#endif + + /* Start connecting. */ + nn_usock_connect (&self->usock, (struct sockaddr*) &ss, + sizeof (struct sockaddr_un)); + self->state = NN_CIPC_STATE_CONNECTING; + + nn_epbase_stat_increment (&self->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, 1); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/cipc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/cipc.h new file mode 100644 index 0000000..4036bba --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/cipc.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CIPC_INCLUDED +#define NN_CIPC_INCLUDED + +#include "../../transport.h" +#include "../../ipc.h" + +/* State machine managing connected IPC socket. */ + +int nn_cipc_create (void *hint, struct nn_epbase **epbase); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/ipc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/ipc.c new file mode 100644 index 0000000..c4fe740 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/ipc.c @@ -0,0 +1,167 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ipc.h" +#include "bipc.h" +#include "cipc.h" + +#include "../../ipc.h" + +#include "../../utils/err.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/list.h" +#include "../../utils/cont.h" + +#include +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#include +#endif + +/* IPC-specific socket options. */ +struct nn_ipc_optset { + struct nn_optset base; + + /* Win32 Security Attribute */ + void* sec_attr; + + int outbuffersz; + int inbuffersz; +}; + +static void nn_ipc_optset_destroy (struct nn_optset *self); +static int nn_ipc_optset_setopt (struct nn_optset *self, int option, + const void *optval, size_t optvallen); +static int nn_ipc_optset_getopt (struct nn_optset *self, int option, + void *optval, size_t *optvallen); +static const struct nn_optset_vfptr nn_ipc_optset_vfptr = { + nn_ipc_optset_destroy, + nn_ipc_optset_setopt, + nn_ipc_optset_getopt +}; + +/* nn_transport interface. */ +static int nn_ipc_bind (void *hint, struct nn_epbase **epbase); +static int nn_ipc_connect (void *hint, struct nn_epbase **epbase); +static struct nn_optset *nn_ipc_optset (void); + +static struct nn_transport nn_ipc_vfptr = { + "ipc", + NN_IPC, + NULL, + NULL, + nn_ipc_bind, + nn_ipc_connect, + nn_ipc_optset, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_transport *nn_ipc = &nn_ipc_vfptr; + +static int nn_ipc_bind (void *hint, struct nn_epbase **epbase) +{ + return nn_bipc_create (hint, epbase); +} + +static int nn_ipc_connect (void *hint, struct nn_epbase **epbase) +{ + return nn_cipc_create (hint, epbase); +} + +static struct nn_optset *nn_ipc_optset () +{ + struct nn_ipc_optset *optset; + + optset = nn_alloc (sizeof (struct nn_ipc_optset), "optset (ipc)"); + alloc_assert (optset); + optset->base.vfptr = &nn_ipc_optset_vfptr; + + /* Default values for the IPC options */ + optset->sec_attr = NULL; + optset->outbuffersz = 4096; + optset->inbuffersz = 4096; + + return &optset->base; +} + +static void nn_ipc_optset_destroy (struct nn_optset *self) +{ + struct nn_ipc_optset *optset; + + optset = nn_cont (self, struct nn_ipc_optset, base); + nn_free (optset); +} + +static int nn_ipc_optset_setopt (struct nn_optset *self, int option, + const void *optval, size_t optvallen) +{ + struct nn_ipc_optset *optset; + + optset = nn_cont (self, struct nn_ipc_optset, base); + if (optvallen < sizeof (int)) { + return -EINVAL; + } + + switch (option) { + case NN_IPC_SEC_ATTR: + optset->sec_attr = (void *)optval; + return 0; + case NN_IPC_OUTBUFSZ: + optset->outbuffersz = *(int *)optval; + return 0; + case NN_IPC_INBUFSZ: + optset->inbuffersz = *(int *)optval; + return 0; + default: + return -ENOPROTOOPT; + } +} + +static int nn_ipc_optset_getopt (struct nn_optset *self, int option, + void *optval, size_t *optvallen) +{ + struct nn_ipc_optset *optset; + + optset = nn_cont (self, struct nn_ipc_optset, base); + + switch (option) { + case NN_IPC_SEC_ATTR: + memcpy(optval, &optset->sec_attr, sizeof(optset->sec_attr)); + *optvallen = sizeof(optset->sec_attr); + return 0; + case NN_IPC_OUTBUFSZ: + *(int *)optval = optset->outbuffersz; + *optvallen = sizeof (int); + return 0; + case NN_IPC_INBUFSZ: + *(int *)optval = optset->inbuffersz; + *optvallen = sizeof (int); + return 0; + default: + return -ENOPROTOOPT; + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/ipc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/ipc.h new file mode 100644 index 0000000..8c52780 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/ipc.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_IPC_INCLUDED +#define NN_IPC_INCLUDED + +#include "../../transport.h" + +extern struct nn_transport *nn_ipc; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/sipc.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/sipc.c new file mode 100644 index 0000000..8375d49 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/sipc.c @@ -0,0 +1,422 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sipc.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/wire.h" +#include "../../utils/attr.h" + +/* Types of messages passed via IPC transport. */ +#define NN_SIPC_MSG_NORMAL 1 +#define NN_SIPC_MSG_SHMEM 2 + +/* States of the object as a whole. */ +#define NN_SIPC_STATE_IDLE 1 +#define NN_SIPC_STATE_PROTOHDR 2 +#define NN_SIPC_STATE_STOPPING_STREAMHDR 3 +#define NN_SIPC_STATE_ACTIVE 4 +#define NN_SIPC_STATE_SHUTTING_DOWN 5 +#define NN_SIPC_STATE_DONE 6 +#define NN_SIPC_STATE_STOPPING 7 + +/* Subordinated srcptr objects. */ +#define NN_SIPC_SRC_USOCK 1 +#define NN_SIPC_SRC_STREAMHDR 2 + +/* Possible states of the inbound part of the object. */ +#define NN_SIPC_INSTATE_HDR 1 +#define NN_SIPC_INSTATE_BODY 2 +#define NN_SIPC_INSTATE_HASMSG 3 + +/* Possible states of the outbound part of the object. */ +#define NN_SIPC_OUTSTATE_IDLE 1 +#define NN_SIPC_OUTSTATE_SENDING 2 + +/* Stream is a special type of pipe. Implementation of the virtual pipe API. */ +static int nn_sipc_send (struct nn_pipebase *self, struct nn_msg *msg); +static int nn_sipc_recv (struct nn_pipebase *self, struct nn_msg *msg); +const struct nn_pipebase_vfptr nn_sipc_pipebase_vfptr = { + nn_sipc_send, + nn_sipc_recv +}; + +/* Private functions. */ +static void nn_sipc_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_sipc_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_sipc_init (struct nn_sipc *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_sipc_handler, nn_sipc_shutdown, + src, self, owner); + self->state = NN_SIPC_STATE_IDLE; + nn_streamhdr_init (&self->streamhdr, NN_SIPC_SRC_STREAMHDR, &self->fsm); + self->usock = NULL; + self->usock_owner.src = -1; + self->usock_owner.fsm = NULL; + nn_pipebase_init (&self->pipebase, &nn_sipc_pipebase_vfptr, epbase); + self->instate = -1; + nn_msg_init (&self->inmsg, 0); + self->outstate = -1; + nn_msg_init (&self->outmsg, 0); + nn_fsm_event_init (&self->done); +} + +void nn_sipc_term (struct nn_sipc *self) +{ + nn_assert_state (self, NN_SIPC_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_msg_term (&self->outmsg); + nn_msg_term (&self->inmsg); + nn_pipebase_term (&self->pipebase); + nn_streamhdr_term (&self->streamhdr); + nn_fsm_term (&self->fsm); +} + +int nn_sipc_isidle (struct nn_sipc *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_sipc_start (struct nn_sipc *self, struct nn_usock *usock) +{ + /* Take ownership of the underlying socket. */ + nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL); + self->usock_owner.src = NN_SIPC_SRC_USOCK; + self->usock_owner.fsm = &self->fsm; + nn_usock_swap_owner (usock, &self->usock_owner); + self->usock = usock; + + /* Launch the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_sipc_stop (struct nn_sipc *self) +{ + nn_fsm_stop (&self->fsm); +} + +static int nn_sipc_send (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_sipc *sipc; + struct nn_iovec iov [3]; + + sipc = nn_cont (self, struct nn_sipc, pipebase); + + nn_assert_state (sipc, NN_SIPC_STATE_ACTIVE); + nn_assert (sipc->outstate == NN_SIPC_OUTSTATE_IDLE); + + /* Move the message to the local storage. */ + nn_msg_term (&sipc->outmsg); + nn_msg_mv (&sipc->outmsg, msg); + + /* Serialise the message header. */ + sipc->outhdr [0] = NN_SIPC_MSG_NORMAL; + nn_putll (sipc->outhdr + 1, nn_chunkref_size (&sipc->outmsg.sphdr) + + nn_chunkref_size (&sipc->outmsg.body)); + + /* Start async sending. */ + iov [0].iov_base = sipc->outhdr; + iov [0].iov_len = sizeof (sipc->outhdr); + iov [1].iov_base = nn_chunkref_data (&sipc->outmsg.sphdr); + iov [1].iov_len = nn_chunkref_size (&sipc->outmsg.sphdr); + iov [2].iov_base = nn_chunkref_data (&sipc->outmsg.body); + iov [2].iov_len = nn_chunkref_size (&sipc->outmsg.body); + nn_usock_send (sipc->usock, iov, 3); + + sipc->outstate = NN_SIPC_OUTSTATE_SENDING; + + return 0; +} + +static int nn_sipc_recv (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_sipc *sipc; + + sipc = nn_cont (self, struct nn_sipc, pipebase); + + nn_assert_state (sipc, NN_SIPC_STATE_ACTIVE); + nn_assert (sipc->instate == NN_SIPC_INSTATE_HASMSG); + + /* Move received message to the user. */ + nn_msg_mv (msg, &sipc->inmsg); + nn_msg_init (&sipc->inmsg, 0); + + /* Start receiving new message. */ + sipc->instate = NN_SIPC_INSTATE_HDR; + nn_usock_recv (sipc->usock, sipc->inhdr, sizeof (sipc->inhdr), NULL); + + return 0; +} + +static void nn_sipc_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_sipc *sipc; + + sipc = nn_cont (self, struct nn_sipc, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_pipebase_stop (&sipc->pipebase); + nn_streamhdr_stop (&sipc->streamhdr); + sipc->state = NN_SIPC_STATE_STOPPING; + } + if (nn_slow (sipc->state == NN_SIPC_STATE_STOPPING)) { + if (nn_streamhdr_isidle (&sipc->streamhdr)) { + nn_usock_swap_owner (sipc->usock, &sipc->usock_owner); + sipc->usock = NULL; + sipc->usock_owner.src = -1; + sipc->usock_owner.fsm = NULL; + sipc->state = NN_SIPC_STATE_IDLE; + nn_fsm_stopped (&sipc->fsm, NN_SIPC_STOPPED); + return; + } + return; + } + + nn_fsm_bad_state(sipc->state, src, type); +} + +static void nn_sipc_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + int rc; + struct nn_sipc *sipc; + uint64_t size; + + sipc = nn_cont (self, struct nn_sipc, fsm); + + + switch (sipc->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_SIPC_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_streamhdr_start (&sipc->streamhdr, sipc->usock, + &sipc->pipebase); + sipc->state = NN_SIPC_STATE_PROTOHDR; + return; + default: + nn_fsm_bad_action (sipc->state, src, type); + } + + default: + nn_fsm_bad_source (sipc->state, src, type); + } + +/******************************************************************************/ +/* PROTOHDR state. */ +/******************************************************************************/ + case NN_SIPC_STATE_PROTOHDR: + switch (src) { + + case NN_SIPC_SRC_STREAMHDR: + switch (type) { + case NN_STREAMHDR_OK: + + /* Before moving to the active state stop the streamhdr + state machine. */ + nn_streamhdr_stop (&sipc->streamhdr); + sipc->state = NN_SIPC_STATE_STOPPING_STREAMHDR; + return; + + case NN_STREAMHDR_ERROR: + + /* Raise the error and move directly to the DONE state. + streamhdr object will be stopped later on. */ + sipc->state = NN_SIPC_STATE_DONE; + nn_fsm_raise (&sipc->fsm, &sipc->done, NN_SIPC_ERROR); + return; + + default: + nn_fsm_bad_action (sipc->state, src, type); + } + + default: + nn_fsm_bad_source (sipc->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_STREAMHDR state. */ +/******************************************************************************/ + case NN_SIPC_STATE_STOPPING_STREAMHDR: + switch (src) { + + case NN_SIPC_SRC_STREAMHDR: + switch (type) { + case NN_STREAMHDR_STOPPED: + + /* Start the pipe. */ + rc = nn_pipebase_start (&sipc->pipebase); + if (nn_slow (rc < 0)) { + sipc->state = NN_SIPC_STATE_DONE; + nn_fsm_raise (&sipc->fsm, &sipc->done, NN_SIPC_ERROR); + return; + } + + /* Start receiving a message in asynchronous manner. */ + sipc->instate = NN_SIPC_INSTATE_HDR; + nn_usock_recv (sipc->usock, &sipc->inhdr, + sizeof (sipc->inhdr), NULL); + + /* Mark the pipe as available for sending. */ + sipc->outstate = NN_SIPC_OUTSTATE_IDLE; + + sipc->state = NN_SIPC_STATE_ACTIVE; + return; + + default: + nn_fsm_bad_action (sipc->state, src, type); + } + + default: + nn_fsm_bad_source (sipc->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_SIPC_STATE_ACTIVE: + switch (src) { + + case NN_SIPC_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + + /* The message is now fully sent. */ + nn_assert (sipc->outstate == NN_SIPC_OUTSTATE_SENDING); + sipc->outstate = NN_SIPC_OUTSTATE_IDLE; + nn_msg_term (&sipc->outmsg); + nn_msg_init (&sipc->outmsg, 0); + nn_pipebase_sent (&sipc->pipebase); + return; + + case NN_USOCK_RECEIVED: + + switch (sipc->instate) { + case NN_SIPC_INSTATE_HDR: + + /* Message header was received. Allocate memory for the + message. */ + nn_assert (sipc->inhdr [0] == NN_SIPC_MSG_NORMAL); + size = nn_getll (sipc->inhdr + 1); + nn_msg_term (&sipc->inmsg); + nn_msg_init (&sipc->inmsg, (size_t) size); + + /* Special case when size of the message body is 0. */ + if (!size) { + sipc->instate = NN_SIPC_INSTATE_HASMSG; + nn_pipebase_received (&sipc->pipebase); + return; + } + + /* Start receiving the message body. */ + sipc->instate = NN_SIPC_INSTATE_BODY; + nn_usock_recv (sipc->usock, + nn_chunkref_data (&sipc->inmsg.body), + (size_t) size, NULL); + + return; + + case NN_SIPC_INSTATE_BODY: + + /* Message body was received. Notify the owner that it + can receive it. */ + sipc->instate = NN_SIPC_INSTATE_HASMSG; + nn_pipebase_received (&sipc->pipebase); + + return; + + default: + nn_assert (0); + } + + case NN_USOCK_SHUTDOWN: + nn_pipebase_stop (&sipc->pipebase); + sipc->state = NN_SIPC_STATE_SHUTTING_DOWN; + return; + + case NN_USOCK_ERROR: + nn_pipebase_stop (&sipc->pipebase); + sipc->state = NN_SIPC_STATE_DONE; + nn_fsm_raise (&sipc->fsm, &sipc->done, NN_SIPC_ERROR); + return; + + + default: + nn_fsm_bad_action (sipc->state, src, type); + } + + default: + nn_fsm_bad_source (sipc->state, src, type); + } + +/******************************************************************************/ +/* SHUTTING_DOWN state. */ +/* The underlying connection is closed. We are just waiting that underlying */ +/* usock being closed */ +/******************************************************************************/ + case NN_SIPC_STATE_SHUTTING_DOWN: + switch (src) { + + case NN_SIPC_SRC_USOCK: + switch (type) { + case NN_USOCK_ERROR: + sipc->state = NN_SIPC_STATE_DONE; + nn_fsm_raise (&sipc->fsm, &sipc->done, NN_SIPC_ERROR); + return; + default: + nn_fsm_bad_action (sipc->state, src, type); + } + + default: + nn_fsm_bad_source (sipc->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/* The underlying connection is closed. There's nothing that can be done in */ +/* this state except stopping the object. */ +/******************************************************************************/ + case NN_SIPC_STATE_DONE: + nn_fsm_bad_source (sipc->state, src, type); + + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (sipc->state, src, type); + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/sipc.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/sipc.h new file mode 100644 index 0000000..eaf1e2b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ipc/sipc.h @@ -0,0 +1,89 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SIPC_INCLUDED +#define NN_SIPC_INCLUDED + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../utils/streamhdr.h" + +#include "../../utils/msg.h" + +/* This state machine handles IPC connection from the point where it is + established to the point when it is broken. */ + +#define NN_SIPC_ERROR 1 +#define NN_SIPC_STOPPED 2 + +struct nn_sipc { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* The underlying socket. */ + struct nn_usock *usock; + + /* Child state machine to do protocol header exchange. */ + struct nn_streamhdr streamhdr; + + /* The original owner of the underlying socket. */ + struct nn_fsm_owner usock_owner; + + /* Pipe connecting this IPC connection to the nanomsg core. */ + struct nn_pipebase pipebase; + + /* State of inbound state machine. */ + int instate; + + /* Buffer used to store the header of incoming message. */ + uint8_t inhdr [9]; + + /* Message being received at the moment. */ + struct nn_msg inmsg; + + /* State of the outbound state machine. */ + int outstate; + + /* Buffer used to store the header of outgoing message. */ + uint8_t outhdr [9]; + + /* Message being sent at the moment. */ + struct nn_msg outmsg; + + /* Event raised when the state machine ends. */ + struct nn_fsm_event done; +}; + +void nn_sipc_init (struct nn_sipc *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_sipc_term (struct nn_sipc *self); + +int nn_sipc_isidle (struct nn_sipc *self); +void nn_sipc_start (struct nn_sipc *self, struct nn_usock *usock); +void nn_sipc_stop (struct nn_sipc *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/atcp.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/atcp.c new file mode 100644 index 0000000..e94be8f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/atcp.c @@ -0,0 +1,311 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "atcp.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/attr.h" + +#define NN_ATCP_STATE_IDLE 1 +#define NN_ATCP_STATE_ACCEPTING 2 +#define NN_ATCP_STATE_ACTIVE 3 +#define NN_ATCP_STATE_STOPPING_STCP 4 +#define NN_ATCP_STATE_STOPPING_USOCK 5 +#define NN_ATCP_STATE_DONE 6 +#define NN_ATCP_STATE_STOPPING_STCP_FINAL 7 +#define NN_ATCP_STATE_STOPPING 8 + +#define NN_ATCP_SRC_USOCK 1 +#define NN_ATCP_SRC_STCP 2 +#define NN_ATCP_SRC_LISTENER 3 + +/* Private functions. */ +static void nn_atcp_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_atcp_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_atcp_init (struct nn_atcp *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_atcp_handler, nn_atcp_shutdown, + src, self, owner); + self->state = NN_ATCP_STATE_IDLE; + self->epbase = epbase; + nn_usock_init (&self->usock, NN_ATCP_SRC_USOCK, &self->fsm); + self->listener = NULL; + self->listener_owner.src = -1; + self->listener_owner.fsm = NULL; + nn_stcp_init (&self->stcp, NN_ATCP_SRC_STCP, epbase, &self->fsm); + nn_fsm_event_init (&self->accepted); + nn_fsm_event_init (&self->done); + nn_list_item_init (&self->item); +} + +void nn_atcp_term (struct nn_atcp *self) +{ + nn_assert_state (self, NN_ATCP_STATE_IDLE); + + nn_list_item_term (&self->item); + nn_fsm_event_term (&self->done); + nn_fsm_event_term (&self->accepted); + nn_stcp_term (&self->stcp); + nn_usock_term (&self->usock); + nn_fsm_term (&self->fsm); +} + +int nn_atcp_isidle (struct nn_atcp *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_atcp_start (struct nn_atcp *self, struct nn_usock *listener) +{ + nn_assert_state (self, NN_ATCP_STATE_IDLE); + + /* Take ownership of the listener socket. */ + self->listener = listener; + self->listener_owner.src = NN_ATCP_SRC_LISTENER; + self->listener_owner.fsm = &self->fsm; + nn_usock_swap_owner (listener, &self->listener_owner); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_atcp_stop (struct nn_atcp *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_atcp_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_atcp *atcp; + + atcp = nn_cont (self, struct nn_atcp, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (!nn_stcp_isidle (&atcp->stcp)) { + nn_epbase_stat_increment (atcp->epbase, + NN_STAT_DROPPED_CONNECTIONS, 1); + nn_stcp_stop (&atcp->stcp); + } + atcp->state = NN_ATCP_STATE_STOPPING_STCP_FINAL; + } + if (nn_slow (atcp->state == NN_ATCP_STATE_STOPPING_STCP_FINAL)) { + if (!nn_stcp_isidle (&atcp->stcp)) + return; + nn_usock_stop (&atcp->usock); + atcp->state = NN_ATCP_STATE_STOPPING; + } + if (nn_slow (atcp->state == NN_ATCP_STATE_STOPPING)) { + if (!nn_usock_isidle (&atcp->usock)) + return; + if (atcp->listener) { + nn_assert (atcp->listener_owner.fsm); + nn_usock_swap_owner (atcp->listener, &atcp->listener_owner); + atcp->listener = NULL; + atcp->listener_owner.src = -1; + atcp->listener_owner.fsm = NULL; + } + atcp->state = NN_ATCP_STATE_IDLE; + nn_fsm_stopped (&atcp->fsm, NN_ATCP_STOPPED); + return; + } + + nn_fsm_bad_action(atcp->state, src, type); +} + +static void nn_atcp_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_atcp *atcp; + int val; + size_t sz; + + atcp = nn_cont (self, struct nn_atcp, fsm); + + switch (atcp->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The state machine wasn't yet started. */ +/******************************************************************************/ + case NN_ATCP_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_usock_accept (&atcp->usock, atcp->listener); + atcp->state = NN_ATCP_STATE_ACCEPTING; + return; + default: + nn_fsm_bad_action (atcp->state, src, type); + } + + default: + nn_fsm_bad_source (atcp->state, src, type); + } + +/******************************************************************************/ +/* ACCEPTING state. */ +/* Waiting for incoming connection. */ +/******************************************************************************/ + case NN_ATCP_STATE_ACCEPTING: + switch (src) { + + case NN_ATCP_SRC_USOCK: + switch (type) { + case NN_USOCK_ACCEPTED: + nn_epbase_clear_error (atcp->epbase); + + /* Set the relevant socket options. */ + sz = sizeof (val); + nn_epbase_getopt (atcp->epbase, NN_SOL_SOCKET, NN_SNDBUF, + &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&atcp->usock, SOL_SOCKET, SO_SNDBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (atcp->epbase, NN_SOL_SOCKET, NN_RCVBUF, + &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&atcp->usock, SOL_SOCKET, SO_RCVBUF, + &val, sizeof (val)); + + /* Return ownership of the listening socket to the parent. */ + nn_usock_swap_owner (atcp->listener, &atcp->listener_owner); + atcp->listener = NULL; + atcp->listener_owner.src = -1; + atcp->listener_owner.fsm = NULL; + nn_fsm_raise (&atcp->fsm, &atcp->accepted, NN_ATCP_ACCEPTED); + + /* Start the stcp state machine. */ + nn_usock_activate (&atcp->usock); + nn_stcp_start (&atcp->stcp, &atcp->usock); + atcp->state = NN_ATCP_STATE_ACTIVE; + + nn_epbase_stat_increment (atcp->epbase, + NN_STAT_ACCEPTED_CONNECTIONS, 1); + + return; + + default: + nn_fsm_bad_action (atcp->state, src, type); + } + + case NN_ATCP_SRC_LISTENER: + switch (type) { + + case NN_USOCK_ACCEPT_ERROR: + nn_epbase_set_error (atcp->epbase, + nn_usock_geterrno(atcp->listener)); + nn_epbase_stat_increment (atcp->epbase, + NN_STAT_ACCEPT_ERRORS, 1); + nn_usock_accept (&atcp->usock, atcp->listener); + return; + + default: + nn_fsm_bad_action (atcp->state, src, type); + } + + default: + nn_fsm_bad_source (atcp->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_ATCP_STATE_ACTIVE: + switch (src) { + + case NN_ATCP_SRC_STCP: + switch (type) { + case NN_STCP_ERROR: + nn_stcp_stop (&atcp->stcp); + atcp->state = NN_ATCP_STATE_STOPPING_STCP; + nn_epbase_stat_increment (atcp->epbase, + NN_STAT_BROKEN_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (atcp->state, src, type); + } + + default: + nn_fsm_bad_source (atcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_STCP state. */ +/******************************************************************************/ + case NN_ATCP_STATE_STOPPING_STCP: + switch (src) { + + case NN_ATCP_SRC_STCP: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_STCP_STOPPED: + nn_usock_stop (&atcp->usock); + atcp->state = NN_ATCP_STATE_STOPPING_USOCK; + return; + default: + nn_fsm_bad_action (atcp->state, src, type); + } + + default: + nn_fsm_bad_source (atcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_USOCK state. */ +/******************************************************************************/ + case NN_ATCP_STATE_STOPPING_USOCK: + switch (src) { + + case NN_ATCP_SRC_USOCK: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_STOPPED: + nn_fsm_raise (&atcp->fsm, &atcp->done, NN_ATCP_ERROR); + atcp->state = NN_ATCP_STATE_DONE; + return; + default: + nn_fsm_bad_action (atcp->state, src, type); + } + + default: + nn_fsm_bad_source (atcp->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (atcp->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/atcp.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/atcp.h new file mode 100644 index 0000000..435d2a8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/atcp.h @@ -0,0 +1,80 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_ATCP_INCLUDED +#define NN_ATCP_INCLUDED + +#include "stcp.h" + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/list.h" + +/* State machine handling accepted TCP sockets. */ + +/* In btcp, some events are just *assumed* to come from a child atcp object. + By using non-trivial event codes, we can do more reliable sanity checking + in such scenarios. */ +#define NN_ATCP_ACCEPTED 34231 +#define NN_ATCP_ERROR 34232 +#define NN_ATCP_STOPPED 34233 + +struct nn_atcp { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Pointer to the associated endpoint. */ + struct nn_epbase *epbase; + + /* Underlying socket. */ + struct nn_usock usock; + + /* Listening socket. Valid only while accepting new connection. */ + struct nn_usock *listener; + struct nn_fsm_owner listener_owner; + + /* State machine that takes care of the connection in the active state. */ + struct nn_stcp stcp; + + /* Events generated by atcp state machine. */ + struct nn_fsm_event accepted; + struct nn_fsm_event done; + + /* This member can be used by owner to keep individual atcps in a list. */ + struct nn_list_item item; +}; + +void nn_atcp_init (struct nn_atcp *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_atcp_term (struct nn_atcp *self); + +int nn_atcp_isidle (struct nn_atcp *self); +void nn_atcp_start (struct nn_atcp *self, struct nn_usock *listener); +void nn_atcp_stop (struct nn_atcp *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/btcp.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/btcp.c new file mode 100644 index 0000000..1b012c8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/btcp.c @@ -0,0 +1,407 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "btcp.h" +#include "atcp.h" + +#include "../utils/port.h" +#include "../utils/iface.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../utils/backoff.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/fast.h" + +#include + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#endif + +/* The backlog is set relatively high so that there are not too many failed + connection attemps during re-connection storms. */ +#define NN_BTCP_BACKLOG 100 + +#define NN_BTCP_STATE_IDLE 1 +#define NN_BTCP_STATE_ACTIVE 2 +#define NN_BTCP_STATE_STOPPING_ATCP 3 +#define NN_BTCP_STATE_STOPPING_USOCK 4 +#define NN_BTCP_STATE_STOPPING_ATCPS 5 + +#define NN_BTCP_SRC_USOCK 1 +#define NN_BTCP_SRC_ATCP 2 + +struct nn_btcp { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is a specific type of endpoint. + Thus it is derived from epbase. */ + struct nn_epbase epbase; + + /* The underlying listening TCP socket. */ + struct nn_usock usock; + + /* The connection being accepted at the moment. */ + struct nn_atcp *atcp; + + /* List of accepted connections. */ + struct nn_list atcps; +}; + +/* nn_epbase virtual interface implementation. */ +static void nn_btcp_stop (struct nn_epbase *self); +static void nn_btcp_destroy (struct nn_epbase *self); +const struct nn_epbase_vfptr nn_btcp_epbase_vfptr = { + nn_btcp_stop, + nn_btcp_destroy +}; + +/* Private functions. */ +static void nn_btcp_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_btcp_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static int nn_btcp_listen (struct nn_btcp *self); +static void nn_btcp_start_accepting (struct nn_btcp *self); + +int nn_btcp_create (void *hint, struct nn_epbase **epbase) +{ + int rc; + struct nn_btcp *self; + const char *addr; + const char *end; + const char *pos; + struct sockaddr_storage ss; + size_t sslen; + int ipv4only; + size_t ipv4onlylen; + + /* Allocate the new endpoint object. */ + self = nn_alloc (sizeof (struct nn_btcp), "btcp"); + alloc_assert (self); + + /* Initalise the epbase. */ + nn_epbase_init (&self->epbase, &nn_btcp_epbase_vfptr, hint); + addr = nn_epbase_getaddr (&self->epbase); + + /* Parse the port. */ + end = addr + strlen (addr); + pos = strrchr (addr, ':'); + if (nn_slow (!pos)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + ++pos; + rc = nn_port_resolve (pos, end - pos); + if (nn_slow (rc < 0)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + /* Parse the address. */ + rc = nn_iface_resolve (addr, pos - addr - 1, ipv4only, &ss, &sslen); + if (nn_slow (rc < 0)) { + nn_epbase_term (&self->epbase); + return -ENODEV; + } + + /* Initialise the structure. */ + nn_fsm_init_root (&self->fsm, nn_btcp_handler, nn_btcp_shutdown, + nn_epbase_getctx (&self->epbase)); + self->state = NN_BTCP_STATE_IDLE; + self->atcp = NULL; + nn_list_init (&self->atcps); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + nn_usock_init (&self->usock, NN_BTCP_SRC_USOCK, &self->fsm); + + rc = nn_btcp_listen (self); + if (rc != 0) { + nn_epbase_term (&self->epbase); + return rc; + } + + /* Return the base class as an out parameter. */ + *epbase = &self->epbase; + + return 0; +} + +static void nn_btcp_stop (struct nn_epbase *self) +{ + struct nn_btcp *btcp; + + btcp = nn_cont (self, struct nn_btcp, epbase); + + nn_fsm_stop (&btcp->fsm); +} + +static void nn_btcp_destroy (struct nn_epbase *self) +{ + struct nn_btcp *btcp; + + btcp = nn_cont (self, struct nn_btcp, epbase); + + nn_assert_state (btcp, NN_BTCP_STATE_IDLE); + nn_list_term (&btcp->atcps); + nn_assert (btcp->atcp == NULL); + nn_usock_term (&btcp->usock); + nn_epbase_term (&btcp->epbase); + nn_fsm_term (&btcp->fsm); + + nn_free (btcp); +} + +static void nn_btcp_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_btcp *btcp; + struct nn_list_item *it; + struct nn_atcp *atcp; + + btcp = nn_cont (self, struct nn_btcp, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (btcp->atcp) { + nn_atcp_stop (btcp->atcp); + btcp->state = NN_BTCP_STATE_STOPPING_ATCP; + } + else { + btcp->state = NN_BTCP_STATE_STOPPING_USOCK; + } + } + if (nn_slow (btcp->state == NN_BTCP_STATE_STOPPING_ATCP)) { + if (!nn_atcp_isidle (btcp->atcp)) + return; + nn_atcp_term (btcp->atcp); + nn_free (btcp->atcp); + btcp->atcp = NULL; + nn_usock_stop (&btcp->usock); + btcp->state = NN_BTCP_STATE_STOPPING_USOCK; + } + if (nn_slow (btcp->state == NN_BTCP_STATE_STOPPING_USOCK)) { + if (!nn_usock_isidle (&btcp->usock)) + return; + for (it = nn_list_begin (&btcp->atcps); + it != nn_list_end (&btcp->atcps); + it = nn_list_next (&btcp->atcps, it)) { + atcp = nn_cont (it, struct nn_atcp, item); + nn_atcp_stop (atcp); + } + btcp->state = NN_BTCP_STATE_STOPPING_ATCPS; + goto atcps_stopping; + } + if (nn_slow (btcp->state == NN_BTCP_STATE_STOPPING_ATCPS)) { + nn_assert (src == NN_BTCP_SRC_ATCP && type == NN_ATCP_STOPPED); + atcp = (struct nn_atcp *) srcptr; + nn_list_erase (&btcp->atcps, &atcp->item); + nn_atcp_term (atcp); + nn_free (atcp); + + /* If there are no more atcp state machines, we can stop the whole + btcp object. */ +atcps_stopping: + if (nn_list_empty (&btcp->atcps)) { + btcp->state = NN_BTCP_STATE_IDLE; + nn_fsm_stopped_noevent (&btcp->fsm); + nn_epbase_stopped (&btcp->epbase); + return; + } + + return; + } + + nn_fsm_bad_action(btcp->state, src, type); +} + +static void nn_btcp_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_btcp *btcp; + struct nn_atcp *atcp; + + btcp = nn_cont (self, struct nn_btcp, fsm); + + switch (btcp->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_BTCP_STATE_IDLE: + nn_assert (src == NN_FSM_ACTION); + nn_assert (type == NN_FSM_START); + btcp->state = NN_BTCP_STATE_ACTIVE; + return; + +/******************************************************************************/ +/* ACTIVE state. */ +/* The execution is yielded to the atcp state machine in this state. */ +/******************************************************************************/ + case NN_BTCP_STATE_ACTIVE: + if (src == NN_BTCP_SRC_USOCK) { + /* usock object cleaning up */ + nn_assert (type == NN_USOCK_SHUTDOWN || type == NN_USOCK_STOPPED); + return; + } + + /* All other events come from child atcp objects. */ + nn_assert (src == NN_BTCP_SRC_ATCP); + atcp = (struct nn_atcp*) srcptr; + switch (type) { + case NN_ATCP_ACCEPTED: + nn_assert (btcp->atcp == atcp) ; + nn_list_insert (&btcp->atcps, &atcp->item, + nn_list_end (&btcp->atcps)); + btcp->atcp = NULL; + nn_btcp_start_accepting (btcp); + return; + case NN_ATCP_ERROR: + nn_atcp_stop (atcp); + return; + case NN_ATCP_STOPPED: + nn_list_erase (&btcp->atcps, &atcp->item); + nn_atcp_term (atcp); + nn_free (atcp); + return; + default: + nn_fsm_bad_action (btcp->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (btcp->state, src, type); + } +} + +static int nn_btcp_listen (struct nn_btcp *self) +{ + int rc; + struct sockaddr_storage ss; + size_t sslen; + int ipv4only; + size_t ipv4onlylen; + const char *addr; + const char *end; + const char *pos; + uint16_t port; + + /* First, resolve the IP address. */ + addr = nn_epbase_getaddr (&self->epbase); + memset (&ss, 0, sizeof (ss)); + + /* Parse the port. */ + end = addr + strlen (addr); + pos = strrchr (addr, ':'); + if (pos == NULL) { + return -EINVAL; + } + ++pos; + rc = nn_port_resolve (pos, end - pos); + if (rc <= 0) + return rc; + port = (uint16_t) rc; + + /* Parse the address. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + rc = nn_iface_resolve (addr, pos - addr - 1, ipv4only, &ss, &sslen); + if (rc < 0) { + return rc; + } + + /* Combine the port and the address. */ + switch (ss.ss_family) { + case AF_INET: + ((struct sockaddr_in*) &ss)->sin_port = htons (port); + sslen = sizeof (struct sockaddr_in); + break; + case AF_INET6: + ((struct sockaddr_in6*) &ss)->sin6_port = htons (port); + sslen = sizeof (struct sockaddr_in6); + break; + default: + nn_assert (0); + } + + /* Start listening for incoming connections. */ + rc = nn_usock_start (&self->usock, ss.ss_family, SOCK_STREAM, 0); + if (rc < 0) { + return rc; + } + + rc = nn_usock_bind (&self->usock, (struct sockaddr*) &ss, (size_t) sslen); + if (rc < 0) { + nn_usock_stop (&self->usock); + return rc; + } + + rc = nn_usock_listen (&self->usock, NN_BTCP_BACKLOG); + if (rc < 0) { + nn_usock_stop (&self->usock); + return rc; + } + nn_btcp_start_accepting(self); + + return 0; +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_btcp_start_accepting (struct nn_btcp *self) +{ + nn_assert (self->atcp == NULL); + + /* Allocate new atcp state machine. */ + self->atcp = nn_alloc (sizeof (struct nn_atcp), "atcp"); + alloc_assert (self->atcp); + nn_atcp_init (self->atcp, NN_BTCP_SRC_ATCP, &self->epbase, &self->fsm); + + /* Start waiting for a new incoming connection. */ + nn_atcp_start (self->atcp, &self->usock); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/btcp.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/btcp.h new file mode 100644 index 0000000..30aca24 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/btcp.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BTCP_INCLUDED +#define NN_BTCP_INCLUDED + +#include "../../transport.h" + +/* State machine managing bound TCP socket. */ + +int nn_btcp_create (void *hint, struct nn_epbase **epbase); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.c new file mode 100644 index 0000000..d46ddf7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.c @@ -0,0 +1,630 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ctcp.h" +#include "stcp.h" + +#include "../../tcp.h" + +#include "../utils/dns.h" +#include "../utils/port.h" +#include "../utils/iface.h" +#include "../utils/backoff.h" +#include "../utils/literal.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/attr.h" + +#include + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#include +#endif + +#define NN_CTCP_STATE_IDLE 1 +#define NN_CTCP_STATE_RESOLVING 2 +#define NN_CTCP_STATE_STOPPING_DNS 3 +#define NN_CTCP_STATE_CONNECTING 4 +#define NN_CTCP_STATE_ACTIVE 5 +#define NN_CTCP_STATE_STOPPING_STCP 6 +#define NN_CTCP_STATE_STOPPING_USOCK 7 +#define NN_CTCP_STATE_WAITING 8 +#define NN_CTCP_STATE_STOPPING_BACKOFF 9 +#define NN_CTCP_STATE_STOPPING_STCP_FINAL 10 +#define NN_CTCP_STATE_STOPPING 11 + +#define NN_CTCP_SRC_USOCK 1 +#define NN_CTCP_SRC_RECONNECT_TIMER 2 +#define NN_CTCP_SRC_DNS 3 +#define NN_CTCP_SRC_STCP 4 + +struct nn_ctcp { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is a specific type of endpoint. + Thus it is derived from epbase. */ + struct nn_epbase epbase; + + /* The underlying TCP socket. */ + struct nn_usock usock; + + /* Used to wait before retrying to connect. */ + struct nn_backoff retry; + + /* State machine that handles the active part of the connection + lifetime. */ + struct nn_stcp stcp; + + /* DNS resolver used to convert textual address into actual IP address + along with the variable to hold the result. */ + struct nn_dns dns; + struct nn_dns_result dns_result; +}; + +/* nn_epbase virtual interface implementation. */ +static void nn_ctcp_stop (struct nn_epbase *self); +static void nn_ctcp_destroy (struct nn_epbase *self); +const struct nn_epbase_vfptr nn_ctcp_epbase_vfptr = { + nn_ctcp_stop, + nn_ctcp_destroy +}; + +/* Private functions. */ +static void nn_ctcp_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_ctcp_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_ctcp_start_resolving (struct nn_ctcp *self); +static void nn_ctcp_start_connecting (struct nn_ctcp *self, + struct sockaddr_storage *ss, size_t sslen); + +int nn_ctcp_create (void *hint, struct nn_epbase **epbase) +{ + int rc; + const char *addr; + size_t addrlen; + const char *semicolon; + const char *hostname; + const char *colon; + const char *end; + struct sockaddr_storage ss; + size_t sslen; + int ipv4only; + size_t ipv4onlylen; + struct nn_ctcp *self; + int reconnect_ivl; + int reconnect_ivl_max; + size_t sz; + + /* Allocate the new endpoint object. */ + self = nn_alloc (sizeof (struct nn_ctcp), "ctcp"); + alloc_assert (self); + + /* Initalise the endpoint. */ + nn_epbase_init (&self->epbase, &nn_ctcp_epbase_vfptr, hint); + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + /* Start parsing the address. */ + addr = nn_epbase_getaddr (&self->epbase); + addrlen = strlen (addr); + semicolon = strchr (addr, ';'); + hostname = semicolon ? semicolon + 1 : addr; + colon = strrchr (addr, ':'); + end = addr + addrlen; + + /* Parse the port. */ + if (nn_slow (!colon)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + rc = nn_port_resolve (colon + 1, end - colon - 1); + if (nn_slow (rc < 0)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + + /* Check whether the host portion of the address is either a literal + or a valid hostname. */ + if (nn_dns_check_hostname (hostname, colon - hostname) < 0 && + nn_literal_resolve (hostname, colon - hostname, ipv4only, + &ss, &sslen) < 0) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + + /* If local address is specified, check whether it is valid. */ + if (semicolon) { + rc = nn_iface_resolve (addr, semicolon - addr, ipv4only, &ss, &sslen); + if (rc < 0) { + nn_epbase_term (&self->epbase); + return -ENODEV; + } + } + + /* Initialise the structure. */ + nn_fsm_init_root (&self->fsm, nn_ctcp_handler, nn_ctcp_shutdown, + nn_epbase_getctx (&self->epbase)); + self->state = NN_CTCP_STATE_IDLE; + nn_usock_init (&self->usock, NN_CTCP_SRC_USOCK, &self->fsm); + sz = sizeof (reconnect_ivl); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL, + &reconnect_ivl, &sz); + nn_assert (sz == sizeof (reconnect_ivl)); + sz = sizeof (reconnect_ivl_max); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL_MAX, + &reconnect_ivl_max, &sz); + nn_assert (sz == sizeof (reconnect_ivl_max)); + if (reconnect_ivl_max == 0) + reconnect_ivl_max = reconnect_ivl; + nn_backoff_init (&self->retry, NN_CTCP_SRC_RECONNECT_TIMER, + reconnect_ivl, reconnect_ivl_max, &self->fsm); + nn_stcp_init (&self->stcp, NN_CTCP_SRC_STCP, &self->epbase, &self->fsm); + nn_dns_init (&self->dns, NN_CTCP_SRC_DNS, &self->fsm); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + /* Return the base class as an out parameter. */ + *epbase = &self->epbase; + + return 0; +} + +static void nn_ctcp_stop (struct nn_epbase *self) +{ + struct nn_ctcp *ctcp; + + ctcp = nn_cont (self, struct nn_ctcp, epbase); + + nn_fsm_stop (&ctcp->fsm); +} + +static void nn_ctcp_destroy (struct nn_epbase *self) +{ + struct nn_ctcp *ctcp; + + ctcp = nn_cont (self, struct nn_ctcp, epbase); + + nn_dns_term (&ctcp->dns); + nn_stcp_term (&ctcp->stcp); + nn_backoff_term (&ctcp->retry); + nn_usock_term (&ctcp->usock); + nn_fsm_term (&ctcp->fsm); + nn_epbase_term (&ctcp->epbase); + + nn_free (ctcp); +} + +static void nn_ctcp_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_ctcp *ctcp; + + ctcp = nn_cont (self, struct nn_ctcp, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (!nn_stcp_isidle (&ctcp->stcp)) { + nn_epbase_stat_increment (&ctcp->epbase, + NN_STAT_DROPPED_CONNECTIONS, 1); + nn_stcp_stop (&ctcp->stcp); + } + ctcp->state = NN_CTCP_STATE_STOPPING_STCP_FINAL; + } + if (nn_slow (ctcp->state == NN_CTCP_STATE_STOPPING_STCP_FINAL)) { + if (!nn_stcp_isidle (&ctcp->stcp)) + return; + nn_backoff_stop (&ctcp->retry); + nn_usock_stop (&ctcp->usock); + nn_dns_stop (&ctcp->dns); + ctcp->state = NN_CTCP_STATE_STOPPING; + } + if (nn_slow (ctcp->state == NN_CTCP_STATE_STOPPING)) { + if (!nn_backoff_isidle (&ctcp->retry) || + !nn_usock_isidle (&ctcp->usock) || + !nn_dns_isidle (&ctcp->dns)) + return; + ctcp->state = NN_CTCP_STATE_IDLE; + nn_fsm_stopped_noevent (&ctcp->fsm); + nn_epbase_stopped (&ctcp->epbase); + return; + } + + nn_fsm_bad_state (ctcp->state, src, type); +} + +static void nn_ctcp_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_ctcp *ctcp; + + ctcp = nn_cont (self, struct nn_ctcp, fsm); + + switch (ctcp->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The state machine wasn't yet started. */ +/******************************************************************************/ + case NN_CTCP_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_ctcp_start_resolving (ctcp); + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* RESOLVING state. */ +/* Name of the host to connect to is being resolved to get an IP address. */ +/******************************************************************************/ + case NN_CTCP_STATE_RESOLVING: + switch (src) { + + case NN_CTCP_SRC_DNS: + switch (type) { + case NN_DNS_DONE: + nn_dns_stop (&ctcp->dns); + ctcp->state = NN_CTCP_STATE_STOPPING_DNS; + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_DNS state. */ +/* dns object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CTCP_STATE_STOPPING_DNS: + switch (src) { + + case NN_CTCP_SRC_DNS: + switch (type) { + case NN_DNS_STOPPED: + if (ctcp->dns_result.error == 0) { + nn_ctcp_start_connecting (ctcp, &ctcp->dns_result.addr, + ctcp->dns_result.addrlen); + return; + } + nn_backoff_start (&ctcp->retry); + ctcp->state = NN_CTCP_STATE_WAITING; + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* CONNECTING state. */ +/* Non-blocking connect is under way. */ +/******************************************************************************/ + case NN_CTCP_STATE_CONNECTING: + switch (src) { + + case NN_CTCP_SRC_USOCK: + switch (type) { + case NN_USOCK_CONNECTED: + nn_stcp_start (&ctcp->stcp, &ctcp->usock); + ctcp->state = NN_CTCP_STATE_ACTIVE; + nn_epbase_stat_increment (&ctcp->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&ctcp->epbase, + NN_STAT_ESTABLISHED_CONNECTIONS, 1); + nn_epbase_clear_error (&ctcp->epbase); + return; + case NN_USOCK_ERROR: + nn_epbase_set_error (&ctcp->epbase, + nn_usock_geterrno (&ctcp->usock)); + nn_usock_stop (&ctcp->usock); + ctcp->state = NN_CTCP_STATE_STOPPING_USOCK; + nn_epbase_stat_increment (&ctcp->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&ctcp->epbase, + NN_STAT_CONNECT_ERRORS, 1); + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* Connection is established and handled by the stcp state machine. */ +/******************************************************************************/ + case NN_CTCP_STATE_ACTIVE: + switch (src) { + + case NN_CTCP_SRC_STCP: + switch (type) { + case NN_STCP_ERROR: + nn_stcp_stop (&ctcp->stcp); + ctcp->state = NN_CTCP_STATE_STOPPING_STCP; + nn_epbase_stat_increment (&ctcp->epbase, + NN_STAT_BROKEN_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_STCP state. */ +/* stcp object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CTCP_STATE_STOPPING_STCP: + switch (src) { + + case NN_CTCP_SRC_STCP: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_STCP_STOPPED: + nn_usock_stop (&ctcp->usock); + ctcp->state = NN_CTCP_STATE_STOPPING_USOCK; + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_USOCK state. */ +/* usock object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CTCP_STATE_STOPPING_USOCK: + switch (src) { + + case NN_CTCP_SRC_USOCK: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_STOPPED: + nn_backoff_start (&ctcp->retry); + ctcp->state = NN_CTCP_STATE_WAITING; + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* WAITING state. */ +/* Waiting before re-connection is attempted. This way we won't overload */ +/* the system by continuous re-connection attemps. */ +/******************************************************************************/ + case NN_CTCP_STATE_WAITING: + switch (src) { + + case NN_CTCP_SRC_RECONNECT_TIMER: + switch (type) { + case NN_BACKOFF_TIMEOUT: + nn_backoff_stop (&ctcp->retry); + ctcp->state = NN_CTCP_STATE_STOPPING_BACKOFF; + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_BACKOFF state. */ +/* backoff object was asked to stop, but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CTCP_STATE_STOPPING_BACKOFF: + switch (src) { + + case NN_CTCP_SRC_RECONNECT_TIMER: + switch (type) { + case NN_BACKOFF_STOPPED: + nn_ctcp_start_resolving (ctcp); + return; + default: + nn_fsm_bad_action (ctcp->state, src, type); + } + + default: + nn_fsm_bad_source (ctcp->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (ctcp->state, src, type); + } +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_ctcp_start_resolving (struct nn_ctcp *self) +{ + const char *addr; + const char *begin; + const char *end; + int ipv4only; + size_t ipv4onlylen; + + /* Extract the hostname part from address string. */ + addr = nn_epbase_getaddr (&self->epbase); + begin = strchr (addr, ';'); + if (!begin) + begin = addr; + else + ++begin; + end = strrchr (addr, ':'); + nn_assert (end); + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + /* TODO: Get the actual value of IPV4ONLY option. */ + nn_dns_start (&self->dns, begin, end - begin, ipv4only, &self->dns_result); + + self->state = NN_CTCP_STATE_RESOLVING; +} + +static void nn_ctcp_start_connecting (struct nn_ctcp *self, + struct sockaddr_storage *ss, size_t sslen) +{ + int rc; + struct sockaddr_storage remote; + size_t remotelen; + struct sockaddr_storage local; + size_t locallen; + const char *addr; + const char *end; + const char *colon; + const char *semicolon; + uint16_t port; + int ipv4only; + size_t ipv4onlylen; + int val; + size_t sz; + + /* Create IP address from the address string. */ + addr = nn_epbase_getaddr (&self->epbase); + memset (&remote, 0, sizeof (remote)); + + /* Parse the port. */ + end = addr + strlen (addr); + colon = strrchr (addr, ':'); + rc = nn_port_resolve (colon + 1, end - colon - 1); + errnum_assert (rc > 0, -rc); + port = rc; + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + /* Parse the local address, if any. */ + semicolon = strchr (addr, ';'); + memset (&local, 0, sizeof (local)); + if (semicolon) + rc = nn_iface_resolve (addr, semicolon - addr, ipv4only, + &local, &locallen); + else + rc = nn_iface_resolve ("*", 1, ipv4only, &local, &locallen); + if (nn_slow (rc < 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CTCP_STATE_WAITING; + return; + } + + /* Combine the remote address and the port. */ + remote = *ss; + remotelen = sslen; + if (remote.ss_family == AF_INET) + ((struct sockaddr_in*) &remote)->sin_port = htons (port); + else if (remote.ss_family == AF_INET6) + ((struct sockaddr_in6*) &remote)->sin6_port = htons (port); + else + nn_assert (0); + + /* Try to start the underlying socket. */ + rc = nn_usock_start (&self->usock, remote.ss_family, SOCK_STREAM, 0); + if (nn_slow (rc < 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CTCP_STATE_WAITING; + return; + } + + /* Set the relevant socket options. */ + sz = sizeof (val); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_SNDBUF, &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&self->usock, SOL_SOCKET, SO_SNDBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RCVBUF, &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&self->usock, SOL_SOCKET, SO_RCVBUF, + &val, sizeof (val)); + + /* Bind the socket to the local network interface. */ + rc = nn_usock_bind (&self->usock, (struct sockaddr*) &local, locallen); + if (nn_slow (rc != 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CTCP_STATE_WAITING; + return; + } + + /* Start connecting. */ + nn_usock_connect (&self->usock, (struct sockaddr*) &remote, remotelen); + self->state = NN_CTCP_STATE_CONNECTING; + nn_epbase_stat_increment (&self->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, 1); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.h new file mode 100644 index 0000000..92b1694 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/ctcp.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CTCP_INCLUDED +#define NN_CTCP_INCLUDED + +#include "../../transport.h" + +/* State machine managing connected TCP socket. */ + +int nn_ctcp_create (void *hint, struct nn_epbase **epbase); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/stcp.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/stcp.c new file mode 100644 index 0000000..5abe536 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/stcp.c @@ -0,0 +1,430 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "stcp.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/wire.h" +#include "../../utils/attr.h" + +/* States of the object as a whole. */ +#define NN_STCP_STATE_IDLE 1 +#define NN_STCP_STATE_PROTOHDR 2 +#define NN_STCP_STATE_STOPPING_STREAMHDR 3 +#define NN_STCP_STATE_ACTIVE 4 +#define NN_STCP_STATE_SHUTTING_DOWN 5 +#define NN_STCP_STATE_DONE 6 +#define NN_STCP_STATE_STOPPING 7 + +/* Possible states of the inbound part of the object. */ +#define NN_STCP_INSTATE_HDR 1 +#define NN_STCP_INSTATE_BODY 2 +#define NN_STCP_INSTATE_HASMSG 3 + +/* Possible states of the outbound part of the object. */ +#define NN_STCP_OUTSTATE_IDLE 1 +#define NN_STCP_OUTSTATE_SENDING 2 + +/* Subordinate srcptr objects. */ +#define NN_STCP_SRC_USOCK 1 +#define NN_STCP_SRC_STREAMHDR 2 + +/* Stream is a special type of pipe. Implementation of the virtual pipe API. */ +static int nn_stcp_send (struct nn_pipebase *self, struct nn_msg *msg); +static int nn_stcp_recv (struct nn_pipebase *self, struct nn_msg *msg); +const struct nn_pipebase_vfptr nn_stcp_pipebase_vfptr = { + nn_stcp_send, + nn_stcp_recv +}; + +/* Private functions. */ +static void nn_stcp_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_stcp_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_stcp_init (struct nn_stcp *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_stcp_handler, nn_stcp_shutdown, + src, self, owner); + self->state = NN_STCP_STATE_IDLE; + nn_streamhdr_init (&self->streamhdr, NN_STCP_SRC_STREAMHDR, &self->fsm); + self->usock = NULL; + self->usock_owner.src = -1; + self->usock_owner.fsm = NULL; + nn_pipebase_init (&self->pipebase, &nn_stcp_pipebase_vfptr, epbase); + self->instate = -1; + nn_msg_init (&self->inmsg, 0); + self->outstate = -1; + nn_msg_init (&self->outmsg, 0); + nn_fsm_event_init (&self->done); +} + +void nn_stcp_term (struct nn_stcp *self) +{ + nn_assert_state (self, NN_STCP_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_msg_term (&self->outmsg); + nn_msg_term (&self->inmsg); + nn_pipebase_term (&self->pipebase); + nn_streamhdr_term (&self->streamhdr); + nn_fsm_term (&self->fsm); +} + +int nn_stcp_isidle (struct nn_stcp *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_stcp_start (struct nn_stcp *self, struct nn_usock *usock) +{ + /* Take ownership of the underlying socket. */ + nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL); + self->usock_owner.src = NN_STCP_SRC_USOCK; + self->usock_owner.fsm = &self->fsm; + nn_usock_swap_owner (usock, &self->usock_owner); + self->usock = usock; + + /* Launch the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_stcp_stop (struct nn_stcp *self) +{ + nn_fsm_stop (&self->fsm); +} + +static int nn_stcp_send (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_stcp *stcp; + struct nn_iovec iov [3]; + + stcp = nn_cont (self, struct nn_stcp, pipebase); + + nn_assert_state (stcp, NN_STCP_STATE_ACTIVE); + nn_assert (stcp->outstate == NN_STCP_OUTSTATE_IDLE); + + /* Move the message to the local storage. */ + nn_msg_term (&stcp->outmsg); + nn_msg_mv (&stcp->outmsg, msg); + + /* Serialise the message header. */ + nn_putll (stcp->outhdr, nn_chunkref_size (&stcp->outmsg.sphdr) + + nn_chunkref_size (&stcp->outmsg.body)); + + /* Start async sending. */ + iov [0].iov_base = stcp->outhdr; + iov [0].iov_len = sizeof (stcp->outhdr); + iov [1].iov_base = nn_chunkref_data (&stcp->outmsg.sphdr); + iov [1].iov_len = nn_chunkref_size (&stcp->outmsg.sphdr); + iov [2].iov_base = nn_chunkref_data (&stcp->outmsg.body); + iov [2].iov_len = nn_chunkref_size (&stcp->outmsg.body); + nn_usock_send (stcp->usock, iov, 3); + + stcp->outstate = NN_STCP_OUTSTATE_SENDING; + + return 0; +} + +static int nn_stcp_recv (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_stcp *stcp; + + stcp = nn_cont (self, struct nn_stcp, pipebase); + + nn_assert_state (stcp, NN_STCP_STATE_ACTIVE); + nn_assert (stcp->instate == NN_STCP_INSTATE_HASMSG); + + /* Move received message to the user. */ + nn_msg_mv (msg, &stcp->inmsg); + nn_msg_init (&stcp->inmsg, 0); + + /* Start receiving new message. */ + stcp->instate = NN_STCP_INSTATE_HDR; + nn_usock_recv (stcp->usock, stcp->inhdr, sizeof (stcp->inhdr), NULL); + + return 0; +} + +static void nn_stcp_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_stcp *stcp; + + stcp = nn_cont (self, struct nn_stcp, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_pipebase_stop (&stcp->pipebase); + nn_streamhdr_stop (&stcp->streamhdr); + stcp->state = NN_STCP_STATE_STOPPING; + } + if (nn_slow (stcp->state == NN_STCP_STATE_STOPPING)) { + if (nn_streamhdr_isidle (&stcp->streamhdr)) { + nn_usock_swap_owner (stcp->usock, &stcp->usock_owner); + stcp->usock = NULL; + stcp->usock_owner.src = -1; + stcp->usock_owner.fsm = NULL; + stcp->state = NN_STCP_STATE_IDLE; + nn_fsm_stopped (&stcp->fsm, NN_STCP_STOPPED); + return; + } + return; + } + + nn_fsm_bad_state(stcp->state, src, type); +} + +static void nn_stcp_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + int rc; + struct nn_stcp *stcp; + uint64_t size; + int opt; + size_t opt_sz = sizeof (opt); + + stcp = nn_cont (self, struct nn_stcp, fsm); + + switch (stcp->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_STCP_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_streamhdr_start (&stcp->streamhdr, stcp->usock, + &stcp->pipebase); + stcp->state = NN_STCP_STATE_PROTOHDR; + return; + default: + nn_fsm_bad_action (stcp->state, src, type); + } + + default: + nn_fsm_bad_source (stcp->state, src, type); + } + +/******************************************************************************/ +/* PROTOHDR state. */ +/******************************************************************************/ + case NN_STCP_STATE_PROTOHDR: + switch (src) { + + case NN_STCP_SRC_STREAMHDR: + switch (type) { + case NN_STREAMHDR_OK: + + /* Before moving to the active state stop the streamhdr + state machine. */ + nn_streamhdr_stop (&stcp->streamhdr); + stcp->state = NN_STCP_STATE_STOPPING_STREAMHDR; + return; + + case NN_STREAMHDR_ERROR: + + /* Raise the error and move directly to the DONE state. + streamhdr object will be stopped later on. */ + stcp->state = NN_STCP_STATE_DONE; + nn_fsm_raise (&stcp->fsm, &stcp->done, NN_STCP_ERROR); + return; + + default: + nn_fsm_bad_action (stcp->state, src, type); + } + + default: + nn_fsm_bad_source (stcp->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_STREAMHDR state. */ +/******************************************************************************/ + case NN_STCP_STATE_STOPPING_STREAMHDR: + switch (src) { + + case NN_STCP_SRC_STREAMHDR: + switch (type) { + case NN_STREAMHDR_STOPPED: + + /* Start the pipe. */ + rc = nn_pipebase_start (&stcp->pipebase); + if (nn_slow (rc < 0)) { + stcp->state = NN_STCP_STATE_DONE; + nn_fsm_raise (&stcp->fsm, &stcp->done, NN_STCP_ERROR); + return; + } + + /* Start receiving a message in asynchronous manner. */ + stcp->instate = NN_STCP_INSTATE_HDR; + nn_usock_recv (stcp->usock, &stcp->inhdr, + sizeof (stcp->inhdr), NULL); + + /* Mark the pipe as available for sending. */ + stcp->outstate = NN_STCP_OUTSTATE_IDLE; + + stcp->state = NN_STCP_STATE_ACTIVE; + return; + + default: + nn_fsm_bad_action (stcp->state, src, type); + } + + default: + nn_fsm_bad_source (stcp->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_STCP_STATE_ACTIVE: + switch (src) { + + case NN_STCP_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + + /* The message is now fully sent. */ + nn_assert (stcp->outstate == NN_STCP_OUTSTATE_SENDING); + stcp->outstate = NN_STCP_OUTSTATE_IDLE; + nn_msg_term (&stcp->outmsg); + nn_msg_init (&stcp->outmsg, 0); + nn_pipebase_sent (&stcp->pipebase); + return; + + case NN_USOCK_RECEIVED: + + switch (stcp->instate) { + case NN_STCP_INSTATE_HDR: + + /* Message header was received. Check that message size + is acceptable by comparing with NN_RCVMAXSIZE; + if it's too large, drop the connection. */ + size = nn_getll (stcp->inhdr); + + nn_pipebase_getopt (&stcp->pipebase, NN_SOL_SOCKET, + NN_RCVMAXSIZE, &opt, &opt_sz); + + if (opt >= 0 && size > (unsigned)opt) { + stcp->state = NN_STCP_STATE_DONE; + nn_fsm_raise (&stcp->fsm, &stcp->done, NN_STCP_ERROR); + return; + } + + /* Allocate memory for the message. */ + nn_msg_term (&stcp->inmsg); + nn_msg_init (&stcp->inmsg, (size_t) size); + + /* Special case when size of the message body is 0. */ + if (!size) { + stcp->instate = NN_STCP_INSTATE_HASMSG; + nn_pipebase_received (&stcp->pipebase); + return; + } + + /* Start receiving the message body. */ + stcp->instate = NN_STCP_INSTATE_BODY; + nn_usock_recv (stcp->usock, + nn_chunkref_data (&stcp->inmsg.body), + (size_t) size, NULL); + + return; + + case NN_STCP_INSTATE_BODY: + + /* Message body was received. Notify the owner that it + can receive it. */ + stcp->instate = NN_STCP_INSTATE_HASMSG; + nn_pipebase_received (&stcp->pipebase); + + return; + + default: + nn_fsm_error("Unexpected socket instate", + stcp->state, src, type); + } + + case NN_USOCK_SHUTDOWN: + nn_pipebase_stop (&stcp->pipebase); + stcp->state = NN_STCP_STATE_SHUTTING_DOWN; + return; + + case NN_USOCK_ERROR: + nn_pipebase_stop (&stcp->pipebase); + stcp->state = NN_STCP_STATE_DONE; + nn_fsm_raise (&stcp->fsm, &stcp->done, NN_STCP_ERROR); + return; + + default: + nn_fsm_bad_action (stcp->state, src, type); + } + + default: + nn_fsm_bad_source (stcp->state, src, type); + } + +/******************************************************************************/ +/* SHUTTING_DOWN state. */ +/* The underlying connection is closed. We are just waiting that underlying */ +/* usock being closed */ +/******************************************************************************/ + case NN_STCP_STATE_SHUTTING_DOWN: + switch (src) { + + case NN_STCP_SRC_USOCK: + switch (type) { + case NN_USOCK_ERROR: + stcp->state = NN_STCP_STATE_DONE; + nn_fsm_raise (&stcp->fsm, &stcp->done, NN_STCP_ERROR); + return; + default: + nn_fsm_bad_action (stcp->state, src, type); + } + + default: + nn_fsm_bad_source (stcp->state, src, type); + } + + +/******************************************************************************/ +/* DONE state. */ +/* The underlying connection is closed. There's nothing that can be done in */ +/* this state except stopping the object. */ +/******************************************************************************/ + case NN_STCP_STATE_DONE: + nn_fsm_bad_source (stcp->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (stcp->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/stcp.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/stcp.h new file mode 100644 index 0000000..d817807 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/stcp.h @@ -0,0 +1,90 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_STCP_INCLUDED +#define NN_STCP_INCLUDED + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../utils/streamhdr.h" + +#include "../../utils/msg.h" + +/* This state machine handles TCP connection from the point where it is + established to the point when it is broken. */ + +#define NN_STCP_ERROR 1 +#define NN_STCP_STOPPED 2 + +struct nn_stcp { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* The underlying socket. */ + struct nn_usock *usock; + + /* Child state machine to do protocol header exchange. */ + struct nn_streamhdr streamhdr; + + /* The original owner of the underlying socket. */ + struct nn_fsm_owner usock_owner; + + /* Pipe connecting this TCP connection to the nanomsg core. */ + struct nn_pipebase pipebase; + + /* State of inbound state machine. */ + int instate; + + /* Buffer used to store the header of incoming message. */ + uint8_t inhdr [8]; + + /* Message being received at the moment. */ + struct nn_msg inmsg; + + /* State of the outbound state machine. */ + int outstate; + + /* Buffer used to store the header of outgoing message. */ + uint8_t outhdr [8]; + + /* Message being sent at the moment. */ + struct nn_msg outmsg; + + /* Event raised when the state machine ends. */ + struct nn_fsm_event done; +}; + +void nn_stcp_init (struct nn_stcp *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_stcp_term (struct nn_stcp *self); + +int nn_stcp_isidle (struct nn_stcp *self); +void nn_stcp_start (struct nn_stcp *self, struct nn_usock *usock); +void nn_stcp_stop (struct nn_stcp *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/tcp.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/tcp.c new file mode 100644 index 0000000..3039e21 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/tcp.c @@ -0,0 +1,159 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "tcp.h" +#include "btcp.h" +#include "ctcp.h" + +#include "../../tcp.h" + +#include "../utils/port.h" +#include "../utils/iface.h" + +#include "../../utils/err.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/list.h" +#include "../../utils/cont.h" + +#include + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#endif + +/* TCP-specific socket options. */ + +struct nn_tcp_optset { + struct nn_optset base; + int nodelay; +}; + +static void nn_tcp_optset_destroy (struct nn_optset *self); +static int nn_tcp_optset_setopt (struct nn_optset *self, int option, + const void *optval, size_t optvallen); +static int nn_tcp_optset_getopt (struct nn_optset *self, int option, + void *optval, size_t *optvallen); +static const struct nn_optset_vfptr nn_tcp_optset_vfptr = { + nn_tcp_optset_destroy, + nn_tcp_optset_setopt, + nn_tcp_optset_getopt +}; + +/* nn_transport interface. */ +static int nn_tcp_bind (void *hint, struct nn_epbase **epbase); +static int nn_tcp_connect (void *hint, struct nn_epbase **epbase); +static struct nn_optset *nn_tcp_optset (void); + +static struct nn_transport nn_tcp_vfptr = { + "tcp", + NN_TCP, + NULL, + NULL, + nn_tcp_bind, + nn_tcp_connect, + nn_tcp_optset, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_transport *nn_tcp = &nn_tcp_vfptr; + +static int nn_tcp_bind (void *hint, struct nn_epbase **epbase) +{ + return nn_btcp_create (hint, epbase); +} + +static int nn_tcp_connect (void *hint, struct nn_epbase **epbase) +{ + return nn_ctcp_create (hint, epbase); +} + +static struct nn_optset *nn_tcp_optset () +{ + struct nn_tcp_optset *optset; + + optset = nn_alloc (sizeof (struct nn_tcp_optset), "optset (tcp)"); + alloc_assert (optset); + optset->base.vfptr = &nn_tcp_optset_vfptr; + + /* Default values for TCP socket options. */ + optset->nodelay = 0; + + return &optset->base; +} + +static void nn_tcp_optset_destroy (struct nn_optset *self) +{ + struct nn_tcp_optset *optset; + + optset = nn_cont (self, struct nn_tcp_optset, base); + nn_free (optset); +} + +static int nn_tcp_optset_setopt (struct nn_optset *self, int option, + const void *optval, size_t optvallen) +{ + struct nn_tcp_optset *optset; + int val; + + optset = nn_cont (self, struct nn_tcp_optset, base); + + /* At this point we assume that all options are of type int. */ + if (optvallen != sizeof (int)) + return -EINVAL; + val = *(int*) optval; + + switch (option) { + case NN_TCP_NODELAY: + if (nn_slow (val != 0 && val != 1)) + return -EINVAL; + optset->nodelay = val; + return 0; + default: + return -ENOPROTOOPT; + } +} + +static int nn_tcp_optset_getopt (struct nn_optset *self, int option, + void *optval, size_t *optvallen) +{ + struct nn_tcp_optset *optset; + int intval; + + optset = nn_cont (self, struct nn_tcp_optset, base); + + switch (option) { + case NN_TCP_NODELAY: + intval = optset->nodelay; + break; + default: + return -ENOPROTOOPT; + } + memcpy (optval, &intval, + *optvallen < sizeof (int) ? *optvallen : sizeof (int)); + *optvallen = sizeof (int); + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/tcp.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/tcp.h new file mode 100644 index 0000000..ab55485 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/tcp/tcp.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_TCP_INCLUDED +#define NN_TCP_INCLUDED + +#include "../../transport.h" + +extern struct nn_transport *nn_tcp; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/README b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/README new file mode 100644 index 0000000..809a334 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/README @@ -0,0 +1,2 @@ +This directory contains the utilities that can be used when creating new +transports. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/backoff.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/backoff.c new file mode 100644 index 0000000..803ac42 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/backoff.c @@ -0,0 +1,67 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "backoff.h" + +void nn_backoff_init (struct nn_backoff *self, int src, int minivl, int maxivl, + struct nn_fsm *owner) +{ + nn_timer_init (&self->timer, src, owner); + self->minivl = minivl; + self->maxivl = maxivl; + self->n = 1; +} + +void nn_backoff_term (struct nn_backoff *self) +{ + nn_timer_term (&self->timer); +} + +int nn_backoff_isidle (struct nn_backoff *self) +{ + return nn_timer_isidle (&self->timer); +} + +void nn_backoff_start (struct nn_backoff *self) +{ + int timeout; + + /* Start the timer for the actual n value. If the interval haven't yet + exceeded the maximum, double the next timeout value. */ + timeout = (self->n - 1) * self->minivl; + if (timeout > self->maxivl) + timeout = self->maxivl; + else + self->n *= 2; + nn_timer_start (&self->timer, timeout); +} + +void nn_backoff_stop (struct nn_backoff *self) +{ + nn_timer_stop (&self->timer); +} + +void nn_backoff_reset (struct nn_backoff *self) +{ + self->n = 1; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/backoff.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/backoff.h new file mode 100644 index 0000000..2ff1a6d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/backoff.h @@ -0,0 +1,52 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BACKOFF_INCLUDED +#define NN_BACKOFF_INCLUDED + +#include "../../aio/timer.h" + +/* Timer with exponential backoff. Actual wating time is (2^n-1)*minivl, + meaning that first wait is 0 ms long, second one is minivl ms long etc. */ + +#define NN_BACKOFF_TIMEOUT NN_TIMER_TIMEOUT +#define NN_BACKOFF_STOPPED NN_TIMER_STOPPED + +struct nn_backoff { + struct nn_timer timer; + int minivl; + int maxivl; + int n; +}; + +void nn_backoff_init (struct nn_backoff *self, int src, int minivl, int maxivl, + struct nn_fsm *owner); +void nn_backoff_term (struct nn_backoff *self); + +int nn_backoff_isidle (struct nn_backoff *self); +void nn_backoff_start (struct nn_backoff *self); +void nn_backoff_stop (struct nn_backoff *self); + +void nn_backoff_reset (struct nn_backoff *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/base64.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/base64.c new file mode 100644 index 0000000..24bedb2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/base64.c @@ -0,0 +1,151 @@ +/* + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "base64.h" + +#include + +int nn_base64_decode (const char *in, size_t in_len, + uint8_t *out, size_t out_len) +{ + unsigned ii; + unsigned io; + unsigned rem; + uint32_t v; + uint8_t ch; + + /* Unrolled lookup of ASCII code points. + 0xFF represents a non-base64 valid character. */ + const uint8_t DECODEMAP [256] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, + 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, + 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + + for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) { + if (isspace (in [ii])) + continue; + + if (in [ii] == '=') + break; + + ch = DECODEMAP [(int)(in [ii])]; + + /* Discard invalid characters as per RFC 2045. */ + if (ch == 0xFF) + break; + + v = (v << 6) | ch; + rem += 6; + + if (rem >= 8) { + rem -= 8; + if (io >= out_len) + return -ENOBUFS; + out [io++] = (v >> rem) & 255; + } + } + if (rem >= 8) { + rem -= 8; + if (io >= out_len) + return -ENOBUFS; + out [io++] = (v >> rem) & 255; + } + return io; +} + +int nn_base64_encode (const uint8_t *in, size_t in_len, + char *out, size_t out_len) +{ + unsigned ii; + unsigned io; + unsigned rem; + uint32_t v; + uint8_t ch; + + const uint8_t ENCODEMAP [64] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + + for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) { + ch = in [ii]; + v = (v << 8) | ch; + rem += 8; + while (rem >= 6) { + rem -= 6; + if (io >= out_len) + return -ENOBUFS; + out [io++] = ENCODEMAP [(v >> rem) & 63]; + } + } + + if (rem) { + v <<= (6 - rem); + if (io >= out_len) + return -ENOBUFS; + out [io++] = ENCODEMAP [v & 63]; + } + + /* Pad to a multiple of 3. */ + while (io & 3) { + if (io >= out_len) + return -ENOBUFS; + out [io++] = '='; + } + + if (io >= out_len) + return -ENOBUFS; + + out [io] = '\0'; + + return io; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/base64.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/base64.h new file mode 100644 index 0000000..c1c72e9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/base64.h @@ -0,0 +1,43 @@ +/* + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BASE64_INCLUDED +#define NN_BASE64_INCLUDED + +#include "../../utils/err.h" + +#include +#include + +/* Based on base64.c (Public Domain) by Jon Mayo. + Base64 is defined in RFC 2045, section 6.8. */ + +/* This function encodes an arbitrary byte array into base64 + null-terminated string. */ +int nn_base64_encode (const uint8_t *in, size_t in_len, + char *out, size_t out_len); + +/* This function decodes a base64 string into supplied buffer. */ +int nn_base64_decode (const char *in, size_t in_len, + uint8_t *out, size_t out_len); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns.c new file mode 100644 index 0000000..af42e55 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "dns.h" + +#include "../../utils/err.h" + +#include + +int nn_dns_check_hostname (const char *name, size_t namelen) +{ + int labelsz; + + /* There has to be at least one label in the hostname. + Additionally, hostnames are up to 255 characters long. */ + if (namelen < 1 || namelen > 255) + return -EINVAL; + + /* Hyphen can't be used as a first character of the hostname. */ + if (*name == '-') + return -EINVAL; + + labelsz = 0; + while (1) { + + /* End of the hostname. */ + if (namelen == 0) { + + /* The last label cannot be empty. */ + if (labelsz == 0) + return -EINVAL; + + /* Success! */ + return 0; + } + + /* End of a label. */ + if (*name == '.') { + + /* The old label cannot be empty. */ + if (labelsz == 0) + return -EINVAL; + + /* Start new label. */ + labelsz = 0; + ++name; + --namelen; + continue; + } + + /* Valid character. */ + if ((*name >= 'a' && *name <= 'z') || + (*name >= 'A' && *name <= 'Z') || + (*name >= '0' && *name <= '9') || + *name == '-') { + ++name; + --namelen; + ++labelsz; + + /* Labels longer than 63 charcters are not permitted. */ + if (labelsz > 63) + return -EINVAL; + + continue; + } + + /* Invalid character. */ + return -EINVAL; + } +} + +#if defined NN_HAVE_GETADDRINFO_A && !defined NN_DISABLE_GETADDRINFO_A +#include "dns_getaddrinfo_a.inc" +#else +#include "dns_getaddrinfo.inc" +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns.h new file mode 100644 index 0000000..d7ae270 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns.h @@ -0,0 +1,58 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_DNS_INCLUDED +#define NN_DNS_INCLUDED + +#include "../../aio/fsm.h" + +#include + +/* Checks the hostname according to RFC 952 and RFC 1123. + Returns 0 in case the it is valid. */ +int nn_dns_check_hostname (const char *name, size_t namelen); + +/* Events generated by the DNS state machine. */ +#define NN_DNS_DONE 1 +#define NN_DNS_STOPPED 2 + +#if defined NN_HAVE_GETADDRINFO_A && !defined NN_DISABLE_GETADDRINFO_A +#include "dns_getaddrinfo_a.h" +#else +#include "dns_getaddrinfo.h" +#endif + +struct nn_dns_result { + int error; + struct sockaddr_storage addr; + size_t addrlen; +}; + +void nn_dns_init (struct nn_dns *self, int src, struct nn_fsm *owner); +void nn_dns_term (struct nn_dns *self); + +int nn_dns_isidle (struct nn_dns *self); +void nn_dns_start (struct nn_dns *self, const char *addr, size_t addrlen, + int ipv4only, struct nn_dns_result *result); +void nn_dns_stop (struct nn_dns *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo.h new file mode 100644 index 0000000..69ae3d7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo.h @@ -0,0 +1,35 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#endif + +struct nn_dns { + struct nn_fsm fsm; + int state; + struct nn_dns_result *result; + struct nn_fsm_event done; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo.inc b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo.inc new file mode 100644 index 0000000..77dd114 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo.inc @@ -0,0 +1,182 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "literal.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/attr.h" + +#include + +#ifndef NN_HAVE_WINDOWS +#include +#include +#include +#endif + +#define NN_DNS_STATE_IDLE 1 +#define NN_DNS_STATE_DONE 2 + +/* Private functions. */ +static void nn_dns_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_dns_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_dns_init (struct nn_dns *self, int src, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_dns_handler, nn_dns_shutdown, + src, self, owner); + self->state = NN_DNS_STATE_IDLE; + nn_fsm_event_init (&self->done); +} + +void nn_dns_term (struct nn_dns *self) +{ + nn_assert_state (self, NN_DNS_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_fsm_term (&self->fsm); +} + +int nn_dns_isidle (struct nn_dns *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_dns_start (struct nn_dns *self, const char *addr, size_t addrlen, + int ipv4only, struct nn_dns_result *result) +{ + int rc; + struct addrinfo query; + struct addrinfo *reply; + char hostname [NN_SOCKADDR_MAX]; + + nn_assert_state (self, NN_DNS_STATE_IDLE); + + self->result = result; + + /* Try to resolve the supplied string as a literal address. In this case, + there's no DNS lookup involved. */ + rc = nn_literal_resolve (addr, addrlen, ipv4only, &self->result->addr, + &self->result->addrlen); + if (rc == 0) { + self->result->error = 0; + nn_fsm_start (&self->fsm); + return; + } + errnum_assert (rc == -EINVAL, -rc); + + /* The name is not a literal. Let's do an actual DNS lookup. */ + memset (&query, 0, sizeof (query)); + if (ipv4only) + query.ai_family = AF_INET; + else { + query.ai_family = AF_INET6; +#ifdef AI_V4MAPPED + query.ai_flags = AI_V4MAPPED; +#endif + } + nn_assert (sizeof (hostname) > addrlen); + query.ai_socktype = SOCK_STREAM; + memcpy (hostname, addr, addrlen); + hostname [addrlen] = 0; + + /* Perform the DNS lookup itself. */ + self->result->error = getaddrinfo (hostname, NULL, &query, &reply); + if (self->result->error) { + nn_fsm_start (&self->fsm); + return; + } + + /* Take just the first address and store it. (RFC recommends that we + iterate through addresses until one works, but that doesn't match + our state model. This is the best we can do.) */ + self->result->error = 0; + memcpy (&self->result->addr, reply->ai_addr, reply->ai_addrlen); + self->result->addrlen = reply->ai_addrlen; + freeaddrinfo (reply); + + nn_fsm_start (&self->fsm); +} + +void nn_dns_stop (struct nn_dns *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_dns_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_dns *dns; + + dns = nn_cont (self, struct nn_dns, fsm); + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_fsm_stopped (&dns->fsm, NN_DNS_STOPPED); + dns->state = NN_DNS_STATE_IDLE; + return; + } + + nn_fsm_bad_state(dns->state, src, type); +} + +static void nn_dns_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_dns *dns; + + dns = nn_cont (self, struct nn_dns, fsm); + + switch (dns->state) { +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_DNS_STATE_IDLE: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_fsm_raise (&dns->fsm, &dns->done, NN_DNS_DONE); + dns->state = NN_DNS_STATE_DONE; + return; + default: + nn_fsm_bad_action (dns->state, src, type); + } + default: + nn_fsm_bad_source (dns->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/******************************************************************************/ + case NN_DNS_STATE_DONE: + nn_fsm_bad_source (dns->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (dns->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo_a.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo_a.h new file mode 100644 index 0000000..9140689 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo_a.h @@ -0,0 +1,43 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include + +#include "../../nn.h" + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#endif + +struct nn_dns { + struct nn_fsm fsm; + int state; + int error; + char hostname [NN_SOCKADDR_MAX]; + struct addrinfo request; + struct gaicb gcb; + struct nn_dns_result *result; + struct nn_fsm_event done; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo_a.inc b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo_a.inc new file mode 100644 index 0000000..f9bc244 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/dns_getaddrinfo_a.inc @@ -0,0 +1,260 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "literal.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/attr.h" + +#include "../../aio/ctx.h" + +#include + +#define NN_DNS_STATE_IDLE 1 +#define NN_DNS_STATE_RESOLVING 2 +#define NN_DNS_STATE_DONE 3 +#define NN_DNS_STATE_STOPPING 4 + +#define NN_DNS_ACTION_DONE 1 +#define NN_DNS_ACTION_CANCELLED 2 + +/* Private functions. */ +static void nn_dns_notify (union sigval); +static void nn_dns_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_dns_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_dns_init (struct nn_dns *self, int src, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_dns_handler, nn_dns_shutdown, src, self, owner); + self->state = NN_DNS_STATE_IDLE; + nn_fsm_event_init (&self->done); +} + +void nn_dns_term (struct nn_dns *self) +{ + nn_assert_state (self, NN_DNS_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_fsm_term (&self->fsm); +} + +int nn_dns_isidle (struct nn_dns *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_dns_start (struct nn_dns *self, const char *addr, size_t addrlen, + int ipv4only, struct nn_dns_result *result) +{ + int rc; + struct gaicb *pgcb; + struct sigevent sev; + + nn_assert_state (self, NN_DNS_STATE_IDLE); + + self->result = result; + + /* Try to resolve the supplied string as a literal address. In this case, + there's no DNS lookup involved. */ + rc = nn_literal_resolve (addr, addrlen, ipv4only, &self->result->addr, + &self->result->addrlen); + if (rc == 0) { + self->result->error = 0; + nn_fsm_start (&self->fsm); + return; + } + errnum_assert (rc == -EINVAL, -rc); + + /* Make a zero-terminated copy of the address string. */ + nn_assert (sizeof (self->hostname) > addrlen); + memcpy (self->hostname, addr, addrlen); + self->hostname [addrlen] = 0; + + /* Start asynchronous DNS lookup. */ + memset (&self->request, 0, sizeof (self->request)); + if (ipv4only) + self->request.ai_family = AF_INET; + else { + self->request.ai_family = AF_INET6; +#ifdef AI_V4MAPPED + self->request.ai_flags = AI_V4MAPPED; +#endif + } + self->request.ai_socktype = SOCK_STREAM; + + memset (&self->gcb, 0, sizeof (self->gcb)); + self->gcb.ar_name = self->hostname; + self->gcb.ar_service = NULL; + self->gcb.ar_request = &self->request; + self->gcb.ar_result = NULL; + pgcb = &self->gcb; + + memset (&sev, 0, sizeof (sev)); + sev.sigev_notify = SIGEV_THREAD; + sev.sigev_notify_function = nn_dns_notify; + sev.sigev_value.sival_ptr = self; + + rc = getaddrinfo_a (GAI_NOWAIT, &pgcb, 1, &sev); + nn_assert (rc == 0); + + self->result->error = EINPROGRESS; + nn_fsm_start (&self->fsm); +} + +void nn_dns_stop (struct nn_dns *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_dns_notify (union sigval sval) +{ + int rc; + struct nn_dns *self; + + self = (struct nn_dns*) sval.sival_ptr; + + nn_ctx_enter (self->fsm.ctx); + rc = gai_error (&self->gcb); + if (rc == EAI_CANCELED) { + nn_fsm_action (&self->fsm, NN_DNS_ACTION_CANCELLED); + } + else if (rc != 0) { + self->result->error = EINVAL; + nn_fsm_action (&self->fsm, NN_DNS_ACTION_DONE); + } + else { + self->result->error = 0; + nn_assert (self->gcb.ar_result->ai_addrlen <= + sizeof (struct sockaddr_storage)); + memcpy (&self->result->addr, self->gcb.ar_result->ai_addr, + self->gcb.ar_result->ai_addrlen); + self->result->addrlen = (size_t) self->gcb.ar_result->ai_addrlen; + freeaddrinfo(self->gcb.ar_result); + nn_fsm_action (&self->fsm, NN_DNS_ACTION_DONE); + } + nn_ctx_leave (self->fsm.ctx); +} + +static void nn_dns_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + int rc; + struct nn_dns *dns; + + dns = nn_cont (self, struct nn_dns, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (dns->state == NN_DNS_STATE_RESOLVING) { + rc = gai_cancel (&dns->gcb); + if (rc == EAI_CANCELED) { + nn_fsm_stopped (&dns->fsm, NN_DNS_STOPPED); + dns->state = NN_DNS_STATE_IDLE; + return; + } + if (rc == EAI_NOTCANCELED || rc == EAI_ALLDONE) { + dns->state = NN_DNS_STATE_STOPPING; + return; + } + nn_assert (0); + } + nn_fsm_stopped (&dns->fsm, NN_DNS_STOPPED); + dns->state = NN_DNS_STATE_IDLE; + return; + } + if (nn_slow (dns->state == NN_DNS_STATE_STOPPING)) { + if (src == NN_FSM_ACTION && (type == NN_DNS_ACTION_CANCELLED || + type == NN_DNS_ACTION_DONE)) { + nn_fsm_stopped (&dns->fsm, NN_DNS_STOPPED); + dns->state = NN_DNS_STATE_IDLE; + return; + } + return; + } + + nn_fsm_bad_state (dns->state, src, type); +} + +static void nn_dns_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_dns *dns; + + dns = nn_cont (self, struct nn_dns, fsm); + + switch (dns->state) { +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_DNS_STATE_IDLE: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + if (dns->result->error == EINPROGRESS) { + dns->state = NN_DNS_STATE_RESOLVING; + return; + } + nn_fsm_raise (&dns->fsm, &dns->done, NN_DNS_DONE); + dns->state = NN_DNS_STATE_DONE; + return; + default: + nn_fsm_bad_action (dns->state, src, type); + } + default: + nn_fsm_bad_source (dns->state, src, type); + } + +/******************************************************************************/ +/* RESOLVING state. */ +/******************************************************************************/ + case NN_DNS_STATE_RESOLVING: + switch (src) { + case NN_FSM_ACTION: + switch (type) { + case NN_DNS_ACTION_DONE: + nn_fsm_raise (&dns->fsm, &dns->done, NN_DNS_DONE); + dns->state = NN_DNS_STATE_DONE; + return; + default: + nn_fsm_bad_action (dns->state, src, type); + } + default: + nn_fsm_bad_source (dns->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/******************************************************************************/ + case NN_DNS_STATE_DONE: + nn_fsm_bad_source (dns->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (dns->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/iface.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/iface.c new file mode 100644 index 0000000..5b5f7cc --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/iface.c @@ -0,0 +1,83 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "iface.h" +#include "literal.h" + +#include "../../utils/err.h" +#include "../../utils/closefd.h" + +#include + +#ifndef NN_HAVE_WINDOWS +#include +#include +#endif + +/* Private functions. */ +static void nn_iface_any (int ipv4only, struct sockaddr_storage *result, + size_t *resultlen); + +/* We no longer resolve interface names. This feature was non-portable + and fragile. Only IP addresses may be used. They are provided in + the form of string literals. */ +int nn_iface_resolve (const char *addr, size_t addrlen, int ipv4only, + struct sockaddr_storage *result, size_t *resultlen) +{ + int rc; + + /* Asterisk is a special name meaning "all interfaces". */ + if (addrlen == 1 && addr [0] == '*') { + nn_iface_any (ipv4only, result, resultlen); + return 0; + } + + rc = nn_literal_resolve (addr, addrlen, ipv4only, result, resultlen); + if (rc == -EINVAL) + return -ENODEV; + errnum_assert (rc == 0, -rc); + return 0; +} + +static void nn_iface_any (int ipv4only, struct sockaddr_storage *result, + size_t *resultlen) +{ + if (ipv4only) { + if (result) { + result->ss_family = AF_INET; + ((struct sockaddr_in*) result)->sin_addr.s_addr = + htonl (INADDR_ANY); + } + if (resultlen) + *resultlen = sizeof (struct sockaddr_in); + } + else { + if (result) { + result->ss_family = AF_INET6; + memcpy (&((struct sockaddr_in6*) result)->sin6_addr, + &in6addr_any, sizeof (in6addr_any)); + } + if (resultlen) + *resultlen = sizeof (struct sockaddr_in6); + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/iface.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/iface.h new file mode 100644 index 0000000..30e2078 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/iface.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_IFACE_INCLUDED +#define NN_IFACE_INCLUDED + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#endif + +#include + +/* Resolves name of a local network interface into the address itself. + Name '*' is resolved as 'all interfaces'. */ +int nn_iface_resolve (const char *addr, size_t addrlen, int ipv4only, + struct sockaddr_storage *result, size_t *resultlen); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/literal.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/literal.c new file mode 100644 index 0000000..629de79 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/literal.c @@ -0,0 +1,133 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "literal.h" + +#include "../../utils/err.h" +#include "../../utils/fast.h" + +#include + +#ifndef NN_HAVE_WINDOWS +#include +#include +#endif + +/* On Windows XS there's no inet_pton() function. */ +#if defined NN_HAVE_WINDOWS && ((_WIN32_WINNT <= 0x0501) || (WINVER <= 0x0501)) + +static int nn_inet_pton(int family, const char *src, void *dst) +{ + int rc; + struct sockaddr_storage addr; + int addr_len = sizeof(addr); + + if (nn_slow (family != AF_INET && family != AF_INET6)) { + errno = EAFNOSUPPORT; + return -1; + } + + addr.ss_family = family; + rc = WSAStringToAddressA ((char*) src, family, NULL, + (struct sockaddr*) &addr, &addr_len); + if (rc != 0) + return 0; + + if (family == AF_INET) { + memcpy(dst, &((struct sockaddr_in *) &addr)->sin_addr, + sizeof(struct in_addr)); + } else if (family == AF_INET6) { + memcpy(dst, &((struct sockaddr_in6 *)&addr)->sin6_addr, + sizeof(struct in6_addr)); + } + + return 1; +} + +#else + +static int nn_inet_pton(int family, const char *src, void *dst) +{ + return inet_pton (family, src, dst); +} + +#endif + +int nn_literal_resolve (const char *addr, size_t addrlen, + int ipv4only, struct sockaddr_storage *result, size_t *resultlen) +{ + int rc; + char addrz [INET6_ADDRSTRLEN > INET_ADDRSTRLEN ? + INET6_ADDRSTRLEN : INET_ADDRSTRLEN]; + struct in_addr inaddr; + struct in6_addr in6addr; + + /* Try to treat the address as a literal string. If the size of + the address is larger than longest possible literal, skip the step. + If the literal in enclosed in square brackets ignore them. */ + if (addrlen > 0 && addr [0] == '[') { + if (addr [addrlen - 1] != ']') + return -EINVAL; + if (addrlen - 2 + 1 > sizeof (addrz)) + return -EINVAL; + memcpy (addrz, addr + 1, addrlen - 2); + addrz [addrlen - 2] = 0; + } + else { + if (addrlen + 1 > sizeof (addrz)) + return -EINVAL; + memcpy (addrz, addr, addrlen); + addrz [addrlen] = 0; + } + + /* Try to interpret the literal as an IPv6 address. */ + if (!ipv4only) { + rc = nn_inet_pton (AF_INET6, addrz, &in6addr); + if (rc == 1) { + if (result) { + result->ss_family = AF_INET6; + ((struct sockaddr_in6*) result)->sin6_addr = in6addr; + } + if (resultlen) + *resultlen = sizeof (struct sockaddr_in6); + return 0; + } + errno_assert (rc == 0); + } + + /* Try to interpret the literal as an IPv4 address. */ + rc = nn_inet_pton (AF_INET, addrz, &inaddr); + if (rc == 1) { + if (result) { + result->ss_family = AF_INET; + ((struct sockaddr_in*) result)->sin_addr = inaddr; + } + if (resultlen) + *resultlen = sizeof (struct sockaddr_in); + return 0; + } + errno_assert (rc == 0); + + /* The supplied string is not a valid literal address. */ + return -EINVAL; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/literal.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/literal.h new file mode 100644 index 0000000..57506a4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/literal.h @@ -0,0 +1,38 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_LITERAL_INCLUDED +#define NN_LITERAL_INCLUDED + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#endif + +#include + +/* Resolves a literal IPv4 or IPv6 address. */ +int nn_literal_resolve (const char *addr, size_t addrlen, int ipv4only, + struct sockaddr_storage *result, size_t *resultlen); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/port.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/port.c new file mode 100644 index 0000000..988d2e2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/port.c @@ -0,0 +1,49 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "port.h" + +#include "../../utils/err.h" + +int nn_port_resolve (const char *port, size_t portlen) +{ + int res; + size_t i; + + res = 0; + for (i = 0; i != portlen; ++i) { + if (port [i] < '0' || port [i] > '9') + return -EINVAL; + res *= 10; + res += port [i] - '0'; + if (res > 0xffff) + return -EINVAL; + } + + /* Port 0 has special meaning (assign an ephemeral port to the socket), + thus it is illegal to use it in the connection string. */ + if (res == 0) + return -EINVAL; + + return res; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/port.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/port.h new file mode 100644 index 0000000..d6a3fff --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/port.h @@ -0,0 +1,32 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_PORT_INCLUDED +#define NN_PORT_INCLUDED + +#include + +/* Parse the string containing a port number. Returns port number in integer + form or -EINVAL if the string doesn't contain a port number. */ +int nn_port_resolve (const char *port, size_t portlen); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.c new file mode 100644 index 0000000..6af8061 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.c @@ -0,0 +1,332 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "streamhdr.h" + +#include "../../aio/timer.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/wire.h" +#include "../../utils/attr.h" + +#include +#include + +#define NN_STREAMHDR_STATE_IDLE 1 +#define NN_STREAMHDR_STATE_SENDING 2 +#define NN_STREAMHDR_STATE_RECEIVING 3 +#define NN_STREAMHDR_STATE_STOPPING_TIMER_ERROR 4 +#define NN_STREAMHDR_STATE_STOPPING_TIMER_DONE 5 +#define NN_STREAMHDR_STATE_DONE 6 +#define NN_STREAMHDR_STATE_STOPPING 7 + +#define NN_STREAMHDR_SRC_USOCK 1 +#define NN_STREAMHDR_SRC_TIMER 2 + +/* Private functions. */ +static void nn_streamhdr_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_streamhdr_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_streamhdr_init (struct nn_streamhdr *self, int src, + struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_streamhdr_handler, nn_streamhdr_shutdown, + src, self, owner); + self->state = NN_STREAMHDR_STATE_IDLE; + nn_timer_init (&self->timer, NN_STREAMHDR_SRC_TIMER, &self->fsm); + nn_fsm_event_init (&self->done); + + self->usock = NULL; + self->usock_owner.src = -1; + self->usock_owner.fsm = NULL; + self->pipebase = NULL; +} + +void nn_streamhdr_term (struct nn_streamhdr *self) +{ + nn_assert_state (self, NN_STREAMHDR_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_timer_term (&self->timer); + nn_fsm_term (&self->fsm); +} + +int nn_streamhdr_isidle (struct nn_streamhdr *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_streamhdr_start (struct nn_streamhdr *self, struct nn_usock *usock, + struct nn_pipebase *pipebase) +{ + size_t sz; + int protocol; + + /* Take ownership of the underlying socket. */ + nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL); + self->usock_owner.src = NN_STREAMHDR_SRC_USOCK; + self->usock_owner.fsm = &self->fsm; + nn_usock_swap_owner (usock, &self->usock_owner); + self->usock = usock; + self->pipebase = pipebase; + + /* Get the protocol identifier. */ + sz = sizeof (protocol); + nn_pipebase_getopt (pipebase, NN_SOL_SOCKET, NN_PROTOCOL, &protocol, &sz); + nn_assert (sz == sizeof (protocol)); + + /* Compose the protocol header. */ + memcpy (self->protohdr, "\0SP\0\0\0\0\0", 8); + nn_puts (self->protohdr + 4, (uint16_t) protocol); + + /* Launch the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_streamhdr_stop (struct nn_streamhdr *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_streamhdr_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_streamhdr *streamhdr; + + streamhdr = nn_cont (self, struct nn_streamhdr, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_timer_stop (&streamhdr->timer); + streamhdr->state = NN_STREAMHDR_STATE_STOPPING; + } + if (nn_slow (streamhdr->state == NN_STREAMHDR_STATE_STOPPING)) { + if (!nn_timer_isidle (&streamhdr->timer)) + return; + streamhdr->state = NN_STREAMHDR_STATE_IDLE; + nn_fsm_stopped (&streamhdr->fsm, NN_STREAMHDR_STOPPED); + return; + } + + nn_fsm_bad_state (streamhdr->state, src, type); +} + +static void nn_streamhdr_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_streamhdr *streamhdr; + struct nn_iovec iovec; + int protocol; + + streamhdr = nn_cont (self, struct nn_streamhdr, fsm); + + + switch (streamhdr->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_STREAMHDR_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_timer_start (&streamhdr->timer, 1000); + iovec.iov_base = streamhdr->protohdr; + iovec.iov_len = sizeof (streamhdr->protohdr); + nn_usock_send (streamhdr->usock, &iovec, 1); + streamhdr->state = NN_STREAMHDR_STATE_SENDING; + return; + default: + nn_fsm_bad_action (streamhdr->state, src, type); + } + + default: + nn_fsm_bad_source (streamhdr->state, src, type); + } + +/******************************************************************************/ +/* SENDING state. */ +/******************************************************************************/ + case NN_STREAMHDR_STATE_SENDING: + switch (src) { + + case NN_STREAMHDR_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + nn_usock_recv (streamhdr->usock, streamhdr->protohdr, + sizeof (streamhdr->protohdr), NULL); + streamhdr->state = NN_STREAMHDR_STATE_RECEIVING; + return; + case NN_USOCK_SHUTDOWN: + /* Ignore it. Wait for ERROR event */ + return; + case NN_USOCK_ERROR: + nn_timer_stop (&streamhdr->timer); + streamhdr->state = NN_STREAMHDR_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (streamhdr->state, src, type); + } + + case NN_STREAMHDR_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&streamhdr->timer); + streamhdr->state = NN_STREAMHDR_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (streamhdr->state, src, type); + } + + default: + nn_fsm_bad_source (streamhdr->state, src, type); + } + +/******************************************************************************/ +/* RECEIVING state. */ +/******************************************************************************/ + case NN_STREAMHDR_STATE_RECEIVING: + switch (src) { + + case NN_STREAMHDR_SRC_USOCK: + switch (type) { + case NN_USOCK_RECEIVED: + + /* Here we are checking whether the peer speaks the same + protocol as this socket. */ + if (memcmp (streamhdr->protohdr, "\0SP\0", 4) != 0) + goto invalidhdr; + protocol = nn_gets (streamhdr->protohdr + 4); + if (!nn_pipebase_ispeer (streamhdr->pipebase, protocol)) + goto invalidhdr; + nn_timer_stop (&streamhdr->timer); + streamhdr->state = NN_STREAMHDR_STATE_STOPPING_TIMER_DONE; + return; + case NN_USOCK_SHUTDOWN: + /* Ignore it. Wait for ERROR event */ + return; + case NN_USOCK_ERROR: +invalidhdr: + nn_timer_stop (&streamhdr->timer); + streamhdr->state = NN_STREAMHDR_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_assert (0); + } + + case NN_STREAMHDR_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&streamhdr->timer); + streamhdr->state = NN_STREAMHDR_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (streamhdr->state, src, type); + } + + default: + nn_fsm_bad_source (streamhdr->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_TIMER_ERROR state. */ +/******************************************************************************/ + case NN_STREAMHDR_STATE_STOPPING_TIMER_ERROR: + switch (src) { + + case NN_STREAMHDR_SRC_USOCK: + /* It's safe to ignore usock event when we are stopping, but there + is only a subset of events that are plausible. */ + nn_assert (type == NN_USOCK_ERROR); + return; + + case NN_STREAMHDR_SRC_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + nn_usock_swap_owner (streamhdr->usock, &streamhdr->usock_owner); + streamhdr->usock = NULL; + streamhdr->usock_owner.src = -1; + streamhdr->usock_owner.fsm = NULL; + streamhdr->state = NN_STREAMHDR_STATE_DONE; + nn_fsm_raise (&streamhdr->fsm, &streamhdr->done, + NN_STREAMHDR_ERROR); + return; + default: + nn_fsm_bad_action (streamhdr->state, src, type); + } + + default: + nn_fsm_bad_source (streamhdr->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_TIMER_DONE state. */ +/******************************************************************************/ + case NN_STREAMHDR_STATE_STOPPING_TIMER_DONE: + switch (src) { + + case NN_STREAMHDR_SRC_USOCK: + /* It's safe to ignore usock event when we are stopping, but there + is only a subset of events that are plausible. */ + nn_assert (type == NN_USOCK_ERROR); + return; + + case NN_STREAMHDR_SRC_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + nn_usock_swap_owner (streamhdr->usock, &streamhdr->usock_owner); + streamhdr->usock = NULL; + streamhdr->usock_owner.src = -1; + streamhdr->usock_owner.fsm = NULL; + streamhdr->state = NN_STREAMHDR_STATE_DONE; + nn_fsm_raise (&streamhdr->fsm, &streamhdr->done, + NN_STREAMHDR_OK); + return; + default: + nn_fsm_bad_action (streamhdr->state, src, type); + } + + default: + nn_fsm_bad_source (streamhdr->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/* The header exchange was either done successfully of failed. There's */ +/* nothing that can be done in this state except stopping the object. */ +/******************************************************************************/ + case NN_STREAMHDR_STATE_DONE: + nn_fsm_bad_source (streamhdr->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (streamhdr->state, src, type); + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.h new file mode 100644 index 0000000..7398db8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/utils/streamhdr.h @@ -0,0 +1,73 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_STREAMHDR_INCLUDED +#define NN_STREAMHDR_INCLUDED + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" +#include "../../aio/timer.h" + +/* This state machine exchanges protocol headers on top of + a stream-based bi-directional connection. */ + +#define NN_STREAMHDR_OK 1 +#define NN_STREAMHDR_ERROR 2 +#define NN_STREAMHDR_STOPPED 3 + +struct nn_streamhdr { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Used to timeout the protocol header exchange. */ + struct nn_timer timer; + + /* The underlying socket. */ + struct nn_usock *usock; + + /* The original owner of the underlying socket. */ + struct nn_fsm_owner usock_owner; + + /* Handle to the pipe. */ + struct nn_pipebase *pipebase; + + /* Protocol header. */ + uint8_t protohdr [8]; + + /* Event fired when the state machine ends. */ + struct nn_fsm_event done; +}; + +void nn_streamhdr_init (struct nn_streamhdr *self, int src, + struct nn_fsm *owner); +void nn_streamhdr_term (struct nn_streamhdr *self); + +int nn_streamhdr_isidle (struct nn_streamhdr *self); +void nn_streamhdr_start (struct nn_streamhdr *self, struct nn_usock *usock, + struct nn_pipebase *pipebase); +void nn_streamhdr_stop (struct nn_streamhdr *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/aws.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/aws.c new file mode 100644 index 0000000..bb025e4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/aws.c @@ -0,0 +1,333 @@ +/* + Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014-2016 Jack R. Dunaway. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "aws.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/attr.h" +#include "../../ws.h" + +#define NN_AWS_STATE_IDLE 1 +#define NN_AWS_STATE_ACCEPTING 2 +#define NN_AWS_STATE_ACTIVE 3 +#define NN_AWS_STATE_STOPPING_SWS 4 +#define NN_AWS_STATE_STOPPING_USOCK 5 +#define NN_AWS_STATE_DONE 6 +#define NN_AWS_STATE_STOPPING_SWS_FINAL 7 +#define NN_AWS_STATE_STOPPING 8 + +#define NN_AWS_SRC_USOCK 1 +#define NN_AWS_SRC_SWS 2 +#define NN_AWS_SRC_LISTENER 3 + +/* Private functions. */ +static void nn_aws_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_aws_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +void nn_aws_init (struct nn_aws *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_aws_handler, nn_aws_shutdown, + src, self, owner); + self->state = NN_AWS_STATE_IDLE; + self->epbase = epbase; + nn_usock_init (&self->usock, NN_AWS_SRC_USOCK, &self->fsm); + self->listener = NULL; + self->listener_owner.src = -1; + self->listener_owner.fsm = NULL; + nn_sws_init (&self->sws, NN_AWS_SRC_SWS, epbase, &self->fsm); + nn_fsm_event_init (&self->accepted); + nn_fsm_event_init (&self->done); + nn_list_item_init (&self->item); +} + +void nn_aws_term (struct nn_aws *self) +{ + nn_assert_state (self, NN_AWS_STATE_IDLE); + + nn_list_item_term (&self->item); + nn_fsm_event_term (&self->done); + nn_fsm_event_term (&self->accepted); + nn_sws_term (&self->sws); + nn_usock_term (&self->usock); + nn_fsm_term (&self->fsm); +} + +int nn_aws_isidle (struct nn_aws *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_aws_start (struct nn_aws *self, struct nn_usock *listener) +{ + nn_assert_state (self, NN_AWS_STATE_IDLE); + + /* Take ownership of the listener socket. */ + self->listener = listener; + self->listener_owner.src = NN_AWS_SRC_LISTENER; + self->listener_owner.fsm = &self->fsm; + nn_usock_swap_owner (listener, &self->listener_owner); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_aws_stop (struct nn_aws *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_aws_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_aws *aws; + + aws = nn_cont (self, struct nn_aws, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (!nn_sws_isidle (&aws->sws)) { + nn_epbase_stat_increment (aws->epbase, + NN_STAT_DROPPED_CONNECTIONS, 1); + nn_sws_stop (&aws->sws); + } + aws->state = NN_AWS_STATE_STOPPING_SWS_FINAL; + } + if (nn_slow (aws->state == NN_AWS_STATE_STOPPING_SWS_FINAL)) { + if (!nn_sws_isidle (&aws->sws)) + return; + nn_usock_stop (&aws->usock); + aws->state = NN_AWS_STATE_STOPPING; + } + if (nn_slow (aws->state == NN_AWS_STATE_STOPPING)) { + if (!nn_usock_isidle (&aws->usock)) + return; + if (aws->listener) { + nn_assert (aws->listener_owner.fsm); + nn_usock_swap_owner (aws->listener, &aws->listener_owner); + aws->listener = NULL; + aws->listener_owner.src = -1; + aws->listener_owner.fsm = NULL; + } + aws->state = NN_AWS_STATE_IDLE; + nn_fsm_stopped (&aws->fsm, NN_AWS_STOPPED); + return; + } + + nn_fsm_bad_action (aws->state, src, type); +} + +static void nn_aws_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_aws *aws; + int val; + size_t sz; + uint8_t msg_type; + + aws = nn_cont (self, struct nn_aws, fsm); + + switch (aws->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The state machine wasn't yet started. */ +/******************************************************************************/ + case NN_AWS_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_usock_accept (&aws->usock, aws->listener); + aws->state = NN_AWS_STATE_ACCEPTING; + return; + default: + nn_fsm_bad_action (aws->state, src, type); + } + + default: + nn_fsm_bad_source (aws->state, src, type); + } + +/******************************************************************************/ +/* ACCEPTING state. */ +/* Waiting for incoming connection. */ +/******************************************************************************/ + case NN_AWS_STATE_ACCEPTING: + switch (src) { + + case NN_AWS_SRC_USOCK: + switch (type) { + case NN_USOCK_ACCEPTED: + nn_epbase_clear_error (aws->epbase); + + /* Set the relevant socket options. */ + sz = sizeof (val); + nn_epbase_getopt (aws->epbase, NN_SOL_SOCKET, NN_SNDBUF, + &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&aws->usock, SOL_SOCKET, SO_SNDBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (aws->epbase, NN_SOL_SOCKET, NN_RCVBUF, + &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&aws->usock, SOL_SOCKET, SO_RCVBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (aws->epbase, NN_WS, NN_WS_MSG_TYPE, + &val, &sz); + msg_type = (uint8_t)val; + + /* Since the WebSocket handshake must poll, the receive + timeout is set to zero. Later, it will be set again + to the value specified by the socket option. */ + val = 0; + sz = sizeof (val); + nn_usock_setsockopt (&aws->usock, SOL_SOCKET, SO_RCVTIMEO, + &val, sizeof (val)); + + /* Return ownership of the listening socket to the parent. */ + nn_usock_swap_owner (aws->listener, &aws->listener_owner); + aws->listener = NULL; + aws->listener_owner.src = -1; + aws->listener_owner.fsm = NULL; + nn_fsm_raise (&aws->fsm, &aws->accepted, NN_AWS_ACCEPTED); + + /* Start the sws state machine. */ + nn_usock_activate (&aws->usock); + nn_sws_start (&aws->sws, &aws->usock, NN_WS_SERVER, + NULL, NULL, msg_type); + aws->state = NN_AWS_STATE_ACTIVE; + + nn_epbase_stat_increment (aws->epbase, + NN_STAT_ACCEPTED_CONNECTIONS, 1); + + return; + + default: + nn_fsm_bad_action (aws->state, src, type); + } + + case NN_AWS_SRC_LISTENER: + switch (type) { + + case NN_USOCK_ACCEPT_ERROR: + nn_epbase_set_error (aws->epbase, + nn_usock_geterrno (aws->listener)); + nn_epbase_stat_increment (aws->epbase, + NN_STAT_ACCEPT_ERRORS, 1); + nn_usock_accept (&aws->usock, aws->listener); + return; + + default: + nn_fsm_bad_action (aws->state, src, type); + } + + default: + nn_fsm_bad_source (aws->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_AWS_STATE_ACTIVE: + switch (src) { + + case NN_AWS_SRC_SWS: + switch (type) { + case NN_SWS_RETURN_CLOSE_HANDSHAKE: + /* Peer closed connection without intention to reconnect, or + local endpoint failed remote because of invalid data. */ + nn_sws_stop (&aws->sws); + aws->state = NN_AWS_STATE_STOPPING_SWS; + return; + case NN_SWS_RETURN_ERROR: + nn_sws_stop (&aws->sws); + aws->state = NN_AWS_STATE_STOPPING_SWS; + nn_epbase_stat_increment (aws->epbase, + NN_STAT_BROKEN_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (aws->state, src, type); + } + + default: + nn_fsm_bad_source (aws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_SWS state. */ +/******************************************************************************/ + case NN_AWS_STATE_STOPPING_SWS: + switch (src) { + + case NN_AWS_SRC_SWS: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_SWS_RETURN_STOPPED: + nn_usock_stop (&aws->usock); + aws->state = NN_AWS_STATE_STOPPING_USOCK; + return; + default: + nn_fsm_bad_action (aws->state, src, type); + } + + default: + nn_fsm_bad_source (aws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_USOCK state. */ +/******************************************************************************/ + case NN_AWS_STATE_STOPPING_USOCK: + switch (src) { + + case NN_AWS_SRC_USOCK: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_STOPPED: + nn_fsm_raise (&aws->fsm, &aws->done, NN_AWS_ERROR); + aws->state = NN_AWS_STATE_DONE; + return; + default: + nn_fsm_bad_action (aws->state, src, type); + } + + default: + nn_fsm_bad_source (aws->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (aws->state, src, type); + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/aws.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/aws.h new file mode 100644 index 0000000..ae271be --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/aws.h @@ -0,0 +1,81 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_AWS_INCLUDED +#define NN_AWS_INCLUDED + +#include "sws.h" + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/list.h" + +/* State machine handling accepted WS sockets. */ + +/* In bws, some events are just *assumed* to come from a child aws object. + By using non-trivial event codes, we can do more reliable sanity checking + in such scenarios. */ +#define NN_AWS_ACCEPTED 34231 +#define NN_AWS_ERROR 34232 +#define NN_AWS_STOPPED 34233 + +struct nn_aws { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Pointer to the associated endpoint. */ + struct nn_epbase *epbase; + + /* Underlying socket. */ + struct nn_usock usock; + + /* Listening socket. Valid only while accepting new connection. */ + struct nn_usock *listener; + struct nn_fsm_owner listener_owner; + + /* State machine that takes care of the connection in the active state. */ + struct nn_sws sws; + + /* Events generated by aws state machine. */ + struct nn_fsm_event accepted; + struct nn_fsm_event done; + + /* This member can be used by owner to keep individual awss in a list. */ + struct nn_list_item item; +}; + +void nn_aws_init (struct nn_aws *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_aws_term (struct nn_aws *self); + +int nn_aws_isidle (struct nn_aws *self); +void nn_aws_start (struct nn_aws *self, struct nn_usock *listener); +void nn_aws_stop (struct nn_aws *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/bws.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/bws.c new file mode 100644 index 0000000..da3a53f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/bws.c @@ -0,0 +1,408 @@ +/* + Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014-2016 Jack R. Dunaway. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "bws.h" +#include "aws.h" + +#include "../utils/port.h" +#include "../utils/iface.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/list.h" +#include "../../utils/fast.h" + +#include + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#endif + +/* The backlog is set relatively high so that there are not too many failed + connection attemps during re-connection storms. */ +#define NN_BWS_BACKLOG 100 + +#define NN_BWS_STATE_IDLE 1 +#define NN_BWS_STATE_ACTIVE 2 +#define NN_BWS_STATE_STOPPING_AWS 3 +#define NN_BWS_STATE_STOPPING_USOCK 4 +#define NN_BWS_STATE_STOPPING_AWSS 5 + +#define NN_BWS_SRC_USOCK 1 +#define NN_BWS_SRC_AWS 2 + +struct nn_bws { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is a specific type of endpoint. + Thus it is derived from epbase. */ + struct nn_epbase epbase; + + /* The underlying listening WS socket. */ + struct nn_usock usock; + + /* The connection being accepted at the moment. */ + struct nn_aws *aws; + + /* List of accepted connections. */ + struct nn_list awss; +}; + +/* nn_epbase virtual interface implementation. */ +static void nn_bws_stop (struct nn_epbase *self); +static void nn_bws_destroy (struct nn_epbase *self); +const struct nn_epbase_vfptr nn_bws_epbase_vfptr = { + nn_bws_stop, + nn_bws_destroy +}; + +/* Private functions. */ +static void nn_bws_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_bws_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static int nn_bws_listen (struct nn_bws *self); +static void nn_bws_start_accepting (struct nn_bws *self); + +int nn_bws_create (void *hint, struct nn_epbase **epbase) +{ + int rc; + struct nn_bws *self; + const char *addr; + const char *end; + const char *pos; + struct sockaddr_storage ss; + size_t sslen; + int ipv4only; + size_t ipv4onlylen; + + /* Allocate the new endpoint object. */ + self = nn_alloc (sizeof (struct nn_bws), "bws"); + alloc_assert (self); + + /* Initalise the epbase. */ + nn_epbase_init (&self->epbase, &nn_bws_epbase_vfptr, hint); + addr = nn_epbase_getaddr (&self->epbase); + + /* Parse the port. */ + end = addr + strlen (addr); + pos = strrchr (addr, ':'); + if (nn_slow (!pos)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + ++pos; + rc = nn_port_resolve (pos, end - pos); + if (nn_slow (rc < 0)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + /* Parse the address. */ + rc = nn_iface_resolve (addr, pos - addr - 1, ipv4only, &ss, &sslen); + if (nn_slow (rc < 0)) { + nn_epbase_term (&self->epbase); + return -ENODEV; + } + + /* Initialise the structure. */ + nn_fsm_init_root (&self->fsm, nn_bws_handler, nn_bws_shutdown, + nn_epbase_getctx (&self->epbase)); + self->state = NN_BWS_STATE_IDLE; + self->aws = NULL; + nn_list_init (&self->awss); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + nn_usock_init (&self->usock, NN_BWS_SRC_USOCK, &self->fsm); + + rc = nn_bws_listen (self); + if (rc != 0) { + nn_epbase_term (&self->epbase); + return rc; + } + + /* Return the base class as an out parameter. */ + *epbase = &self->epbase; + + return 0; +} + +static void nn_bws_stop (struct nn_epbase *self) +{ + struct nn_bws *bws; + + bws = nn_cont (self, struct nn_bws, epbase); + + nn_fsm_stop (&bws->fsm); +} + +static void nn_bws_destroy (struct nn_epbase *self) +{ + struct nn_bws *bws; + + bws = nn_cont (self, struct nn_bws, epbase); + + nn_assert_state (bws, NN_BWS_STATE_IDLE); + nn_list_term (&bws->awss); + nn_assert (bws->aws == NULL); + nn_usock_term (&bws->usock); + nn_epbase_term (&bws->epbase); + nn_fsm_term (&bws->fsm); + + nn_free (bws); +} + +static void nn_bws_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_bws *bws; + struct nn_list_item *it; + struct nn_aws *aws; + + bws = nn_cont (self, struct nn_bws, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (bws->aws) { + nn_aws_stop (bws->aws); + bws->state = NN_BWS_STATE_STOPPING_AWS; + } + else { + bws->state = NN_BWS_STATE_STOPPING_USOCK; + } + } + if (nn_slow (bws->state == NN_BWS_STATE_STOPPING_AWS)) { + if (!nn_aws_isidle (bws->aws)) + return; + nn_aws_term (bws->aws); + nn_free (bws->aws); + bws->aws = NULL; + nn_usock_stop (&bws->usock); + bws->state = NN_BWS_STATE_STOPPING_USOCK; + } + if (nn_slow (bws->state == NN_BWS_STATE_STOPPING_USOCK)) { + if (!nn_usock_isidle (&bws->usock)) + return; + for (it = nn_list_begin (&bws->awss); + it != nn_list_end (&bws->awss); + it = nn_list_next (&bws->awss, it)) { + aws = nn_cont (it, struct nn_aws, item); + nn_aws_stop (aws); + } + bws->state = NN_BWS_STATE_STOPPING_AWSS; + goto awss_stopping; + } + if (nn_slow (bws->state == NN_BWS_STATE_STOPPING_AWSS)) { + nn_assert (src == NN_BWS_SRC_AWS && type == NN_AWS_STOPPED); + aws = (struct nn_aws *) srcptr; + nn_list_erase (&bws->awss, &aws->item); + nn_aws_term (aws); + nn_free (aws); + + /* If there are no more aws state machines, we can stop the whole + bws object. */ +awss_stopping: + if (nn_list_empty (&bws->awss)) { + bws->state = NN_BWS_STATE_IDLE; + nn_fsm_stopped_noevent (&bws->fsm); + nn_epbase_stopped (&bws->epbase); + return; + } + + return; + } + + nn_fsm_bad_action (bws->state, src, type); +} + +static void nn_bws_handler (struct nn_fsm *self, int src, int type, + void *srcptr) +{ + struct nn_bws *bws; + struct nn_aws *aws; + + bws = nn_cont (self, struct nn_bws, fsm); + + switch (bws->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_BWS_STATE_IDLE: + nn_assert (src == NN_FSM_ACTION); + nn_assert (type == NN_FSM_START); + bws->state = NN_BWS_STATE_ACTIVE; + return; + +/******************************************************************************/ +/* ACTIVE state. */ +/* The execution is yielded to the aws state machine in this state. */ +/******************************************************************************/ + case NN_BWS_STATE_ACTIVE: + if (src == NN_BWS_SRC_USOCK) { + nn_assert (type == NN_USOCK_SHUTDOWN || type == NN_USOCK_STOPPED); + return; + } + + /* For all remaining events we'll assume they are coming from one + of remaining child aws objects. */ + nn_assert (src == NN_BWS_SRC_AWS); + aws = (struct nn_aws*) srcptr; + switch (type) { + case NN_AWS_ACCEPTED: + + /* Move the newly created connection to the list of existing + connections. */ + nn_list_insert (&bws->awss, &bws->aws->item, + nn_list_end (&bws->awss)); + bws->aws = NULL; + + /* Start waiting for a new incoming connection. */ + nn_bws_start_accepting (bws); + return; + + case NN_AWS_ERROR: + nn_aws_stop (aws); + return; + case NN_AWS_STOPPED: + nn_list_erase (&bws->awss, &aws->item); + nn_aws_term (aws); + nn_free (aws); + return; + default: + nn_fsm_bad_action (bws->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (bws->state, src, type); + } +} + +static int nn_bws_listen (struct nn_bws *self) +{ + int rc; + struct sockaddr_storage ss; + size_t sslen; + int ipv4only; + size_t ipv4onlylen; + const char *addr; + const char *end; + const char *pos; + uint16_t port; + + /* First, resolve the IP address. */ + addr = nn_epbase_getaddr (&self->epbase); + memset (&ss, 0, sizeof (ss)); + + /* Parse the port. */ + end = addr + strlen (addr); + pos = strrchr (addr, ':'); + nn_assert (pos); + ++pos; + rc = nn_port_resolve (pos, end - pos); + if (rc < 0) { + return rc; + } + port = (uint16_t) rc; + + /* Parse the address. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + rc = nn_iface_resolve (addr, pos - addr - 1, ipv4only, &ss, &sslen); + if (rc < 0) { + return rc; + } + + /* Combine the port and the address. */ + if (ss.ss_family == AF_INET) { + ((struct sockaddr_in*) &ss)->sin_port = htons (port); + sslen = sizeof (struct sockaddr_in); + } + else if (ss.ss_family == AF_INET6) { + ((struct sockaddr_in6*) &ss)->sin6_port = htons (port); + sslen = sizeof (struct sockaddr_in6); + } + else + nn_assert (0); + + /* Start listening for incoming connections. */ + rc = nn_usock_start (&self->usock, ss.ss_family, SOCK_STREAM, 0); + if (rc < 0) { + return rc; + } + + rc = nn_usock_bind (&self->usock, (struct sockaddr*) &ss, (size_t) sslen); + if (rc < 0) { + nn_usock_stop (&self->usock); + return rc; + } + + rc = nn_usock_listen (&self->usock, NN_BWS_BACKLOG); + if (rc < 0) { + nn_usock_stop (&self->usock); + return rc; + } + nn_bws_start_accepting(self); + + return 0; +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_bws_start_accepting (struct nn_bws *self) +{ + nn_assert (self->aws == NULL); + + /* Allocate new aws state machine. */ + self->aws = nn_alloc (sizeof (struct nn_aws), "aws"); + alloc_assert (self->aws); + nn_aws_init (self->aws, NN_BWS_SRC_AWS, &self->epbase, &self->fsm); + + /* Start waiting for a new incoming connection. */ + nn_aws_start (self->aws, &self->usock); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/bws.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/bws.h new file mode 100644 index 0000000..9203b2e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/bws.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_BWS_INCLUDED +#define NN_BWS_INCLUDED + +#include "../../transport.h" + +/* State machine managing bound WS socket. */ + +int nn_bws_create (void *hint, struct nn_epbase **epbase); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/cws.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/cws.c new file mode 100644 index 0000000..627d1ec --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/cws.c @@ -0,0 +1,683 @@ +/* + Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014-2016 Jack R. Dunaway. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "cws.h" +#include "sws.h" + +#include "../../ws.h" + +#include "../utils/dns.h" +#include "../utils/port.h" +#include "../utils/iface.h" +#include "../utils/backoff.h" +#include "../utils/literal.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/attr.h" + +#include + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#include +#include +#endif + +#define NN_CWS_STATE_IDLE 1 +#define NN_CWS_STATE_RESOLVING 2 +#define NN_CWS_STATE_STOPPING_DNS 3 +#define NN_CWS_STATE_CONNECTING 4 +#define NN_CWS_STATE_ACTIVE 5 +#define NN_CWS_STATE_STOPPING_SWS 6 +#define NN_CWS_STATE_STOPPING_USOCK 7 +#define NN_CWS_STATE_WAITING 8 +#define NN_CWS_STATE_STOPPING_BACKOFF 9 +#define NN_CWS_STATE_STOPPING_SWS_FINAL 10 +#define NN_CWS_STATE_STOPPING 11 + +#define NN_CWS_SRC_USOCK 1 +#define NN_CWS_SRC_RECONNECT_TIMER 2 +#define NN_CWS_SRC_DNS 3 +#define NN_CWS_SRC_SWS 4 + +struct nn_cws { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* This object is a specific type of endpoint. + Thus it is derived from epbase. */ + struct nn_epbase epbase; + + /* The underlying WS socket. */ + struct nn_usock usock; + + /* Used to wait before retrying to connect. */ + struct nn_backoff retry; + + /* Defines message validation and framing. */ + uint8_t msg_type; + + /* State machine that handles the active part of the connection + lifetime. */ + struct nn_sws sws; + + /* Parsed parts of the connection URI. */ + struct nn_chunkref resource; + struct nn_chunkref remote_host; + struct nn_chunkref nic; + int remote_port; + size_t remote_hostname_len; + + /* If a close handshake is performed, this flag signals to not + begin automatic reconnect retries. */ + int peer_gone; + + /* DNS resolver used to convert textual address into actual IP address + along with the variable to hold the result. */ + struct nn_dns dns; + struct nn_dns_result dns_result; +}; + +/* nn_epbase virtual interface implementation. */ +static void nn_cws_stop (struct nn_epbase *self); +static void nn_cws_destroy (struct nn_epbase *self); +const struct nn_epbase_vfptr nn_cws_epbase_vfptr = { + nn_cws_stop, + nn_cws_destroy +}; + +/* Private functions. */ +static void nn_cws_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_cws_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_cws_start_resolving (struct nn_cws *self); +static void nn_cws_start_connecting (struct nn_cws *self, + struct sockaddr_storage *ss, size_t sslen); + +int nn_cws_create (void *hint, struct nn_epbase **epbase) +{ + int rc; + const char *addr; + size_t addrlen; + const char *semicolon; + const char *hostname; + size_t hostlen; + const char *colon; + const char *slash; + const char *resource; + size_t resourcelen; + struct sockaddr_storage ss; + size_t sslen; + int ipv4only; + size_t ipv4onlylen; + struct nn_cws *self; + int reconnect_ivl; + int reconnect_ivl_max; + int msg_type; + size_t sz; + + /* Allocate the new endpoint object. */ + self = nn_alloc (sizeof (struct nn_cws), "cws"); + alloc_assert (self); + + /* Initalise the endpoint. */ + nn_epbase_init (&self->epbase, &nn_cws_epbase_vfptr, hint); + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + /* Start parsing the address. */ + addr = nn_epbase_getaddr (&self->epbase); + addrlen = strlen (addr); + semicolon = strchr (addr, ';'); + hostname = semicolon ? semicolon + 1 : addr; + colon = strrchr (addr, ':'); + slash = colon ? strchr (colon, '/') : strchr (addr, '/'); + resource = slash ? slash : addr + addrlen; + self->remote_hostname_len = colon ? colon - hostname : resource - hostname; + + /* Host contains both hostname and port. */ + hostlen = resource - hostname; + + /* Parse the port; assume port 80 if not explicitly declared. */ + if (nn_slow (colon != NULL)) { + rc = nn_port_resolve (colon + 1, resource - colon - 1); + if (nn_slow (rc < 0)) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + self->remote_port = rc; + } + else { + self->remote_port = 80; + } + + /* Check whether the host portion of the address is either a literal + or a valid hostname. */ + if (nn_dns_check_hostname (hostname, self->remote_hostname_len) < 0 && + nn_literal_resolve (hostname, self->remote_hostname_len, ipv4only, + &ss, &sslen) < 0) { + nn_epbase_term (&self->epbase); + return -EINVAL; + } + + /* If local address is specified, check whether it is valid. */ + if (semicolon) { + rc = nn_iface_resolve (addr, semicolon - addr, ipv4only, &ss, &sslen); + if (rc < 0) { + nn_epbase_term (&self->epbase); + return -ENODEV; + } + } + + /* At this point, the address is valid, so begin allocating resources. */ + nn_chunkref_init (&self->remote_host, hostlen + 1); + memcpy (nn_chunkref_data (&self->remote_host), hostname, hostlen); + ((uint8_t *) nn_chunkref_data (&self->remote_host)) [hostlen] = '\0'; + + if (semicolon) { + nn_chunkref_init (&self->nic, semicolon - addr); + memcpy (nn_chunkref_data (&self->nic), + addr, semicolon - addr); + } + else { + nn_chunkref_init (&self->nic, 1); + memcpy (nn_chunkref_data (&self->nic), "*", 1); + } + + /* The requested resource is used in opening handshake. */ + resourcelen = strlen (resource); + if (resourcelen) { + nn_chunkref_init (&self->resource, resourcelen + 1); + strncpy (nn_chunkref_data (&self->resource), + resource, resourcelen + 1); + } + else { + /* No resource specified, so allocate base path. */ + nn_chunkref_init (&self->resource, 2); + strncpy (nn_chunkref_data (&self->resource), "/", 2); + } + + /* Initialise the structure. */ + nn_fsm_init_root (&self->fsm, nn_cws_handler, nn_cws_shutdown, + nn_epbase_getctx (&self->epbase)); + self->state = NN_CWS_STATE_IDLE; + nn_usock_init (&self->usock, NN_CWS_SRC_USOCK, &self->fsm); + + sz = sizeof (msg_type); + nn_epbase_getopt (&self->epbase, NN_WS, NN_WS_MSG_TYPE, + &msg_type, &sz); + nn_assert (sz == sizeof (msg_type)); + self->msg_type = (uint8_t) msg_type; + + sz = sizeof (reconnect_ivl); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL, + &reconnect_ivl, &sz); + nn_assert (sz == sizeof (reconnect_ivl)); + sz = sizeof (reconnect_ivl_max); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL_MAX, + &reconnect_ivl_max, &sz); + nn_assert (sz == sizeof (reconnect_ivl_max)); + if (reconnect_ivl_max == 0) + reconnect_ivl_max = reconnect_ivl; + nn_backoff_init (&self->retry, NN_CWS_SRC_RECONNECT_TIMER, + reconnect_ivl, reconnect_ivl_max, &self->fsm); + + nn_sws_init (&self->sws, NN_CWS_SRC_SWS, &self->epbase, &self->fsm); + nn_dns_init (&self->dns, NN_CWS_SRC_DNS, &self->fsm); + + /* Start the state machine. */ + nn_fsm_start (&self->fsm); + + /* Return the base class as an out parameter. */ + *epbase = &self->epbase; + + return 0; +} + +static void nn_cws_stop (struct nn_epbase *self) +{ + struct nn_cws *cws; + + cws = nn_cont (self, struct nn_cws, epbase); + + nn_fsm_stop (&cws->fsm); +} + +static void nn_cws_destroy (struct nn_epbase *self) +{ + struct nn_cws *cws; + + cws = nn_cont (self, struct nn_cws, epbase); + + nn_chunkref_term (&cws->resource); + nn_chunkref_term (&cws->remote_host); + nn_chunkref_term (&cws->nic); + nn_dns_term (&cws->dns); + nn_sws_term (&cws->sws); + nn_backoff_term (&cws->retry); + nn_usock_term (&cws->usock); + nn_fsm_term (&cws->fsm); + nn_epbase_term (&cws->epbase); + + nn_free (cws); +} + +static void nn_cws_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_cws *cws; + + cws = nn_cont (self, struct nn_cws, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + if (!nn_sws_isidle (&cws->sws)) { + nn_epbase_stat_increment (&cws->epbase, + NN_STAT_DROPPED_CONNECTIONS, 1); + nn_sws_stop (&cws->sws); + } + cws->state = NN_CWS_STATE_STOPPING_SWS_FINAL; + } + if (nn_slow (cws->state == NN_CWS_STATE_STOPPING_SWS_FINAL)) { + if (!nn_sws_isidle (&cws->sws)) + return; + nn_backoff_stop (&cws->retry); + nn_usock_stop (&cws->usock); + nn_dns_stop (&cws->dns); + cws->state = NN_CWS_STATE_STOPPING; + } + if (nn_slow (cws->state == NN_CWS_STATE_STOPPING)) { + if (!nn_backoff_isidle (&cws->retry) || + !nn_usock_isidle (&cws->usock) || + !nn_dns_isidle (&cws->dns)) + return; + cws->state = NN_CWS_STATE_IDLE; + nn_fsm_stopped_noevent (&cws->fsm); + nn_epbase_stopped (&cws->epbase); + return; + } + + nn_fsm_bad_state (cws->state, src, type); +} + +static void nn_cws_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_cws *cws; + + cws = nn_cont (self, struct nn_cws, fsm); + + switch (cws->state) { + +/******************************************************************************/ +/* IDLE state. */ +/* The state machine wasn't yet started. */ +/******************************************************************************/ + case NN_CWS_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_cws_start_resolving (cws); + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* RESOLVING state. */ +/* Name of the host to connect to is being resolved to get an IP address. */ +/******************************************************************************/ + case NN_CWS_STATE_RESOLVING: + switch (src) { + + case NN_CWS_SRC_DNS: + switch (type) { + case NN_DNS_DONE: + nn_dns_stop (&cws->dns); + cws->state = NN_CWS_STATE_STOPPING_DNS; + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_DNS state. */ +/* dns object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CWS_STATE_STOPPING_DNS: + switch (src) { + + case NN_CWS_SRC_DNS: + switch (type) { + case NN_DNS_STOPPED: + if (cws->dns_result.error == 0) { + nn_cws_start_connecting (cws, &cws->dns_result.addr, + cws->dns_result.addrlen); + return; + } + nn_backoff_start (&cws->retry); + cws->state = NN_CWS_STATE_WAITING; + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* CONNECTING state. */ +/* Non-blocking connect is under way. */ +/******************************************************************************/ + case NN_CWS_STATE_CONNECTING: + switch (src) { + + case NN_CWS_SRC_USOCK: + switch (type) { + case NN_USOCK_CONNECTED: + nn_sws_start (&cws->sws, &cws->usock, NN_WS_CLIENT, + nn_chunkref_data (&cws->resource), + nn_chunkref_data (&cws->remote_host), cws->msg_type); + cws->state = NN_CWS_STATE_ACTIVE; + cws->peer_gone = 0; + nn_epbase_stat_increment (&cws->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&cws->epbase, + NN_STAT_ESTABLISHED_CONNECTIONS, 1); + nn_epbase_clear_error (&cws->epbase); + return; + case NN_USOCK_ERROR: + nn_epbase_set_error (&cws->epbase, + nn_usock_geterrno (&cws->usock)); + nn_usock_stop (&cws->usock); + cws->state = NN_CWS_STATE_STOPPING_USOCK; + nn_epbase_stat_increment (&cws->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, -1); + nn_epbase_stat_increment (&cws->epbase, + NN_STAT_CONNECT_ERRORS, 1); + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/* Connection is established and handled by the sws state machine. */ +/******************************************************************************/ + case NN_CWS_STATE_ACTIVE: + switch (src) { + + case NN_CWS_SRC_SWS: + switch (type) { + case NN_SWS_RETURN_CLOSE_HANDSHAKE: + /* Peer closed connection without intention to reconnect, or + local endpoint failed remote because of invalid data. */ + nn_sws_stop (&cws->sws); + cws->state = NN_CWS_STATE_STOPPING_SWS; + cws->peer_gone = 1; + return; + case NN_SWS_RETURN_ERROR: + nn_sws_stop (&cws->sws); + cws->state = NN_CWS_STATE_STOPPING_SWS; + nn_epbase_stat_increment (&cws->epbase, + NN_STAT_BROKEN_CONNECTIONS, 1); + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_SWS state. */ +/* sws object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CWS_STATE_STOPPING_SWS: + switch (src) { + + case NN_CWS_SRC_SWS: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_SWS_RETURN_STOPPED: + nn_usock_stop (&cws->usock); + cws->state = NN_CWS_STATE_STOPPING_USOCK; + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_USOCK state. */ +/* usock object was asked to stop but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CWS_STATE_STOPPING_USOCK: + switch (src) { + + case NN_CWS_SRC_USOCK: + switch (type) { + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_STOPPED: + /* If the peer has confirmed itself gone with a Closing + Handshake, or if the local endpoint failed the remote, + don't try to reconnect. */ + if (!cws->peer_gone) { + nn_backoff_start (&cws->retry); + cws->state = NN_CWS_STATE_WAITING; + } + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* WAITING state. */ +/* Waiting before re-connection is attempted. This way we won't overload */ +/* the system by continuous re-connection attemps. */ +/******************************************************************************/ + case NN_CWS_STATE_WAITING: + switch (src) { + + case NN_CWS_SRC_RECONNECT_TIMER: + switch (type) { + case NN_BACKOFF_TIMEOUT: + nn_backoff_stop (&cws->retry); + cws->state = NN_CWS_STATE_STOPPING_BACKOFF; + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_BACKOFF state. */ +/* backoff object was asked to stop, but it haven't stopped yet. */ +/******************************************************************************/ + case NN_CWS_STATE_STOPPING_BACKOFF: + switch (src) { + + case NN_CWS_SRC_RECONNECT_TIMER: + switch (type) { + case NN_BACKOFF_STOPPED: + nn_cws_start_resolving (cws); + return; + default: + nn_fsm_bad_action (cws->state, src, type); + } + + default: + nn_fsm_bad_source (cws->state, src, type); + } + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (cws->state, src, type); + } +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_cws_start_resolving (struct nn_cws *self) +{ + int ipv4only; + size_t ipv4onlylen; + char *host; + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + host = nn_chunkref_data (&self->remote_host); + nn_assert (strlen (host) > 0); + + nn_dns_start (&self->dns, host, self->remote_hostname_len, ipv4only, + &self->dns_result); + + self->state = NN_CWS_STATE_RESOLVING; +} + +static void nn_cws_start_connecting (struct nn_cws *self, + struct sockaddr_storage *ss, size_t sslen) +{ + int rc; + struct sockaddr_storage remote; + size_t remotelen; + struct sockaddr_storage local; + size_t locallen; + int ipv4only; + size_t ipv4onlylen; + int val; + size_t sz; + + memset (&remote, 0, sizeof (remote)); + memset (&local, 0, sizeof (local)); + + /* Check whether IPv6 is to be used. */ + ipv4onlylen = sizeof (ipv4only); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_IPV4ONLY, + &ipv4only, &ipv4onlylen); + nn_assert (ipv4onlylen == sizeof (ipv4only)); + + rc = nn_iface_resolve (nn_chunkref_data (&self->nic), + nn_chunkref_size (&self->nic), ipv4only, &local, &locallen); + + if (nn_slow (rc < 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CWS_STATE_WAITING; + return; + } + + /* Combine the remote address and the port. */ + remote = *ss; + remotelen = sslen; + if (remote.ss_family == AF_INET) + ((struct sockaddr_in*) &remote)->sin_port = htons (self->remote_port); + else if (remote.ss_family == AF_INET6) + ((struct sockaddr_in6*) &remote)->sin6_port = htons (self->remote_port); + else + nn_assert (0); + + /* Try to start the underlying socket. */ + rc = nn_usock_start (&self->usock, remote.ss_family, SOCK_STREAM, 0); + if (nn_slow (rc < 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CWS_STATE_WAITING; + return; + } + + /* Set the relevant socket options. */ + sz = sizeof (val); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_SNDBUF, &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&self->usock, SOL_SOCKET, SO_SNDBUF, + &val, sizeof (val)); + sz = sizeof (val); + nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RCVBUF, &val, &sz); + nn_assert (sz == sizeof (val)); + nn_usock_setsockopt (&self->usock, SOL_SOCKET, SO_RCVBUF, + &val, sizeof (val)); + + /* Bind the socket to the local network interface. */ + rc = nn_usock_bind (&self->usock, (struct sockaddr*) &local, locallen); + if (nn_slow (rc != 0)) { + nn_backoff_start (&self->retry); + self->state = NN_CWS_STATE_WAITING; + return; + } + + /* Start connecting. */ + nn_usock_connect (&self->usock, (struct sockaddr*) &remote, remotelen); + self->state = NN_CWS_STATE_CONNECTING; + nn_epbase_stat_increment (&self->epbase, + NN_STAT_INPROGRESS_CONNECTIONS, 1); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/cws.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/cws.h new file mode 100644 index 0000000..6c25b38 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/cws.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CWS_INCLUDED +#define NN_CWS_INCLUDED + +#include "../../transport.h" + +/* State machine managing connected WS socket. */ + +int nn_cws_create (void *hint, struct nn_epbase **epbase); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sha1.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sha1.c new file mode 100644 index 0000000..d58a3eb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sha1.c @@ -0,0 +1,143 @@ +/* + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sha1.h" + +#define sha1_rol32(num,bits) ((num << bits) | (num >> (32 - bits))) + +void nn_sha1_init (struct nn_sha1 *self) +{ + /* Detect endianness. */ + union { + uint32_t i; + char c[4]; + } test = { 0x00000001 }; + + self->is_little_endian = test.c[0]; + + /* Initial state of the hash. */ + self->state [0] = 0x67452301; + self->state [1] = 0xefcdab89; + self->state [2] = 0x98badcfe; + self->state [3] = 0x10325476; + self->state [4] = 0xc3d2e1f0; + self->bytes_hashed = 0; + self->buffer_offset = 0; +} + +static void nn_sha1_add (struct nn_sha1 *self, uint8_t data) +{ + uint8_t i; + uint32_t a, b, c, d, e, t; + uint8_t * const buf = (uint8_t*) self->buffer; + + if (self->is_little_endian) + buf [self->buffer_offset ^ 3] = data; + else + buf [self->buffer_offset] = data; + + self->buffer_offset++; + if (self->buffer_offset == SHA1_BLOCK_LEN) { + a = self->state [0]; + b = self->state [1]; + c = self->state [2]; + d = self->state [3]; + e = self->state [4]; + for (i = 0; i < 80; i++) { + if (i >= 16) { + t = self->buffer [(i + 13) & 15] ^ + self->buffer [(i + 8) & 15] ^ + self->buffer [(i + 2) & 15] ^ + self->buffer [i & 15]; + self->buffer [i & 15] = sha1_rol32 (t, 1); + } + + if (i < 20) + t = (d ^ (b & (c ^ d))) + 0x5A827999; + else if (i < 40) + t = (b ^ c ^ d) + 0x6ED9EBA1; + else if (i < 60) + t = ((b & c) | (d & (b | c))) + 0x8F1BBCDC; + else + t = (b ^ c ^ d) + 0xCA62C1D6; + + t += sha1_rol32 (a, 5) + e + self->buffer [i & 15]; + e = d; + d = c; + c = sha1_rol32 (b, 30); + b = a; + a = t; + } + + self->state [0] += a; + self->state [1] += b; + self->state [2] += c; + self->state [3] += d; + self->state [4] += e; + + self->buffer_offset = 0; + } +} + +void nn_sha1_hashbyte (struct nn_sha1 *self, uint8_t data) +{ + ++self->bytes_hashed; + nn_sha1_add (self, data); +} + +uint8_t* nn_sha1_result (struct nn_sha1 *self) +{ + int i; + + /* Pad to complete the last block. */ + nn_sha1_add (self, 0x80); + + while (self->buffer_offset != 56) + nn_sha1_add (self, 0x00); + + /* Append length in the last 8 bytes. SHA-1 supports 64-bit hashes, so + zero-pad the top bits. Shifting to multiply by 8 as SHA-1 supports + bit- as well as byte-streams. */ + nn_sha1_add (self, 0); + nn_sha1_add (self, 0); + nn_sha1_add (self, 0); + nn_sha1_add (self, self->bytes_hashed >> 29); + nn_sha1_add (self, self->bytes_hashed >> 21); + nn_sha1_add (self, self->bytes_hashed >> 13); + nn_sha1_add (self, self->bytes_hashed >> 5); + nn_sha1_add (self, self->bytes_hashed << 3); + + /* Correct byte order for little-endian systems. */ + if (self->is_little_endian) { + for (i = 0; i < 5; i++) { + self->state [i] = + (((self->state [i]) << 24) & 0xFF000000) | + (((self->state [i]) << 8) & 0x00FF0000) | + (((self->state [i]) >> 8) & 0x0000FF00) | + (((self->state [i]) >> 24) & 0x000000FF); + } + } + + /* 20-octet pointer to hash. */ + return (uint8_t*) self->state; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sha1.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sha1.h new file mode 100644 index 0000000..b130b57 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sha1.h @@ -0,0 +1,57 @@ +/* + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SHA1_INCLUDED +#define NN_SHA1_INCLUDED + +#include + +/*****************************************************************************/ +/* SHA-1 SECURITY NOTICE: */ +/* The algorithm as designed below is not intended for general purpose use. */ +/* As-designed, it is a single-purpose function for this WebSocket */ +/* Opening Handshake. As per RFC 6455 10.8, SHA-1 usage "doesn't depend on */ +/* any security properties of SHA-1, such as collision resistance or */ +/* resistance to the second pre-image attack (as described in [RFC4270])". */ +/* Caveat emptor for uses of this function elsewhere. */ +/* */ +/* Based on sha1.c (Public Domain) by Steve Reid, these functions calculate */ +/* the SHA1 hash of arbitrary byte locations byte-by-byte. */ +/*****************************************************************************/ + +#define SHA1_HASH_LEN 20 +#define SHA1_BLOCK_LEN 64 + +struct nn_sha1 { + uint32_t buffer [SHA1_BLOCK_LEN / sizeof (uint32_t)]; + uint32_t state [SHA1_HASH_LEN / sizeof (uint32_t)]; + uint32_t bytes_hashed; + uint8_t buffer_offset; + uint8_t is_little_endian; +}; + +void nn_sha1_init (struct nn_sha1 *self); +void nn_sha1_hashbyte (struct nn_sha1 *self, uint8_t data); +uint8_t* nn_sha1_result (struct nn_sha1 *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sws.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sws.c new file mode 100644 index 0000000..cbb2a77 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sws.c @@ -0,0 +1,1560 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014-2016 Jack R. Dunaway. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sws.h" +#include "../../ws.h" +#include "../../nn.h" + +#include "../../utils/alloc.h" +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/wire.h" +#include "../../utils/attr.h" +#include "../../utils/random.h" + +/* States of the object as a whole. */ +#define NN_SWS_STATE_IDLE 1 +#define NN_SWS_STATE_HANDSHAKE 2 +#define NN_SWS_STATE_STOPPING_HANDSHAKE 3 +#define NN_SWS_STATE_ACTIVE 4 +#define NN_SWS_STATE_CLOSING_CONNECTION 5 +#define NN_SWS_STATE_BROKEN_CONNECTION 6 +#define NN_SWS_STATE_DONE 7 +#define NN_SWS_STATE_STOPPING 8 + +/* Possible states of the inbound part of the object. */ +#define NN_SWS_INSTATE_RECV_HDR 1 +#define NN_SWS_INSTATE_RECV_HDREXT 2 +#define NN_SWS_INSTATE_RECV_PAYLOAD 3 +#define NN_SWS_INSTATE_RECVD_CHUNKED 4 +#define NN_SWS_INSTATE_RECVD_CONTROL 5 +#define NN_SWS_INSTATE_FAILING 6 +#define NN_SWS_INSTATE_CLOSED 7 + +/* Possible states of the outbound part of the object. */ +#define NN_SWS_OUTSTATE_IDLE 1 +#define NN_SWS_OUTSTATE_SENDING 2 + +/* Subordinate srcptr objects. */ +#define NN_SWS_SRC_USOCK 1 +#define NN_SWS_SRC_HANDSHAKE 2 + +/* WebSocket opcode constants as per RFC 6455 5.2. */ +#define NN_WS_OPCODE_FRAGMENT 0x00 +#define NN_WS_OPCODE_TEXT NN_WS_MSG_TYPE_TEXT +#define NN_WS_OPCODE_BINARY NN_WS_MSG_TYPE_BINARY +#define NN_WS_OPCODE_UNUSED3 0x03 +#define NN_WS_OPCODE_UNUSED4 0x04 +#define NN_WS_OPCODE_UNUSED5 0x05 +#define NN_WS_OPCODE_UNUSED6 0x06 +#define NN_WS_OPCODE_UNUSED7 0x07 +#define NN_WS_OPCODE_CLOSE 0x08 +#define NN_WS_OPCODE_PING 0x09 +#define NN_WS_OPCODE_PONG 0x0A +#define NN_WS_OPCODE_UNUSEDB 0x0B +#define NN_WS_OPCODE_UNUSEDC 0x0C +#define NN_WS_OPCODE_UNUSEDD 0x0D +#define NN_WS_OPCODE_UNUSEDE 0x0E +#define NN_WS_OPCODE_UNUSEDF 0x0F + +/* WebSocket protocol header bit masks as per RFC 6455. */ +#define NN_SWS_FRAME_BITMASK_MASKED 0x80 +#define NN_SWS_FRAME_BITMASK_NOT_MASKED 0x00 +#define NN_SWS_FRAME_BITMASK_LENGTH 0x7F + +/* WebSocket Close Status Codes (1004-1006 and 1015 are reserved). */ +#define NN_SWS_CLOSE_NORMAL 1000 +#define NN_SWS_CLOSE_GOING_AWAY 1001 +#define NN_SWS_CLOSE_ERR_PROTO 1002 +#define NN_SWS_CLOSE_ERR_WUT 1003 +#define NN_SWS_CLOSE_ERR_INVALID_FRAME 1007 +#define NN_SWS_CLOSE_ERR_POLICY 1008 +#define NN_SWS_CLOSE_ERR_TOOBIG 1009 +#define NN_SWS_CLOSE_ERR_EXTENSION 1010 +#define NN_SWS_CLOSE_ERR_SERVER 1011 + +/* UTF-8 validation. */ +#define NN_SWS_UTF8_INVALID -2 +#define NN_SWS_UTF8_FRAGMENT -1 + +/* Stream is a special type of pipe. Implementation of the virtual pipe API. */ +static int nn_sws_send (struct nn_pipebase *self, struct nn_msg *msg); +static int nn_sws_recv (struct nn_pipebase *self, struct nn_msg *msg); +const struct nn_pipebase_vfptr nn_sws_pipebase_vfptr = { + nn_sws_send, + nn_sws_recv +}; + +/* Private functions. */ +static void nn_sws_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_sws_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); + +/* Ceases further I/O on the underlying socket and prepares to send a + close handshake on the next receive. */ +static void nn_sws_fail_conn (struct nn_sws *self, int code, char *reason); + +/* Start receiving new message chunk. */ +static int nn_sws_recv_hdr (struct nn_sws *self); + +/* Mask or unmask message payload. */ +static void nn_sws_mask_payload (uint8_t *payload, size_t payload_len, + const uint8_t *mask, size_t mask_len, int *mask_start_pos); + +/* Validates incoming text chunks for UTF-8 compliance as per RFC 3629. */ +static void nn_sws_validate_utf8_chunk (struct nn_sws *self); + +/* Ensures that Close frames received from peer conform to + RFC 6455 section 7. */ +static void nn_sws_acknowledge_close_handshake (struct nn_sws *self); + +void nn_sws_init (struct nn_sws *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_sws_handler, nn_sws_shutdown, + src, self, owner); + self->state = NN_SWS_STATE_IDLE; + self->epbase = epbase; + nn_ws_handshake_init (&self->handshaker, + NN_SWS_SRC_HANDSHAKE, &self->fsm); + self->usock = NULL; + self->usock_owner.src = -1; + self->usock_owner.fsm = NULL; + nn_pipebase_init (&self->pipebase, &nn_sws_pipebase_vfptr, epbase); + self->instate = -1; + nn_list_init (&self->inmsg_array); + self->outstate = -1; + nn_msg_init (&self->outmsg, 0); + + self->continuing = 0; + + memset (self->utf8_code_pt_fragment, 0, + NN_SWS_UTF8_MAX_CODEPOINT_LEN); + self->utf8_code_pt_fragment_len = 0; + + self->pings_sent = 0; + self->pongs_sent = 0; + self->pings_received = 0; + self->pongs_received = 0; + + nn_fsm_event_init (&self->done); +} + +void nn_sws_term (struct nn_sws *self) +{ + nn_assert_state (self, NN_SWS_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_msg_term (&self->outmsg); + nn_msg_array_term (&self->inmsg_array); + nn_pipebase_term (&self->pipebase); + nn_ws_handshake_term (&self->handshaker); + nn_fsm_term (&self->fsm); +} + +int nn_sws_isidle (struct nn_sws *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_sws_start (struct nn_sws *self, struct nn_usock *usock, int mode, + const char *resource, const char *host, uint8_t msg_type) +{ + /* Take ownership of the underlying socket. */ + nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL); + self->usock_owner.src = NN_SWS_SRC_USOCK; + self->usock_owner.fsm = &self->fsm; + nn_usock_swap_owner (usock, &self->usock_owner); + self->usock = usock; + self->mode = mode; + self->resource = resource; + self->remote_host = host; + + self->msg_type = msg_type; + + /* Launch the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_sws_stop (struct nn_sws *self) +{ + nn_fsm_stop (&self->fsm); +} + +void *nn_msg_chunk_new (size_t size, struct nn_list *msg_array) +{ + struct msg_chunk *self; + + self = nn_alloc (sizeof (struct msg_chunk), "msg_chunk"); + alloc_assert (self); + + nn_chunkref_init (&self->chunk, size); + nn_list_item_init (&self->item); + + nn_list_insert (msg_array, &self->item, nn_list_end (msg_array)); + + return nn_chunkref_data (&self->chunk); +} + +void nn_msg_chunk_term (struct msg_chunk *it, struct nn_list *msg_array) +{ + nn_chunkref_term (&it->chunk); + nn_list_erase (msg_array, &it->item); + nn_list_item_term (&it->item); + nn_free (it); +} + +void nn_msg_array_term (struct nn_list *msg_array) +{ + struct nn_list_item *it; + struct msg_chunk *ch; + + while (!nn_list_empty (msg_array)) { + it = nn_list_begin (msg_array); + ch = nn_cont (it, struct msg_chunk, item); + nn_msg_chunk_term (ch, msg_array); + } + + nn_list_term (msg_array); +} + +/* Given a buffer location, this function determines whether the leading + octets form a valid UTF-8 code point. */ +static int nn_utf8_code_point (const uint8_t *buffer, size_t len) +{ + /* The lack of information is considered neither valid nor invalid. */ + if (!buffer || !len) + return NN_SWS_UTF8_FRAGMENT; + + /* RFC 3629 section 4 UTF8-1. */ + if (buffer [0] <= 0x7F) + return 1; + + /* 0xC2, or 11000001, is the smallest conceivable multi-octet code + point that is not an illegal overlong encoding. */ + if (buffer [0] < 0xC2) + return NN_SWS_UTF8_INVALID; + + /* Largest 2-octet code point starts with 0xDF (11011111). */ + if (buffer [0] <= 0xDF) { + if (len < 2) + return NN_SWS_UTF8_FRAGMENT; + /* Ensure continuation byte in form of 10xxxxxx */ + else if ((buffer [1] & 0xC0) != 0x80) + return NN_SWS_UTF8_INVALID; + else + return 2; + } + + /* RFC 3629 section 4 UTF8-3, where 0xEF is 11101111. */ + if (buffer [0] <= 0xEF) { + /* Fragment. */ + if (len < 2) + return NN_SWS_UTF8_FRAGMENT; + /* Illegal overlong sequence detection. */ + else if (buffer [0] == 0xE0 && (buffer [1] < 0xA0 || buffer [1] == 0x80)) + return NN_SWS_UTF8_INVALID; + /* Illegal UTF-16 surrogate pair half U+D800 through U+DFFF. */ + else if (buffer [0] == 0xED && buffer [1] >= 0xA0) + return NN_SWS_UTF8_INVALID; + /* Fragment. */ + else if (len < 3) + return NN_SWS_UTF8_FRAGMENT; + /* Ensure continuation bytes 2 and 3 in form of 10xxxxxx */ + else if ((buffer [1] & 0xC0) != 0x80 || (buffer [2] & 0xC0) != 0x80) + return NN_SWS_UTF8_INVALID; + else + return 3; + } + + /* RFC 3629 section 4 UTF8-4, where 0xF4 is 11110100. Why + not 11110111 to follow the pattern? Because UTF-8 encoding + stops at 0x10FFFF as per RFC 3629. */ + if (buffer [0] <= 0xF4) { + /* Fragment. */ + if (len < 2) + return NN_SWS_UTF8_FRAGMENT; + /* Illegal overlong sequence detection. */ + else if (buffer [0] == 0xF0 && buffer [1] < 0x90) + return NN_SWS_UTF8_INVALID; + /* Illegal code point greater than U+10FFFF. */ + else if (buffer [0] == 0xF4 && buffer [1] >= 0x90) + return NN_SWS_UTF8_INVALID; + /* Fragment. */ + else if (len < 4) + return NN_SWS_UTF8_FRAGMENT; + /* Ensure continuation bytes 2, 3, and 4 in form of 10xxxxxx */ + else if ((buffer [1] & 0xC0) != 0x80 || + (buffer [2] & 0xC0) != 0x80 || + (buffer [3] & 0xC0) != 0x80) + return NN_SWS_UTF8_INVALID; + else + return 4; + } + + /* UTF-8 encoding stops at U+10FFFF and only defines up to 4-octet + code point sequences. */ + if (buffer [0] >= 0xF5) + return NN_SWS_UTF8_INVALID; + + /* Algorithm error; a case above should have been satisfied. */ + nn_assert (0); +} + +static void nn_sws_mask_payload (uint8_t *payload, size_t payload_len, + const uint8_t *mask, size_t mask_len, int *mask_start_pos) +{ + unsigned i; + + if (mask_start_pos) { + for (i = 0; i < payload_len; i++) { + payload [i] ^= mask [(i + *mask_start_pos) % mask_len]; + } + + *mask_start_pos = (i + *mask_start_pos) % mask_len; + + return; + } + else { + for (i = 0; i < payload_len; i++) { + payload [i] ^= mask [i % mask_len]; + } + return; + } +} + +static int nn_sws_recv_hdr (struct nn_sws *self) +{ + if (!self->continuing) { + nn_assert (nn_list_empty (&self->inmsg_array)); + + self->inmsg_current_chunk_buf = NULL; + self->inmsg_chunks = 0; + self->inmsg_current_chunk_len = 0; + self->inmsg_total_size = 0; + } + + memset (self->inmsg_control, 0, NN_SWS_PAYLOAD_MAX_LENGTH); + memset (self->inhdr, 0, NN_SWS_FRAME_MAX_HDR_LEN); + self->instate = NN_SWS_INSTATE_RECV_HDR; + nn_usock_recv (self->usock, self->inhdr, NN_SWS_FRAME_SIZE_INITIAL, NULL); + + return 0; +} + +static int nn_sws_send (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_sws *sws; + struct nn_iovec iov [3]; + int mask_pos; + size_t nn_msg_size; + size_t hdr_len; + struct nn_cmsghdr *cmsg; + struct nn_msghdr msghdr; + uint8_t rand_mask [NN_SWS_FRAME_SIZE_MASK]; + + sws = nn_cont (self, struct nn_sws, pipebase); + + nn_assert_state (sws, NN_SWS_STATE_ACTIVE); + nn_assert (sws->outstate == NN_SWS_OUTSTATE_IDLE); + + /* Move the message to the local storage. */ + nn_msg_term (&sws->outmsg); + nn_msg_mv (&sws->outmsg, msg); + + memset (sws->outhdr, 0, sizeof (sws->outhdr)); + + hdr_len = NN_SWS_FRAME_SIZE_INITIAL; + + cmsg = NULL; + msghdr.msg_iov = NULL; + msghdr.msg_iovlen = 0; + msghdr.msg_controllen = nn_chunkref_size (&sws->outmsg.hdrs); + + /* If the outgoing message has specified an opcode and control framing in + its header, properly frame it as per RFC 6455 5.2. */ + if (msghdr.msg_controllen > 0) { + msghdr.msg_control = nn_chunkref_data (&sws->outmsg.hdrs); + cmsg = NN_CMSG_FIRSTHDR (&msghdr); + while (cmsg) { + if (cmsg->cmsg_level == NN_WS && cmsg->cmsg_type == NN_WS_MSG_TYPE) + break; + cmsg = NN_CMSG_NXTHDR (&msghdr, cmsg); + } + } + + /* If the header does not specify an opcode, take default from option. */ + if (cmsg) + sws->outhdr [0] = *(uint8_t *) NN_CMSG_DATA (cmsg); + else + sws->outhdr [0] = sws->msg_type; + + /* For now, enforce that outgoing messages are the final frame. */ + sws->outhdr [0] |= NN_SWS_FRAME_BITMASK_FIN; + + nn_msg_size = nn_chunkref_size (&sws->outmsg.sphdr) + + nn_chunkref_size (&sws->outmsg.body); + + /* Framing WebSocket payload size in network byte order (big endian). */ + if (nn_msg_size <= NN_SWS_PAYLOAD_MAX_LENGTH) { + sws->outhdr [1] |= (uint8_t) nn_msg_size; + hdr_len += NN_SWS_FRAME_SIZE_PAYLOAD_0; + } + else if (nn_msg_size <= NN_SWS_PAYLOAD_MAX_LENGTH_16) { + sws->outhdr [1] |= NN_SWS_PAYLOAD_FRAME_16; + nn_puts (&sws->outhdr [hdr_len], (uint16_t) nn_msg_size); + hdr_len += NN_SWS_FRAME_SIZE_PAYLOAD_16; + } + else { + sws->outhdr [1] |= NN_SWS_PAYLOAD_FRAME_63; + nn_putll (&sws->outhdr [hdr_len], (uint64_t) nn_msg_size); + hdr_len += NN_SWS_FRAME_SIZE_PAYLOAD_63; + } + + if (sws->mode == NN_WS_CLIENT) { + sws->outhdr [1] |= NN_SWS_FRAME_BITMASK_MASKED; + + /* Generate 32-bit mask as per RFC 6455 5.3. */ + nn_random_generate (rand_mask, NN_SWS_FRAME_SIZE_MASK); + + memcpy (&sws->outhdr [hdr_len], rand_mask, NN_SWS_FRAME_SIZE_MASK); + hdr_len += NN_SWS_FRAME_SIZE_MASK; + + /* Mask payload, beginning with header and moving to body. */ + mask_pos = 0; + + nn_sws_mask_payload (nn_chunkref_data (&sws->outmsg.sphdr), + nn_chunkref_size (&sws->outmsg.sphdr), + rand_mask, NN_SWS_FRAME_SIZE_MASK, &mask_pos); + + nn_sws_mask_payload (nn_chunkref_data (&sws->outmsg.body), + nn_chunkref_size (&sws->outmsg.body), + rand_mask, NN_SWS_FRAME_SIZE_MASK, &mask_pos); + + } + else if (sws->mode == NN_WS_SERVER) { + sws->outhdr [1] |= NN_SWS_FRAME_BITMASK_NOT_MASKED; + } + else { + /* Developer error; sws object was not constructed properly. */ + nn_assert (0); + } + + /* Start async sending. */ + iov [0].iov_base = sws->outhdr; + iov [0].iov_len = hdr_len; + iov [1].iov_base = nn_chunkref_data (&sws->outmsg.sphdr); + iov [1].iov_len = nn_chunkref_size (&sws->outmsg.sphdr); + iov [2].iov_base = nn_chunkref_data (&sws->outmsg.body); + iov [2].iov_len = nn_chunkref_size (&sws->outmsg.body); + nn_usock_send (sws->usock, iov, 3); + + sws->outstate = NN_SWS_OUTSTATE_SENDING; + + return 0; +} + +static int nn_sws_recv (struct nn_pipebase *self, struct nn_msg *msg) +{ + struct nn_sws *sws; + struct nn_list_item *it; + struct msg_chunk *ch; + struct nn_cmsghdr *cmsg; + uint8_t opcode_hdr; + uint8_t opcode; + size_t cmsgsz; + size_t pos; + + sws = nn_cont (self, struct nn_sws, pipebase); + + nn_assert_state (sws, NN_SWS_STATE_ACTIVE); + + switch (sws->instate) { + case NN_SWS_INSTATE_RECVD_CHUNKED: + + /* Relay opcode to the user in order to interpret payload. */ + opcode_hdr = sws->inmsg_hdr; + + /* This library should not deliver fragmented messages to the + application, so it's expected that this is the final frame. */ + nn_assert (sws->is_final_frame); + nn_assert (opcode_hdr & NN_SWS_FRAME_BITMASK_FIN); + opcode_hdr &= ~NN_SWS_FRAME_BITMASK_FIN; + + /* The library is expected to have failed any connections with other + opcodes; these are the only two opcodes that can be chunked. */ + opcode = opcode_hdr & NN_SWS_FRAME_BITMASK_OPCODE; + nn_assert (opcode == NN_WS_OPCODE_BINARY || + opcode == NN_WS_OPCODE_TEXT); + + nn_msg_init (msg, sws->inmsg_total_size); + + pos = 0; + + /* Reassemble incoming message scatter array. */ + while (!nn_list_empty (&sws->inmsg_array)) { + it = nn_list_begin (&sws->inmsg_array); + ch = nn_cont (it, struct msg_chunk, item); + memcpy (((uint8_t*) nn_chunkref_data (&msg->body)) + pos, + nn_chunkref_data (&ch->chunk), + nn_chunkref_size (&ch->chunk)); + pos += nn_chunkref_size (&ch->chunk); + nn_msg_chunk_term (ch, &sws->inmsg_array); + } + + nn_assert (pos == sws->inmsg_total_size); + nn_assert (nn_list_empty (&sws->inmsg_array)); + + /* No longer collecting scatter array of incoming msg chunks. */ + sws->continuing = 0; + + nn_sws_recv_hdr (sws); + + break; + + case NN_SWS_INSTATE_RECVD_CONTROL: + + /* Relay opcode to the user in order to interpret payload. */ + opcode_hdr = sws->inhdr [0]; + + /* This library should not deliver fragmented messages to the + application, so it's expected that this is the final frame. */ + nn_assert (sws->is_final_frame); + nn_assert (opcode_hdr & NN_SWS_FRAME_BITMASK_FIN); + opcode_hdr &= ~NN_SWS_FRAME_BITMASK_FIN; + + /* The library is expected to have failed any connections with other + opcodes; these are the only two control opcodes delivered. */ + opcode = opcode_hdr & NN_SWS_FRAME_BITMASK_OPCODE; + nn_assert (opcode == NN_WS_OPCODE_PING || + opcode == NN_WS_OPCODE_PONG); + + nn_msg_init (msg, sws->inmsg_current_chunk_len); + + memcpy (((uint8_t*) nn_chunkref_data (&msg->body)), + sws->inmsg_control, sws->inmsg_current_chunk_len); + + nn_sws_recv_hdr (sws); + + break; + + default: + /* Unexpected state. */ + nn_assert (0); + break; + } + + /* Allocate and populate WebSocket-specific control headers. */ + cmsgsz = NN_CMSG_SPACE (sizeof (opcode_hdr)); + nn_chunkref_init (&msg->hdrs, cmsgsz); + cmsg = nn_chunkref_data (&msg->hdrs); + cmsg->cmsg_level = NN_WS; + cmsg->cmsg_type = NN_WS_MSG_TYPE; + cmsg->cmsg_len = cmsgsz; + memcpy (NN_CMSG_DATA (cmsg), &opcode_hdr, sizeof (opcode_hdr)); + + return 0; +} + +static void nn_sws_validate_utf8_chunk (struct nn_sws *self) +{ + uint8_t *pos; + int code_point_len; + size_t len; + + len = self->inmsg_current_chunk_len; + pos = self->inmsg_current_chunk_buf; + + /* For chunked transfers, it's possible that a previous chunk was cut + intra-code point. That partially-validated code point is reassembled + with the beginning of the current chunk and checked. */ + if (self->utf8_code_pt_fragment_len) { + + nn_assert (self->utf8_code_pt_fragment_len < + NN_SWS_UTF8_MAX_CODEPOINT_LEN); + + /* Keep adding octets from fresh buffer to previous code point + fragment to check for validity. */ + while (len > 0) { + self->utf8_code_pt_fragment [self->utf8_code_pt_fragment_len] = *pos; + self->utf8_code_pt_fragment_len++; + pos++; + len--; + + code_point_len = nn_utf8_code_point (self->utf8_code_pt_fragment, + self->utf8_code_pt_fragment_len); + + if (code_point_len > 0) { + /* Valid code point found; continue validating. */ + break; + } + else if (code_point_len == NN_SWS_UTF8_INVALID) { + nn_sws_fail_conn (self, NN_SWS_CLOSE_ERR_INVALID_FRAME, + "Invalid UTF-8 code point split on previous frame."); + return; + } + else if (code_point_len == NN_SWS_UTF8_FRAGMENT) { + if (self->is_final_frame) { + nn_sws_fail_conn (self, NN_SWS_CLOSE_ERR_INVALID_FRAME, + "Truncated UTF-8 payload with invalid code point."); + return; + } + else { + /* This chunk is well-formed; now recv the next chunk. */ + nn_sws_recv_hdr (self); + return; + } + } + } + } + + if (self->utf8_code_pt_fragment_len >= NN_SWS_UTF8_MAX_CODEPOINT_LEN) + nn_assert (0); + + while (len > 0) { + code_point_len = nn_utf8_code_point (pos, len); + + if (code_point_len > 0) { + /* Valid code point found; continue validating. */ + nn_assert (len >= (size_t) code_point_len); + len -= code_point_len; + pos += code_point_len; + continue; + } + else if (code_point_len == NN_SWS_UTF8_INVALID) { + self->utf8_code_pt_fragment_len = 0; + memset (self->utf8_code_pt_fragment, 0, + NN_SWS_UTF8_MAX_CODEPOINT_LEN); + nn_sws_fail_conn (self, NN_SWS_CLOSE_ERR_INVALID_FRAME, + "Invalid UTF-8 code point in payload."); + return; + } + else if (code_point_len == NN_SWS_UTF8_FRAGMENT) { + nn_assert (len < NN_SWS_UTF8_MAX_CODEPOINT_LEN); + self->utf8_code_pt_fragment_len = len; + memcpy (self->utf8_code_pt_fragment, pos, len); + if (self->is_final_frame) { + nn_sws_fail_conn (self, NN_SWS_CLOSE_ERR_INVALID_FRAME, + "Truncated UTF-8 payload with invalid code point."); + } + else { + /* Previous frame ended in the middle of a code point; + receive more. */ + nn_sws_recv_hdr (self); + } + return; + } + } + + /* Entire buffer is well-formed. */ + nn_assert (len == 0); + + self->utf8_code_pt_fragment_len = 0; + memset (self->utf8_code_pt_fragment, 0, NN_SWS_UTF8_MAX_CODEPOINT_LEN); + + if (self->is_final_frame) { + self->instate = NN_SWS_INSTATE_RECVD_CHUNKED; + nn_pipebase_received (&self->pipebase); + } + else { + nn_sws_recv_hdr (self); + } + + return; +} + +static void nn_sws_acknowledge_close_handshake (struct nn_sws *self) +{ + uint8_t *pos; + uint16_t close_code; + int code_point_len; + size_t len; + + len = self->inmsg_current_chunk_len; + pos = self->inmsg_current_chunk_buf; + + /* Peer did not provide a Close Code, so choose our own here. */ + if (len == 0) { + nn_sws_fail_conn (self, NN_SWS_CLOSE_NORMAL, ""); + return; + } + + /* If the payload is not even long enough for the required 2-octet + Close Code, the connection should have already been failed. */ + nn_assert (len >= NN_SWS_CLOSE_CODE_LEN); + len -= NN_SWS_CLOSE_CODE_LEN; + pos += NN_SWS_CLOSE_CODE_LEN; + + /* As per RFC 6455 7.1.6, the Close Reason following the Close Code + must be well-formed UTF-8. */ + while (len > 0) { + code_point_len = nn_utf8_code_point (pos, len); + + if (code_point_len > 0) { + /* Valid code point found; continue validating. */ + nn_assert (len >= (size_t) code_point_len); + len -= code_point_len; + pos += code_point_len; + continue; + } + else { + /* RFC 6455 7.1.6 */ + nn_sws_fail_conn (self, NN_SWS_CLOSE_ERR_PROTO, + "Invalid UTF-8 sent as Close Reason."); + return; + } + } + + /* Entire Close Reason is well-formed UTF-8 (or empty) */ + nn_assert (len == 0); + + close_code = nn_gets (self->inmsg_current_chunk_buf); + + if (close_code == NN_SWS_CLOSE_NORMAL || + close_code == NN_SWS_CLOSE_GOING_AWAY || + close_code == NN_SWS_CLOSE_ERR_PROTO || + close_code == NN_SWS_CLOSE_ERR_WUT || + close_code == NN_SWS_CLOSE_ERR_INVALID_FRAME || + close_code == NN_SWS_CLOSE_ERR_POLICY || + close_code == NN_SWS_CLOSE_ERR_TOOBIG || + close_code == NN_SWS_CLOSE_ERR_EXTENSION || + close_code == NN_SWS_CLOSE_ERR_SERVER || + (close_code >= 3000 && close_code <= 3999) || + (close_code >= 4000 && close_code <= 4999)) { + /* Repeat close code, per RFC 6455 7.4.1 and 7.4.2 */ + nn_sws_fail_conn (self, (int) close_code, ""); + } + else { + nn_sws_fail_conn (self, NN_SWS_CLOSE_ERR_PROTO, + "Unrecognized close code."); + } + + return; +} + +static void nn_sws_fail_conn (struct nn_sws *self, int code, char *reason) +{ + size_t reason_len; + size_t payload_len; + uint8_t rand_mask [NN_SWS_FRAME_SIZE_MASK]; + uint8_t *payload_pos; + struct nn_iovec iov; + + nn_assert_state (self, NN_SWS_STATE_ACTIVE); + + /* Stop user send/recv actions. */ + self->instate = NN_SWS_INSTATE_CLOSED; + nn_pipebase_stop (&self->pipebase); + + /* Destroy any remnant incoming message fragments. */ + nn_msg_array_term (&self->inmsg_array); + + reason_len = strlen (reason); + + payload_len = reason_len + NN_SWS_CLOSE_CODE_LEN; + + /* Ensure text is short enough to also include code and framing. */ + nn_assert (payload_len <= NN_SWS_PAYLOAD_MAX_LENGTH); + + /* RFC 6455 section 5.5.1. */ + self->fail_msg [0] = NN_SWS_FRAME_BITMASK_FIN | NN_WS_OPCODE_CLOSE; + + /* Size of the payload, which is the status code plus the reason. */ + self->fail_msg [1] = (char)payload_len; + + self->fail_msg_len = NN_SWS_FRAME_SIZE_INITIAL; + + switch (self->mode) { + case NN_WS_SERVER: + self->fail_msg [1] |= NN_SWS_FRAME_BITMASK_NOT_MASKED; + break; + case NN_WS_CLIENT: + self->fail_msg [1] |= NN_SWS_FRAME_BITMASK_MASKED; + + /* Generate 32-bit mask as per RFC 6455 5.3. */ + nn_random_generate (rand_mask, NN_SWS_FRAME_SIZE_MASK); + + memcpy (&self->fail_msg [NN_SWS_FRAME_SIZE_INITIAL], + rand_mask, NN_SWS_FRAME_SIZE_MASK); + + self->fail_msg_len += NN_SWS_FRAME_SIZE_MASK; + break; + default: + /* Developer error. */ + nn_assert (0); + } + + payload_pos = (uint8_t*) (&self->fail_msg [self->fail_msg_len]); + + /* Copy Status Code in network order (big-endian). */ + nn_puts (payload_pos, (uint16_t) code); + self->fail_msg_len += NN_SWS_CLOSE_CODE_LEN; + + /* Copy Close Reason immediately following the code. */ + memcpy (payload_pos + NN_SWS_CLOSE_CODE_LEN, reason, reason_len); + + /* If this is a client, apply mask. */ + if (self->mode == NN_WS_CLIENT) { + nn_sws_mask_payload (payload_pos, payload_len, + rand_mask, NN_SWS_FRAME_SIZE_MASK, NULL); + } + + self->fail_msg_len += payload_len; + + if (self->outstate == NN_SWS_OUTSTATE_IDLE) { + iov.iov_base = self->fail_msg; + iov.iov_len = self->fail_msg_len; + nn_usock_send (self->usock, &iov, 1); + self->outstate = NN_SWS_OUTSTATE_SENDING; + self->state = NN_SWS_STATE_CLOSING_CONNECTION; + } else { + self->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&self->fsm, &self->done, NN_SWS_RETURN_CLOSE_HANDSHAKE); + } + + return; +} + +static void nn_sws_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_sws *sws; + + sws = nn_cont (self, struct nn_sws, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + /* TODO: Consider sending a close code here? */ + nn_pipebase_stop (&sws->pipebase); + nn_ws_handshake_stop (&sws->handshaker); + sws->state = NN_SWS_STATE_STOPPING; + } + if (nn_slow (sws->state == NN_SWS_STATE_STOPPING)) { + if (nn_ws_handshake_isidle (&sws->handshaker)) { + nn_usock_swap_owner (sws->usock, &sws->usock_owner); + sws->usock = NULL; + sws->usock_owner.src = -1; + sws->usock_owner.fsm = NULL; + sws->state = NN_SWS_STATE_IDLE; + nn_fsm_stopped (&sws->fsm, NN_SWS_RETURN_STOPPED); + return; + } + return; + } + + nn_fsm_bad_state (sws->state, src, type); +} + +static void nn_sws_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_sws *sws; + int rc; + int opt; + size_t opt_sz = sizeof (opt); + + sws = nn_cont (self, struct nn_sws, fsm); + + switch (sws->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_SWS_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_ws_handshake_start (&sws->handshaker, sws->usock, + &sws->pipebase, sws->mode, sws->resource, sws->remote_host); + sws->state = NN_SWS_STATE_HANDSHAKE; + return; + default: + nn_fsm_bad_action (sws->state, src, type); + } + + default: + nn_fsm_bad_source (sws->state, src, type); + } + +/******************************************************************************/ +/* HANDSHAKE state. */ +/******************************************************************************/ + case NN_SWS_STATE_HANDSHAKE: + switch (src) { + + case NN_SWS_SRC_HANDSHAKE: + switch (type) { + case NN_WS_HANDSHAKE_OK: + + /* Before moving to the active state stop the handshake + state machine. */ + nn_ws_handshake_stop (&sws->handshaker); + sws->state = NN_SWS_STATE_STOPPING_HANDSHAKE; + return; + + case NN_WS_HANDSHAKE_ERROR: + + /* Raise the error and move directly to the DONE state. + ws_handshake object will be stopped later on. */ + sws->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&sws->fsm, &sws->done, + NN_SWS_RETURN_CLOSE_HANDSHAKE); + return; + + default: + nn_fsm_bad_action (sws->state, src, type); + } + + default: + nn_fsm_bad_source (sws->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_HANDSHAKE state. */ +/******************************************************************************/ + case NN_SWS_STATE_STOPPING_HANDSHAKE: + switch (src) { + + case NN_SWS_SRC_HANDSHAKE: + switch (type) { + case NN_WS_HANDSHAKE_STOPPED: + + /* Start the pipe. */ + rc = nn_pipebase_start (&sws->pipebase); + if (nn_slow (rc < 0)) { + sws->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&sws->fsm, &sws->done, NN_SWS_RETURN_ERROR); + return; + } + + /* Start receiving a message in asynchronous manner. */ + nn_sws_recv_hdr (sws); + + /* Mark the pipe as available for sending. */ + sws->outstate = NN_SWS_OUTSTATE_IDLE; + + sws->state = NN_SWS_STATE_ACTIVE; + return; + + default: + nn_fsm_bad_action (sws->state, src, type); + } + + default: + nn_fsm_bad_source (sws->state, src, type); + } + +/******************************************************************************/ +/* ACTIVE state. */ +/******************************************************************************/ + case NN_SWS_STATE_ACTIVE: + switch (src) { + + case NN_SWS_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + + /* The message is now fully sent. */ + nn_assert (sws->outstate == NN_SWS_OUTSTATE_SENDING); + sws->outstate = NN_SWS_OUTSTATE_IDLE; + nn_msg_term (&sws->outmsg); + nn_msg_init (&sws->outmsg, 0); + nn_pipebase_sent (&sws->pipebase); + return; + + case NN_USOCK_RECEIVED: + + switch (sws->instate) { + case NN_SWS_INSTATE_RECV_HDR: + + /* Require RSV1, RSV2, and RSV3 bits to be unset for + x-nanomsg protocol as per RFC 6455 section 5.2. */ + if (sws->inhdr [0] & NN_SWS_FRAME_BITMASK_RSV1 || + sws->inhdr [0] & NN_SWS_FRAME_BITMASK_RSV2 || + sws->inhdr [0] & NN_SWS_FRAME_BITMASK_RSV3) { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "RSV1, RSV2, and RSV3 must be unset."); + return; + } + + sws->is_final_frame = sws->inhdr [0] & + NN_SWS_FRAME_BITMASK_FIN; + sws->masked = sws->inhdr [1] & + NN_SWS_FRAME_BITMASK_MASKED; + + switch (sws->mode) { + case NN_WS_SERVER: + /* Require mask bit to be set from client. */ + if (sws->masked) { + /* Continue receiving header for this frame. */ + sws->ext_hdr_len = NN_SWS_FRAME_SIZE_MASK; + break; + } + else { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Server expects MASK bit to be set."); + return; + } + case NN_WS_CLIENT: + /* Require mask bit to be unset from server. */ + if (sws->masked) { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Client expects MASK bit to be unset."); + return; + } + else { + /* Continue receiving header for this frame. */ + sws->ext_hdr_len = 0; + break; + } + default: + /* Only two modes of this endpoint are expected. */ + nn_assert (0); + return; + } + + sws->opcode = sws->inhdr [0] & + NN_SWS_FRAME_BITMASK_OPCODE; + sws->payload_ctl = sws->inhdr [1] & + NN_SWS_FRAME_BITMASK_LENGTH; + + /* Prevent unexpected continuation frame. */ + if (!sws->continuing && + sws->opcode == NN_WS_OPCODE_FRAGMENT) { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "No message to continue."); + return; + } + + /* Preserve initial message opcode and RSV bits in case + this is a fragmented message. */ + if (!sws->continuing) + sws->inmsg_hdr = sws->inhdr [0] | + NN_SWS_FRAME_BITMASK_FIN; + + if (sws->payload_ctl <= NN_SWS_PAYLOAD_MAX_LENGTH) { + sws->ext_hdr_len += NN_SWS_FRAME_SIZE_PAYLOAD_0; + } + else if (sws->payload_ctl == NN_SWS_PAYLOAD_FRAME_16) { + sws->ext_hdr_len += NN_SWS_FRAME_SIZE_PAYLOAD_16; + } + else if (sws->payload_ctl == NN_SWS_PAYLOAD_FRAME_63) { + sws->ext_hdr_len += NN_SWS_FRAME_SIZE_PAYLOAD_63; + } + else { + /* Developer error parsing/handling length. */ + nn_assert (0); + return; + } + + switch (sws->opcode) { + + case NN_WS_OPCODE_TEXT: + /* Fall thru; TEXT and BINARY handled alike. */ + case NN_WS_OPCODE_BINARY: + + sws->is_control_frame = 0; + + if (sws->continuing) { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Expected continuation frame opcode."); + return; + } + + if (!sws->is_final_frame) + sws->continuing = 1; + + if (sws->ext_hdr_len == 0 && sws->payload_ctl == 0) { + /* Only a remote server could send a 2-byte msg; + sanity-check that this endpoint is a client. */ + nn_assert (sws->mode == NN_WS_CLIENT); + + sws->inmsg_current_chunk_len = 0; + + if (sws->continuing) { + /* This frame was empty, but continue + next frame in fragmented sequence. */ + nn_sws_recv_hdr (sws); + return; + } + else { + /* Special case when there is no payload, + mask, or additional frames. */ + sws->instate = NN_SWS_INSTATE_RECVD_CHUNKED; + nn_pipebase_received (&sws->pipebase); + return; + } + } + /* Continue to receive extended header+payload. */ + break; + + case NN_WS_OPCODE_FRAGMENT: + + sws->is_control_frame = 0; + sws->continuing = !sws->is_final_frame; + + if (sws->ext_hdr_len == 0 && sws->payload_ctl == 0) { + /* Only a remote server could send a 2-byte msg; + sanity-check that this endpoint is a client. */ + nn_assert (sws->mode == NN_WS_CLIENT); + + sws->inmsg_current_chunk_len = 0; + + if (sws->continuing) { + /* This frame was empty, but continue + next frame in fragmented sequence. */ + nn_sws_recv_hdr (sws); + return; + } + else { + /* Special case when there is no payload, + mask, or additional frames. */ + sws->instate = NN_SWS_INSTATE_RECVD_CHUNKED; + nn_pipebase_received (&sws->pipebase); + return; + } + } + /* Continue to receive extended header+payload. */ + break; + + case NN_WS_OPCODE_PING: + sws->is_control_frame = 1; + sws->pings_received++; + if (sws->payload_ctl > NN_SWS_PAYLOAD_MAX_LENGTH) { + /* As per RFC 6455 section 5.4, large payloads on + control frames is not allowed, and on receipt the + endpoint MUST close connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Control frame payload exceeds allowable length."); + return; + } + if (!sws->is_final_frame) { + /* As per RFC 6455 section 5.4, fragmentation of + control frames is not allowed; on receipt the + endpoint MUST close connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Cannot fragment control message (FIN=0)."); + return; + } + + if (sws->ext_hdr_len == 0 && sws->payload_ctl == 0) { + /* Special case when there is no payload, + mask, or additional frames. */ + sws->inmsg_current_chunk_len = 0; + sws->instate = NN_SWS_INSTATE_RECVD_CONTROL; + nn_pipebase_received (&sws->pipebase); + return; + } + /* Continue to receive extended header+payload. */ + break; + + case NN_WS_OPCODE_PONG: + sws->is_control_frame = 1; + sws->pongs_received++; + if (sws->payload_ctl > NN_SWS_PAYLOAD_MAX_LENGTH) { + /* As per RFC 6455 section 5.4, large payloads on + control frames is not allowed, and on receipt the + endpoint MUST close connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Control frame payload exceeds allowable length."); + return; + } + if (!sws->is_final_frame) { + /* As per RFC 6455 section 5.4, fragmentation of + control frames is not allowed; on receipt the + endpoint MUST close connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Cannot fragment control message (FIN=0)."); + return; + } + + if (sws->ext_hdr_len == 0 && sws->payload_ctl == 0) { + /* Special case when there is no payload, + mask, or additional frames. */ + sws->inmsg_current_chunk_len = 0; + sws->instate = NN_SWS_INSTATE_RECVD_CONTROL; + nn_pipebase_received (&sws->pipebase); + return; + } + /* Continue to receive extended header+payload. */ + break; + + case NN_WS_OPCODE_CLOSE: + /* RFC 6455 section 5.5.1. */ + sws->is_control_frame = 1; + if (!sws->is_final_frame) { + /* As per RFC 6455 section 5.4, fragmentation of + control frames is not allowed; on receipt the + endpoint MUST close connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Cannot fragment control message (FIN=0)."); + return; + } + + if (sws->payload_ctl > NN_SWS_PAYLOAD_MAX_LENGTH) { + /* As per RFC 6455 section 5.4, large payloads on + control frames is not allowed, and on receipt the + endpoint MUST close connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Control frame payload exceeds allowable length."); + return; + } + + if (sws->payload_ctl == 1) { + /* As per RFC 6455 section 5.5.1, if a payload is + to accompany a close frame, the first two bytes + MUST be the close code. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Expected 2byte close code."); + return; + } + + if (sws->ext_hdr_len == 0 && sws->payload_ctl == 0) { + /* Special case when there is no payload, + mask, or additional frames. */ + sws->inmsg_current_chunk_len = 0; + nn_sws_acknowledge_close_handshake (sws); + return; + } + /* Continue to receive extended header+payload. */ + break; + + default: + /* Client sent an invalid opcode; as per RFC 6455 + section 10.7, close connection with code. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Invalid opcode."); + return; + + } + + if (sws->ext_hdr_len == 0) { + /* Only a remote server could send a 2-byte msg; + sanity-check that this endpoint is a client. */ + nn_assert (sws->mode == NN_WS_CLIENT); + + /* In the case of no additional header, the payload + is known to be within these bounds. */ + nn_assert (0 < sws->payload_ctl && + sws->payload_ctl <= NN_SWS_PAYLOAD_MAX_LENGTH); + + sws->inmsg_current_chunk_len = sws->payload_ctl; + + /* Use scatter/gather array for application messages, + and a fixed-width buffer for control messages. This + is convenient since control messages can be + interspersed between chunked application msgs. */ + if (sws->is_control_frame) { + sws->inmsg_current_chunk_buf = sws->inmsg_control; + } + else { + sws->inmsg_total_size += sws->inmsg_current_chunk_len; + /* Protect non-control messages against the + NN_RCVMAXSIZE threshold; control messages already + have a small pre-allocated buffer, and therefore + are not subject to this limit. */ + nn_pipebase_getopt (&sws->pipebase, NN_SOL_SOCKET, + NN_RCVMAXSIZE, &opt, &opt_sz); + if (opt >= 0 && sws->inmsg_total_size > (size_t) opt) { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_TOOBIG, + "Message larger than application allows."); + return; + } + sws->inmsg_chunks++; + sws->inmsg_current_chunk_buf = + nn_msg_chunk_new (sws->inmsg_current_chunk_len, + &sws->inmsg_array); + } + + sws->instate = NN_SWS_INSTATE_RECV_PAYLOAD; + nn_usock_recv (sws->usock, sws->inmsg_current_chunk_buf, + sws->inmsg_current_chunk_len, NULL); + return; + } + else { + /* Continue receiving the rest of the header frame. */ + sws->instate = NN_SWS_INSTATE_RECV_HDREXT; + nn_usock_recv (sws->usock, + sws->inhdr + NN_SWS_FRAME_SIZE_INITIAL, + sws->ext_hdr_len, + NULL); + return; + } + + case NN_SWS_INSTATE_RECV_HDREXT: + nn_assert (sws->ext_hdr_len > 0); + + if (sws->payload_ctl <= NN_SWS_PAYLOAD_MAX_LENGTH) { + sws->inmsg_current_chunk_len = sws->payload_ctl; + if (sws->masked) { + sws->mask = sws->inhdr + NN_SWS_FRAME_SIZE_INITIAL; + } + else { + sws->mask = NULL; + } + } + else if (sws->payload_ctl == NN_SWS_PAYLOAD_FRAME_16) { + sws->inmsg_current_chunk_len = + nn_gets (sws->inhdr + NN_SWS_FRAME_SIZE_INITIAL); + if (sws->masked) { + sws->mask = sws->inhdr + + NN_SWS_FRAME_SIZE_INITIAL + + NN_SWS_FRAME_SIZE_PAYLOAD_16; + } + else { + sws->mask = NULL; + } + } + else if (sws->payload_ctl == NN_SWS_PAYLOAD_FRAME_63) { + sws->inmsg_current_chunk_len = + (size_t) nn_getll (sws->inhdr + + NN_SWS_FRAME_SIZE_INITIAL); + if (sws->masked) { + sws->mask = sws->inhdr + + NN_SWS_FRAME_SIZE_INITIAL + + NN_SWS_FRAME_SIZE_PAYLOAD_63; + } + else { + sws->mask = NULL; + } + } + else { + /* Client sent invalid data; as per RFC 6455, + server closes the connection immediately. */ + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_PROTO, + "Invalid payload length."); + return; + } + + /* Handle zero-length message bodies. */ + if (sws->inmsg_current_chunk_len == 0) { + if (sws->is_final_frame) { + if (sws->opcode == NN_WS_OPCODE_CLOSE) { + nn_sws_acknowledge_close_handshake (sws); + } + else { + sws->instate = (sws->is_control_frame ? + NN_SWS_INSTATE_RECVD_CONTROL : + NN_SWS_INSTATE_RECVD_CHUNKED); + nn_pipebase_received (&sws->pipebase); + } + } + else { + nn_sws_recv_hdr (sws); + } + return; + } + + nn_assert (sws->inmsg_current_chunk_len > 0); + + /* Use scatter/gather array for application messages, + and a fixed-width buffer for control messages. This + is convenient since control messages can be + interspersed between chunked application msgs. */ + if (sws->is_control_frame) { + sws->inmsg_current_chunk_buf = sws->inmsg_control; + } + else { + sws->inmsg_total_size += sws->inmsg_current_chunk_len; + /* Protect non-control messages against the + NN_RCVMAXSIZE threshold; control messages already + have a small pre-allocated buffer, and therefore + are not subject to this limit. */ + nn_pipebase_getopt (&sws->pipebase, NN_SOL_SOCKET, + NN_RCVMAXSIZE, &opt, &opt_sz); + if (opt >= 0 && sws->inmsg_total_size > (size_t) opt) { + nn_sws_fail_conn (sws, NN_SWS_CLOSE_ERR_TOOBIG, + "Message size exceeds limit."); + return; + } + sws->inmsg_chunks++; + sws->inmsg_current_chunk_buf = + nn_msg_chunk_new (sws->inmsg_current_chunk_len, + &sws->inmsg_array); + } + + sws->instate = NN_SWS_INSTATE_RECV_PAYLOAD; + nn_usock_recv (sws->usock, sws->inmsg_current_chunk_buf, + sws->inmsg_current_chunk_len, NULL); + return; + + case NN_SWS_INSTATE_RECV_PAYLOAD: + + /* Unmask if necessary. */ + if (sws->masked) { + nn_sws_mask_payload (sws->inmsg_current_chunk_buf, + sws->inmsg_current_chunk_len, sws->mask, + NN_SWS_FRAME_SIZE_MASK, NULL); + } + + switch (sws->opcode) { + + case NN_WS_OPCODE_TEXT: + nn_sws_validate_utf8_chunk (sws); + return; + + case NN_WS_OPCODE_BINARY: + if (sws->is_final_frame) { + sws->instate = NN_SWS_INSTATE_RECVD_CHUNKED; + nn_pipebase_received (&sws->pipebase); + } + else { + nn_sws_recv_hdr (sws); + } + return; + + case NN_WS_OPCODE_FRAGMENT: + /* Must check original opcode to see if this fragment + needs UTF-8 validation. */ + if ((sws->inmsg_hdr & NN_SWS_FRAME_BITMASK_OPCODE) == + NN_WS_OPCODE_TEXT) { + nn_sws_validate_utf8_chunk (sws); + } + else if (sws->is_final_frame) { + sws->instate = NN_SWS_INSTATE_RECVD_CHUNKED; + nn_pipebase_received (&sws->pipebase); + } + else { + nn_sws_recv_hdr (sws); + } + return; + + case NN_WS_OPCODE_PING: + sws->instate = NN_SWS_INSTATE_RECVD_CONTROL; + nn_pipebase_received (&sws->pipebase); + return; + + case NN_WS_OPCODE_PONG: + sws->instate = NN_SWS_INSTATE_RECVD_CONTROL; + nn_pipebase_received (&sws->pipebase); + return; + + case NN_WS_OPCODE_CLOSE: + nn_sws_acknowledge_close_handshake (sws); + return; + + default: + /* This should have been prevented upstream. */ + nn_assert (0); + return; + } + + default: + nn_fsm_error ("Unexpected socket instate", + sws->state, src, type); + } + + case NN_USOCK_SHUTDOWN: + nn_pipebase_stop (&sws->pipebase); + sws->state = NN_SWS_STATE_BROKEN_CONNECTION; + return; + + case NN_USOCK_ERROR: + nn_pipebase_stop (&sws->pipebase); + sws->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&sws->fsm, &sws->done, NN_SWS_RETURN_ERROR); + return; + + default: + nn_fsm_bad_action (sws->state, src, type); + } + + break; + + default: + nn_fsm_bad_source (sws->state, src, type); + } + +/******************************************************************************/ +/* CLOSING_CONNECTION state. */ +/* Wait for acknowledgement closing handshake was successfully sent. */ +/******************************************************************************/ + case NN_SWS_STATE_CLOSING_CONNECTION: + switch (src) { + + case NN_SWS_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + /* Wait for acknowledgement closing handshake was sent + to peer. */ + nn_assert (sws->outstate == NN_SWS_OUTSTATE_SENDING); + sws->outstate = NN_SWS_OUTSTATE_IDLE; + sws->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&sws->fsm, &sws->done, + NN_SWS_RETURN_CLOSE_HANDSHAKE); + return; + case NN_USOCK_SHUTDOWN: + return; + case NN_USOCK_ERROR: + sws->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&sws->fsm, &sws->done, NN_SWS_RETURN_ERROR); + return; + default: + nn_fsm_bad_action (sws->state, src, type); + } + + default: + nn_fsm_bad_source (sws->state, src, type); + } + +/******************************************************************************/ +/* SHUTTING_DOWN state. */ +/* The underlying connection is closed. We are just waiting that underlying */ +/* usock being closed */ +/******************************************************************************/ + case NN_SWS_STATE_BROKEN_CONNECTION: + switch (src) { + + case NN_SWS_SRC_USOCK: + switch (type) { + case NN_USOCK_ERROR: + sws->state = NN_SWS_STATE_DONE; + nn_fsm_raise (&sws->fsm, &sws->done, NN_SWS_RETURN_ERROR); + return; + default: + nn_fsm_bad_action (sws->state, src, type); + } + + default: + nn_fsm_bad_source (sws->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/* The underlying connection is closed. There's nothing that can be done in */ +/* this state except stopping the object. */ +/******************************************************************************/ + case NN_SWS_STATE_DONE: + nn_fsm_bad_source (sws->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (sws->state, src, type); + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sws.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sws.h new file mode 100644 index 0000000..9ab02e6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/sws.h @@ -0,0 +1,205 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SWS_INCLUDED +#define NN_SWS_INCLUDED + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" + +#include "ws_handshake.h" + +#include "../../utils/msg.h" +#include "../../utils/list.h" + +/* This state machine handles WebSocket connection from the point where it is + established to the point when it is broken. */ + +/* Return codes of this state machine. */ +#define NN_SWS_RETURN_ERROR 1 +#define NN_SWS_RETURN_CLOSE_HANDSHAKE 2 +#define NN_SWS_RETURN_STOPPED 3 + +/* WebSocket protocol header frame sizes. */ +#define NN_SWS_FRAME_SIZE_INITIAL 2 +#define NN_SWS_FRAME_SIZE_PAYLOAD_0 0 +#define NN_SWS_FRAME_SIZE_PAYLOAD_16 2 +#define NN_SWS_FRAME_SIZE_PAYLOAD_63 8 +#define NN_SWS_FRAME_SIZE_MASK 4 + +/* WebSocket control bitmasks as per RFC 6455 5.2. */ +#define NN_SWS_FRAME_BITMASK_FIN 0x80 +#define NN_SWS_FRAME_BITMASK_RSV1 0x40 +#define NN_SWS_FRAME_BITMASK_RSV2 0x20 +#define NN_SWS_FRAME_BITMASK_RSV3 0x10 +#define NN_SWS_FRAME_BITMASK_OPCODE 0x0F + +/* UTF-8 validation. */ +#define NN_SWS_UTF8_MAX_CODEPOINT_LEN 4 + +/* The longest possible header frame length. As per RFC 6455 5.2: + first 2 bytes of initial framing + up to 8 bytes of additional + extended payload length header + 4 byte mask = 14bytes + Not all messages will use the maximum amount allocated, but + statically allocating this buffer for convenience. */ +#define NN_SWS_FRAME_MAX_HDR_LEN 14 + +/* WebSocket protocol payload length framing RFC 6455 section 5.2. */ +#define NN_SWS_PAYLOAD_MAX_LENGTH 125 +#define NN_SWS_PAYLOAD_MAX_LENGTH_16 65535 +#define NN_SWS_PAYLOAD_MAX_LENGTH_63 9223372036854775807 +#define NN_SWS_PAYLOAD_FRAME_16 0x7E +#define NN_SWS_PAYLOAD_FRAME_63 0x7F + +/* WebSocket Close Status Code length. */ +#define NN_SWS_CLOSE_CODE_LEN 2 + +struct nn_sws { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Endpoint base. */ + struct nn_epbase *epbase; + + /* Default message type set on outbound frames. */ + uint8_t msg_type; + + /* Controls Tx/Rx framing based on whether this peer is acting as + a Client or a Server. */ + int mode; + + /* The underlying socket. */ + struct nn_usock *usock; + + /* Child state machine to do protocol header exchange. */ + struct nn_ws_handshake handshaker; + + /* The original owner of the underlying socket. */ + struct nn_fsm_owner usock_owner; + + /* Pipe connecting this WebSocket connection to the nanomsg core. */ + struct nn_pipebase pipebase; + + /* Requested resource when acting as client. */ + const char* resource; + + /* Remote Host in header request when acting as client. */ + const char* remote_host; + + /* State of inbound state machine. */ + int instate; + + /* Buffer used to store the framing of incoming message. */ + uint8_t inhdr [NN_SWS_FRAME_MAX_HDR_LEN]; + + /* Parsed header frames. */ + uint8_t opcode; + uint8_t payload_ctl; + uint8_t masked; + uint8_t *mask; + size_t ext_hdr_len; + int is_final_frame; + int is_control_frame; + + /* As valid fragments are being received, this flag stays true until + the FIN bit is received. This state is also used to determine + peer sequencing anamolies that trigger this endpoint to fail the + connection. */ + int continuing; + + /* When validating continuation frames of UTF-8, it may be necessary + to buffer tail-end of the previous frame in order to continue + validation in the case that frames are chopped on intra-code point + boundaries. */ + uint8_t utf8_code_pt_fragment [NN_SWS_UTF8_MAX_CODEPOINT_LEN]; + size_t utf8_code_pt_fragment_len; + + /* Statistics on control frames. */ + int pings_sent; + int pongs_sent; + int pings_received; + int pongs_received; + + /* Fragments of message being received at the moment. */ + struct nn_list inmsg_array; + uint8_t *inmsg_current_chunk_buf; + size_t inmsg_current_chunk_len; + size_t inmsg_total_size; + int inmsg_chunks; + uint8_t inmsg_hdr; + + /* Control message being received at the moment. Because these can be + interspersed between fragmented TEXT and BINARY messages, they are + stored in this buffer so as not to interrupt the message array. */ + uint8_t inmsg_control [NN_SWS_PAYLOAD_MAX_LENGTH]; + + /* Reason this connection is closing to send as closing handshake. */ + char fail_msg [NN_SWS_PAYLOAD_MAX_LENGTH]; + size_t fail_msg_len; + + /* State of the outbound state machine. */ + int outstate; + + /* Buffer used to store the header of outgoing message. */ + uint8_t outhdr [NN_SWS_FRAME_MAX_HDR_LEN]; + + /* Message being sent at the moment. */ + struct nn_msg outmsg; + + /* Event raised when the state machine ends. */ + struct nn_fsm_event done; +}; + +/* Scatter/gather array element type forincoming message chunks. Fragmented + message frames are reassembled prior to notifying the user. */ +struct msg_chunk { + struct nn_list_item item; + struct nn_chunkref chunk; +}; + +/* Allocate a new message chunk, append it to message array, and return + pointer to its buffer. */ +void *nn_msg_chunk_new (size_t size, struct nn_list *msg_array); + +/* Deallocate a message chunk and remove it from array. */ +void nn_msg_chunk_term (struct msg_chunk *it, struct nn_list *msg_array); + +/* Deallocate an entire message array. */ +void nn_msg_array_term (struct nn_list *msg_array); + +void nn_sws_init (struct nn_sws *self, int src, + struct nn_epbase *epbase, struct nn_fsm *owner); +void nn_sws_term (struct nn_sws *self); + +int nn_sws_isidle (struct nn_sws *self); +void nn_sws_start (struct nn_sws *self, struct nn_usock *usock, int mode, + const char *resource, const char *host, uint8_t msg_type); +void nn_sws_stop (struct nn_sws *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws.c new file mode 100644 index 0000000..af5bf8b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws.c @@ -0,0 +1,160 @@ +/* + Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ws.h" +#include "bws.h" +#include "cws.h" +#include "sws.h" + +#include "../../ws.h" + +#include "../utils/port.h" +#include "../utils/iface.h" + +#include "../../utils/err.h" +#include "../../utils/alloc.h" +#include "../../utils/fast.h" +#include "../../utils/list.h" +#include "../../utils/cont.h" + +#include + +#if defined NN_HAVE_WINDOWS +#include "../../utils/win.h" +#else +#include +#endif + +/* WebSocket-specific socket options. */ +struct nn_ws_optset { + struct nn_optset base; + int msg_type; +}; + +static void nn_ws_optset_destroy (struct nn_optset *self); +static int nn_ws_optset_setopt (struct nn_optset *self, int option, + const void *optval, size_t optvallen); +static int nn_ws_optset_getopt (struct nn_optset *self, int option, + void *optval, size_t *optvallen); +static const struct nn_optset_vfptr nn_ws_optset_vfptr = { + nn_ws_optset_destroy, + nn_ws_optset_setopt, + nn_ws_optset_getopt +}; + +/* nn_transport interface. */ +static int nn_ws_bind (void *hint, struct nn_epbase **epbase); +static int nn_ws_connect (void *hint, struct nn_epbase **epbase); +static struct nn_optset *nn_ws_optset (void); + +static struct nn_transport nn_ws_vfptr = { + "ws", + NN_WS, + NULL, + NULL, + nn_ws_bind, + nn_ws_connect, + nn_ws_optset, + NN_LIST_ITEM_INITIALIZER +}; + +struct nn_transport *nn_ws = &nn_ws_vfptr; + +static int nn_ws_bind (void *hint, struct nn_epbase **epbase) +{ + return nn_bws_create (hint, epbase); +} + +static int nn_ws_connect (void *hint, struct nn_epbase **epbase) +{ + return nn_cws_create (hint, epbase); +} + +static struct nn_optset *nn_ws_optset () +{ + struct nn_ws_optset *optset; + + optset = nn_alloc (sizeof (struct nn_ws_optset), "optset (ws)"); + alloc_assert (optset); + optset->base.vfptr = &nn_ws_optset_vfptr; + + /* Default values for WebSocket options. */ + optset->msg_type = NN_WS_MSG_TYPE_BINARY; + + return &optset->base; +} + +static void nn_ws_optset_destroy (struct nn_optset *self) +{ + struct nn_ws_optset *optset; + + optset = nn_cont (self, struct nn_ws_optset, base); + nn_free (optset); +} + +static int nn_ws_optset_setopt (struct nn_optset *self, int option, + const void *optval, size_t optvallen) +{ + struct nn_ws_optset *optset; + int val; + + optset = nn_cont (self, struct nn_ws_optset, base); + if (optvallen != sizeof (int)) { + return -EINVAL; + } + val = *(int *)optval; + + switch (option) { + case NN_WS_MSG_TYPE: + switch (val) { + case NN_WS_MSG_TYPE_TEXT: + case NN_WS_MSG_TYPE_BINARY: + optset->msg_type = val; + return 0; + default: + return -EINVAL; + } + default: + return -ENOPROTOOPT; + } +} + +static int nn_ws_optset_getopt (struct nn_optset *self, int option, + void *optval, size_t *optvallen) +{ + struct nn_ws_optset *optset; + + optset = nn_cont (self, struct nn_ws_optset, base); + + switch (option) { + case NN_WS_MSG_TYPE: + memcpy (optval, &optset->msg_type, + *optvallen < sizeof (int) ? *optvallen : sizeof (int)); + *optvallen = sizeof (int); + return 0; + default: + return -ENOPROTOOPT; + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws.h new file mode 100644 index 0000000..10fb408 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws.h @@ -0,0 +1,31 @@ +/* + Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_WS_INCLUDED +#define NN_WS_INCLUDED + +#include "../../transport.h" + +extern struct nn_transport *nn_ws; + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.c b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.c new file mode 100644 index 0000000..45b62b1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.c @@ -0,0 +1,1365 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014-2016 Jack R. Dunaway. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "ws_handshake.h" +#include "sha1.h" + +#include "../../aio/timer.h" + +#include "../../core/sock.h" + +#include "../utils/base64.h" + +#include "../../utils/alloc.h" +#include "../../utils/err.h" +#include "../../utils/cont.h" +#include "../../utils/fast.h" +#include "../../utils/wire.h" +#include "../../utils/attr.h" +#include "../../utils/random.h" + +#include +#include +#include + +/*****************************************************************************/ +/*** BEGIN undesirable dependency *******************************************/ +/*****************************************************************************/ +/* TODO: A transport should be SP agnostic; alas, these includes are */ +/* required for the map. Ideally, this map would live in another */ +/* abstraction layer; perhaps a "registry" of Scalability Protocols? */ +/*****************************************************************************/ +#include "../../pair.h" +#include "../../reqrep.h" +#include "../../pubsub.h" +#include "../../survey.h" +#include "../../pipeline.h" +#include "../../bus.h" + +static const struct nn_ws_sp_map NN_WS_HANDSHAKE_SP_MAP[] = { + { NN_PAIR, NN_PAIR, "pair.sp.nanomsg.org" }, + { NN_REQ, NN_REP, "req.sp.nanomsg.org" }, + { NN_REP, NN_REQ, "rep.sp.nanomsg.org" }, + { NN_PUB, NN_SUB, "pub.sp.nanomsg.org" }, + { NN_SUB, NN_PUB, "sub.sp.nanomsg.org" }, + { NN_SURVEYOR, NN_RESPONDENT, "surveyor.sp.nanomsg.org" }, + { NN_RESPONDENT, NN_SURVEYOR, "respondent.sp.nanomsg.org" }, + { NN_PUSH, NN_PULL, "push.sp.nanomsg.org" }, + { NN_PULL, NN_PUSH, "pull.sp.nanomsg.org" }, + { NN_BUS, NN_BUS, "bus.sp.nanomsg.org" } +}; + +const size_t NN_WS_HANDSHAKE_SP_MAP_LEN = sizeof (NN_WS_HANDSHAKE_SP_MAP) / + sizeof (NN_WS_HANDSHAKE_SP_MAP [0]); +/*****************************************************************************/ +/*** END undesirable dependency *********************************************/ +/*****************************************************************************/ + +/* State machine finite states. */ +#define NN_WS_HANDSHAKE_STATE_IDLE 1 +#define NN_WS_HANDSHAKE_STATE_SERVER_RECV 2 +#define NN_WS_HANDSHAKE_STATE_SERVER_REPLY 3 +#define NN_WS_HANDSHAKE_STATE_CLIENT_SEND 4 +#define NN_WS_HANDSHAKE_STATE_CLIENT_RECV 5 +#define NN_WS_HANDSHAKE_STATE_HANDSHAKE_SENT 6 +#define NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR 7 +#define NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_DONE 8 +#define NN_WS_HANDSHAKE_STATE_DONE 9 +#define NN_WS_HANDSHAKE_STATE_STOPPING 10 + +/* Subordinate srcptr objects. */ +#define NN_WS_HANDSHAKE_SRC_USOCK 1 +#define NN_WS_HANDSHAKE_SRC_TIMER 2 + +/* Time allowed to complete handshake. */ +#define NN_WS_HANDSHAKE_TIMEOUT 5000 + +/* Possible return codes internal to the parsing operations. */ +#define NN_WS_HANDSHAKE_NOMATCH 0 +#define NN_WS_HANDSHAKE_MATCH 1 + +/* Possible return codes from parsing opening handshake from peer. */ +#define NN_WS_HANDSHAKE_VALID 0 +#define NN_WS_HANDSHAKE_RECV_MORE 1 +#define NN_WS_HANDSHAKE_INVALID -1 + +/* Possible handshake responses to send to client when acting as server. */ +#define NN_WS_HANDSHAKE_RESPONSE_NULL -1 +#define NN_WS_HANDSHAKE_RESPONSE_OK 0 +#define NN_WS_HANDSHAKE_RESPONSE_TOO_BIG 1 +#define NN_WS_HANDSHAKE_RESPONSE_UNUSED2 2 +#define NN_WS_HANDSHAKE_RESPONSE_WSPROTO 3 +#define NN_WS_HANDSHAKE_RESPONSE_WSVERSION 4 +#define NN_WS_HANDSHAKE_RESPONSE_NNPROTO 5 +#define NN_WS_HANDSHAKE_RESPONSE_NOTPEER 6 +#define NN_WS_HANDSHAKE_RESPONSE_UNKNOWNTYPE 7 + +/* Private functions. */ +static void nn_ws_handshake_handler (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_ws_handshake_shutdown (struct nn_fsm *self, int src, int type, + void *srcptr); +static void nn_ws_handshake_leave (struct nn_ws_handshake *self, int rc); + +/* WebSocket protocol support functions. */ +static int nn_ws_handshake_parse_client_opening (struct nn_ws_handshake *self); +static void nn_ws_handshake_server_reply (struct nn_ws_handshake *self); +static void nn_ws_handshake_client_request (struct nn_ws_handshake *self); +static int nn_ws_handshake_parse_server_response (struct nn_ws_handshake *self); +static int nn_ws_handshake_hash_key (const char *key, size_t key_len, + char *hashed, size_t hashed_len); + +/* String parsing support functions. */ + +/* Scans for reference token against subject string, optionally ignoring + case sensitivity and/or leading spaces in subject. On match, advances + the subject pointer to the next non-ignored character past match. Both + strings must be NULL terminated to avoid undefined behavior. Returns + NN_WS_HANDSHAKE_MATCH on match; else, NN_WS_HANDSHAKE_NOMATCH. */ +static int nn_ws_match_token (const char* token, const char **subj, + int case_insensitive, int ignore_leading_sp); + +/* Scans subject string for termination sequence, optionally ignoring + leading and/or trailing spaces in subject. On match, advances + the subject pointer to the next character past match. Both + strings must be NULL terminated to avoid undefined behavior. If the + match succeeds, values are stored into *addr and *len. */ +static int nn_ws_match_value (const char* termseq, const char **subj, + int ignore_leading_sp, int ignore_trailing_sp, const char **addr, + size_t* const len); + +/* Compares subject octet stream to expected value, optionally ignoring + case sensitivity. Returns non-zero on success, zero on failure. */ +static int nn_ws_validate_value (const char* expected, const char *subj, + size_t subj_len, int case_insensitive); + +void nn_ws_handshake_init (struct nn_ws_handshake *self, int src, + struct nn_fsm *owner) +{ + nn_fsm_init (&self->fsm, nn_ws_handshake_handler, nn_ws_handshake_shutdown, + src, self, owner); + self->state = NN_WS_HANDSHAKE_STATE_IDLE; + nn_timer_init (&self->timer, NN_WS_HANDSHAKE_SRC_TIMER, &self->fsm); + nn_fsm_event_init (&self->done); + self->timeout = NN_WS_HANDSHAKE_TIMEOUT; + self->usock = NULL; + self->usock_owner.src = -1; + self->usock_owner.fsm = NULL; + self->pipebase = NULL; +} + +void nn_ws_handshake_term (struct nn_ws_handshake *self) +{ + nn_assert_state (self, NN_WS_HANDSHAKE_STATE_IDLE); + + nn_fsm_event_term (&self->done); + nn_timer_term (&self->timer); + nn_fsm_term (&self->fsm); +} + +int nn_ws_handshake_isidle (struct nn_ws_handshake *self) +{ + return nn_fsm_isidle (&self->fsm); +} + +void nn_ws_handshake_start (struct nn_ws_handshake *self, + struct nn_usock *usock, struct nn_pipebase *pipebase, + int mode, const char *resource, const char *host) +{ + /* It's expected this resource has been allocated during intial connect. */ + if (mode == NN_WS_CLIENT) + nn_assert (strlen (resource) >= 1); + + /* Take ownership of the underlying socket. */ + nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL); + self->usock_owner.src = NN_WS_HANDSHAKE_SRC_USOCK; + self->usock_owner.fsm = &self->fsm; + nn_usock_swap_owner (usock, &self->usock_owner); + self->usock = usock; + self->pipebase = pipebase; + self->mode = mode; + self->resource = resource; + self->remote_host = host; + + memset (self->opening_hs, 0, sizeof (self->opening_hs)); + memset (self->response, 0, sizeof (self->response)); + + self->recv_pos = 0; + self->retries = 0; + + /* Calculate the absolute minimum length possible for a valid opening + handshake. This is an optimization since we must poll for the + remainder of the opening handshake in small byte chunks. */ + switch (self->mode) { + case NN_WS_SERVER: + self->recv_len = strlen ( + "GET x HTTP/1.1\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Host: x\r\n" + "Origin: x\r\n" + "Sec-WebSocket-Key: xxxxxxxxxxxxxxxxxxxxxxxx\r\n" + "Sec-WebSocket-Version: xx\r\n\r\n"); + break; + case NN_WS_CLIENT: + /* Shortest conceiveable response from server is a terse status. */ + self->recv_len = strlen ("HTTP/1.1 xxx\r\n\r\n"); + break; + default: + /* Developer error; unexpected mode. */ + nn_assert (0); + break; + } + + /* Launch the state machine. */ + nn_fsm_start (&self->fsm); +} + +void nn_ws_handshake_stop (struct nn_ws_handshake *self) +{ + nn_fsm_stop (&self->fsm); +} + +static void nn_ws_handshake_shutdown (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_ws_handshake *handshaker; + + handshaker = nn_cont (self, struct nn_ws_handshake, fsm); + + if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING; + } + if (nn_slow (handshaker->state == NN_WS_HANDSHAKE_STATE_STOPPING)) { + if (!nn_timer_isidle (&handshaker->timer)) + return; + handshaker->state = NN_WS_HANDSHAKE_STATE_IDLE; + nn_fsm_stopped (&handshaker->fsm, NN_WS_HANDSHAKE_STOPPED); + return; + } + + nn_fsm_bad_state (handshaker->state, src, type); +} + +static int nn_ws_match_token (const char* token, const char **subj, + int case_insensitive, int ignore_leading_sp) +{ + const char *pos; + + nn_assert (token && *subj); + + pos = *subj; + + if (ignore_leading_sp) { + while (*pos == '\x20' && *pos) { + pos++; + } + } + + if (case_insensitive) { + while (*token && *pos) { + if (tolower (*token) != tolower (*pos)) + return NN_WS_HANDSHAKE_NOMATCH; + token++; + pos++; + } + } + else { + while (*token && *pos) { + if (*token != *pos) + return NN_WS_HANDSHAKE_NOMATCH; + token++; + pos++; + } + } + + /* Encountered end of subject before matching completed. */ + if (!*pos && *token) + return NN_WS_HANDSHAKE_NOMATCH; + + /* Entire token has been matched. */ + nn_assert (!*token); + + /* On success, advance subject position. */ + *subj = pos; + + return NN_WS_HANDSHAKE_MATCH; +} + +static int nn_ws_match_value (const char* termseq, const char **subj, + int ignore_leading_sp, int ignore_trailing_sp, const char **addr, + size_t* const len) +{ + const char *start; + const char *end; + + nn_assert (termseq && *subj); + + start = *subj; + if (addr) + *addr = NULL; + if (len) + *len = 0; + + /* Find first occurence of termination sequence. */ + end = strstr (start, termseq); + + /* Was a termination sequence found? */ + if (end) { + *subj = end + strlen (termseq); + } + else { + return NN_WS_HANDSHAKE_NOMATCH; + } + + if (ignore_leading_sp) { + while (*start == '\x20' && start < end) { + start++; + } + } + + if (addr) + *addr = start; + + /* In this special case, the value was "found", but is just empty or + ignored space. */ + if (start == end) + return NN_WS_HANDSHAKE_MATCH; + + if (ignore_trailing_sp) { + while (*(end - 1) == '\x20' && start < end) { + end--; + } + } + + if (len) + *len = end - start; + + return NN_WS_HANDSHAKE_MATCH; +} + +static int nn_ws_validate_value (const char* expected, const char *subj, + size_t subj_len, int case_insensitive) +{ + if (strlen (expected) != subj_len) + return NN_WS_HANDSHAKE_NOMATCH; + + if (case_insensitive) { + while (*expected && *subj) { + if (tolower (*expected) != tolower (*subj)) + return NN_WS_HANDSHAKE_NOMATCH; + expected++; + subj++; + } + } + else { + while (*expected && *subj) { + if (*expected != *subj) + return NN_WS_HANDSHAKE_NOMATCH; + expected++; + subj++; + } + } + + return NN_WS_HANDSHAKE_MATCH; +} + +static void nn_ws_handshake_handler (struct nn_fsm *self, int src, int type, + NN_UNUSED void *srcptr) +{ + struct nn_ws_handshake *handshaker; + + size_t i; + + handshaker = nn_cont (self, struct nn_ws_handshake, fsm); + + switch (handshaker->state) { + +/******************************************************************************/ +/* IDLE state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_IDLE: + switch (src) { + + case NN_FSM_ACTION: + switch (type) { + case NN_FSM_START: + nn_assert (handshaker->recv_pos == 0); + nn_assert (handshaker->recv_len >= NN_WS_HANDSHAKE_TERMSEQ_LEN); + + nn_timer_start (&handshaker->timer, handshaker->timeout); + + switch (handshaker->mode) { + case NN_WS_CLIENT: + /* Send opening handshake to server. */ + nn_assert (handshaker->recv_len <= + sizeof (handshaker->response)); + handshaker->state = NN_WS_HANDSHAKE_STATE_CLIENT_SEND; + nn_ws_handshake_client_request (handshaker); + return; + case NN_WS_SERVER: + /* Begin receiving opening handshake from client. */ + nn_assert (handshaker->recv_len <= + sizeof (handshaker->opening_hs)); + handshaker->state = NN_WS_HANDSHAKE_STATE_SERVER_RECV; + nn_usock_recv (handshaker->usock, handshaker->opening_hs, + handshaker->recv_len, NULL); + return; + default: + /* Unexpected mode. */ + nn_assert (0); + return; + } + + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* SERVER_RECV state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_SERVER_RECV: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + switch (type) { + case NN_USOCK_RECEIVED: + /* Parse bytes received thus far. */ + switch (nn_ws_handshake_parse_client_opening (handshaker)) { + case NN_WS_HANDSHAKE_INVALID: + /* Opening handshake parsed successfully but does not + contain valid values. Respond failure to client. */ + handshaker->state = NN_WS_HANDSHAKE_STATE_SERVER_REPLY; + nn_ws_handshake_server_reply (handshaker); + return; + case NN_WS_HANDSHAKE_VALID: + /* Opening handshake parsed successfully, and is valid. + Respond success to client. */ + handshaker->state = NN_WS_HANDSHAKE_STATE_SERVER_REPLY; + nn_ws_handshake_server_reply (handshaker); + return; + case NN_WS_HANDSHAKE_RECV_MORE: + /* Not enough bytes have been received to determine + validity; remain in the receive state, and retrieve + more bytes from client. */ + handshaker->recv_pos += handshaker->recv_len; + + /* Validate the previous recv operation. */ + nn_assert (handshaker->recv_pos < + sizeof (handshaker->opening_hs)); + + /* Ensure we can back-track at least the length of the + termination sequence to determine how many bytes to + receive on the next retry. This is an assertion, not + a conditional, since under no condition is it + necessary to initially receive so few bytes. */ + nn_assert (handshaker->recv_pos >= + (int) NN_WS_HANDSHAKE_TERMSEQ_LEN); + + /* We only compare if we have at least one byte to + compare against. When i drops to zero, it means + we don't have any bytes to match against, and it is + automatically true. */ + for (i = NN_WS_HANDSHAKE_TERMSEQ_LEN; i > 0; i--) { + if (memcmp (NN_WS_HANDSHAKE_TERMSEQ, + handshaker->opening_hs + handshaker->recv_pos - i, + i) == 0) { + break; + } + } + + nn_assert (i < NN_WS_HANDSHAKE_TERMSEQ_LEN); + + handshaker->recv_len = NN_WS_HANDSHAKE_TERMSEQ_LEN - i; + + /* In the unlikely case the client would overflow what we + assumed was a sufficiently-large buffer to receive the + handshake, we fail the client. */ + if (handshaker->recv_len + handshaker->recv_pos > + sizeof (handshaker->opening_hs)) { + handshaker->response_code = + NN_WS_HANDSHAKE_RESPONSE_TOO_BIG; + handshaker->state = + NN_WS_HANDSHAKE_STATE_SERVER_REPLY; + nn_ws_handshake_server_reply (handshaker); + } + else { + handshaker->retries++; + nn_usock_recv (handshaker->usock, + handshaker->opening_hs + handshaker->recv_pos, + handshaker->recv_len, NULL); + } + return; + default: + nn_fsm_error ("Unexpected handshake result", + handshaker->state, src, type); + } + return; + case NN_USOCK_SHUTDOWN: + /* Ignore it and wait for ERROR event. */ + return; + case NN_USOCK_ERROR: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* SERVER_REPLY state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_SERVER_REPLY: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + /* As per RFC 6455 4.2.2, the handshake is now complete + and the connection is immediately ready for send/recv. */ + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_DONE; + case NN_USOCK_SHUTDOWN: + /* Ignore it and wait for ERROR event. */ + return; + case NN_USOCK_ERROR: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* CLIENT_SEND state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_CLIENT_SEND: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + handshaker->state = NN_WS_HANDSHAKE_STATE_CLIENT_RECV; + nn_usock_recv (handshaker->usock, handshaker->response, + handshaker->recv_len, NULL); + return; + case NN_USOCK_SHUTDOWN: + /* Ignore it and wait for ERROR event. */ + return; + case NN_USOCK_ERROR: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* CLIENT_RECV state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_CLIENT_RECV: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + switch (type) { + case NN_USOCK_RECEIVED: + /* Parse bytes received thus far. */ + switch (nn_ws_handshake_parse_server_response (handshaker)) { + case NN_WS_HANDSHAKE_INVALID: + /* Opening handshake parsed successfully but does not + contain valid values. Fail connection. */ + nn_timer_stop (&handshaker->timer); + handshaker->state = + NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + case NN_WS_HANDSHAKE_VALID: + /* As per RFC 6455 4.2.2, the handshake is now complete + and the connection is immediately ready for send/recv. */ + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_DONE; + return; + case NN_WS_HANDSHAKE_RECV_MORE: + /* Not enough bytes have been received to determine + validity; remain in the receive state, and retrieve + more bytes from client. */ + handshaker->recv_pos += handshaker->recv_len; + + /* Validate the previous recv operation. */ + nn_assert (handshaker->recv_pos < + sizeof (handshaker->response)); + + /* Ensure we can back-track at least the length of the + termination sequence to determine how many bytes to + receive on the next retry. This is an assertion, not + a conditional, since under no condition is it + necessary to initially receive so few bytes. */ + nn_assert (handshaker->recv_pos >= + (int) NN_WS_HANDSHAKE_TERMSEQ_LEN); + + /* If i goes to 0, it no need to compare. */ + for (i = NN_WS_HANDSHAKE_TERMSEQ_LEN; i > 0; i--) { + if (memcmp (NN_WS_HANDSHAKE_TERMSEQ, + handshaker->response + handshaker->recv_pos - i, + i) == 0) { + break; + } + } + + nn_assert (i < NN_WS_HANDSHAKE_TERMSEQ_LEN); + + handshaker->recv_len = NN_WS_HANDSHAKE_TERMSEQ_LEN - i; + + /* In the unlikely case the client would overflow what we + assumed was a sufficiently-large buffer to receive the + handshake, we fail the connection. */ + if (handshaker->recv_len + handshaker->recv_pos > + sizeof (handshaker->response)) { + nn_timer_stop (&handshaker->timer); + handshaker->state = + NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + } + else { + handshaker->retries++; + nn_usock_recv (handshaker->usock, + handshaker->response + handshaker->recv_pos, + handshaker->recv_len, NULL); + } + return; + default: + nn_fsm_error ("Unexpected handshake result", + handshaker->state, src, type); + } + return; + case NN_USOCK_SHUTDOWN: + /* Ignore it and wait for ERROR event. */ + return; + case NN_USOCK_ERROR: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* HANDSHAKE_SENT state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_HANDSHAKE_SENT: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + switch (type) { + case NN_USOCK_SENT: + /* As per RFC 6455 4.2.2, the handshake is now complete + and the connection is immediately ready for send/recv. */ + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_DONE; + return; + case NN_USOCK_SHUTDOWN: + /* Ignore it and wait for ERROR event. */ + return; + case NN_USOCK_ERROR: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_TIMEOUT: + nn_timer_stop (&handshaker->timer); + handshaker->state = NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR; + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_TIMER_ERROR state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_ERROR: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + /* Ignore. The only circumstance the client would send bytes is + to notify the server it is closing the connection. Wait for the + socket to eventually error. */ + return; + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + nn_ws_handshake_leave (handshaker, NN_WS_HANDSHAKE_ERROR); + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* STOPPING_TIMER_DONE state. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_STOPPING_TIMER_DONE: + switch (src) { + + case NN_WS_HANDSHAKE_SRC_USOCK: + /* Ignore. The only circumstance the client would send bytes is + to notify the server it is closing the connection. Wait for the + socket to eventually error. */ + return; + + case NN_WS_HANDSHAKE_SRC_TIMER: + switch (type) { + case NN_TIMER_STOPPED: + nn_ws_handshake_leave (handshaker, NN_WS_HANDSHAKE_OK); + return; + default: + nn_fsm_bad_action (handshaker->state, src, type); + } + + default: + nn_fsm_bad_source (handshaker->state, src, type); + } + +/******************************************************************************/ +/* DONE state. */ +/* The header exchange was either done successfully of failed. There's */ +/* nothing that can be done in this state except stopping the object. */ +/******************************************************************************/ + case NN_WS_HANDSHAKE_STATE_DONE: + nn_fsm_bad_source (handshaker->state, src, type); + +/******************************************************************************/ +/* Invalid state. */ +/******************************************************************************/ + default: + nn_fsm_bad_state (handshaker->state, src, type); + } +} + +/******************************************************************************/ +/* State machine actions. */ +/******************************************************************************/ + +static void nn_ws_handshake_leave (struct nn_ws_handshake *self, int rc) +{ + nn_usock_swap_owner (self->usock, &self->usock_owner); + self->usock = NULL; + self->usock_owner.src = -1; + self->usock_owner.fsm = NULL; + self->state = NN_WS_HANDSHAKE_STATE_DONE; + nn_fsm_raise (&self->fsm, &self->done, rc); +} + +static int nn_ws_handshake_parse_client_opening (struct nn_ws_handshake *self) +{ + /* As per RFC 6455 section 1.7, this parser is not intended to be a + general-purpose parser for arbitrary HTTP headers. As with the design + philosophy of nanomsg, application-specific exchanges are better + reserved for accepted connections, not as fields within these + headers. */ + + int rc; + const char *pos; + unsigned i; + + /* Guarantee that a NULL terminator exists to enable treating this + recv buffer like a string. */ + nn_assert (memchr (self->opening_hs, '\0', sizeof (self->opening_hs))); + + /* Having found the NULL terminator, from this point forward string + functions may be used. */ + nn_assert (strlen (self->opening_hs) < sizeof (self->opening_hs)); + + pos = self->opening_hs; + + /* Is the opening handshake from the client fully received? */ + if (!strstr (pos, NN_WS_HANDSHAKE_TERMSEQ)) + return NN_WS_HANDSHAKE_RECV_MORE; + + self->host = NULL; + self->origin = NULL; + self->key = NULL; + self->upgrade = NULL; + self->conn = NULL; + self->version = NULL; + self->protocol = NULL; + self->uri = NULL; + + self->host_len = 0; + self->origin_len = 0; + self->key_len = 0; + self->upgrade_len = 0; + self->conn_len = 0; + self->version_len = 0; + self->protocol_len = 0; + self->uri_len = 0; + + /* This function, if generating a return value that triggers + a response to the client, should replace this sentinel value + with a proper response code. */ + self->response_code = NN_WS_HANDSHAKE_RESPONSE_NULL; + + /* RFC 7230 3.1.1 Request Line: HTTP Method + Note requirement of one space and case sensitivity. */ + if (!nn_ws_match_token ("GET\x20", &pos, 0, 0)) + return NN_WS_HANDSHAKE_RECV_MORE; + + /* RFC 7230 3.1.1 Request Line: Requested Resource. */ + if (!nn_ws_match_value ("\x20", &pos, 0, 0, &self->uri, &self->uri_len)) + return NN_WS_HANDSHAKE_RECV_MORE; + + /* RFC 7230 3.1.1 Request Line: HTTP version. Note case sensitivity. */ + if (!nn_ws_match_token ("HTTP/1.1", &pos, 0, 0)) + return NN_WS_HANDSHAKE_RECV_MORE; + if (!nn_ws_match_token (NN_WS_HANDSHAKE_CRLF, &pos, 0, 0)) + return NN_WS_HANDSHAKE_RECV_MORE; + + /* It's expected the current position is now at the first + header field. Match them one by one. */ + while (strlen (pos)) + { + if (nn_ws_match_token ("Host:", &pos, 1, 0)) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->host, &self->host_len); + } + else if (nn_ws_match_token ("Origin:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->origin, &self->origin_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Key:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->key, &self->key_len); + } + else if (nn_ws_match_token ("Upgrade:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->upgrade, &self->upgrade_len); + } + else if (nn_ws_match_token ("Connection:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->conn, &self->conn_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Version:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->version, &self->version_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Protocol:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->protocol, &self->protocol_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Extensions:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->extensions, &self->extensions_len); + } + else if (nn_ws_match_token (NN_WS_HANDSHAKE_CRLF, + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + /* Exit loop since all headers are parsed. */ + break; + } + else { + /* Skip unknown headers. */ + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + NULL, NULL); + } + + if (rc != NN_WS_HANDSHAKE_MATCH) + return NN_WS_HANDSHAKE_RECV_MORE; + } + + /* Validate the opening handshake is now fully parsed. Additionally, + as per RFC 6455 section 4.1, the client should not send additional data + after the opening handshake, so this assertion validates upstream recv + logic prevented this case. */ + nn_assert (strlen (pos) == 0); + + /* TODO: protocol expectations below this point are hard-coded here as + an initial design decision. Perhaps in the future these values should + be settable via compile time (or run-time socket) options? */ + + /* These header fields are required as per RFC 6455 section 4.1. */ + if (!self->host || !self->upgrade || !self->conn || + !self->key || !self->version) { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_WSPROTO; + return NN_WS_HANDSHAKE_INVALID; + } + + /* RFC 6455 section 4.2.1.6 (version December 2011). */ + if (nn_ws_validate_value ("13", self->version, + self->version_len, 1) != NN_WS_HANDSHAKE_MATCH) { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_WSVERSION; + return NN_WS_HANDSHAKE_INVALID; + } + + /* RFC 6455 section 4.2.1.3 (version December 2011). */ + if (nn_ws_validate_value ("websocket", self->upgrade, + self->upgrade_len, 1) != NN_WS_HANDSHAKE_MATCH) { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_WSPROTO; + return NN_WS_HANDSHAKE_INVALID; + } + + /* RFC 6455 section 4.2.1.4 (version December 2011). */ + if (nn_ws_validate_value ("Upgrade", self->conn, + self->conn_len, 1) != NN_WS_HANDSHAKE_MATCH) { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_WSPROTO; + return NN_WS_HANDSHAKE_INVALID; + } + + /* At this point, client meets RFC 6455 compliance for opening handshake. + Now it's time to check nanomsg-imposed required handshake values. */ + if (self->protocol) { + /* Ensure the client SP is a compatible socket type. */ + for (i = 0; i < NN_WS_HANDSHAKE_SP_MAP_LEN; i++) { + if (nn_ws_validate_value (NN_WS_HANDSHAKE_SP_MAP [i].ws_sp, + self->protocol, self->protocol_len, 1)) { + + if (self->pipebase->sock->socktype->protocol == + NN_WS_HANDSHAKE_SP_MAP [i].server) { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_OK; + return NN_WS_HANDSHAKE_VALID; + } + else { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_NOTPEER; + return NN_WS_HANDSHAKE_INVALID; + } + break; + } + } + + self->response_code = NN_WS_HANDSHAKE_RESPONSE_UNKNOWNTYPE; + return NN_WS_HANDSHAKE_INVALID; + } + else { + /* Be permissive and generous here, assuming that if a protocol is + not explicitly declared, PAIR is presumed. This enables + interoperability with non-nanomsg remote peers, nominally by + making the local socket PAIR type. For any other local + socket type, we expect connection to be rejected as + incompatible if the header is not specified. */ + + if (nn_pipebase_ispeer (self->pipebase, NN_PAIR)) { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_OK; + return NN_WS_HANDSHAKE_VALID; + } + else { + self->response_code = NN_WS_HANDSHAKE_RESPONSE_NOTPEER; + return NN_WS_HANDSHAKE_INVALID; + } + } +} + +static int nn_ws_handshake_parse_server_response (struct nn_ws_handshake *self) +{ + /* As per RFC 6455 section 1.7, this parser is not intended to be a + general-purpose parser for arbitrary HTTP headers. As with the design + philosophy of nanomsg, application-specific exchanges are better + reserved for accepted connections, not as fields within these + headers. */ + + int rc; + const char *pos; + + /* Guarantee that a NULL terminator exists to enable treating this + recv buffer like a string. The lack of such would indicate a failure + upstream to catch a buffer overflow. */ + nn_assert (memchr (self->response, '\0', sizeof (self->response))); + + /* Having found the NULL terminator, from this point forward string + functions may be used. */ + nn_assert (strlen (self->response) < sizeof (self->response)); + + pos = self->response; + + /* Is the response from the server fully received? */ + if (!strstr (pos, NN_WS_HANDSHAKE_TERMSEQ)) + return NN_WS_HANDSHAKE_RECV_MORE; + + self->status_code = NULL; + self->reason_phrase = NULL; + self->server = NULL; + self->accept_key = NULL; + self->upgrade = NULL; + self->conn = NULL; + self->version = NULL; + self->protocol = NULL; + + self->status_code_len = 0; + self->reason_phrase_len = 0; + self->server_len = 0; + self->accept_key_len = 0; + self->upgrade_len = 0; + self->conn_len = 0; + self->version_len = 0; + self->protocol_len = 0; + + /* RFC 7230 3.1.2 Status Line: HTTP Version. */ + if (!nn_ws_match_token ("HTTP/1.1\x20", &pos, 0, 0)) + return NN_WS_HANDSHAKE_RECV_MORE; + + /* RFC 7230 3.1.2 Status Line: Status Code. */ + if (!nn_ws_match_value ("\x20", &pos, 0, 0, &self->status_code, + &self->status_code_len)) + return NN_WS_HANDSHAKE_RECV_MORE; + + /* RFC 7230 3.1.2 Status Line: Reason Phrase. */ + if (!nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 0, 0, + &self->reason_phrase, &self->reason_phrase_len)) + return NN_WS_HANDSHAKE_RECV_MORE; + + /* It's expected the current position is now at the first + header field. Match them one by one. */ + while (strlen (pos)) + { + if (nn_ws_match_token ("Server:", &pos, 1, 0)) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->server, &self->server_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Accept:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->accept_key, &self->accept_key_len); + } + else if (nn_ws_match_token ("Upgrade:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->upgrade, &self->upgrade_len); + } + else if (nn_ws_match_token ("Connection:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->conn, &self->conn_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Version-Server:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->version, &self->version_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Protocol-Server:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->protocol, &self->protocol_len); + } + else if (nn_ws_match_token ("Sec-WebSocket-Extensions:", + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + &self->extensions, &self->extensions_len); + } + else if (nn_ws_match_token (NN_WS_HANDSHAKE_CRLF, + &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) { + /* Exit loop since all headers are parsed. */ + break; + } + else { + /* Skip unknown headers. */ + rc = nn_ws_match_value (NN_WS_HANDSHAKE_CRLF, &pos, 1, 1, + NULL, NULL); + } + + if (rc != NN_WS_HANDSHAKE_MATCH) + return NN_WS_HANDSHAKE_RECV_MORE; + } + + /* Validate the opening handshake is now fully parsed. Additionally, + as per RFC 6455 section 4.1, the client should not send additional data + after the opening handshake, so this assertion validates upstream recv + logic prevented this case. */ + nn_assert (strlen (pos) == 0); + + /* TODO: protocol expectations below this point are hard-coded here as + an initial design decision. Perhaps in the future these values should + be settable via compile time (or run-time socket) options? */ + + /* These header fields are required as per RFC 6455 4.2.2. */ + if (!self->status_code || !self->upgrade || !self->conn || + !self->accept_key) + return NN_WS_HANDSHAKE_INVALID; + + /* TODO: Currently, we only handle a successful connection upgrade. + Anything else is treated as a failed connection. + Consider handling other scenarios like 3xx redirects. */ + if (nn_ws_validate_value ("101", self->status_code, + self->status_code_len, 1) != NN_WS_HANDSHAKE_MATCH) + return NN_WS_HANDSHAKE_INVALID; + + /* RFC 6455 section 4.2.2.5.2 (version December 2011). */ + if (nn_ws_validate_value ("websocket", self->upgrade, + self->upgrade_len, 1) != NN_WS_HANDSHAKE_MATCH) + return NN_WS_HANDSHAKE_INVALID; + + /* RFC 6455 section 4.2.2.5.3 (version December 2011). */ + if (nn_ws_validate_value ("Upgrade", self->conn, + self->conn_len, 1) != NN_WS_HANDSHAKE_MATCH) + return NN_WS_HANDSHAKE_INVALID; + + /* RFC 6455 section 4.2.2.5.4 (version December 2011). */ + if (nn_ws_validate_value (self->expected_accept_key, self->accept_key, + self->accept_key_len, 1) != NN_WS_HANDSHAKE_MATCH) + return NN_WS_HANDSHAKE_INVALID; + + /* Server response meets RFC 6455 compliance for opening handshake. */ + return NN_WS_HANDSHAKE_VALID; +} + +static void nn_ws_handshake_client_request (struct nn_ws_handshake *self) +{ + struct nn_iovec open_request; + size_t encoded_key_len; + int rc; + unsigned i; + + /* Generate random 16-byte key as per RFC 6455 4.1 */ + uint8_t rand_key [16]; + + /* Known length required to base64 encode above random key plus + string NULL terminator. */ + char encoded_key [24 + 1]; + + nn_random_generate (rand_key, sizeof (rand_key)); + + rc = nn_base64_encode (rand_key, sizeof (rand_key), + encoded_key, sizeof (encoded_key)); + nn_assert (rc >=0); + + encoded_key_len = strlen (encoded_key); + + nn_assert (encoded_key_len == sizeof (encoded_key) - 1); + + /* Pre-calculated expected Accept Key value as per + RFC 6455 section 4.2.2.5.4 (version December 2011). */ + rc = nn_ws_handshake_hash_key (encoded_key, encoded_key_len, + self->expected_accept_key, sizeof (self->expected_accept_key)); + + nn_assert (rc == NN_WS_HANDSHAKE_ACCEPT_KEY_LEN); + + /* Lookup SP header value. */ + for (i = 0; i < NN_WS_HANDSHAKE_SP_MAP_LEN; i++) { + if (NN_WS_HANDSHAKE_SP_MAP [i].client == + self->pipebase->sock->socktype->protocol) { + break; + } + } + + /* Guarantee that the socket type was found in the map. */ + nn_assert (i < NN_WS_HANDSHAKE_SP_MAP_LEN); + + sprintf (self->opening_hs, + "GET %s HTTP/1.1\r\n" + "Host: %s\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Key: %s\r\n" + "Sec-WebSocket-Version: 13\r\n" + "Sec-WebSocket-Protocol: %s\r\n\r\n", + self->resource, self->remote_host, encoded_key, + NN_WS_HANDSHAKE_SP_MAP[i].ws_sp); + + open_request.iov_len = strlen (self->opening_hs); + open_request.iov_base = self->opening_hs; + + nn_usock_send (self->usock, &open_request, 1); +} + +static void nn_ws_handshake_server_reply (struct nn_ws_handshake *self) +{ + struct nn_iovec response; + char *code; + char *version; + char *protocol; + int rc; + + /* Allow room for NULL terminator. */ + char accept_key [NN_WS_HANDSHAKE_ACCEPT_KEY_LEN + 1]; + + memset (self->response, 0, sizeof (self->response)); + + if (self->response_code == NN_WS_HANDSHAKE_RESPONSE_OK) { + /* Upgrade connection as per RFC 6455 section 4.2.2. */ + + rc = nn_ws_handshake_hash_key (self->key, self->key_len, + accept_key, sizeof (accept_key)); + nn_assert (rc >= 0); + + nn_assert (strlen (accept_key) == NN_WS_HANDSHAKE_ACCEPT_KEY_LEN); + + protocol = nn_alloc (self->protocol_len + 1, "WebSocket protocol"); + alloc_assert (protocol); + strncpy (protocol, self->protocol, self->protocol_len); + protocol [self->protocol_len] = '\0'; + + sprintf (self->response, + "HTTP/1.1 101 Switching Protocols\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Accept: %s\r\n" + "Sec-WebSocket-Protocol: %s\r\n\r\n", + accept_key, protocol); + + nn_free (protocol); + } + else { + /* Fail the connection with a helpful hint. */ + switch (self->response_code) { + case NN_WS_HANDSHAKE_RESPONSE_TOO_BIG: + code = "400 Opening Handshake Too Long"; + break; + case NN_WS_HANDSHAKE_RESPONSE_WSPROTO: + code = "400 Cannot Have Body"; + break; + case NN_WS_HANDSHAKE_RESPONSE_WSVERSION: + code = "400 Unsupported WebSocket Version"; + break; + case NN_WS_HANDSHAKE_RESPONSE_NNPROTO: + code = "400 Missing nanomsg Required Headers"; + break; + case NN_WS_HANDSHAKE_RESPONSE_NOTPEER: + code = "400 Incompatible Socket Type"; + break; + case NN_WS_HANDSHAKE_RESPONSE_UNKNOWNTYPE: + code = "400 Unrecognized Socket Type"; + break; + default: + /* Unexpected failure response. */ + nn_assert (0); + break; + } + + version = nn_alloc (self->version_len + 1, "WebSocket version"); + alloc_assert (version); + strncpy (version, self->version, self->version_len); + version [self->version_len] = '\0'; + + /* Fail connection as per RFC 6455 4.4. */ + sprintf (self->response, + "HTTP/1.1 %s\r\n" + "Sec-WebSocket-Version: %s\r\n", + code, version); + + nn_free (version); + } + + response.iov_len = strlen (self->response); + response.iov_base = &self->response; + + nn_usock_send (self->usock, &response, 1); + + return; +} + +static int nn_ws_handshake_hash_key (const char *key, size_t key_len, + char *hashed, size_t hashed_len) +{ + int rc; + unsigned i; + struct nn_sha1 hash; + + nn_sha1_init (&hash); + + for (i = 0; i < key_len; i++) + nn_sha1_hashbyte (&hash, key [i]); + + for (i = 0; i < strlen (NN_WS_HANDSHAKE_MAGIC_GUID); i++) + nn_sha1_hashbyte (&hash, NN_WS_HANDSHAKE_MAGIC_GUID [i]); + + rc = nn_base64_encode (nn_sha1_result (&hash), + sizeof (hash.state), hashed, hashed_len); + + return rc; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.h b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.h new file mode 100644 index 0000000..5a7f46a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/transports/ws/ws_handshake.h @@ -0,0 +1,177 @@ +/* + Copyright (c) 2013 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_WS_HANDSHAKE_INCLUDED +#define NN_WS_HANDSHAKE_INCLUDED + +#include "../../transport.h" + +#include "../../aio/fsm.h" +#include "../../aio/usock.h" +#include "../../aio/timer.h" + +/* This state machine exchanges a handshake with a WebSocket client. */ + +/* Return codes of this state machine. */ +#define NN_WS_HANDSHAKE_OK 1 +#define NN_WS_HANDSHAKE_ERROR 2 +#define NN_WS_HANDSHAKE_STOPPED 3 + +/* WebSocket endpoint modes that determine framing of Tx/Rx and + Opening Handshake HTTP headers. */ +#define NN_WS_CLIENT 1 +#define NN_WS_SERVER 2 + +/* A ws:// buffer for nanomsg is intentionally smaller than recommendation of + RFC 7230 3.1.1 since it neither requires nor accepts arbitrarily large + headers. */ +#define NN_WS_HANDSHAKE_MAX_SIZE 4096 + +/* WebSocket protocol tokens as per RFC 6455. */ +#define NN_WS_HANDSHAKE_MAGIC_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" +#define NN_WS_HANDSHAKE_CRLF "\r\n" +#define NN_WS_HANDSHAKE_TERMSEQ "\r\n\r\n" +#define NN_WS_HANDSHAKE_TERMSEQ_LEN strlen (NN_WS_HANDSHAKE_TERMSEQ) + +/* Expected Accept Key length based on RFC 6455 4.2.2.5.4. */ +#define NN_WS_HANDSHAKE_ACCEPT_KEY_LEN 28 + +struct nn_ws_handshake { + + /* The state machine. */ + struct nn_fsm fsm; + int state; + + /* Controls HTTP headers and behavior based on whether this peer is + acting as a Client or a Server. */ + int mode; + + /* Used to timeout opening handshake. */ + struct nn_timer timer; + int timeout; + + /* The underlying socket. */ + struct nn_usock *usock; + + /* The original owner of the underlying socket. */ + struct nn_fsm_owner usock_owner; + + /* Handle to the pipe. */ + struct nn_pipebase *pipebase; + + /* Requested resource when acting as client. */ + const char* resource; + + /* Remote Host in header request when acting as client. */ + const char* remote_host; + + /* Opening handshake verbatim from client as per RFC 6455 1.3. */ + char opening_hs [NN_WS_HANDSHAKE_MAX_SIZE]; + + /* Monitor/control the opening recv poll. */ + int retries; + size_t recv_pos; + size_t recv_len; + + /* Expected handshake fields from client as per RFC 6455 4.1, + where these pointers reference the opening_hs. */ + const char *host; + size_t host_len; + + const char *origin; + size_t origin_len; + + const char *key; + size_t key_len; + + const char *upgrade; + size_t upgrade_len; + + const char *conn; + size_t conn_len; + + const char *version; + size_t version_len; + + /* Expected handshake fields from client required by nanomsg. */ + const char *protocol; + size_t protocol_len; + + /* Expected handshake fields from server as per RFC 6455 4.2.2. */ + const char *server; + size_t server_len; + + const char *accept_key; + size_t accept_key_len; + + char expected_accept_key [NN_WS_HANDSHAKE_ACCEPT_KEY_LEN + 1]; + + const char *status_code; + size_t status_code_len; + + const char *reason_phrase; + size_t reason_phrase_len; + + /* Unused, optional handshake fields. */ + const char *uri; + size_t uri_len; + const char *extensions; + size_t extensions_len; + + /* Identifies the response to be sent to client's opening handshake. */ + int response_code; + + /* Response to send back to client. */ + char response [512]; + + /* Event fired when the state machine ends. */ + struct nn_fsm_event done; +}; + +/* Structure that maps scalability protocol to corresponding + WebSocket header values. */ +struct nn_ws_sp_map { + + /* Scalability Protocol ID for server... */ + int server; + + /* ... and corresponding client Protocol ID */ + int client; + + /* ... and corresponding WebSocket header field value. */ + const char* ws_sp; +}; + +void nn_ws_handshake_init (struct nn_ws_handshake *self, int src, + struct nn_fsm *owner); +void nn_ws_handshake_term (struct nn_ws_handshake *self); + +int nn_ws_handshake_isidle (struct nn_ws_handshake *self); +void nn_ws_handshake_start (struct nn_ws_handshake *self, + struct nn_usock *usock, struct nn_pipebase *pipebase, + int mode, const char *resource, const char *host); +void nn_ws_handshake_stop (struct nn_ws_handshake *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/README b/node/node_modules/nanomsg/deps/nanomsg/src/utils/README new file mode 100644 index 0000000..e4462ed --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/README @@ -0,0 +1,3 @@ +This directory contains the utilities. Utilities are general-purpose components +that may be used by the core library as well as by individual transports and +scalability protocols. diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/alloc.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/alloc.c new file mode 100644 index 0000000..59c229d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/alloc.c @@ -0,0 +1,148 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "alloc.h" + +#if defined NN_ALLOC_MONITOR + +#include "mutex.h" + +#include +#include +#include +#include + +struct nn_alloc_hdr { + size_t size; + const char *name; +}; + +static struct nn_mutex nn_alloc_sync; +static size_t nn_alloc_bytes; +static size_t nn_alloc_blocks; + +void nn_alloc_init (void) +{ + nn_mutex_init (&nn_alloc_sync); + nn_alloc_bytes = 0; + nn_alloc_blocks = 0; +} + +void nn_alloc_term (void) +{ + nn_mutex_term (&nn_alloc_sync); +} + +void *nn_alloc_ (size_t size, const char *name) +{ + uint8_t *chunk; + + chunk = malloc (sizeof (struct nn_alloc_hdr) + size); + if (!chunk) + return NULL; + + nn_mutex_lock (&nn_alloc_sync); + ((struct nn_alloc_hdr*) chunk)->size = size; + ((struct nn_alloc_hdr*) chunk)->name = name; + nn_alloc_bytes += size; + ++nn_alloc_blocks; + printf ("Allocating %s (%zu bytes)\n", name, size); + printf ("Current memory usage: %zu bytes in %zu blocks\n", + nn_alloc_bytes, nn_alloc_blocks); + nn_mutex_unlock (&nn_alloc_sync); + + return chunk + sizeof (struct nn_alloc_hdr); +} + +void *nn_realloc (void *ptr, size_t size) +{ + struct nn_alloc_hdr *oldchunk; + struct nn_alloc_hdr *newchunk; + size_t oldsize; + + oldchunk = ((struct nn_alloc_hdr*) ptr) - 1; + oldsize = oldchunk->size; + newchunk = realloc (oldchunk, sizeof (struct nn_alloc_hdr) + size); + if (!newchunk) + return NULL; + newchunk->size = size; + + nn_mutex_lock (&nn_alloc_sync); + nn_alloc_bytes -= oldsize; + nn_alloc_bytes += size; + printf ("Reallocating %s (%zu bytes to %zu bytes)\n", + newchunk->name, oldsize, size); + printf ("Current memory usage: %zu bytes in %zu blocks\n", + nn_alloc_bytes, nn_alloc_blocks); + nn_mutex_unlock (&nn_alloc_sync); + + return newchunk + sizeof (struct nn_alloc_hdr); +} + +void nn_free (void *ptr) +{ + struct nn_alloc_hdr *chunk; + + if (!ptr) + return; + chunk = ((struct nn_alloc_hdr*) ptr) - 1; + + nn_mutex_lock (&nn_alloc_sync); + nn_alloc_bytes -= chunk->size; + --nn_alloc_blocks; + printf ("Deallocating %s (%zu bytes)\n", chunk->name, chunk->size); + printf ("Current memory usage: %zu bytes in %zu blocks\n", + nn_alloc_bytes, nn_alloc_blocks); + nn_mutex_unlock (&nn_alloc_sync); + + free (chunk); +} + +#else + +#include + +void nn_alloc_init (void) +{ +} + +void nn_alloc_term (void) +{ +} + +void *nn_alloc_ (size_t size) +{ + return malloc (size); +} + +void *nn_realloc (void *ptr, size_t size) +{ + return realloc (ptr, size); +} + +void nn_free (void *ptr) +{ + free (ptr); +} + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/alloc.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/alloc.h new file mode 100644 index 0000000..9c4bf77 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/alloc.h @@ -0,0 +1,45 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_ALLOC_INCLUDED +#define NN_ALLOC_INCLUDED + +#include + +/* These functions allow for interception of memory allocation-related + functionality. */ + +void nn_alloc_init (void); +void nn_alloc_term (void); +void *nn_realloc (void *ptr, size_t size); +void nn_free (void *ptr); + +#if defined NN_ALLOC_MONITOR +#define nn_alloc(size, name) nn_alloc_ (size, name) +void *nn_alloc_ (size_t size, const char *name); +#else +#define nn_alloc(size, name) nn_alloc_(size) +void *nn_alloc_ (size_t size); +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/atomic.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/atomic.c new file mode 100644 index 0000000..4018c7e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/atomic.c @@ -0,0 +1,80 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "atomic.h" +#include "err.h" + +void nn_atomic_init (struct nn_atomic *self, uint32_t n) +{ + self->n = n; +#if defined NN_ATOMIC_MUTEX + nn_mutex_init (&self->sync); +#endif +} + +void nn_atomic_term (struct nn_atomic *self) +{ +#if defined NN_ATOMIC_MUTEX + nn_mutex_term (&self->sync); +#endif +} + +uint32_t nn_atomic_inc (struct nn_atomic *self, uint32_t n) +{ +#if defined NN_ATOMIC_WINAPI + return (uint32_t) InterlockedExchangeAdd ((LONG*) &self->n, n); +#elif defined NN_ATOMIC_SOLARIS + return atomic_add_32_nv (&self->n, n) - n; +#elif defined NN_ATOMIC_GCC_BUILTINS + return (uint32_t) __sync_fetch_and_add (&self->n, n); +#elif defined NN_ATOMIC_MUTEX + uint32_t res; + nn_mutex_lock (&self->sync); + res = self->n; + self->n += n; + nn_mutex_unlock (&self->sync); + return res; +#else +#error +#endif +} + +uint32_t nn_atomic_dec (struct nn_atomic *self, uint32_t n) +{ +#if defined NN_ATOMIC_WINAPI + return (uint32_t) InterlockedExchangeAdd ((LONG*) &self->n, -((LONG) n)); +#elif defined NN_ATOMIC_SOLARIS + return atomic_add_32_nv (&self->n, -((int32_t) n)) + n; +#elif defined NN_ATOMIC_GCC_BUILTINS + return (uint32_t) __sync_fetch_and_sub (&self->n, n); +#elif defined NN_ATOMIC_MUTEX + uint32_t res; + nn_mutex_lock (&self->sync); + res = self->n; + self->n -= n; + nn_mutex_unlock (&self->sync); + return res; +#else +#error +#endif +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/atomic.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/atomic.h new file mode 100644 index 0000000..ba746fe --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/atomic.h @@ -0,0 +1,61 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_ATOMIC_INCLUDED +#define NN_ATOMIC_INCLUDED + +#if defined NN_HAVE_WINDOWS +#include "win.h" +#define NN_ATOMIC_WINAPI +#elif NN_HAVE_ATOMIC_SOLARIS +#include +#define NN_ATOMIC_SOLARIS +#elif defined NN_HAVE_GCC_ATOMIC_BUILTINS +#define NN_ATOMIC_GCC_BUILTINS +#else +#include "mutex.h" +#define NN_ATOMIC_MUTEX +#endif + +#include + +struct nn_atomic { +#if defined NN_ATOMIC_MUTEX + struct nn_mutex sync; +#endif + volatile uint32_t n; +}; + +/* Initialise the object. Set it to value 'n'. */ +void nn_atomic_init (struct nn_atomic *self, uint32_t n); + +/* Destroy the object. */ +void nn_atomic_term (struct nn_atomic *self); + +/* Atomically add n to the object, return old value of the object. */ +uint32_t nn_atomic_inc (struct nn_atomic *self, uint32_t n); + +/* Atomically subtract n from the object, return old value of the object. */ +uint32_t nn_atomic_dec (struct nn_atomic *self, uint32_t n); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/attr.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/attr.h new file mode 100644 index 0000000..9b010e5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/attr.h @@ -0,0 +1,32 @@ +/* + Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_ATTR_INCLUDED +#define NN_ATTR_INCLUDED + +#if defined __GNUC__ || defined __llvm__ +#define NN_UNUSED __attribute__ ((unused)) +#else +#define NN_UNUSED +#endif + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunk.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunk.c new file mode 100644 index 0000000..702fdab --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunk.c @@ -0,0 +1,232 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2014 Achille Roussel All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "chunk.h" +#include "atomic.h" +#include "alloc.h" +#include "fast.h" +#include "wire.h" +#include "err.h" + +#include + +#define NN_CHUNK_TAG 0xdeadcafe +#define NN_CHUNK_TAG_DEALLOCATED 0xbeadfeed + +typedef void (*nn_chunk_free_fn) (void *p); + +struct nn_chunk { + + /* Number of places the chunk is referenced from. */ + struct nn_atomic refcount; + + /* Size of the message in bytes. */ + size_t size; + + /* Deallocation function. */ + nn_chunk_free_fn ffn; + + /* The structure if followed by optional empty space, a 32 bit unsigned + integer specifying the size of said empty space, a 32 bit tag and + the message data itself. */ +}; + +/* Private functions. */ +static struct nn_chunk *nn_chunk_getptr (void *p); +static void *nn_chunk_getdata (struct nn_chunk *c); +static void nn_chunk_default_free (void *p); +static size_t nn_chunk_hdrsize (); + +int nn_chunk_alloc (size_t size, int type, void **result) +{ + size_t sz; + struct nn_chunk *self; + const size_t hdrsz = nn_chunk_hdrsize (); + + /* Compute total size to be allocated. Check for overflow. */ + sz = hdrsz + size; + if (nn_slow (sz < hdrsz)) + return -ENOMEM; + + /* Allocate the actual memory depending on the type. */ + switch (type) { + case 0: + self = nn_alloc (sz, "message chunk"); + break; + default: + return -EINVAL; + } + if (nn_slow (!self)) + return -ENOMEM; + + /* Fill in the chunk header. */ + nn_atomic_init (&self->refcount, 1); + self->size = size; + self->ffn = nn_chunk_default_free; + + /* Fill in the size of the empty space between the chunk header + and the message. */ + nn_putl ((uint8_t*) ((uint32_t*) (self + 1)), 0); + + /* Fill in the tag. */ + nn_putl ((uint8_t*) ((((uint32_t*) (self + 1))) + 1), NN_CHUNK_TAG); + + *result = nn_chunk_getdata (self); + return 0; +} + +int nn_chunk_realloc (size_t size, void **chunk) +{ + struct nn_chunk *self; + struct nn_chunk *new_chunk; + void *new_ptr; + size_t hdr_size; + size_t new_size; + int rc; + + self = nn_chunk_getptr (*chunk); + + /* Check if we only have one reference to this object, in that case we can + reallocate the memory chunk. */ + if (self->refcount.n == 1) { + + /* Compute new size, check for overflow. */ + hdr_size = nn_chunk_hdrsize (); + new_size = hdr_size + size; + if (nn_slow (new_size < hdr_size)) + return -ENOMEM; + + /* Reallocate memory chunk. */ + new_chunk = nn_realloc (self, new_size); + if (nn_slow (new_chunk == NULL)) + return -ENOMEM; + + new_chunk->size = size; + *chunk = nn_chunk_getdata (new_chunk); + } + + /* There are many references to this memory chunk, we have to create a new + one and copy the data. */ + else { + new_ptr = NULL; + rc = nn_chunk_alloc (size, 0, &new_ptr); + + if (nn_slow (rc != 0)) { + return rc; + } + + memcpy (new_ptr, nn_chunk_getdata (self), self->size); + *chunk = new_ptr; + nn_atomic_dec (&self->refcount, 1); + } + + return 0; +} + +void nn_chunk_free (void *p) +{ + struct nn_chunk *self; + + self = nn_chunk_getptr (p); + + /* Decrement the reference count. Actual deallocation happens only if + it drops to zero. */ + if (nn_atomic_dec (&self->refcount, 1) <= 1) { + + /* Mark chunk as deallocated. */ + nn_putl ((uint8_t*) (((uint32_t*) p) - 1), NN_CHUNK_TAG_DEALLOCATED); + + /* Deallocate the resources held by the chunk. */ + nn_atomic_term (&self->refcount); + + /* Deallocate the memory block according to the allocation + mechanism specified. */ + self->ffn (self); + } +} + +void nn_chunk_addref (void *p, uint32_t n) +{ + struct nn_chunk *self; + + self = nn_chunk_getptr (p); + + nn_atomic_inc (&self->refcount, n); +} + + +size_t nn_chunk_size (void *p) +{ + return nn_chunk_getptr (p)->size; +} + +void *nn_chunk_trim (void *p, size_t n) +{ + struct nn_chunk *self; + const size_t hdrsz = sizeof (struct nn_chunk) + 2 * sizeof (uint32_t); + size_t empty_space; + + self = nn_chunk_getptr (p); + + /* Sanity check. We cannot trim more bytes than there are in the chunk. */ + nn_assert (n <= self->size); + + /* Adjust the chunk header. */ + p = ((uint8_t*) p) + n; + nn_putl ((uint8_t*) (((uint32_t*) p) - 1), NN_CHUNK_TAG); + empty_space = (uint8_t*) p - (uint8_t*) self - hdrsz; + nn_assert(empty_space < UINT32_MAX); + nn_putl ((uint8_t*) (((uint32_t*) p) - 2), (uint32_t) empty_space); + + /* Adjust the size of the message. */ + self->size -= n; + + return p; +} + +static struct nn_chunk *nn_chunk_getptr (void *p) +{ + uint32_t off; + + nn_assert (nn_getl ((uint8_t*) p - sizeof (uint32_t)) == NN_CHUNK_TAG); + off = nn_getl ((uint8_t*) p - 2 * sizeof (uint32_t)); + + return (struct nn_chunk*) ((uint8_t*) p - 2 *sizeof (uint32_t) - off - + sizeof (struct nn_chunk)); +} + +static void *nn_chunk_getdata (struct nn_chunk *self) +{ + return ((uint8_t*) (self + 1)) + 2 * sizeof (uint32_t); +} + +static void nn_chunk_default_free (void *p) +{ + nn_free (p); +} + +static size_t nn_chunk_hdrsize () +{ + return sizeof (struct nn_chunk) + 2 * sizeof (uint32_t); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunk.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunk.h new file mode 100644 index 0000000..762f215 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunk.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CHUNK_INCLUDED +#define NN_CHUNK_INCLUDED + +#include +#include + +/* Allocates the chunk using the allocation mechanism specified by 'type'. */ +int nn_chunk_alloc (size_t size, int type, void **result); + +/* Resizes a chunk previously allocated with nn_chunk_alloc. */ +int nn_chunk_realloc (size_t size, void **chunk); + +/* Releases a reference to the chunk and once the reference count had dropped + to zero, deallocates the chunk. */ +void nn_chunk_free (void *p); + +/* Increases the reference count of the chunk by 'n'. */ +void nn_chunk_addref (void *p, uint32_t n); + +/* Returns size of the chunk buffer. */ +size_t nn_chunk_size (void *p); + +/* Trims n bytes from the beginning of the chunk. Returns pointer to the new + chunk. */ +void *nn_chunk_trim (void *p, size_t n); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunkref.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunkref.c new file mode 100644 index 0000000..8f7eaa8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunkref.c @@ -0,0 +1,156 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "chunkref.h" +#include "err.h" + +#include + +/* nn_chunkref should be reinterpreted as this structure in case the first + byte ('tag') is 0xff. */ +struct nn_chunkref_chunk { + uint8_t tag; + void *chunk; +}; + +/* Check whether VSM are small enough for size to fit into the first byte + of the structure. */ +CT_ASSERT (NN_CHUNKREF_MAX < 255); + +/* Check whether nn_chunkref_chunk fits into nn_chunkref. */ +CT_ASSERT (sizeof (struct nn_chunkref) >= sizeof (struct nn_chunkref_chunk)); + +void nn_chunkref_init (struct nn_chunkref *self, size_t size) +{ + int rc; + struct nn_chunkref_chunk *ch; + + if (size < NN_CHUNKREF_MAX) { + self->u.ref [0] = (uint8_t) size; + return; + } + + ch = (struct nn_chunkref_chunk*) self; + ch->tag = 0xff; + rc = nn_chunk_alloc (size, 0, &ch->chunk); + errno_assert (rc == 0); +} + +void nn_chunkref_init_chunk (struct nn_chunkref *self, void *chunk) +{ + struct nn_chunkref_chunk *ch; + + ch = (struct nn_chunkref_chunk*) self; + ch->tag = 0xff; + ch->chunk = chunk; +} + +void nn_chunkref_term (struct nn_chunkref *self) +{ + struct nn_chunkref_chunk *ch; + + if (self->u.ref [0] == 0xff) { + ch = (struct nn_chunkref_chunk*) self; + nn_chunk_free (ch->chunk); + } +} + +void *nn_chunkref_getchunk (struct nn_chunkref *self) +{ + int rc; + struct nn_chunkref_chunk *ch; + void *chunk; + + if (self->u.ref [0] == 0xff) { + ch = (struct nn_chunkref_chunk*) self; + self->u.ref [0] = 0; + return ch->chunk; + } + + rc = nn_chunk_alloc (self->u.ref [0], 0, &chunk); + errno_assert (rc == 0); + memcpy (chunk, &self->u.ref [1], self->u.ref [0]); + self->u.ref [0] = 0; + return chunk; +} + +void nn_chunkref_mv (struct nn_chunkref *dst, struct nn_chunkref *src) +{ + memcpy (dst, src, src->u.ref [0] == 0xff ? + (int)sizeof (struct nn_chunkref_chunk) : src->u.ref [0] + 1); +} + +void nn_chunkref_cp (struct nn_chunkref *dst, struct nn_chunkref *src) +{ + struct nn_chunkref_chunk *ch; + + if (src->u.ref [0] == 0xff) { + ch = (struct nn_chunkref_chunk*) src; + nn_chunk_addref (ch->chunk, 1); + } + memcpy (dst, src, sizeof (struct nn_chunkref)); +} + +void *nn_chunkref_data (struct nn_chunkref *self) +{ + return self->u.ref [0] == 0xff ? + ((struct nn_chunkref_chunk*) self)->chunk : + &self->u.ref [1]; +} + +size_t nn_chunkref_size (struct nn_chunkref *self) +{ + return self->u.ref [0] == 0xff ? + nn_chunk_size (((struct nn_chunkref_chunk*) self)->chunk) : + self->u.ref [0]; +} + +void nn_chunkref_trim (struct nn_chunkref *self, size_t n) +{ + struct nn_chunkref_chunk *ch; + + if (self->u.ref [0] == 0xff) { + ch = (struct nn_chunkref_chunk*) self; + ch->chunk = nn_chunk_trim (ch->chunk, n); + return; + } + + nn_assert (self->u.ref [0] >= n); + memmove (&self->u.ref [1], &self->u.ref [1 + n], self->u.ref [0] - n); + self->u.ref [0] -= (uint8_t) n; +} + +void nn_chunkref_bulkcopy_start (struct nn_chunkref *self, uint32_t copies) +{ + struct nn_chunkref_chunk *ch; + + if (self->u.ref [0] == 0xff) { + ch = (struct nn_chunkref_chunk*) self; + nn_chunk_addref (ch->chunk, copies); + } +} + +void nn_chunkref_bulkcopy_cp (struct nn_chunkref *dst, struct nn_chunkref *src) +{ + memcpy (dst, src, sizeof (struct nn_chunkref)); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunkref.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunkref.h new file mode 100644 index 0000000..e4b9349 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/chunkref.h @@ -0,0 +1,90 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CHUNKREF_INCLUDED +#define NN_CHUNKREF_INCLUDED + +#define NN_CHUNKREF_MAX 32 + +#include "chunk.h" + +#include +#include + +/* This class represents a reference to a data chunk. It's either an actual + reference to data allocated on the heap, or if short enough, it may store + the data in itself. While user messages are not often short enough to store + them inside the chunkref itself, SP protocol headers mostly are and thus + we can avoid additional memory allocation per message. */ + +struct nn_chunkref { + union { + uint8_t ref [NN_CHUNKREF_MAX]; + + /* This option is present only to force alignemt of nn_chunkref to + the word boudnary. */ + void *unused; + } u; +}; + +/* Initialise the chunkref. The actual storage will be either on stack (for + small messages, or will be allocated via nn_chunk object. */ +void nn_chunkref_init (struct nn_chunkref *self, size_t size); + +/* Create a chunkref from an existing chunk object. */ +void nn_chunkref_init_chunk (struct nn_chunkref *self, void *chunk); + +/* Deallocate the chunk. */ +void nn_chunkref_term (struct nn_chunkref *self); + +/* Get the underlying chunk. If it doesn't exist (small messages) it allocates + one. Chunkref points to empty chunk after the call. */ +void *nn_chunkref_getchunk (struct nn_chunkref *self); + +/* Moves chunk content from src to dst. dst should not be initialised before + calling this function. After the call, dst becomes initialised and src + becomes uninitialised. */ +void nn_chunkref_mv (struct nn_chunkref *dst, struct nn_chunkref *src); + +/* Copies chunk content from src to dst. dst should not be initialised before + calling this function. */ +void nn_chunkref_cp (struct nn_chunkref *dst, struct nn_chunkref *src); + +/* Returns the pointer to the binary data stored in the chunk. */ +void *nn_chunkref_data (struct nn_chunkref *self); + +/* Returns the size of the binary data stored in the chunk. */ +size_t nn_chunkref_size (struct nn_chunkref *self); + +/* Trims n bytes from the beginning of the chunk. */ +void nn_chunkref_trim (struct nn_chunkref *self, size_t n); + +/* Bulk copying is done by first invoking nn_chunkref_bulkcopy_start on the + source chunk and specifying how many copies of the chunk will be made. + Then, nn_chunkref_bulkcopy_cp should be used 'copies' of times to make + individual copies of the source chunk. Note: Using bulk copying is more + efficient than making each copy separately. */ +void nn_chunkref_bulkcopy_start (struct nn_chunkref *self, uint32_t copies); +void nn_chunkref_bulkcopy_cp (struct nn_chunkref *dst, struct nn_chunkref *src); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/clock.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/clock.c new file mode 100644 index 0000000..28d7f9b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/clock.c @@ -0,0 +1,90 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2012 Julien Ammous + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#if defined NN_HAVE_WINDOWS +#include "win.h" +#elif defined NN_HAVE_OSX +#include +#elif defined NN_HAVE_CLOCK_MONOTONIC || defined NN_HAVE_GETHRTIME +#include +#else +#include +#endif + +#include "clock.h" +#include "fast.h" +#include "err.h" +#include "attr.h" + +uint64_t nn_clock_ms (void) +{ +#if defined NN_HAVE_WINDOWS + + LARGE_INTEGER tps; + LARGE_INTEGER time; + double tpms; + + QueryPerformanceFrequency (&tps); + QueryPerformanceCounter (&time); + tpms = (double) (tps.QuadPart / 1000); + return (uint64_t) (time.QuadPart / tpms); + +#elif defined NN_HAVE_OSX + + static mach_timebase_info_data_t nn_clock_timebase_info; + uint64_t ticks; + + /* If the global timebase info is not initialised yet, init it. */ + if (nn_slow (!nn_clock_timebase_info.denom)) + mach_timebase_info (&nn_clock_timebase_info); + + ticks = mach_absolute_time (); + return ticks * nn_clock_timebase_info.numer / + nn_clock_timebase_info.denom / 1000000; + +#elif defined NN_HAVE_CLOCK_MONOTONIC + + int rc; + struct timespec tv; + + rc = clock_gettime (CLOCK_MONOTONIC, &tv); + errno_assert (rc == 0); + return tv.tv_sec * (uint64_t) 1000 + tv.tv_nsec / 1000000; + +#elif defined NN_HAVE_GETHRTIME + + return gethrtime () / 1000000; + +#else + + int rc; + struct timeval tv; + + /* Gettimeofday is slow on some systems. Moreover, it's not necessarily + monotonic. Thus, it's used as a last resort mechanism. */ + rc = gettimeofday (&tv, NULL); + errno_assert (rc == 0); + return tv.tv_sec * (uint64_t) 1000 + tv.tv_usec / 1000; + +#endif +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/clock.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/clock.h new file mode 100644 index 0000000..5f8b1ba --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/clock.h @@ -0,0 +1,32 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CLOCK_INCLUDED +#define NN_CLOCK_INCLUDED + +#include + +/* Returns current time in milliseconds. */ +uint64_t nn_clock_ms (void); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/closefd.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/closefd.c new file mode 100644 index 0000000..1d339a6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/closefd.c @@ -0,0 +1,46 @@ +/* + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#if !defined NN_HAVE_WINDOWS + +#include "closefd.h" +#include "fast.h" +#include "err.h" + +#include + +void nn_closefd (int fd) +{ + int rc; + if (nn_slow (fd < 0)) { + return; + } + rc = close (fd); + if (nn_fast (rc == 0)) + return; + errno_assert (errno == EINTR || errno == ETIMEDOUT || + errno == EWOULDBLOCK || errno == EINPROGRESS || errno == ECONNRESET); +} + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/closefd.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/closefd.h new file mode 100644 index 0000000..fd3c8cf --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/closefd.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CLOSEFD_INCLUDED +#define NN_CLOSEFD_INCLUDED + +#if !defined NN_HAVE_WINDOWS + +void nn_closefd (int fd); + +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/condvar.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/condvar.c new file mode 100644 index 0000000..86f8d94 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/condvar.c @@ -0,0 +1,147 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "mutex.h" +#include "condvar.h" +#include "err.h" + +#if NN_HAVE_WINDOWS + +int nn_condvar_init (nn_condvar_t *cond) +{ + InitializeConditionVariable (&cond->cv); + return (0); +} + +void nn_condvar_term (nn_condvar_t *cond) +{ +} + +int nn_condvar_wait (nn_condvar_t *cond, nn_mutex_t *lock, int timeout) +{ + BOOL brc; + DWORD expire; + + /* Likely this is redundant, but for API correctness be explicit. */ + expire = (timeout < 0) ? INFINITE : (DWORD) timeout; + + /* We must own the lock if we are going to call this. */ + nn_assert (lock->owner == GetCurrentThreadId()); + /* Clear ownership as SleepConditionVariableCS will drop it. */ + lock->owner = 0; + + brc = SleepConditionVariableCS (&cond->cv, &lock->cs, expire); + + /* We have reacquired the lock, so nobody should own it right now. */ + nn_assert (lock->owner == 0); + /* Note we own it now. */ + lock->owner = GetCurrentThreadId(); + + if (!brc && GetLastError () == ERROR_TIMEOUT) { + return (-ETIMEDOUT); + } + return (0); +} + +void nn_condvar_signal (nn_condvar_t *cond) +{ + WakeConditionVariable (&cond->cv); +} + +void nn_condvar_broadcast (nn_condvar_t *cond) +{ + WakeAllConditionVariable (&cond->cv); +} + +#else /* !NN_HAVE_WINDOWS */ + +#include + +int nn_condvar_init (nn_condvar_t *cond) +{ + int rc; + + /* This should really never fail, but the system may do so for + ENOMEM or EAGAIN due to resource exhaustion, or EBUSY if reusing + a condition variable with no intervening destroy call. */ + rc = pthread_cond_init (&cond->cv, NULL); + return (-rc); +} + +void nn_condvar_term (nn_condvar_t *cond) +{ + int rc; + + /* This should never fail, the system is allowed to return EBUSY if + there are outstanding waiters (a serious bug!), or EINVAL if the + cv is somehow invalid or illegal. Either of these cases would + represent a serious programming defect in our caller. */ + rc = pthread_cond_destroy (&cond->cv); + errnum_assert (rc == 0, rc); +} + +int nn_condvar_wait (nn_condvar_t *cond, nn_mutex_t *lock, int timeout) +{ + int rc; + struct timeval tv; + struct timespec ts; + + if (timeout < 0) { + /* This is an infinite sleep. We don't care about return values, + as any error we can treat as just a premature wakeup. */ + (void) pthread_cond_wait (&cond->cv, &lock->mutex); + return (0); + } + + rc = gettimeofday(&tv, NULL); + errnum_assert (rc == 0, rc); + + /* There are extra operations performed here, but they are done to avoid + wrap of the tv_usec and ts_nsec members on 32-bit systems. */ + tv.tv_sec += timeout / 1000; + tv.tv_usec += (timeout % 1000) * 1000; + + ts.tv_sec = tv.tv_sec + (tv.tv_usec / 1000000); + ts.tv_nsec = (tv.tv_usec % 1000000) * 1000; + + rc = pthread_cond_timedwait (&cond->cv, &lock->mutex, &ts); + if (rc == ETIMEDOUT) + return (-ETIMEDOUT); + /* Treat all other cases (including errors) as normal wakeup. */ + return (0); +} + +void nn_condvar_signal (nn_condvar_t *cond) +{ + /* The only legal failure mode here is EINVAL if we passed a bad + condition variable. We don't check that. */ + (void) pthread_cond_signal (&cond->cv); +} + +void nn_condvar_broadcast (nn_condvar_t *cond) +{ + /* The only legal failure mode here is EINVAL if we passed a bad + condition variable. We don't check that. */ + (void) pthread_cond_broadcast (&cond->cv); +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/condvar.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/condvar.h new file mode 100644 index 0000000..2d885e0 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/condvar.h @@ -0,0 +1,67 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CONDVAR_INCLUDED +#define NN_CONDVAR_INCLUDED + +#include "mutex.h" + +#ifdef NN_HAVE_WINDOWS +#include "win.h" +struct nn_condvar { + CONDITION_VARIABLE cv; +}; + +#else /* !NN_HAVE_WINDOWS */ + +#include + +struct nn_condvar { + pthread_cond_t cv; +}; + +#endif /* NN_HAVE_WINDOWS */ + +typedef struct nn_condvar nn_condvar_t; + +/* Initialise the condvar. */ +int nn_condvar_init (nn_condvar_t *cond); + +/* Terminate the condvar. */ +void nn_condvar_term (nn_condvar_t *cond); + +/* Sleep on a condition variable, with a possible timeout. The mutex should + be held when calling, and will be dropped on entry and reacquired + atomically on return. The caller will wake when signaled, or when the + timeout expires, but may be woken spuriously as well. If the timeout + expires without a signal, -ETIMEDOUT will be returned, otherwise 0 + will be returned. If expire is < 0, then no timeout will be used, + representing a potentially infinite wait. */ +int nn_condvar_wait (nn_condvar_t *cond, nn_mutex_t *lock, int timeout); + +/* Signal (wake) one condition variable waiter. */ +void nn_condvar_signal (nn_condvar_t *cond); + +/* Signal all condition variable waiters, waking all of them. */ +void nn_condvar_broadcast (nn_condvar_t *cond); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/cont.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/cont.h new file mode 100644 index 0000000..116578f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/cont.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_CONT_INCLUDED +#define NN_CONT_INCLUDED + +#include + +/* Takes a pointer to a member variable and computes pointer to the structure + that contains it. 'type' is type of the structure, not the member. */ +#define nn_cont(ptr, type, member) \ + (ptr ? ((type*) (((char*) ptr) - offsetof(type, member))) : NULL) + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd.c new file mode 100644 index 0000000..b4ff4ba --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd.c @@ -0,0 +1,175 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "efd.h" +#include "clock.h" + +#if defined NN_USE_EVENTFD + #include "efd_eventfd.inc" +#elif defined NN_USE_PIPE + #include "efd_pipe.inc" +#elif defined NN_USE_SOCKETPAIR + #include "efd_socketpair.inc" +#elif defined NN_USE_WINSOCK + #include "efd_win.inc" +#else + #error +#endif + +#if defined NN_HAVE_POLL + +#include + +int nn_efd_wait (struct nn_efd *self, int timeout) +{ + int rc; + struct pollfd pfd; + uint64_t expire; + + if (timeout > 0) { + expire = nn_clock_ms() + timeout; + } else { + expire = timeout; + } + + /* In order to solve a problem where the poll call doesn't wake up + when a file is closed, we sleep a maximum of 100 msec. This is + a somewhat unfortunate band-aid to prevent hangs caused by a race + condition involving nn_close. In the future this code should be + replaced by a simpler design using condition variables. */ + for (;;) { + pfd.fd = nn_efd_getfd (self); + pfd.events = POLLIN; + if (nn_slow (pfd.fd < 0)) + return -EBADF; + + switch (expire) { + case 0: + /* poll once */ + timeout = 0; + break; + + case (uint64_t)-1: + /* infinite wait */ + timeout = 100; + break; + + default: + /* bounded wait */ + timeout = (int)(expire - nn_clock_ms()); + if (timeout < 0) { + return -ETIMEDOUT; + } + if (timeout > 100) { + timeout = 100; + } + } + rc = poll (&pfd, 1, timeout); + if (nn_slow (rc < 0 && errno == EINTR)) + return -EINTR; + errno_assert (rc >= 0); + if (nn_slow (rc == 0)) { + if (expire == 0) + return -ETIMEDOUT; + if ((expire != (uint64_t)-1) && (expire < nn_clock_ms())) { + return -ETIMEDOUT; + } + continue; + } + return 0; + } +} + +#elif defined NN_HAVE_WINDOWS + +int nn_efd_wait (struct nn_efd *self, int timeout) +{ + int rc; + struct timeval tv; + SOCKET fd = self->r; + uint64_t expire; + + if (timeout > 0) { + expire = nn_clock_ms() + timeout; + tv.tv_sec = timeout / 1000; + tv.tv_usec = timeout % 1000 * 1000; + } else { + expire = timeout; + } + + for (;;) { + if (nn_slow (fd == INVALID_SOCKET)) { + return -EBADF; + } + FD_SET (fd, &self->fds); + switch (expire) { + case 0: + tv.tv_sec = 0; + tv.tv_usec = 0; + break; + case (uint64_t)-1: + tv.tv_sec = 0; + tv.tv_usec = 100000; + break; + default: + timeout = (int)(expire - nn_clock_ms()); + if (timeout < 0) { + return -ETIMEDOUT; + } + if (timeout > 100) { + tv.tv_sec = 0; + tv.tv_usec = 100000; + } else { + tv.tv_sec = timeout / 1000; + tv.tv_usec = timeout % 1000 * 1000; + } + } + rc = select (0, &self->fds, NULL, NULL, &tv); + + if (nn_slow (rc == SOCKET_ERROR)) { + rc = nn_err_wsa_to_posix (WSAGetLastError ()); + errno = rc; + + /* Treat these as a non-fatal errors, typically occuring when the + socket is being closed from a separate thread during a blocking + I/O operation. */ + if (rc == EINTR || rc == ENOTSOCK) + return self->r == INVALID_SOCKET ? -EBADF : -EINTR; + } else if (rc == 0) { + if (expire == 0) + return -ETIMEDOUT; + if ((expire != (uint64_t)-1) && (expire < nn_clock_ms())) { + return -ETIMEDOUT; + } + continue; + } + + wsa_assert (rc >= 0); + return 0; + } +} + +#else + #error +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd.h new file mode 100644 index 0000000..2e5f52d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd.h @@ -0,0 +1,70 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_EFD_INCLUDED +#define NN_EFD_INCLUDED + +/* Provides a way to send signals via file descriptors. The important part + is that nn_efd_getfd() returns an actual OS-level file descriptor that + you can poll on to wait for the event. */ + +#include "fd.h" + +#if defined NN_USE_EVENTFD + #include "efd_eventfd.h" +#elif defined NN_USE_PIPE + #include "efd_pipe.h" +#elif defined NN_USE_SOCKETPAIR + #include "efd_socketpair.h" +#elif defined NN_USE_WINSOCK + #include "efd_win.h" +#else + #error +#endif + +/* Initialise the efd object. */ +int nn_efd_init (struct nn_efd *self); + +/* Uninitialise the efd object. */ +void nn_efd_term (struct nn_efd *self); + +/* Get the OS file descriptor that is readable when the efd object + is signaled. */ +nn_fd nn_efd_getfd (struct nn_efd *self); + +/* Stop the efd object. */ +void nn_efd_stop (struct nn_efd *self); + +/* Switch the object into signaled state. */ +void nn_efd_signal (struct nn_efd *self); + +/* Switch the object into unsignaled state. */ +void nn_efd_unsignal (struct nn_efd *self); + +/* Wait till efd object becomes signaled or when timeout (in milliseconds, + nagative value meaning 'infinite') expires. In the former case 0 is + returened. In the latter, -ETIMEDOUT. */ +int nn_efd_wait (struct nn_efd *self, int timeout); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_eventfd.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_eventfd.h new file mode 100644 index 0000000..4740877 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_eventfd.h @@ -0,0 +1,26 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +struct nn_efd { + int efd; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_eventfd.inc b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_eventfd.inc new file mode 100644 index 0000000..5fe1d7e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_eventfd.inc @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "err.h" +#include "closefd.h" + +#include +#include +#include +#include + +int nn_efd_init (struct nn_efd *self) +{ + int rc; + int flags; + + self->efd = eventfd (0, EFD_CLOEXEC); + if (self->efd == -1 && (errno == EMFILE || errno == ENFILE)) + return -EMFILE; + errno_assert (self->efd != -1); + + flags = fcntl (self->efd, F_GETFL, 0); + if (flags == -1) + flags = 0; + rc = fcntl (self->efd, F_SETFL, flags | O_NONBLOCK); + errno_assert (rc != -1); + + return 0; +} + +void nn_efd_term (struct nn_efd *self) +{ + int fd = self->efd; + self->efd = -1; + nn_closefd (fd); +} + +void nn_efd_stop (struct nn_efd *self) +{ + nn_efd_signal (self); +} + +nn_fd nn_efd_getfd (struct nn_efd *self) +{ + return self->efd; +} + +void nn_efd_signal (struct nn_efd *self) +{ + const uint64_t one = 1; + ssize_t nbytes; + int fd = self->efd; + + if (nn_slow (fd < 0)) + return; + + nbytes = write (fd, &one, sizeof (one)); + errno_assert (nbytes == sizeof (one)); +} + +void nn_efd_unsignal (struct nn_efd *self) +{ + uint64_t count; + int fd = self->efd; + + if (nn_slow (fd < 0)) + return; + + /* Extract all the signals from the eventfd. */ + ssize_t sz = read (fd, &count, sizeof (count)); + errno_assert (sz >= 0); + nn_assert (sz == sizeof (count)); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_pipe.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_pipe.h new file mode 100644 index 0000000..17d7ddc --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_pipe.h @@ -0,0 +1,27 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +struct nn_efd { + int r; + int w; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_pipe.inc b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_pipe.inc new file mode 100644 index 0000000..eeb8891 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_pipe.inc @@ -0,0 +1,123 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "err.h" +#include "fast.h" +#include "closefd.h" + +#include +#include +#include +#include + +int nn_efd_init (struct nn_efd *self) +{ + int rc; + int flags; + int p [2]; + +#if defined NN_HAVE_PIPE2 + rc = pipe2 (p, O_NONBLOCK | O_CLOEXEC); +#else + rc = pipe (p); +#endif + if (rc != 0 && (errno == EMFILE || errno == ENFILE)) + return -EMFILE; + errno_assert (rc == 0); + self->r = p [0]; + self->w = p [1]; + +#if !defined NN_HAVE_PIPE2 && defined FD_CLOEXEC + rc = fcntl (self->r, F_SETFD, FD_CLOEXEC); + errno_assert (rc != -1); + rc = fcntl (self->w, F_SETFD, FD_CLOEXEC); + errno_assert (rc != -1); +#endif + +#if !defined NN_HAVE_PIPE2 + flags = fcntl (self->r, F_GETFL, 0); + if (flags == -1) + flags = 0; + rc = fcntl (self->r, F_SETFL, flags | O_NONBLOCK); + errno_assert (rc != -1); +#endif + + return 0; +} + +void nn_efd_term (struct nn_efd *self) +{ + /* Close the read side first. */ + int fd = self->r; + self->r = -1; + nn_closefd (fd); + + fd = self->w; + self->w = -1; + nn_closefd (fd); +} + +void nn_efd_stop (struct nn_efd *self) +{ + /* Close the write side, which wakes up pollers with POLLHUP. */ + int fd = self->w; + self->w = -1; + nn_closefd (fd); +} + +nn_fd nn_efd_getfd (struct nn_efd *self) +{ + return self->r; +} + +void nn_efd_signal (struct nn_efd *self) +{ + ssize_t nbytes; + char c = 101; + int fd = self->w; + + if (nn_slow (fd < 0)) + return; + nbytes = write (self->w, &c, 1); + errno_assert (nbytes != -1); + nn_assert (nbytes == 1); +} + +void nn_efd_unsignal (struct nn_efd *self) +{ + ssize_t nbytes; + uint8_t buf [16]; + + while (1) { + int fd = self->r; + if (nn_slow (fd < 0)) + return; + nbytes = read (fd, buf, sizeof (buf)); + if (nbytes < 0 && errno == EAGAIN) + nbytes = 0; + errno_assert (nbytes >= 0); + if (nn_fast ((size_t) nbytes < sizeof (buf))) + break; + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_socketpair.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_socketpair.h new file mode 100644 index 0000000..45073b7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_socketpair.h @@ -0,0 +1,29 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +typedef int nn_fd; + +struct nn_efd { + int r; + int w; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_socketpair.inc b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_socketpair.inc new file mode 100644 index 0000000..017017f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_socketpair.inc @@ -0,0 +1,122 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "err.h" +#include "fast.h" +#include "closefd.h" + +#include +#include +#include +#include +#include + +int nn_efd_init (struct nn_efd *self) +{ + int rc; + int flags; + int sp [2]; + +#if defined SOCK_CLOEXEC + rc = socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sp); +#else + rc = socketpair (AF_UNIX, SOCK_STREAM, 0, sp); +#endif + if (rc != 0 && (errno == EMFILE || errno == ENFILE)) + return -EMFILE; + errno_assert (rc == 0); + self->r = sp [0]; + self->w = sp [1]; + +#if !defined SOCK_CLOEXEC && defined FD_CLOEXEC + rc = fcntl (self->r, F_SETFD, FD_CLOEXEC); + errno_assert (rc != -1); + rc = fcntl (self->w, F_SETFD, FD_CLOEXEC); + errno_assert (rc != -1); +#endif + + flags = fcntl (self->r, F_GETFL, 0); + if (flags == -1) + flags = 0; + rc = fcntl (self->r, F_SETFL, flags | O_NONBLOCK); + errno_assert (rc != -1); + + return 0; +} + +void nn_efd_stop (struct nn_efd *self) +{ + int fd = self->w; + self->w = -1; + nn_closefd (fd); +} + +void nn_efd_term (struct nn_efd *self) +{ + int fd = self->r; + self->r = -1; + nn_closefd (fd); + fd = self->w; + self->w = -1; + nn_closefd (fd); +} + +nn_fd nn_efd_getfd (struct nn_efd *self) +{ + return self->r; +} + +void nn_efd_signal (struct nn_efd *self) +{ + ssize_t nbytes; + char c = 101; + int fd = self->w; + + if (nn_slow (fd < 0)) + return; +#if defined MSG_NOSIGNAL + nbytes = send (fd, &c, 1, MSG_NOSIGNAL); +#else + nbytes = send (fd, &c, 1, 0); +#endif + errno_assert (nbytes != -1); + nn_assert (nbytes == 1); +} + +void nn_efd_unsignal (struct nn_efd *self) +{ + ssize_t nbytes; + uint8_t buf [16]; + + while (1) { + int fd = self->r; + if (nn_slow (fd < 0)) + return; + nbytes = recv (self->r, buf, sizeof (buf), 0); + if (nbytes < 0 && errno == EAGAIN) + nbytes = 0; + errno_assert (nbytes >= 0); + if (nn_fast (nbytes < sizeof (buf))) + break; + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_win.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_win.h new file mode 100644 index 0000000..988d4fe --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_win.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "win.h" + +struct nn_efd { + SOCKET r; + SOCKET w; + fd_set fds; +}; + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_win.inc b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_win.inc new file mode 100644 index 0000000..03abbb1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/efd_win.inc @@ -0,0 +1,271 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#define NN_EFD_PORT 5907 +#define NN_EFD_RETRIES 1000 + +#include "err.h" +#include "fast.h" + +#include +#include + +int nn_efd_init (struct nn_efd *self) +{ + SECURITY_ATTRIBUTES sa = {0}; + SECURITY_DESCRIPTOR sd; + BOOL brc; + HANDLE sync; + DWORD dwrc; + SOCKET listener; + int rc; + struct sockaddr_in addr; + int addrlen; + BOOL reuseaddr; + BOOL nodelay; + u_long nonblock; + int i; + + /* Make the following critical section accessible to everyone. */ + sa.nLength = sizeof (sa); + sa.bInheritHandle = FALSE; + brc = InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION); + win_assert (brc); + brc = SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE); + win_assert (brc); + sa.lpSecurityDescriptor = &sd; + + /* This function has to be enclosed in a system-wide critical section + so that two instances of the library don't accidentally create an efd + crossing the process boundary. */ + sync = CreateMutex (&sa, FALSE, "Global\\nanomsg-port-mutex"); + win_assert (sync != NULL); + + /* Enter the critical section. If we cannot get the object in 10 seconds + then something is seriously wrong. Just bail. */ + dwrc = WaitForSingleObject (sync, 10000); + switch (dwrc) { + case WAIT_ABANDONED: + case WAIT_OBJECT_0: + break; + case WAIT_TIMEOUT: + rc = ETIMEDOUT; + goto wsafail3; + default: + rc = nn_err_wsa_to_posix (WSAGetLastError ()); + goto wsafail3; + } + + /* Unfortunately, on Windows the only way to send signal to a file + descriptor (SOCKET) is to create a full-blown TCP connecting on top of + the loopback interface. */ + self->w = INVALID_SOCKET; + self->r = INVALID_SOCKET; + + /* Create listening socket. */ + listener = socket (AF_INET, SOCK_STREAM, 0); + if (nn_slow (listener == SOCKET_ERROR)) + goto wsafail; + brc = SetHandleInformation ((HANDLE) listener, HANDLE_FLAG_INHERIT, 0); + win_assert (brc); + + /* This prevents subsequent attempts to create a signaler to fail bacause + of "TCP port in use" problem. */ + reuseaddr = 1; + rc = setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, + (char*) &reuseaddr, sizeof (reuseaddr)); + if (nn_slow (rc == SOCKET_ERROR)) + goto wsafail; + + /* Bind the listening socket to the local port. */ + memset (&addr, 0, sizeof (addr)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + addr.sin_port = htons (NN_EFD_PORT); + rc = bind (listener, (const struct sockaddr*) &addr, sizeof (addr)); + if (nn_slow (rc == SOCKET_ERROR)) + goto wsafail; + + /* Start listening for the incomming connections. In normal case we are + going to accept just a single connection, so backlog buffer of size + 1 is sufficient. */ + rc = listen (listener, 1); + if (nn_slow (rc == SOCKET_ERROR)) + goto wsafail; + + /* The following code is in the loop, because windows sometimes delays + WSAEADDRINUSE error to the `connect` call. But retrying the connection + works like a charm. Still we want to limit number of retries */ + for(i = 0; i < NN_EFD_RETRIES; ++i) { + + /* Create the writer socket. */ + self->w = socket (AF_INET, SOCK_STREAM, 0); + if (nn_slow (listener == SOCKET_ERROR)) + goto wsafail; + brc = SetHandleInformation ((HANDLE) self->w, HANDLE_FLAG_INHERIT, 0); + win_assert (brc); + + /* Set TCP_NODELAY on the writer socket to make efd as fast as possible. + There's only one byte going to be written, so batching would not make + sense anyway. */ + nodelay = 1; + rc = setsockopt (self->w, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay, + sizeof (nodelay)); + if (nn_slow (rc == SOCKET_ERROR)) + goto wsafail; + + /* Connect the writer socket to the listener socket. */ + rc = connect (self->w, (struct sockaddr*) &addr, sizeof (addr)); + if (nn_slow (rc == SOCKET_ERROR)) { + rc = nn_err_wsa_to_posix (WSAGetLastError ()); + if (rc == EADDRINUSE) { + rc = closesocket (self->w); + if (nn_slow (rc == INVALID_SOCKET)) + goto wsafail; + continue; + } + goto wsafail2; + } + break; + } + if (i == NN_EFD_RETRIES) + goto wsafail2; + + for (;;) { + + /* Accept new incoming connection. */ + addrlen = sizeof (addr); + self->r = accept (listener, (struct sockaddr*) &addr, &addrlen); + if (nn_slow (self->r == INVALID_SOCKET || addrlen != sizeof (addr))) + goto wsafail2; + + /* Check that the connection actually comes from the localhost. */ + if (nn_fast (addr.sin_addr.s_addr == htonl (INADDR_LOOPBACK))) + break; + + /* If not so, close the connection and try again. */ + rc = closesocket (self->r); + if (nn_slow (rc == INVALID_SOCKET)) + goto wsafail; + } + + /* Listener socket can be closed now as no more connections for this efd + are going to be established anyway. */ + rc = closesocket (listener); + if (nn_slow (rc == INVALID_SOCKET)) + goto wsafail; + + /* Leave the critical section. */ + brc = ReleaseMutex (sync); + win_assert (brc != 0); + brc = CloseHandle (sync); + win_assert (brc != 0); + + /* Make the receiving socket non-blocking. */ + nonblock = 1; + rc = ioctlsocket (self->r, FIONBIO, &nonblock); + wsa_assert (rc != SOCKET_ERROR); + + /* Initialise the pre-allocated pollset. */ + FD_ZERO (&self->fds); + + return 0; + +wsafail: + rc = nn_err_wsa_to_posix (WSAGetLastError ()); +wsafail2: + brc = ReleaseMutex (sync); + win_assert (brc != 0); +wsafail3: + brc = CloseHandle (sync); + win_assert (brc != 0); + return -rc; +} + +void nn_efd_stop (struct nn_efd *self) +{ + int rc; + SOCKET s = self->w; + self->w = INVALID_SOCKET; + + if (s != INVALID_SOCKET) { + rc = closesocket (s); + wsa_assert (rc != INVALID_SOCKET); + } +} + +void nn_efd_term (struct nn_efd *self) +{ + int rc; + SOCKET s; + + s = self->r; + self->r = INVALID_SOCKET; + if (s != INVALID_SOCKET) { + rc = closesocket (s); + wsa_assert (rc != INVALID_SOCKET); + } + s = self->w; + self->w = INVALID_SOCKET; + if (s != INVALID_SOCKET) { + rc = closesocket (s); + wsa_assert (rc != INVALID_SOCKET); + } +} + +nn_fd nn_efd_getfd (struct nn_efd *self) +{ + return self->r; +} + +void nn_efd_signal (struct nn_efd *self) +{ + int rc; + unsigned char c = 0xec; + SOCKET s = self->w; + + if (nn_fast (s != INVALID_SOCKET)) { + rc = send (s, (char*) &c, 1, 0); + wsa_assert (rc != SOCKET_ERROR); + nn_assert (rc == 1); + } +} + +void nn_efd_unsignal (struct nn_efd *self) +{ + int rc; + uint8_t buf [16]; + + while (1) { + SOCKET s = self->r; + if (nn_slow (s == INVALID_SOCKET)) + break; + rc = recv (s, (char*) buf, sizeof (buf), 0); + if (rc == SOCKET_ERROR && WSAGetLastError () == WSAEWOULDBLOCK) + rc = 0; + wsa_assert (rc != SOCKET_ERROR); + if (nn_fast (rc < sizeof (buf))) + break; + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/err.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/err.c new file mode 100644 index 0000000..e15148d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/err.c @@ -0,0 +1,212 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "err.h" + +#ifdef NN_HAVE_WINDOWS +#include "win.h" +#endif + +#ifdef NN_HAVE_BACKTRACE +#include + +void nn_backtrace_print (void) +{ + void *frames[50]; + int size; + size = backtrace (frames, sizeof (frames) / sizeof (frames[0])); + if (size > 1) { + /* Don't include the frame nn_backtrace_print itself. */ + backtrace_symbols_fd (&frames[1], size-1, fileno (stderr)); + } +} + +/* XXX: Add Windows backtraces */ + +#else +void nn_backtrace_print (void) +{ +} +#endif + +#include + +void nn_err_abort (void) +{ + abort (); +} + +int nn_err_errno (void) +{ + return errno; +} + +const char *nn_err_strerror (int errnum) +{ + switch (errnum) { +#if defined NN_HAVE_WINDOWS + case ENOTSUP: + return "Not supported"; + case EPROTONOSUPPORT: + return "Protocol not supported"; + case ENOBUFS: + return "No buffer space available"; + case ENETDOWN: + return "Network is down"; + case EADDRINUSE: + return "Address in use"; + case EADDRNOTAVAIL: + return "Address not available"; + case ECONNREFUSED: + return "Connection refused"; + case EINPROGRESS: + return "Operation in progress"; + case ENOTSOCK: + return "Not a socket"; + case EAFNOSUPPORT: + return "Address family not supported"; + case EPROTO: + return "Protocol error"; + case EAGAIN: + return "Resource unavailable, try again"; + case EBADF: + return "Bad file descriptor"; + case EINVAL: + return "Invalid argument"; + case EMFILE: + return "Too many open files"; + case EFAULT: + return "Bad address"; + case EACCES: + return "Permission denied"; + case ENETRESET: + return "Connection aborted by network"; + case ENETUNREACH: + return "Network unreachable"; + case EHOSTUNREACH: + return "Host is unreachable"; + case ENOTCONN: + return "The socket is not connected"; + case EMSGSIZE: + return "Message too large"; + case ETIMEDOUT: + return "Timed out"; + case ECONNABORTED: + return "Connection aborted"; + case ECONNRESET: + return "Connection reset"; + case ENOPROTOOPT: + return "Protocol not available"; + case EISCONN: + return "Socket is connected"; +#endif + case ETERM: + return "Nanomsg library was terminated"; + case EFSM: + return "Operation cannot be performed in this state"; + default: +#if defined _MSC_VER +#pragma warning (push) +#pragma warning (disable:4996) +#endif + return strerror (errnum); +#if defined _MSC_VER +#pragma warning (pop) +#endif + } +} + +#ifdef NN_HAVE_WINDOWS + +int nn_err_wsa_to_posix (int wsaerr) +{ + switch (wsaerr) { + case WSAEINPROGRESS: + return EAGAIN; + case WSAEBADF: + return EBADF; + case WSAEINVAL: + return EINVAL; + case WSAEMFILE: + return EMFILE; + case WSAEFAULT: + return EFAULT; + case WSAEPROTONOSUPPORT: + return EPROTONOSUPPORT; + case WSAENOBUFS: + return ENOBUFS; + case WSAENETDOWN: + return ENETDOWN; + case WSAEADDRINUSE: + return EADDRINUSE; + case WSAEADDRNOTAVAIL: + return EADDRNOTAVAIL; + case WSAEAFNOSUPPORT: + return EAFNOSUPPORT; + case WSAEACCES: + return EACCES; + case WSAENETRESET: + return ENETRESET; + case WSAENETUNREACH: + return ENETUNREACH; + case WSAEHOSTUNREACH: + return EHOSTUNREACH; + case WSAENOTCONN: + return ENOTCONN; + case WSAEMSGSIZE: + return EMSGSIZE; + case WSAETIMEDOUT: + return ETIMEDOUT; + case WSAECONNREFUSED: + return ECONNREFUSED; + case WSAECONNABORTED: + return ECONNABORTED; + case WSAECONNRESET: + return ECONNRESET; + case WSAENOTSOCK: + return ENOTSOCK; + case ERROR_BROKEN_PIPE: + return ECONNRESET; + case WSAESOCKTNOSUPPORT: + return ESOCKTNOSUPPORT; + case ERROR_NOT_CONNECTED: + return ENOTCONN; + case ERROR_PIPE_NOT_CONNECTED: + return ENOTCONN; + case ERROR_NO_DATA: + return EPIPE; + default: + nn_assert (0); + } +} + +void nn_win_error (int err, char *buf, size_t bufsize) +{ + DWORD rc = FormatMessageA ( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, (DWORD) err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, (DWORD) bufsize, NULL ); + nn_assert (rc); +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/err.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/err.h new file mode 100644 index 0000000..fbaf65d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/err.h @@ -0,0 +1,174 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_ERR_INCLUDED +#define NN_ERR_INCLUDED + +#include +#include +#include + +/* Include nn.h header to define nanomsg-specific error codes. */ +#include "../nn.h" + +#include "fast.h" + +#if defined _MSC_VER +#define NN_NORETURN __declspec(noreturn) +#elif defined __GNUC__ +#define NN_NORETURN __attribute__ ((noreturn)) +#else +#define NN_NORETURN +#endif + +/* Same as system assert(). However, under Win32 assert has some deficiencies. + Thus this macro. */ +#define nn_assert(x) \ + do {\ + if (nn_slow (!(x))) {\ + nn_backtrace_print (); \ + fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \ + __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +#define nn_assert_state(obj, state_name) \ + do {\ + if (nn_slow ((obj)->state != state_name)) {\ + nn_backtrace_print (); \ + fprintf (stderr, \ + "Assertion failed: %d == %s (%s:%d)\n", \ + (obj)->state, #state_name, \ + __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +/* Checks whether memory allocation was successful. */ +#define alloc_assert(x) \ + do {\ + if (nn_slow (!x)) {\ + nn_backtrace_print (); \ + fprintf (stderr, "Out of memory (%s:%d)\n",\ + __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +/* Check the condition. If false prints out the errno. */ +#define errno_assert(x) \ + do {\ + if (nn_slow (!(x))) {\ + nn_backtrace_print (); \ + fprintf (stderr, "%s [%d] (%s:%d)\n", nn_err_strerror (errno),\ + (int) errno, __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +/* Checks whether supplied errno number is an error. */ +#define errnum_assert(cond, err) \ + do {\ + if (nn_slow (!(cond))) {\ + nn_backtrace_print (); \ + fprintf (stderr, "%s [%d] (%s:%d)\n", nn_err_strerror (err),\ + (int) (err), __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +/* Checks the condition. If false prints out the GetLastError info. */ +#define win_assert(x) \ + do {\ + if (nn_slow (!(x))) {\ + char errstr [256];\ + DWORD errnum = WSAGetLastError ();\ + nn_backtrace_print (); \ + nn_win_error ((int) errnum, errstr, 256);\ + fprintf (stderr, "%s [%d] (%s:%d)\n",\ + errstr, (int) errnum, __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +/* Checks the condition. If false prints out the WSAGetLastError info. */ +#define wsa_assert(x) \ + do {\ + if (nn_slow (!(x))) {\ + char errstr [256];\ + DWORD errnum = WSAGetLastError ();\ + nn_backtrace_print (); \ + nn_win_error (errnum, errstr, 256);\ + fprintf (stderr, "%s [%d] (%s:%d)\n",\ + errstr, (int) errnum, __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + }\ + } while (0) + +/* Assertion-like macros for easier fsm debugging. */ +#define nn_fsm_error(message, state, src, type) \ + do {\ + nn_backtrace_print(); \ + fprintf (stderr, "%s: state=%d source=%d action=%d (%s:%d)\n", \ + message, state, src, type, __FILE__, __LINE__);\ + fflush (stderr);\ + nn_err_abort ();\ + } while (0) + +#define nn_fsm_bad_action(state, src, type) nn_fsm_error(\ + "Unexpected action", state, src, type) +#define nn_fsm_bad_state(state, src, type) nn_fsm_error(\ + "Unexpected state", state, src, type) +#define nn_fsm_bad_source(state, src, type) nn_fsm_error(\ + "Unexpected source", state, src, type) + +/* Compile-time assert. */ +#define CT_ASSERT_HELPER2(prefix, line) prefix##line +#define CT_ASSERT_HELPER1(prefix, line) CT_ASSERT_HELPER2(prefix, line) +#if defined __COUNTER__ +#define CT_ASSERT(x) \ + typedef int CT_ASSERT_HELPER1(ct_assert_,__COUNTER__) [(x) ? 1 : -1] +#else +#define CT_ASSERT(x) \ + typedef int CT_ASSERT_HELPER1(ct_assert_,__LINE__) [(x) ? 1 : -1] +#endif + +NN_NORETURN void nn_err_abort (void); +int nn_err_errno (void); +const char *nn_err_strerror (int errnum); +void nn_backtrace_print (void); + +#ifdef NN_HAVE_WINDOWS +int nn_err_wsa_to_posix (int wsaerr); +void nn_win_error (int err, char *buf, size_t bufsize); +#endif + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/fast.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/fast.h new file mode 100644 index 0000000..1dc94a5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/fast.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2012Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_FAST_INCLUDED +#define NN_FAST_INCLUDED + +#if defined __GNUC__ || defined __llvm__ +#define nn_fast(x) __builtin_expect ((x), 1) +#define nn_slow(x) __builtin_expect ((x), 0) +#else +#define nn_fast(x) (x) +#define nn_slow(x) (x) +#endif + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/fd.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/fd.h new file mode 100644 index 0000000..ea1dd7d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/fd.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2013 Immanuel Weber, Fraunhofer FHR/AMLS All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_FD_INCLUDED +#define NN_FD_INCLUDED + +#ifdef NN_HAVE_WINDOWS +#include "win.h" +typedef SOCKET nn_fd; +#else +typedef int nn_fd; +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/hash.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/hash.c new file mode 100644 index 0000000..8ffe3e2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/hash.c @@ -0,0 +1,164 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "hash.h" +#include "fast.h" +#include "alloc.h" +#include "cont.h" +#include "err.h" + +#define NN_HASH_INITIAL_SLOTS 32 + +static uint32_t nn_hash_key (uint32_t key); + +void nn_hash_init (struct nn_hash *self) +{ + uint32_t i; + + self->slots = NN_HASH_INITIAL_SLOTS; + self->items = 0; + self->array = nn_alloc (sizeof (struct nn_list) * NN_HASH_INITIAL_SLOTS, + "hash map"); + alloc_assert (self->array); + for (i = 0; i != NN_HASH_INITIAL_SLOTS; ++i) + nn_list_init (&self->array [i]); +} + +void nn_hash_term (struct nn_hash *self) +{ + uint32_t i; + + for (i = 0; i != self->slots; ++i) + nn_list_term (&self->array [i]); + nn_free (self->array); +} + +static void nn_hash_rehash (struct nn_hash *self) { + uint32_t i; + uint32_t oldslots; + struct nn_list *oldarray; + struct nn_hash_item *hitm; + uint32_t newslot; + + /* Allocate new double-sized array of slots. */ + oldslots = self->slots; + oldarray = self->array; + self->slots *= 2; + self->array = nn_alloc (sizeof (struct nn_list) * self->slots, "hash map"); + alloc_assert (self->array); + for (i = 0; i != self->slots; ++i) + nn_list_init (&self->array [i]); + + /* Move the items from old slot array to new slot array. */ + for (i = 0; i != oldslots; ++i) { + while (!nn_list_empty (&oldarray [i])) { + hitm = nn_cont (nn_list_begin (&oldarray [i]), + struct nn_hash_item, list); + nn_list_erase (&oldarray [i], &hitm->list); + newslot = nn_hash_key (hitm->key) % self->slots; + nn_list_insert (&self->array [newslot], &hitm->list, + nn_list_end (&self->array [newslot])); + } + + nn_list_term (&oldarray [i]); + } + + /* Deallocate the old array of slots. */ + nn_free (oldarray); +} + + +void nn_hash_insert (struct nn_hash *self, uint32_t key, + struct nn_hash_item *item) +{ + struct nn_list_item *it; + uint32_t i; + + i = nn_hash_key (key) % self->slots; + + for (it = nn_list_begin (&self->array [i]); + it != nn_list_end (&self->array [i]); + it = nn_list_next (&self->array [i], it)) + nn_assert (nn_cont (it, struct nn_hash_item, list)->key != key); + + item->key = key; + nn_list_insert (&self->array [i], &item->list, + nn_list_end (&self->array [i])); + ++self->items; + + /* If the hash is getting full, double the amount of slots and + re-hash all the items. */ + if (nn_slow (self->items * 2 > self->slots && self->slots < 0x80000000)) + nn_hash_rehash(self); +} + +void nn_hash_erase (struct nn_hash *self, struct nn_hash_item *item) +{ + uint32_t slot; + + slot = nn_hash_key (item->key) % self->slots; + nn_list_erase (&self->array [slot], &item->list); + --self->items; +} + +struct nn_hash_item *nn_hash_get (struct nn_hash *self, uint32_t key) +{ + uint32_t slot; + struct nn_list_item *it; + struct nn_hash_item *item; + + slot = nn_hash_key (key) % self->slots; + + for (it = nn_list_begin (&self->array [slot]); + it != nn_list_end (&self->array [slot]); + it = nn_list_next (&self->array [slot], it)) { + item = nn_cont (it, struct nn_hash_item, list); + if (item->key == key) + return item; + } + + return NULL; +} + +uint32_t nn_hash_key (uint32_t key) +{ + /* TODO: This is a randomly chosen hashing function. Give some thought + to picking a more fitting one. */ + key = (key ^ 61) ^ (key >> 16); + key += key << 3; + key = key ^ (key >> 4); + key = key * 0x27d4eb2d; + key = key ^ (key >> 15); + + return key; +} + +void nn_hash_item_init (struct nn_hash_item *self) +{ + nn_list_item_init (&self->list); +} + +void nn_hash_item_term (struct nn_hash_item *self) +{ + nn_list_item_term (&self->list); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/hash.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/hash.h new file mode 100644 index 0000000..a9b5632 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/hash.h @@ -0,0 +1,70 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_HASH_INCLUDED +#define NN_HASH_INCLUDED + +#include "list.h" + +#include +#include + +/* Use for initialising a hash item statically. */ +#define NN_HASH_ITEM_INITIALIZER {0xffff, NN_LIST_ITEM_INITILIZER} + +struct nn_hash_item { + uint32_t key; + struct nn_list_item list; +}; + +struct nn_hash { + uint32_t slots; + uint32_t items; + struct nn_list *array; +}; + +/* Initialise the hash table. */ +void nn_hash_init (struct nn_hash *self); + +/* Terminate the hash. Note that hash must be manually emptied before the + termination. */ +void nn_hash_term (struct nn_hash *self); + +/* Adds an item to the hash. */ +void nn_hash_insert (struct nn_hash *self, uint32_t key, + struct nn_hash_item *item); + +/* Removes the element from the hash it is in at the moment. */ +void nn_hash_erase (struct nn_hash *self, struct nn_hash_item *item); + +/* Gets an item in the hash based on the key. Returns NULL if there's no + corresponing item in the hash table. */ +struct nn_hash_item *nn_hash_get (struct nn_hash *self, uint32_t key); + +/* Initialise a hash item. At this point it is not a part of any hash table. */ +void nn_hash_item_init (struct nn_hash_item *self); + +/* Terminate a hash item. The item must not be in a hash table prior to + this call. */ +void nn_hash_item_term (struct nn_hash_item *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/list.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/list.c new file mode 100644 index 0000000..90758c5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/list.c @@ -0,0 +1,128 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include + +#include "list.h" +#include "err.h" +#include "attr.h" + +void nn_list_init (struct nn_list *self) +{ + self->first = NULL; + self->last = NULL; +} + +void nn_list_term (struct nn_list *self) +{ + nn_assert (self->first == NULL); + nn_assert (self->last == NULL); +} + +int nn_list_empty (struct nn_list *self) +{ + return self->first ? 0 : 1; +} + +struct nn_list_item *nn_list_begin (struct nn_list *self) +{ + return self->first; +} + +struct nn_list_item *nn_list_end (NN_UNUSED struct nn_list *self) +{ + return NULL; +} + +struct nn_list_item *nn_list_prev (struct nn_list *self, + struct nn_list_item *it) +{ + if (!it) + return self->last; + nn_assert (it->prev != NN_LIST_NOTINLIST); + return it->prev; +} + +struct nn_list_item *nn_list_next (NN_UNUSED struct nn_list *self, + struct nn_list_item *it) +{ + nn_assert (it->next != NN_LIST_NOTINLIST); + return it->next; +} + +void nn_list_insert (struct nn_list *self, struct nn_list_item *item, + struct nn_list_item *it) +{ + nn_assert (!nn_list_item_isinlist (item)); + + item->prev = it ? it->prev : self->last; + item->next = it; + if (item->prev) + item->prev->next = item; + if (item->next) + item->next->prev = item; + if (!self->first || self->first == it) + self->first = item; + if (!it) + self->last = item; +} + +struct nn_list_item *nn_list_erase (struct nn_list *self, + struct nn_list_item *item) +{ + struct nn_list_item *next; + + nn_assert (nn_list_item_isinlist (item)); + + if (item->prev) + item->prev->next = item->next; + else + self->first = item->next; + if (item->next) + item->next->prev = item->prev; + else + self->last = item->prev; + + next = item->next; + + item->prev = NN_LIST_NOTINLIST; + item->next = NN_LIST_NOTINLIST; + + return next; +} + +void nn_list_item_init (struct nn_list_item *self) +{ + self->prev = NN_LIST_NOTINLIST; + self->next = NN_LIST_NOTINLIST; +} + +void nn_list_item_term (struct nn_list_item *self) +{ + nn_assert (!nn_list_item_isinlist (self)); +} + +int nn_list_item_isinlist (struct nn_list_item *self) +{ + return self->prev == NN_LIST_NOTINLIST ? 0 : 1; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/list.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/list.h new file mode 100644 index 0000000..ec1ce13 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/list.h @@ -0,0 +1,86 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_LIST_INCLUDED +#define NN_LIST_INCLUDED + +struct nn_list_item { + struct nn_list_item *next; + struct nn_list_item *prev; +}; + +struct nn_list { + struct nn_list_item *first; + struct nn_list_item *last; +}; + +/* Undefined value for initializing a list item which is not part of a list. */ +#define NN_LIST_NOTINLIST ((struct nn_list_item*) -1) + +/* Use for initializing a list item statically. */ +#define NN_LIST_ITEM_INITIALIZER {NN_LIST_NOTINLIST, NN_LIST_NOTINLIST} + +/* Initialise the list. */ +void nn_list_init (struct nn_list *self); + +/* Terminates the list. Note that all items must be removed before the + termination. */ +void nn_list_term (struct nn_list *self); + +/* Returns 1 is list has zero items, 0 otherwise. */ +int nn_list_empty (struct nn_list *self); + +/* Returns iterator to the first item in the list. */ +struct nn_list_item *nn_list_begin (struct nn_list *self); + +/* Returns iterator to one past the last item in the list. */ +struct nn_list_item *nn_list_end (struct nn_list *self); + +/* Returns iterator to an item prior to the one pointed to by 'it'. */ +struct nn_list_item *nn_list_prev (struct nn_list *self, + struct nn_list_item *it); + +/* Returns iterator to one past the item pointed to by 'it'. */ +struct nn_list_item *nn_list_next (struct nn_list *self, + struct nn_list_item *it); + +/* Adds the item to the list before the item pointed to by 'it'. Priot to + insertion item should not be part of any list. */ +void nn_list_insert (struct nn_list *self, struct nn_list_item *item, + struct nn_list_item *it); + +/* Removes the item from the list and returns pointer to the next item in the + list. Item must be part of the list. */ +struct nn_list_item *nn_list_erase (struct nn_list *self, + struct nn_list_item *item); + +/* Initialize a list item. At this point it is not part of any list. */ +void nn_list_item_init (struct nn_list_item *self); + +/* Terminates a list item. Item must not be part of any list before it's + terminated. */ +void nn_list_item_term (struct nn_list_item *self); + +/* Returns 1 is the item is part of a list, 0 otherwise. */ +int nn_list_item_isinlist (struct nn_list_item *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/msg.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/msg.c new file mode 100644 index 0000000..3c45b32 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/msg.c @@ -0,0 +1,81 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "msg.h" + +#include + +void nn_msg_init (struct nn_msg *self, size_t size) +{ + nn_chunkref_init (&self->sphdr, 0); + nn_chunkref_init (&self->hdrs, 0); + nn_chunkref_init (&self->body, size); +} + +void nn_msg_init_chunk (struct nn_msg *self, void *chunk) +{ + nn_chunkref_init (&self->sphdr, 0); + nn_chunkref_init (&self->hdrs, 0); + nn_chunkref_init_chunk (&self->body, chunk); +} + +void nn_msg_term (struct nn_msg *self) +{ + nn_chunkref_term (&self->sphdr); + nn_chunkref_term (&self->hdrs); + nn_chunkref_term (&self->body); +} + +void nn_msg_mv (struct nn_msg *dst, struct nn_msg *src) +{ + nn_chunkref_mv (&dst->sphdr, &src->sphdr); + nn_chunkref_mv (&dst->hdrs, &src->hdrs); + nn_chunkref_mv (&dst->body, &src->body); +} + +void nn_msg_cp (struct nn_msg *dst, struct nn_msg *src) +{ + nn_chunkref_cp (&dst->sphdr, &src->sphdr); + nn_chunkref_cp (&dst->hdrs, &src->hdrs); + nn_chunkref_cp (&dst->body, &src->body); +} + +void nn_msg_bulkcopy_start (struct nn_msg *self, uint32_t copies) +{ + nn_chunkref_bulkcopy_start (&self->sphdr, copies); + nn_chunkref_bulkcopy_start (&self->hdrs, copies); + nn_chunkref_bulkcopy_start (&self->body, copies); +} + +void nn_msg_bulkcopy_cp (struct nn_msg *dst, struct nn_msg *src) +{ + nn_chunkref_bulkcopy_cp (&dst->sphdr, &src->sphdr); + nn_chunkref_bulkcopy_cp (&dst->hdrs, &src->hdrs); + nn_chunkref_bulkcopy_cp (&dst->body, &src->body); +} + +void nn_msg_replace_body (struct nn_msg *self, struct nn_chunkref new_body) +{ + nn_chunkref_term (&self->body); + self->body = new_body; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/msg.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/msg.h new file mode 100644 index 0000000..e6fe66f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/msg.h @@ -0,0 +1,76 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_MSG_INCLUDED +#define NN_MSG_INCLUDED + +#include "chunkref.h" + +#include + +struct nn_msg { + + /* Contains SP message header. This field directly corresponds + to SP message header as defined in SP RFCs. There's no leading + cmsghdr or trailing padding. */ + struct nn_chunkref sphdr; + + /* Contains any additional transport-level message headers. Format of this + buffer is a list of cmsgs as defined by POSIX (see "ancillary data"). */ + struct nn_chunkref hdrs; + + /* Contains application level message payload. */ + struct nn_chunkref body; +}; + +/* Initialises a message with body 'size' bytes long and empty header. */ +void nn_msg_init (struct nn_msg *self, size_t size); + +/* Initialise message with body provided in the form of chunk pointer. */ +void nn_msg_init_chunk (struct nn_msg *self, void *chunk); + +/* Frees resources allocate with the message. */ +void nn_msg_term (struct nn_msg *self); + +/* Moves the content of the message from src to dst. dst should not be + initialised prior to the operation. src will be uninitialised after the + operation. */ +void nn_msg_mv (struct nn_msg *dst, struct nn_msg *src); + +/* Copies a message from src to dst. dst should not be + initialised prior to the operation. */ +void nn_msg_cp (struct nn_msg *dst, struct nn_msg *src); + +/* Bulk copying is done by first invoking nn_msg_bulkcopy_start on the source + message and specifying how many copies of the message will be made. Then, + nn_msg_bulkcopy_cp should be used 'copies' of times to make individual + copies of the source message. Note: Bulk copying is more efficient than + making each copy separately. */ +void nn_msg_bulkcopy_start (struct nn_msg *self, uint32_t copies); +void nn_msg_bulkcopy_cp (struct nn_msg *dst, struct nn_msg *src); + +/** Replaces the message body with entirely new data. This allows protocols + that substantially rewrite or preprocess the userland message to be written. */ +void nn_msg_replace_body(struct nn_msg *self, struct nn_chunkref newBody); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/mutex.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/mutex.c new file mode 100644 index 0000000..261b0e5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/mutex.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "mutex.h" +#include "err.h" + +#include + +#ifdef NN_HAVE_WINDOWS + +void nn_mutex_init (nn_mutex_t *self) +{ + InitializeCriticalSection (&self->cs); + self->owner = 0; +} + +void nn_mutex_term (nn_mutex_t *self) +{ + /* Make sure we don't free a locked mutex. */ + nn_assert(self->owner == 0); + DeleteCriticalSection (&self->cs); +} + +void nn_mutex_lock (nn_mutex_t *self) +{ + EnterCriticalSection (&self->cs); + + /* Make sure we don't recursively enter mutexes. */ + nn_assert(self->owner == 0); + self->owner = GetCurrentThreadId(); +} + +void nn_mutex_unlock (nn_mutex_t *self) +{ + /* Make sure that we own the mutex we are releasing. */ + nn_assert(self->owner == GetCurrentThreadId()); + self->owner = 0; + LeaveCriticalSection (&self->cs); +} + +#else + +void nn_mutex_init (nn_mutex_t *self) +{ + int rc; + pthread_mutexattr_t attr; + + pthread_mutexattr_init(&attr); + rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); + errnum_assert (rc == 0, rc); + rc = pthread_mutex_init (&self->mutex, NULL); + errnum_assert (rc == 0, rc); + pthread_mutexattr_destroy(&attr); +} + +void nn_mutex_term (nn_mutex_t *self) +{ + int rc; + + rc = pthread_mutex_destroy (&self->mutex); + errnum_assert (rc == 0, rc); +} + +void nn_mutex_lock (nn_mutex_t *self) +{ + int rc; + + rc = pthread_mutex_lock (&self->mutex); + errnum_assert (rc == 0, rc); +} + +void nn_mutex_unlock (nn_mutex_t *self) +{ + int rc; + + rc = pthread_mutex_unlock (&self->mutex); + errnum_assert (rc == 0, rc); +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/mutex.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/mutex.h new file mode 100644 index 0000000..b0f1a7c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/mutex.h @@ -0,0 +1,59 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_MUTEX_INCLUDED +#define NN_MUTEX_INCLUDED + +#ifdef NN_HAVE_WINDOWS +#include "win.h" +#else +#include +#endif + +struct nn_mutex { + /* NB: The fields of this structure are private to the mutex + implementation. */ +#ifdef NN_HAVE_WINDOWS + CRITICAL_SECTION cs; + DWORD owner; + int debug; +#else + pthread_mutex_t mutex; +#endif +}; + +typedef struct nn_mutex nn_mutex_t; + +/* Initialise the mutex. */ +void nn_mutex_init (nn_mutex_t *self); + +/* Terminate the mutex. */ +void nn_mutex_term (nn_mutex_t *self); + +/* Lock the mutex. Behaviour of multiple locks from the same thread is + undefined. */ +void nn_mutex_lock (nn_mutex_t *self); + +/* Unlock the mutex. Behaviour of unlocking an unlocked mutex is undefined */ +void nn_mutex_unlock (nn_mutex_t *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/once.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/once.c new file mode 100644 index 0000000..508c494 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/once.c @@ -0,0 +1,49 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "once.h" +#if NN_HAVE_WINDOWS + +/* This craziness is required because Windows doesn't have the notion of + static initializers for CriticalSections. */ + +BOOL CALLBACK nn_do_once_cb (PINIT_ONCE InitOnce, + PVOID Parameter, PVOID *Context) +{ + void (*func)(void) = Parameter; + func(); + return (TRUE); +} + +void nn_do_once (nn_once_t *once, void (*func)(void)) +{ + (void) InitOnceExecuteOnce(&once->once, nn_do_once_cb, func, NULL); +} + +#else /* !NN_HAVE_WINDOWS */ + +void nn_do_once (nn_once_t *once, void (*func)(void)) +{ + pthread_once (&once->once, func); +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/once.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/once.h new file mode 100644 index 0000000..8bce2e3 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/once.h @@ -0,0 +1,47 @@ +/* + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_ONCE_INCLUDED +#define NN_ONCE_INCLUDED + +#ifdef NN_HAVE_WINDOWS +#include "win.h" +struct nn_once { + INIT_ONCE once; +}; +#define NN_ONCE_INITIALIZER { INIT_ONCE_STATIC_INIT } + +#else /* !NN_HAVE_WINDOWS */ + +#include + +struct nn_once { + pthread_once_t once; +}; +#define NN_ONCE_INITIALIZER { PTHREAD_ONCE_INIT } + +#endif /* NN_HAVE_WINDOWS */ + +typedef struct nn_once nn_once_t; +void nn_do_once (nn_once_t *once, void (*func)(void)); + +#endif /* NN_ONCE_INCLUDED */ diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/queue.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/queue.c new file mode 100644 index 0000000..722c4f2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/queue.c @@ -0,0 +1,109 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include + +#include "queue.h" +#include "err.h" + +void nn_queue_init (struct nn_queue *self) +{ + self->head = NULL; + self->tail = NULL; +} + +void nn_queue_term (struct nn_queue *self) +{ + self->head = NULL; + self->tail = NULL; +} + +int nn_queue_empty (struct nn_queue *self) +{ + return self->head ? 0 : 1; +} + +void nn_queue_push (struct nn_queue *self, struct nn_queue_item *item) +{ + nn_assert (item->next == NN_QUEUE_NOTINQUEUE); + + item->next = NULL; + if (!self->head) + self->head = item; + if (self->tail) + self->tail->next = item; + self->tail = item; +} + +void nn_queue_remove (struct nn_queue *self, struct nn_queue_item *item) +{ + struct nn_queue_item *it; + struct nn_queue_item *prev; + + if (item->next == NN_QUEUE_NOTINQUEUE) + return; + + prev = NULL; + for (it = self->head; it != NULL; it = it->next) { + if (it == item) { + if (self->head == it) + self->head = it->next; + if (self->tail == it) + self->tail = prev; + if (prev) + prev->next = it->next; + item->next = NN_QUEUE_NOTINQUEUE; + return; + } + prev = it; + } +} + +struct nn_queue_item *nn_queue_pop (struct nn_queue *self) +{ + struct nn_queue_item *result; + + if (!self->head) + return NULL; + result = self->head; + self->head = result->next; + if (!self->head) + self->tail = NULL; + result->next = NN_QUEUE_NOTINQUEUE; + return result; +} + +void nn_queue_item_init (struct nn_queue_item *self) +{ + self->next = NN_QUEUE_NOTINQUEUE; +} + +void nn_queue_item_term (struct nn_queue_item *self) +{ + nn_assert (self->next == NN_QUEUE_NOTINQUEUE); +} + +int nn_queue_item_isinqueue (struct nn_queue_item *self) +{ + return self->next == NN_QUEUE_NOTINQUEUE ? 0 : 1; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/queue.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/queue.h new file mode 100644 index 0000000..7b899b4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/queue.h @@ -0,0 +1,72 @@ +/* + Copyright (c) 2012-2014 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_QUEUE_INCLUDED +#define NN_QUEUE_INCLUDED + +/* Undefined value for initialising a queue item which is not + part of a queue. */ +#define NN_QUEUE_NOTINQUEUE ((struct nn_queue_item*) -1) + +/* Use for initialising a queue item statically. */ +#define NN_QUEUE_ITEM_INITIALIZER {NN_LIST_NOTINQUEUE} + +struct nn_queue_item { + struct nn_queue_item *next; +}; + +struct nn_queue { + struct nn_queue_item *head; + struct nn_queue_item *tail; +}; + +/* Initialise the queue. */ +void nn_queue_init (struct nn_queue *self); + +/* Terminate the queue. Note that queue must be manually emptied before the + termination. */ +void nn_queue_term (struct nn_queue *self); + +/* Returns 1 if there are no items in the queue, 0 otherwise. */ +int nn_queue_empty (struct nn_queue *self); + +/* Inserts one element into the queue. */ +void nn_queue_push (struct nn_queue *self, struct nn_queue_item *item); + +/* Remove the item if it is present in the queue. */ +void nn_queue_remove (struct nn_queue *self, struct nn_queue_item *item); + +/* Retrieves one element from the queue. The element is removed + from the queue. Returns NULL if the queue is empty. */ +struct nn_queue_item *nn_queue_pop (struct nn_queue *self); + +/* Initialise a queue item. At this point it is not a part of any queue. */ +void nn_queue_item_init (struct nn_queue_item *self); + +/* Terminate a queue item. The item must not be in a queue prior to + this call. */ +void nn_queue_item_term (struct nn_queue_item *self); + +/* Returns 1 if item is a part of a queue. 0 otherwise. */ +int nn_queue_item_isinqueue (struct nn_queue_item *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/random.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/random.c new file mode 100644 index 0000000..51e4472 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/random.c @@ -0,0 +1,73 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "random.h" +#include "clock.h" +#include "fast.h" + +#ifdef NN_HAVE_WINDOWS +#include "win.h" +#else +#include +#include +#endif + +#include + +static uint64_t nn_random_state; + +void nn_random_seed () +{ + uint64_t pid; + +#ifdef NN_HAVE_WINDOWS + pid = (uint64_t) GetCurrentProcessId (); +#else + pid = (uint64_t) getpid (); +#endif + + /* The initial state for pseudo-random number generator is computed from + the exact timestamp and process ID. */ + memcpy (&nn_random_state, "\xfa\x9b\x23\xe3\x07\xcc\x61\x1f", 8); + nn_random_state ^= pid + nn_clock_ms(); +} + +void nn_random_generate (void *buf, size_t len) +{ + uint8_t *pos; + + pos = (uint8_t*) buf; + + while (1) { + + /* Generate a pseudo-random integer. */ + nn_random_state = nn_random_state * 1103515245 + 12345; + + /* Move the bytes to the output buffer. */ + memcpy (pos, &nn_random_state, len > 8 ? 8 : len); + if (nn_fast (len <= 8)) + return; + len -= 8; + pos += 8; + } +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/random.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/random.h new file mode 100644 index 0000000..8e8c0d1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/random.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_RANDOM_INCLUDED +#define NN_RANDOM_INCLUDED + +#include + +/* Seeds the pseudorandom number generator. */ +void nn_random_seed (); + +/* Generate a pseudorandom byte sequence. */ +void nn_random_generate (void *buf, size_t len); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/sem.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sem.c new file mode 100644 index 0000000..17943d5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sem.c @@ -0,0 +1,169 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sem.h" +#include "err.h" +#include "fast.h" + +#if defined NN_HAVE_OSX + +void nn_sem_init (struct nn_sem *self) +{ + int rc; + + rc = pthread_mutex_init (&self->mutex, NULL); + errnum_assert (rc == 0, rc); + rc = pthread_cond_init (&self->cond, NULL); + errnum_assert (rc == 0, rc); + self->signaled = 0; +} + +void nn_sem_term (struct nn_sem *self) +{ + int rc; + + rc = pthread_cond_destroy (&self->cond); + errnum_assert (rc == 0, rc); + rc = pthread_mutex_destroy (&self->mutex); + errnum_assert (rc == 0, rc); +} + +void nn_sem_post (struct nn_sem *self) +{ + int rc; + + rc = pthread_mutex_lock (&self->mutex); + errnum_assert (rc == 0, rc); + nn_assert (self->signaled == 0); + self->signaled = 1; + rc = pthread_cond_signal (&self->cond); + errnum_assert (rc == 0, rc); + rc = pthread_mutex_unlock (&self->mutex); + errnum_assert (rc == 0, rc); +} + +int nn_sem_wait (struct nn_sem *self) +{ + int rc; + + /* With OSX, semaphores are global named objects. They are not useful for + our use case. To get a similar object we exploit the implementation + detail of pthread_cond_wait() in Darwin kernel: It exits if signal is + caught. Note that this behaviour is not mandated by POSIX + and may break with future versions of Darwin. */ + rc = pthread_mutex_lock (&self->mutex); + errnum_assert (rc == 0, rc); + if (nn_fast (self->signaled)) { + rc = pthread_mutex_unlock (&self->mutex); + errnum_assert (rc == 0, rc); + return 0; + } + rc = pthread_cond_wait (&self->cond, &self->mutex); + errnum_assert (rc == 0, rc); + if (nn_slow (!self->signaled)) { + rc = pthread_mutex_unlock (&self->mutex); + errnum_assert (rc == 0, rc); + return -EINTR; + } + self->signaled = 0; + rc = pthread_mutex_unlock (&self->mutex); + errnum_assert (rc == 0, rc); + + return 0; +} + +#elif defined NN_HAVE_WINDOWS + +void nn_sem_init (struct nn_sem *self) +{ + self->h = CreateEvent (NULL, FALSE, FALSE, NULL); + win_assert (self->h); +} + +void nn_sem_term (struct nn_sem *self) +{ + BOOL brc; + + brc = CloseHandle (self->h); + win_assert (brc); +} + +void nn_sem_post (struct nn_sem *self) +{ + BOOL brc; + + brc = SetEvent (self->h); + win_assert (brc); +} + +int nn_sem_wait (struct nn_sem *self) +{ + DWORD rc; + + rc = WaitForSingleObject (self->h, INFINITE); + win_assert (rc != WAIT_FAILED); + nn_assert (rc == WAIT_OBJECT_0); + + return 0; +} + +#elif defined NN_HAVE_SEMAPHORE + +void nn_sem_init (struct nn_sem *self) +{ + int rc; + + rc = sem_init (&self->sem, 0, 0); + errno_assert (rc == 0); +} + +void nn_sem_term (struct nn_sem *self) +{ + int rc; + + rc = sem_destroy (&self->sem); + errno_assert (rc == 0); +} + +void nn_sem_post (struct nn_sem *self) +{ + int rc; + + rc = sem_post (&self->sem); + errno_assert (rc == 0); +} + +int nn_sem_wait (struct nn_sem *self) +{ + int rc; + + rc = sem_wait (&self->sem); + if (nn_slow (rc < 0 && errno == EINTR)) + return -EINTR; + errno_assert (rc == 0); + return 0; +} + +#else +#error +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/sem.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sem.h new file mode 100644 index 0000000..6cfc021 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sem.h @@ -0,0 +1,71 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SEM_INCLUDED +#define NN_SEM_INCLUDED + +/* Simple semaphore. It can have only two values (0/1 i.e. locked/unlocked). */ + +struct nn_sem; + +/* Initialise the sem object. It is created in locked state. */ +void nn_sem_init (struct nn_sem *self); + +/* Uninitialise the sem object. */ +void nn_sem_term (struct nn_sem *self); + +/* Unlock the semaphore. */ +void nn_sem_post (struct nn_sem *self); + +/* Waits till sem object becomes unlocked and locks it. */ +int nn_sem_wait (struct nn_sem *self); + +#if defined NN_HAVE_OSX + +#include + +struct nn_sem { + pthread_mutex_t mutex; + pthread_cond_t cond; + int signaled; +}; + +#elif defined NN_HAVE_WINDOWS + +#include "win.h" + +struct nn_sem { + HANDLE h; +}; + +#elif defined NN_HAVE_SEMAPHORE + +#include + +struct nn_sem { + sem_t sem; +}; + +#endif + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/sleep.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sleep.c new file mode 100644 index 0000000..6ae30bc --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sleep.c @@ -0,0 +1,50 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "sleep.h" +#include "err.h" + +#ifdef NN_HAVE_WINDOWS + +#include "win.h" + +void nn_sleep (int milliseconds) +{ + Sleep (milliseconds); +} + +#else + +#include + +void nn_sleep (int milliseconds) +{ + int rc; + struct timespec ts; + + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = milliseconds % 1000 * 1000000; + rc = nanosleep (&ts, NULL); + errno_assert (rc == 0); +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/sleep.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sleep.h new file mode 100644 index 0000000..de943c4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/sleep.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_SLEEP_INCLUDED +#define NN_SLEEP_INCLUDED + +/* Platform independent implementation of sleeping. */ + +void nn_sleep (int milliseconds); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/stopwatch.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/stopwatch.c new file mode 100644 index 0000000..e0cc1d3 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/stopwatch.c @@ -0,0 +1,75 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "stopwatch.h" + +#if defined NN_HAVE_WINDOWS + +#include "win.h" + +void nn_stopwatch_init (struct nn_stopwatch *self) +{ + LARGE_INTEGER time; + + QueryPerformanceCounter (&time); + self->start = (uint64_t) (time.QuadPart); +} + +uint64_t nn_stopwatch_term (struct nn_stopwatch *self) +{ + LARGE_INTEGER tps; + LARGE_INTEGER time; + + QueryPerformanceFrequency (&tps); + QueryPerformanceCounter (&time); + return (uint64_t) ((time.QuadPart - self->start) * 1000000 / tps.QuadPart); +} + +#else + +#include +#include +#include + +void nn_stopwatch_init (struct nn_stopwatch *self) +{ + int rc; + struct timeval tv; + + rc = gettimeofday (&tv, NULL); + assert (rc == 0); + self->start = (uint64_t) (((uint64_t) tv.tv_sec) * 1000000 + tv.tv_usec); +} + +uint64_t nn_stopwatch_term (struct nn_stopwatch *self) +{ + int rc; + struct timeval tv; + uint64_t end; + + rc = gettimeofday (&tv, NULL); + assert (rc == 0); + end = (uint64_t) (((uint64_t) tv.tv_sec) * 1000000 + tv.tv_usec); + return end - self->start; +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/stopwatch.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/stopwatch.h new file mode 100644 index 0000000..6d09fa6 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/stopwatch.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_STOPWATCH_INCLUDED +#define NN_STOPWATCH_INCLUDED + +#include + +#include "err.h" + +/* Check whether measured time is the expected time (in microseconds). + The upper tolerance is 50ms so that the test doesn't fail even on + very slow or very loaded systems. Likewise on some systems we can + wind up firing up to a single tick early (Windows), so the lower bound + is pretty low. The consequence of this is that programs which specify + a timeout should be a little more pessimistic (at least 10ms) then they + might otherwise think they need to be. */ +#define time_assert(actual,expected) \ + nn_assert (actual > ((expected) - 10000) && actual < ((expected) + 50000)); + +/* Measures time interval in microseconds. */ + +struct nn_stopwatch { + uint64_t start; +}; + +void nn_stopwatch_init (struct nn_stopwatch *self); +uint64_t nn_stopwatch_term (struct nn_stopwatch *self); + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread.c new file mode 100644 index 0000000..9516faa --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread.c @@ -0,0 +1,29 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "thread.h" + +#ifdef NN_HAVE_WINDOWS +#include "thread_win.inc" +#else +#include "thread_posix.inc" +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread.h new file mode 100644 index 0000000..d6bebc4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread.h @@ -0,0 +1,41 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_THREAD_INCLUDED +#define NN_THREAD_INCLUDED + +/* Platform independent implementation of threading. */ + +typedef void (nn_thread_routine) (void*); + +#if defined NN_HAVE_WINDOWS +#include "thread_win.h" +#else +#include "thread_posix.h" +#endif + +void nn_thread_init (struct nn_thread *self, + nn_thread_routine *routine, void *arg); +void nn_thread_term (struct nn_thread *self); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_posix.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_posix.h new file mode 100644 index 0000000..c007fa0 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_posix.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include + +struct nn_thread +{ + nn_thread_routine *routine; + void *arg; + pthread_t handle; +}; diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_posix.inc b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_posix.inc new file mode 100644 index 0000000..88da1fd --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_posix.inc @@ -0,0 +1,71 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + Copyright (c) 2014 Achille Roussel All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "err.h" + +#include + +static void *nn_thread_main_routine (void *arg) +{ + struct nn_thread *self; + + self = (struct nn_thread*) arg; + + /* Run the thread routine. */ + self->routine (self->arg); + return NULL; +} + +void nn_thread_init (struct nn_thread *self, + nn_thread_routine *routine, void *arg) +{ + int rc; + sigset_t new_sigmask; + sigset_t old_sigmask; + + /* No signals should be processed by this thread. The library doesn't + use signals and thus all the signals should be delivered to application + threads, not to worker threads. */ + rc = sigfillset (&new_sigmask); + errno_assert (rc == 0); + rc = pthread_sigmask (SIG_BLOCK, &new_sigmask, &old_sigmask); + errnum_assert (rc == 0, rc); + + self->routine = routine; + self->arg = arg; + rc = pthread_create (&self->handle, NULL, nn_thread_main_routine, + (void*) self); + errnum_assert (rc == 0, rc); + + /* Restore signal set to what it was before. */ + rc = pthread_sigmask (SIG_SETMASK, &old_sigmask, NULL); + errnum_assert (rc == 0, rc); +} + +void nn_thread_term (struct nn_thread *self) +{ + int rc; + + rc = pthread_join (self->handle, NULL); + errnum_assert (rc == 0, rc); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_win.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_win.h new file mode 100644 index 0000000..5edb5c7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_win.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "win.h" + +struct nn_thread +{ + nn_thread_routine *routine; + void *arg; + HANDLE handle; +}; diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_win.inc b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_win.inc new file mode 100644 index 0000000..a8d23b2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/thread_win.inc @@ -0,0 +1,53 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "err.h" + +static unsigned int __stdcall nn_thread_main_routine (void *arg) +{ + struct nn_thread *self; + + self = (struct nn_thread*) arg; + self->routine (self->arg); + return 0; +} + +void nn_thread_init (struct nn_thread *self, + nn_thread_routine *routine, void *arg) +{ + self->routine = routine; + self->arg = arg; + self->handle = (HANDLE) _beginthreadex (NULL, 0, + nn_thread_main_routine, (void*) self, 0 , NULL); + win_assert (self->handle != NULL); +} + +void nn_thread_term (struct nn_thread *self) +{ + DWORD rc; + BOOL brc; + + rc = WaitForSingleObject (self->handle, INFINITE); + win_assert (rc != WAIT_FAILED); + brc = CloseHandle (self->handle); + win_assert (brc != 0); +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/win.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/win.h new file mode 100644 index 0000000..dcfe06a --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/win.h @@ -0,0 +1,45 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_WIN_INCLUDED +#define NN_WIN_INCLUDED + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include +#include +#include +#include +#include + +/* This structure does not exist on Windows platform. Let's fake it. */ +struct sockaddr_un { + short sun_family; + char sun_path [sizeof (struct sockaddr_storage) - + sizeof (short)]; +}; + +#define ssize_t int + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/wire.c b/node/node_modules/nanomsg/deps/nanomsg/src/utils/wire.c new file mode 100644 index 0000000..cd91f34 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/wire.c @@ -0,0 +1,82 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "wire.h" + +#if defined NN_HAVE_WINDOWS +#include "win.h" +#else +#include +#endif + +uint16_t nn_gets (const uint8_t *buf) +{ + return (((uint16_t) buf [0]) << 8) | + ((uint16_t) buf [1]); +} + +void nn_puts (uint8_t *buf, uint16_t val) +{ + buf [0] = (uint8_t) (((val) >> 8) & 0xff); + buf [1] = (uint8_t) (val & 0xff); +} + +uint32_t nn_getl (const uint8_t *buf) +{ + return (((uint32_t) buf [0]) << 24) | + (((uint32_t) buf [1]) << 16) | + (((uint32_t) buf [2]) << 8) | + ((uint32_t) buf [3]); +} + +void nn_putl (uint8_t *buf, uint32_t val) +{ + buf [0] = (uint8_t) (((val) >> 24) & 0xff); + buf [1] = (uint8_t) (((val) >> 16) & 0xff); + buf [2] = (uint8_t) (((val) >> 8) & 0xff); + buf [3] = (uint8_t) (val & 0xff); +} + +uint64_t nn_getll (const uint8_t *buf) +{ + return (((uint64_t) buf [0]) << 56) | + (((uint64_t) buf [1]) << 48) | + (((uint64_t) buf [2]) << 40) | + (((uint64_t) buf [3]) << 32) | + (((uint64_t) buf [4]) << 24) | + (((uint64_t) buf [5]) << 16) | + (((uint64_t) buf [6]) << 8) | + (((uint64_t) buf [7] << 0)); +} + +void nn_putll (uint8_t *buf, uint64_t val) +{ + buf [0] = (uint8_t) ((val >> 56) & 0xff); + buf [1] = (uint8_t) ((val >> 48) & 0xff); + buf [2] = (uint8_t) ((val >> 40) & 0xff); + buf [3] = (uint8_t) ((val >> 32) & 0xff); + buf [4] = (uint8_t) ((val >> 24) & 0xff); + buf [5] = (uint8_t) ((val >> 16) & 0xff); + buf [6] = (uint8_t) ((val >> 8) & 0xff); + buf [7] = (uint8_t) (val & 0xff); +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/utils/wire.h b/node/node_modules/nanomsg/deps/nanomsg/src/utils/wire.h new file mode 100644 index 0000000..69ac591 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/utils/wire.h @@ -0,0 +1,36 @@ +/* + Copyright (c) 2012-2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_WIRE_INCLUDED +#define NN_WIRE_INCLUDED + +#include + +uint16_t nn_gets (const uint8_t *buf); +void nn_puts (uint8_t *buf, uint16_t val); +uint32_t nn_getl (const uint8_t *buf); +void nn_putl (uint8_t *buf, uint32_t val); +uint64_t nn_getll (const uint8_t *buf); +void nn_putll (uint8_t *buf, uint64_t val); + +#endif + diff --git a/node/node_modules/nanomsg/deps/nanomsg/src/ws.h b/node/node_modules/nanomsg/deps/nanomsg/src/ws.h new file mode 100644 index 0000000..b7f66b4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/src/ws.h @@ -0,0 +1,49 @@ +/* + Copyright (c) 2012 250bpm s.r.o. All rights reserved. + Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef WS_H_INCLUDED +#define WS_H_INCLUDED + +#include "nn.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NN_WS -4 + +/* NN_WS level socket/cmsg options. Note that only NN_WSMG_TYPE_TEXT and + NN_WS_MSG_TYPE_BINARY messages are supported fully by this implementation. + Attempting to set other message types is undefined. */ +#define NN_WS_MSG_TYPE 1 + +/* WebSocket opcode constants as per RFC 6455 5.2 */ +#define NN_WS_MSG_TYPE_TEXT 0x01 +#define NN_WS_MSG_TYPE_BINARY 0x02 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/README b/node/node_modules/nanomsg/deps/nanomsg/tests/README new file mode 100644 index 0000000..e7088b1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/README @@ -0,0 +1,9 @@ +This directory contains automatic tests for nanomsg library. To run the tests +do "make test" in the build directory, or alternatively run ctest. + +Note that the code here is probably ill-suited for demonstration purposes, as +it is primarily oriented towards testing the library, rather than serving as +any sort of example. + +Instead, we recommend looking in ../demo for some example programs that +demonstrate the API as we feel it is meant to be used. diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/async_shutdown.c b/node/node_modules/nanomsg/deps/nanomsg/tests/async_shutdown.c new file mode 100644 index 0000000..5b853fb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/async_shutdown.c @@ -0,0 +1,80 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2015 Jack R. Dunaway. All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/pipeline.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" +#include "../src/utils/atomic.c" + +/* Test condition of closing sockets that are blocking in another thread. */ + +#define TEST_LOOPS 10 + +struct nn_atomic active; + +static void routine (NN_UNUSED void *arg) +{ + int s; + int rc; + int msg; + + nn_assert (arg); + + s = *((int *) arg); + + /* We don't expect to actually receive a message here; + therefore, the datatype of 'msg' is irrelevant. */ + rc = nn_recv (s, &msg, sizeof(msg), 0); + + errno_assert (rc == -1 && nn_errno () == EBADF); +} + +int main (int argc, const char *argv[]) +{ + int sb; + int i; + struct nn_thread thread; + char socket_address[128]; + + test_addr_from(socket_address, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + for (i = 0; i != TEST_LOOPS; ++i) { + sb = test_socket (AF_SP, NN_PULL); + test_bind (sb, socket_address); + nn_sleep (100); + nn_thread_init (&thread, routine, &sb); + nn_sleep (100); + test_close (sb); + nn_thread_term (&thread); + } + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/block.c b/node/node_modules/nanomsg/deps/nanomsg/tests/block.c new file mode 100644 index 0000000..ffb6222 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/block.c @@ -0,0 +1,72 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +/* This test checks whether blocking on send/recv works as expected. */ + +#define SOCKET_ADDRESS "inproc://a" + +int sc; +int sb; + +void worker (NN_UNUSED void *arg) +{ + /* Wait 0.1 sec for the main thread to block. */ + nn_sleep (100); + + test_send (sc, "ABC"); + + /* Wait 0.1 sec for the main thread to process the previous message + and block once again. */ + nn_sleep (100); + + test_send (sc, "ABC"); +} + +int main () +{ + struct nn_thread thread; + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + nn_thread_init (&thread, worker, NULL); + + test_recv (sb, "ABC"); + test_recv (sb, "ABC"); + + nn_thread_term (&thread); + + test_close (sc); + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/bug328.c b/node/node_modules/nanomsg/deps/nanomsg/tests/bug328.c new file mode 100644 index 0000000..dfb8d1e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/bug328.c @@ -0,0 +1,55 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "testutil.h" + +int main (int argc, const char *argv[]) +{ + int sb; + int sc; + char socket_address[128]; + + test_addr_from(socket_address, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + + nn_sleep(100); + test_send (sc, "ABC"); + test_recv (sb, "ABC"); + nn_assert (nn_get_statistic (sc, NN_STAT_CURRENT_CONNECTIONS) == 1); + test_close (sb); + nn_sleep(300); + nn_assert (nn_get_statistic (sc, NN_STAT_CURRENT_CONNECTIONS) == 0); + test_close (sc); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/bus.c b/node/node_modules/nanomsg/deps/nanomsg/tests/bus.c new file mode 100644 index 0000000..8d931d5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/bus.c @@ -0,0 +1,82 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/bus.h" +#include "testutil.h" + +#define SOCKET_ADDRESS_A "inproc://a" +#define SOCKET_ADDRESS_B "inproc://b" + +int main () +{ + int rc; + int bus1; + int bus2; + int bus3; + char buf [3]; + + /* Create a simple bus topology consisting of 3 nodes. */ + bus1 = test_socket (AF_SP, NN_BUS); + test_bind (bus1, SOCKET_ADDRESS_A); + bus2 = test_socket (AF_SP, NN_BUS); + test_bind (bus2, SOCKET_ADDRESS_B); + test_connect (bus2, SOCKET_ADDRESS_A); + bus3 = test_socket (AF_SP, NN_BUS); + test_connect (bus3, SOCKET_ADDRESS_A); + test_connect (bus3, SOCKET_ADDRESS_B); + + /* Send a message from each node. */ + test_send (bus1, "A"); + test_send (bus2, "AB"); + test_send (bus3, "ABC"); + + /* Check that two messages arrived at each node. */ + rc = nn_recv (bus1, buf, 3, 0); + errno_assert (rc >= 0); + nn_assert (rc == 2 || rc == 3); + rc = nn_recv (bus1, buf, 3, 0); + errno_assert (rc >= 0); + nn_assert (rc == 2 || rc == 3); + rc = nn_recv (bus2, buf, 3, 0); + errno_assert (rc >= 0); + nn_assert (rc == 1 || rc == 3); + rc = nn_recv (bus2, buf, 3, 0); + errno_assert (rc >= 0); + nn_assert (rc == 1 || rc == 3); + rc = nn_recv (bus3, buf, 3, 0); + errno_assert (rc >= 0); + nn_assert (rc == 1 || rc == 2); + rc = nn_recv (bus3, buf, 3, 0); + errno_assert (rc >= 0); + nn_assert (rc == 1 || rc == 2); + + /* Wait till both connections are established. */ + nn_sleep (10); + + test_close (bus3); + test_close (bus2); + test_close (bus1); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/cmsg.c b/node/node_modules/nanomsg/deps/nanomsg/tests/cmsg.c new file mode 100644 index 0000000..2c2c67e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/cmsg.c @@ -0,0 +1,116 @@ +/* + Copyright (c) 2014 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/tcp.h" +#include "../src/reqrep.h" + +#include "testutil.h" + +int main (int argc, const char *argv[]) +{ + int rc; + int rep; + int req; + struct nn_msghdr hdr; + struct nn_iovec iovec; + unsigned char body [3]; + unsigned char ctrl [256]; + struct nn_cmsghdr *cmsg; + unsigned char *data; + void *buf; + char socket_address[128]; + + test_addr_from(socket_address, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + rep = test_socket (AF_SP_RAW, NN_REP); + test_bind (rep, socket_address); + req = test_socket (AF_SP, NN_REQ); + test_connect (req, socket_address); + + /* Test ancillary data in static buffer. */ + + test_send (req, "ABC"); + + iovec.iov_base = body; + iovec.iov_len = sizeof (body); + hdr.msg_iov = &iovec; + hdr.msg_iovlen = 1; + hdr.msg_control = ctrl; + hdr.msg_controllen = sizeof (ctrl); + rc = nn_recvmsg (rep, &hdr, 0); + errno_assert (rc == 3); + + cmsg = NN_CMSG_FIRSTHDR (&hdr); + while (1) { + nn_assert (cmsg); + if (cmsg->cmsg_level == PROTO_SP && cmsg->cmsg_type == SP_HDR) + break; + cmsg = NN_CMSG_NXTHDR (&hdr, cmsg); + } + nn_assert (cmsg->cmsg_len == NN_CMSG_SPACE (8+sizeof (size_t))); + data = NN_CMSG_DATA (cmsg); + nn_assert (!(data[0+sizeof (size_t)] & 0x80)); + nn_assert (data[4+sizeof (size_t)] & 0x80); + + rc = nn_sendmsg (rep, &hdr, 0); + nn_assert (rc == 3); + test_recv (req, "ABC"); + + /* Test ancillary data in dynamically allocated buffer (NN_MSG). */ + + test_send (req, "ABC"); + + iovec.iov_base = body; + iovec.iov_len = sizeof (body); + hdr.msg_iov = &iovec; + hdr.msg_iovlen = 1; + hdr.msg_control = &buf; + hdr.msg_controllen = NN_MSG; + rc = nn_recvmsg (rep, &hdr, 0); + errno_assert (rc == 3); + + cmsg = NN_CMSG_FIRSTHDR (&hdr); + while (1) { + nn_assert (cmsg); + if (cmsg->cmsg_level == PROTO_SP && cmsg->cmsg_type == SP_HDR) + break; + cmsg = NN_CMSG_NXTHDR (&hdr, cmsg); + } + nn_assert (cmsg->cmsg_len == NN_CMSG_SPACE (8+sizeof (size_t))); + data = NN_CMSG_DATA (cmsg); + nn_assert (!(data[0+sizeof (size_t)] & 0x80)); + nn_assert (data[4+sizeof (size_t)] & 0x80); + + rc = nn_sendmsg (rep, &hdr, 0); + nn_assert (rc == 3); + test_recv (req, "ABC"); + + test_close (req); + test_close (rep); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/device.c b/node/node_modules/nanomsg/deps/nanomsg/tests/device.c new file mode 100644 index 0000000..34cbc91 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/device.c @@ -0,0 +1,189 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/bus.h" +#include "../src/pair.h" +#include "../src/pipeline.h" +#include "../src/inproc.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +#define SOCKET_ADDRESS_A "inproc://a" +#define SOCKET_ADDRESS_B "inproc://b" +#define SOCKET_ADDRESS_C "inproc://c" +#define SOCKET_ADDRESS_D "inproc://d" +#define SOCKET_ADDRESS_E "inproc://e" + +void device1 (NN_UNUSED void *arg) +{ + int rc; + int deva; + int devb; + + /* Intialise the device sockets. */ + deva = test_socket (AF_SP_RAW, NN_PAIR); + test_bind (deva, SOCKET_ADDRESS_A); + devb = test_socket (AF_SP_RAW, NN_PAIR); + test_bind (devb, SOCKET_ADDRESS_B); + + /* Run the device. */ + rc = nn_device (deva, devb); + nn_assert (rc < 0 && (nn_errno () == EBADF)); + + /* Clean up. */ + test_close (devb); + test_close (deva); +} + +void device2 (NN_UNUSED void *arg) +{ + int rc; + int devc; + int devd; + + /* Intialise the device sockets. */ + devc = test_socket (AF_SP_RAW, NN_PULL); + test_bind (devc, SOCKET_ADDRESS_C); + devd = test_socket (AF_SP_RAW, NN_PUSH); + test_bind (devd, SOCKET_ADDRESS_D); + + /* Run the device. */ + rc = nn_device (devc, devd); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (devd); + test_close (devc); +} + +void device3 (NN_UNUSED void *arg) +{ + int rc; + int deve; + + /* Intialise the device socket. */ + deve = test_socket (AF_SP_RAW, NN_BUS); + test_bind (deve, SOCKET_ADDRESS_E); + + /* Run the device. */ + rc = nn_device (deve, -1); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (deve); +} + +int main () +{ + int enda; + int endb; + int endc; + int endd; + int ende1; + int ende2; + struct nn_thread thread1; + struct nn_thread thread2; + struct nn_thread thread3; + int timeo; + + /* Test the bi-directional device. */ + + /* Start the device. */ + nn_thread_init (&thread1, device1, NULL); + + /* Create two sockets to connect to the device. */ + enda = test_socket (AF_SP, NN_PAIR); + test_connect (enda, SOCKET_ADDRESS_A); + endb = test_socket (AF_SP, NN_PAIR); + test_connect (endb, SOCKET_ADDRESS_B); + + /* Pass a pair of messages between endpoints. */ + test_send (enda, "ABC"); + test_recv (endb, "ABC"); + test_send (endb, "ABC"); + test_recv (enda, "ABC"); + + /* Clean up. */ + test_close (endb); + test_close (enda); + + /* Test the uni-directional device. */ + + /* Start the device. */ + nn_thread_init (&thread2, device2, NULL); + + /* Create two sockets to connect to the device. */ + endc = test_socket (AF_SP, NN_PUSH); + test_connect (endc, SOCKET_ADDRESS_C); + endd = test_socket (AF_SP, NN_PULL); + test_connect (endd, SOCKET_ADDRESS_D); + + /* Pass a message between endpoints. */ + test_send (endc, "XYZ"); + test_recv (endd, "XYZ"); + + /* Clean up. */ + test_close (endd); + test_close (endc); + + /* Test the loopback device. */ + + /* Start the device. */ + nn_thread_init (&thread3, device3, NULL); + + /* Create two sockets to connect to the device. */ + ende1 = test_socket (AF_SP, NN_BUS); + test_connect (ende1, SOCKET_ADDRESS_E); + ende2 = test_socket (AF_SP, NN_BUS); + test_connect (ende2, SOCKET_ADDRESS_E); + + /* BUS is unreliable so wait a bit for connections to be established. */ + nn_sleep (100); + + /* Pass a message to the bus. */ + test_send (ende1, "KLM"); + test_recv (ende2, "KLM"); + + /* Make sure that the message doesn't arrive at the socket it was + originally sent to. */ + timeo = 100; + test_setsockopt (ende1, NN_SOL_SOCKET, NN_RCVTIMEO, + &timeo, sizeof (timeo)); + test_drop (ende1, ETIMEDOUT); + + /* Clean up. */ + test_close (ende2); + test_close (ende1); + + /* Shut down the devices. */ + nn_term (); + nn_thread_term (&thread1); + nn_thread_term (&thread2); + nn_thread_term (&thread3); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/device4.c b/node/node_modules/nanomsg/deps/nanomsg/tests/device4.c new file mode 100644 index 0000000..c7428a1 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/device4.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/reqrep.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +static char socket_address_f[128], socket_address_g[128]; + +void device4 (NN_UNUSED void *arg) +{ + int rc; + int devf; + int devg; + + /* Intialise the device sockets. */ + devf = test_socket (AF_SP_RAW, NN_REP); + test_bind (devf, socket_address_f); + devg = test_socket (AF_SP_RAW, NN_REQ); + test_bind (devg, socket_address_g); + + /* Run the device. */ + rc = nn_device (devf, devg); + nn_assert (rc < 0 && (nn_errno () == EBADF)); + + /* Clean up. */ + test_close (devg); + test_close (devf); +} + +int main (int argc, const char *argv[]) +{ + int endf; + int endg; + struct nn_thread thread4; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address_f, "tcp", "127.0.0.1", port); + test_addr_from(socket_address_g, "tcp", "127.0.0.1", port + 1); + + /* Test the bi-directional device with REQ/REP (headers). */ + + /* Start the device. */ + nn_thread_init (&thread4, device4, NULL); + + /* Create two sockets to connect to the device. */ + endf = test_socket (AF_SP, NN_REQ); + test_connect (endf, socket_address_f); + endg = test_socket (AF_SP, NN_REP); + test_connect (endg, socket_address_g); + + /* Wait for TCP to establish. */ + nn_sleep (100); + + /* Pass a message between endpoints. */ + test_send (endf, "XYZ"); + test_recv (endg, "XYZ"); + + /* Now send a reply. */ + test_send (endg, "REPLYXYZ"); + test_recv (endf, "REPLYXYZ"); + + /* Clean up. */ + test_close (endg); + test_close (endf); + + /* Shut down the devices. */ + nn_term (); + nn_thread_term (&thread4); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/device5.c b/node/node_modules/nanomsg/deps/nanomsg/tests/device5.c new file mode 100644 index 0000000..5582d95 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/device5.c @@ -0,0 +1,124 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/reqrep.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +static char socket_address_h[128], socket_address_i[128], socket_address_j[128]; + +void device5 (NN_UNUSED void *arg) +{ + int rc; + int dev0; + int dev1; + + /* Intialise the device sockets. */ + dev0 = test_socket (AF_SP_RAW, NN_REP); + test_bind (dev0, socket_address_h); + dev1 = test_socket (AF_SP_RAW, NN_REQ); + test_bind (dev1, socket_address_i); + + /* Run the device. */ + rc = nn_device (dev0, dev1); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev0); + test_close (dev1); +} + +void device6 (NN_UNUSED void *arg) +{ + int rc; + int dev2; + int dev3; + + dev2 = test_socket (AF_SP_RAW, NN_REP); + test_connect (dev2, socket_address_i); + dev3 = test_socket (AF_SP_RAW, NN_REQ); + test_bind (dev3, socket_address_j); + + /* Run the device. */ + rc = nn_device (dev2, dev3); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev2); + test_close (dev3); +} + +int main (int argc, const char *argv[]) +{ + int end0; + int end1; + struct nn_thread thread5; + struct nn_thread thread6; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address_h, "tcp", "127.0.0.1", port); + test_addr_from(socket_address_i, "tcp", "127.0.0.1", port + 1); + test_addr_from(socket_address_j, "tcp", "127.0.0.1", port + 2); + + /* Test the bi-directional device with REQ/REP (headers). */ + + /* Start the devices. */ + nn_thread_init (&thread5, device5, NULL); + nn_thread_init (&thread6, device6, NULL); + + /* Create two sockets to connect to the device. */ + end0 = test_socket (AF_SP, NN_REQ); + test_connect (end0, socket_address_h); + end1 = test_socket (AF_SP, NN_REP); + test_connect (end1, socket_address_j); + + /* Wait for TCP to establish. */ + nn_sleep (100); + + /* Pass a message between endpoints. */ + test_send (end0, "XYZ"); + test_recv (end1, "XYZ"); + + /* Now send a reply. */ + test_send (end1, "REPLYXYZ"); + test_recv (end0, "REPLYXYZ"); + + /* Clean up. */ + test_close (end0); + test_close (end1); + + /* Shut down the devices. */ + nn_term (); + nn_thread_term (&thread5); + nn_thread_term (&thread6); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/device6.c b/node/node_modules/nanomsg/deps/nanomsg/tests/device6.c new file mode 100644 index 0000000..ccfe195 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/device6.c @@ -0,0 +1,124 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/survey.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +static char socket_address_h[128], socket_address_i[128], socket_address_j[128]; + +void device5 (NN_UNUSED void *arg) +{ + int rc; + int dev0; + int dev1; + + /* Intialise the device sockets. */ + dev0 = test_socket (AF_SP_RAW, NN_RESPONDENT); + test_bind (dev0, socket_address_h); + dev1 = test_socket (AF_SP_RAW, NN_SURVEYOR); + test_bind (dev1, socket_address_i); + + /* Run the device. */ + rc = nn_device (dev0, dev1); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev0); + test_close (dev1); +} + +void device6 (NN_UNUSED void *arg) +{ + int rc; + int dev2; + int dev3; + + dev2 = test_socket (AF_SP_RAW, NN_RESPONDENT); + test_connect (dev2, socket_address_i); + dev3 = test_socket (AF_SP_RAW, NN_SURVEYOR); + test_bind (dev3, socket_address_j); + + /* Run the device. */ + rc = nn_device (dev2, dev3); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev2); + test_close (dev3); +} + +int main (int argc, const char *argv[]) +{ + int end0; + int end1; + struct nn_thread thread5; + struct nn_thread thread6; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address_h, "tcp", "127.0.0.1", port); + test_addr_from(socket_address_i, "tcp", "127.0.0.1", port + 1); + test_addr_from(socket_address_j, "tcp", "127.0.0.1", port + 2); + + /* Test the bi-directional device with SURVEYOR(headers). */ + + /* Start the devices. */ + nn_thread_init (&thread5, device5, NULL); + nn_thread_init (&thread6, device6, NULL); + + /* Create two sockets to connect to the device. */ + end0 = test_socket (AF_SP, NN_SURVEYOR); + test_connect (end0, socket_address_h); + end1 = test_socket (AF_SP, NN_RESPONDENT); + test_connect (end1, socket_address_j); + + /* Wait up to a second for TCP to establish. */ + nn_sleep (1000); + + /* Pass a message between endpoints. */ + test_send (end0, "XYZ"); + test_recv (end1, "XYZ"); + + /* Now send a reply. */ + test_send (end1, "REPLYXYZ"); + test_recv (end0, "REPLYXYZ"); + + /* Clean up. */ + test_close (end0); + test_close (end1); + + /* Shut down the devices. */ + nn_term (); + nn_thread_term (&thread5); + nn_thread_term (&thread6); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/device7.c b/node/node_modules/nanomsg/deps/nanomsg/tests/device7.c new file mode 100644 index 0000000..d509c6b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/device7.c @@ -0,0 +1,126 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/reqrep.h" +#include "../src/tcp.h" +#include "../src/inproc.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +#define SOCKET_ADDRESS_I "inproc://nobody" + +static char socket_address_h[128], socket_address_j[128]; + +void device5 (NN_UNUSED void *arg) +{ + int rc; + int dev0; + int dev1; + + /* Intialise the device sockets. */ + dev0 = test_socket (AF_SP_RAW, NN_REP); + test_bind (dev0, socket_address_h); + dev1 = test_socket (AF_SP_RAW, NN_REQ); + test_bind (dev1, SOCKET_ADDRESS_I); + + /* Run the device. */ + rc = nn_device (dev0, dev1); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev0); + test_close (dev1); +} + +void device6 (NN_UNUSED void *arg) +{ + int rc; + int dev2; + int dev3; + + dev2 = test_socket (AF_SP_RAW, NN_REP); + test_connect (dev2, SOCKET_ADDRESS_I); + dev3 = test_socket (AF_SP_RAW, NN_REQ); + test_bind (dev3, socket_address_j); + + /* Run the device. */ + rc = nn_device (dev2, dev3); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev2); + test_close (dev3); +} + +int main (int argc, const char *argv[]) +{ + int end0; + int end1; + struct nn_thread thread5; + struct nn_thread thread6; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address_h, "tcp", "127.0.0.1", port); + test_addr_from(socket_address_j, "tcp", "127.0.0.1", port + 1); + + /* Test the bi-directional device with REQ/REP (headers). */ + + /* Start the devices. */ + nn_thread_init (&thread5, device5, NULL); + nn_thread_init (&thread6, device6, NULL); + + /* Create two sockets to connect to the device. */ + end0 = test_socket (AF_SP, NN_REQ); + test_connect (end0, socket_address_h); + end1 = test_socket (AF_SP, NN_REP); + test_connect (end1, socket_address_j); + + /* Wait for TCP to establish. */ + nn_sleep (1000); + + /* Pass a message between endpoints. */ + test_send (end0, "XYZ"); + test_recv (end1, "XYZ"); + + /* Now send a reply. */ + test_send (end1, "REPLYXYZ"); + test_recv (end0, "REPLYXYZ"); + + /* Clean up. */ + test_close (end0); + test_close (end1); + + /* Shut down the devices. */ + nn_term (); + nn_thread_term (&thread5); + nn_thread_term (&thread6); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/domain.c b/node/node_modules/nanomsg/deps/nanomsg/tests/domain.c new file mode 100644 index 0000000..d0a5e44 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/domain.c @@ -0,0 +1,54 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "testutil.h" + +/* Test the NN_DOMAIN and NN_PROTOCOL socket options. */ + +int main () +{ + int rc; + int s; + int op; + size_t opsz; + + s = test_socket (AF_SP, NN_PAIR); + + opsz = sizeof (op); + rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_DOMAIN, &op, &opsz); + errno_assert (rc == 0); + nn_assert (opsz == sizeof (op)); + nn_assert (op == AF_SP); + + opsz = sizeof (op); + rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_PROTOCOL, &op, &opsz); + errno_assert (rc == 0); + nn_assert (opsz == sizeof (op)); + nn_assert (op == NN_PAIR); + + test_close (s); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/emfile.c b/node/node_modules/nanomsg/deps/nanomsg/tests/emfile.c new file mode 100644 index 0000000..79b9ee7 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/emfile.c @@ -0,0 +1,54 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/tcp.h" +#include "../src/utils/err.c" + +#define MAX_SOCKETS 1000 + +int main () +{ + int rc; + int i; + int socks [MAX_SOCKETS]; + + /* First, just create as much SP sockets as possible. */ + for (i = 0; i != MAX_SOCKETS; ++i) { + socks [i] = nn_socket (AF_SP, NN_PAIR); + if (socks [i] < 0) { + errno_assert (nn_errno () == EMFILE); + break; + } + } + while (1) { + --i; + if (i == -1) + break; + rc = nn_close (socks [i]); + errno_assert (rc == 0); + } + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/hash.c b/node/node_modules/nanomsg/deps/nanomsg/tests/hash.c new file mode 100644 index 0000000..e51d5ad --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/hash.c @@ -0,0 +1,60 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/utils/err.c" +#include "../src/utils/list.c" +#include "../src/utils/hash.c" +#include "../src/utils/alloc.c" + +int main () +{ + struct nn_hash hash; + uint32_t k; + struct nn_hash_item *item; + struct nn_hash_item *item5000 = NULL; + + nn_hash_init (&hash); + + /* Insert 10000 elements into the hash table. */ + for (k = 0; k != 10000; ++k) { + item = nn_alloc (sizeof (struct nn_hash_item), "item"); + nn_assert (item); + if (k == 5000) + item5000 = item; + nn_hash_item_init (item); + nn_hash_insert (&hash, k, item); + } + + /* Find one element and check whether it is the correct one. */ + nn_assert (nn_hash_get (&hash, 5000) == item5000); + + /* Remove all the elements from the hash table and terminate it. */ + for (k = 0; k != 10000; ++k) { + item = nn_hash_get (&hash, k); + nn_hash_erase (&hash, item); + nn_free (item); + } + nn_hash_term (&hash); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/inproc.c b/node/node_modules/nanomsg/deps/nanomsg/tests/inproc.c new file mode 100644 index 0000000..421f690 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/inproc.c @@ -0,0 +1,222 @@ + /* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/bus.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/reqrep.h" +#include "../src/inproc.h" + +#include "testutil.h" + +/* Tests inproc transport. */ + +#define SOCKET_ADDRESS "inproc://test" + +int main () +{ + int rc; + int sb; + int sc; + int s1, s2; + int i; + char buf [256]; + int val; + struct nn_msghdr hdr; + struct nn_iovec iovec; + unsigned char body [3]; + void *control; + struct nn_cmsghdr *cmsg; + unsigned char *data; + + /* Create a simple topology. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + + /* Try a duplicate bind. It should fail. */ + rc = nn_bind (sc, SOCKET_ADDRESS); + nn_assert (rc < 0 && errno == EADDRINUSE); + + /* Ping-pong test. */ + for (i = 0; i != 100; ++i) { + + test_send (sc, "ABC"); + test_recv (sb, "ABC"); + test_send (sb, "DEFG"); + test_recv (sc, "DEFG"); + } + + /* Batch transfer test. */ + for (i = 0; i != 100; ++i) { + test_send (sc, "XYZ"); + } + for (i = 0; i != 100; ++i) { + test_recv (sb, "XYZ"); + } + + test_close (sc); + test_close (sb); + + /* Test whether queue limits are observed. */ + sb = test_socket (AF_SP, NN_PAIR); + val = 200; + test_setsockopt (sb, NN_SOL_SOCKET, NN_RCVBUF, &val, sizeof (val)); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + val = 200; + test_setsockopt (sc, NN_SOL_SOCKET, NN_SNDTIMEO, &val, sizeof (val)); + i = 0; + while (1) { + rc = nn_send (sc, "0123456789", 10, 0); + if (rc < 0 && nn_errno () == ETIMEDOUT) + break; + errno_assert (rc >= 0); + nn_assert (rc == 10); + ++i; + } + nn_assert (i == 20); + test_recv (sb, "0123456789"); + test_send (sc, "0123456789"); + rc = nn_send (sc, "0123456789", 10, 0); + nn_assert (rc < 0 && nn_errno () == ETIMEDOUT); + for (i = 0; i != 20; ++i) { + test_recv (sb, "0123456789"); + } + + /* Make sure that even a message that doesn't fit into the buffers + gets across. */ + for (i = 0; i != sizeof (buf); ++i) + buf [i] = 'A'; + rc = nn_send (sc, buf, 256, 0); + errno_assert (rc >= 0); + nn_assert (rc == 256); + rc = nn_recv (sb, buf, sizeof (buf), 0); + errno_assert (rc >= 0); + nn_assert (rc == 256); + + test_close (sc); + test_close (sb); + +#if 0 + /* Test whether connection rejection is handled decently. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + s1 = test_socket (AF_SP, NN_PAIR); + test_connect (s1, SOCKET_ADDRESS); + s2 = test_socket (AF_SP, NN_PAIR); + test_connect (s2, SOCKET_ADDRESS); + nn_sleep (100); + test_close (s2); + test_close (s1); + test_close (sb); +#endif + + /* Check whether SP message header is transferred correctly. */ + sb = test_socket (AF_SP_RAW, NN_REP); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_REQ); + test_connect (sc, SOCKET_ADDRESS); + + test_send (sc, "ABC"); + + iovec.iov_base = body; + iovec.iov_len = sizeof (body); + hdr.msg_iov = &iovec; + hdr.msg_iovlen = 1; + hdr.msg_control = &control; + hdr.msg_controllen = NN_MSG; + rc = nn_recvmsg (sb, &hdr, 0); + errno_assert (rc == 3); + + cmsg = NN_CMSG_FIRSTHDR (&hdr); + while (1) { + nn_assert (cmsg); + if (cmsg->cmsg_level == PROTO_SP && cmsg->cmsg_type == SP_HDR) + break; + cmsg = NN_CMSG_NXTHDR (&hdr, cmsg); + } + nn_assert (cmsg->cmsg_len == NN_CMSG_SPACE (8+sizeof (size_t))); + data = NN_CMSG_DATA (cmsg); + nn_assert (!(data[0+sizeof (size_t)] & 0x80)); + nn_assert (data[4+sizeof (size_t)] & 0x80); + + nn_freemsg (control); + + test_close (sc); + test_close (sb); + + /* Test binding a new socket after originally bound socket shuts down. */ + sb = test_socket (AF_SP, NN_BUS); + test_bind (sb, SOCKET_ADDRESS); + + sc = test_socket (AF_SP, NN_BUS); + test_connect (sc, SOCKET_ADDRESS); + + s1 = test_socket (AF_SP, NN_BUS); + test_connect (s1, SOCKET_ADDRESS); + + /* Close bound socket, leaving connected sockets connect. */ + test_close (sb); + + nn_sleep (100); + + /* Rebind a new socket to the address to which our connected sockets are listening. */ + s2 = test_socket (AF_SP, NN_BUS); + test_bind (s2, SOCKET_ADDRESS); + + /* Ping-pong test. */ + for (i = 0; i != 100; ++i) { + + test_send (sc, "ABC"); + test_send (s1, "QRS"); + test_recv (s2, "ABC"); + test_recv (s2, "QRS"); + test_send (s2, "DEFG"); + test_recv (sc, "DEFG"); + test_recv (s1, "DEFG"); + } + + /* Batch transfer test. */ + for (i = 0; i != 100; ++i) { + test_send (sc, "XYZ"); + } + for (i = 0; i != 100; ++i) { + test_recv (s2, "XYZ"); + } + for (i = 0; i != 100; ++i) { + test_send (s1, "MNO"); + } + for (i = 0; i != 100; ++i) { + test_recv (s2, "MNO"); + } + + test_close (s1); + test_close (sc); + test_close (s2); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/inproc_shutdown.c b/node/node_modules/nanomsg/deps/nanomsg/tests/inproc_shutdown.c new file mode 100644 index 0000000..1b8b4bc --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/inproc_shutdown.c @@ -0,0 +1,72 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/inproc.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +/* Stress test the inproc transport. */ + +#define THREAD_COUNT 100 +#define SOCKET_ADDRESS "inproc://test" + +static void routine (NN_UNUSED void *arg) +{ + int s; + + s = nn_socket (AF_SP, NN_SUB); + if (s < 0 && nn_errno () == EMFILE) + return; + errno_assert (s >= 0); + test_connect (s, SOCKET_ADDRESS); + test_close (s); +} + +int main () +{ + int sb; + int i; + int j; + struct nn_thread threads [THREAD_COUNT]; + + /* Stress the shutdown algorithm. */ + + sb = test_socket (AF_SP, NN_PUB); + test_bind (sb, SOCKET_ADDRESS); + + for (j = 0; j != 10; ++j) { + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_init (&threads [i], routine, NULL); + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_term (&threads [i]); + } + + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/iovec.c b/node/node_modules/nanomsg/deps/nanomsg/tests/iovec.c new file mode 100644 index 0000000..a9c5970 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/iovec.c @@ -0,0 +1,74 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "testutil.h" + +#include + +#define SOCKET_ADDRESS "inproc://a" + +int main () +{ + int rc; + int sb; + int sc; + struct nn_iovec iov [2]; + struct nn_msghdr hdr; + char buf [6]; + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + iov [0].iov_base = "AB"; + iov [0].iov_len = 2; + iov [1].iov_base = "CDEF"; + iov [1].iov_len = 4; + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = iov; + hdr.msg_iovlen = 2; + rc = nn_sendmsg (sc, &hdr, 0); + errno_assert (rc >= 0); + nn_assert (rc == 6); + + iov [0].iov_base = buf; + iov [0].iov_len = 4; + iov [1].iov_base = buf + 4; + iov [1].iov_len = 2; + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = iov; + hdr.msg_iovlen = 2; + rc = nn_recvmsg (sb, &hdr, 0); + errno_assert (rc >= 0); + nn_assert (rc == 6); + nn_assert (memcmp (buf, "ABCDEF", 6) == 0); + + test_close (sc); + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/ipc.c b/node/node_modules/nanomsg/deps/nanomsg/tests/ipc.c new file mode 100644 index 0000000..d086ffb --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/ipc.c @@ -0,0 +1,133 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/ipc.h" + +#include "testutil.h" + +/* Tests IPC transport. */ + +#define SOCKET_ADDRESS "ipc://test.ipc" + +int main () +{ + int sb; + int sc; + int i; + int s1, s2; +#if !defined(NN_HAVE_WINDOWS) + int rc; +#endif + + int size; + char * buf; + + /* Try closing a IPC socket while it not connected. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + test_close (sc); + + /* Open the socket anew. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + /* Leave enough time for at least one re-connect attempt. */ + nn_sleep (200); + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + + /* Ping-pong test. */ + for (i = 0; i != 1; ++i) { + test_send (sc, "0123456789012345678901234567890123456789"); + test_recv (sb, "0123456789012345678901234567890123456789"); + test_send (sb, "0123456789012345678901234567890123456789"); + test_recv (sc, "0123456789012345678901234567890123456789"); + } + + /* Batch transfer test. */ + for (i = 0; i != 100; ++i) { + test_send (sc, "XYZ"); + } + for (i = 0; i != 100; ++i) { + test_recv (sb, "XYZ"); + } + + /* Send something large enough to trigger overlapped I/O on Windows. */ + size = 10000; + buf = malloc (size); + for (i = 0; i < size; ++i) { + buf[i] = 48 + i % 10; + } + buf[size-1] = '\0'; + test_send (sc, buf); + test_recv (sb, buf); + free (buf); + + test_close (sc); + test_close (sb); + + /* Test whether connection rejection is handled decently. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + s1 = test_socket (AF_SP, NN_PAIR); + test_connect (s1, SOCKET_ADDRESS); + s2 = test_socket (AF_SP, NN_PAIR); + test_connect (s2, SOCKET_ADDRESS); + nn_sleep (100); + test_close (s2); + test_close (s1); + test_close (sb); + +/* On Windows, CreateNamedPipeA does not run exclusively. + We should look at fixing this, but it will require + changing the usock code for Windows. In the meantime just + disable this test on Windows. */ +#if !defined(NN_HAVE_WINDOWS) + /* Test two sockets binding to the same address. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + s1 = test_socket (AF_SP, NN_PAIR); + rc = nn_bind (s1, SOCKET_ADDRESS); + nn_assert (rc < 0); + errno_assert (nn_errno () == EADDRINUSE); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + nn_sleep (100); + test_send (sb, "ABC"); + test_recv (sc, "ABC"); + test_close (sb); + test_close (sc); + test_close (s1); +#endif + + /* Test closing a socket that is waiting to connect. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + nn_sleep (100); + test_close (sc); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/ipc_shutdown.c b/node/node_modules/nanomsg/deps/nanomsg/tests/ipc_shutdown.c new file mode 100644 index 0000000..a69bd35 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/ipc_shutdown.c @@ -0,0 +1,121 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/pipeline.h" +#include "../src/ipc.h" + +#include "testutil.h" +#include "../src/utils/thread.c" + +/* Stress test the IPC transport. */ + +#define THREAD_COUNT 100 +#define TEST2_THREAD_COUNT 10 +#define MESSAGES_PER_THREAD 10 +#define TEST_LOOPS 10 +#define SOCKET_ADDRESS "ipc://test-shutdown.ipc" + +volatile int active; + +static void routine (NN_UNUSED void *arg) +{ + int s; + + s = nn_socket (AF_SP, NN_SUB); + if (s < 0 && nn_errno () == EMFILE) + return; + errno_assert (s >= 0); + test_connect (s, SOCKET_ADDRESS); + test_close (s); +} + +static void routine2 (NN_UNUSED void *arg) +{ + int s; + int i; + + s = test_socket (AF_SP, NN_PULL); + + for (i = 0; i < 10; ++i) { + test_connect (s, SOCKET_ADDRESS); + } + + for (i = 0; i < MESSAGES_PER_THREAD; ++i) { + test_recv (s, "hello"); + } + + test_close (s); + active --; +} + +int main () +{ + int sb; + int i; + int j; + struct nn_thread threads [THREAD_COUNT]; + + /* Stress the shutdown algorithm. */ + +#if defined(SIGPIPE) && defined(SIG_IGN) + signal (SIGPIPE, SIG_IGN); +#endif + + sb = test_socket (AF_SP, NN_PUB); + test_bind (sb, SOCKET_ADDRESS); + + for (j = 0; j != TEST_LOOPS; ++j) { + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_init (&threads [i], routine, NULL); + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_term (&threads [i]); + } + + test_close (sb); + + /* Test race condition of sending message while socket shutting down */ + + sb = test_socket (AF_SP, NN_PUSH); + test_bind (sb, SOCKET_ADDRESS); + + for (j = 0; j != TEST_LOOPS; ++j) { + for (i = 0; i != TEST2_THREAD_COUNT; ++i) + nn_thread_init (&threads [i], routine2, NULL); + active = TEST2_THREAD_COUNT; + + while (active) { + (void) nn_send (sb, "hello", 5, NN_DONTWAIT); + nn_sleep (0); + } + + for (i = 0; i != TEST2_THREAD_COUNT; ++i) + nn_thread_term (&threads [i]); + } + + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/ipc_stress.c b/node/node_modules/nanomsg/deps/nanomsg/tests/ipc_stress.c new file mode 100644 index 0000000..91b45c5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/ipc_stress.c @@ -0,0 +1,115 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/pipeline.h" +#include "../src/ipc.h" + +#include "testutil.h" +#include "../src/utils/thread.c" +#include "../src/utils/atomic.h" +#include "../src/utils/atomic.c" + +/* Stress test the IPC transport. */ + +#define THREAD_COUNT 10 +#define TEST_LOOPS 10 +#define SOCKET_ADDRESS "ipc://test-stress.ipc" + +static void server(NN_UNUSED void *arg) +{ + int bytes; + int count; + int sock = nn_socket(AF_SP, NN_PULL); + int res[TEST_LOOPS]; + nn_assert(sock >= 0); + nn_assert(nn_bind(sock, SOCKET_ADDRESS) >= 0); + count = THREAD_COUNT * TEST_LOOPS; + memset(res, 0, sizeof (res)); + while (count > 0) + { + char *buf = NULL; + int tid; + int num; + bytes = nn_recv(sock, &buf, NN_MSG, 0); + nn_assert(bytes >= 0); + nn_assert(bytes >= 2); + nn_assert(buf[0] >= 'A' && buf[0] <= 'Z'); + nn_assert(buf[1] >= 'a' && buf[0] <= 'z'); + tid = buf[0]-'A'; + num = buf[1]-'a'; + nn_assert(tid < THREAD_COUNT); + nn_assert(res[tid] == num); + res[tid]=num+1; + nn_freemsg(buf); + count--; + } + nn_close(sock); +} + +static void client(void *arg) +{ + intptr_t id = (intptr_t)arg; + int bytes; + char msg[3]; + size_t sz_msg; + int i; + + msg[0] = 'A' + id%26; + msg[1] = 'a'; + msg[2] = '\0'; + /* '\0' too */ + sz_msg = strlen (msg) + 1; + + for (i = 0; i < TEST_LOOPS; i++) { + int cli_sock = nn_socket (AF_SP, NN_PUSH); + msg[1] = 'a' + i%26; + nn_assert (cli_sock >= 0); + nn_assert (nn_connect (cli_sock, SOCKET_ADDRESS) >= 0); + /* Give time to allow for connect to establish. */ + nn_sleep (50); + bytes = nn_send (cli_sock, msg, sz_msg, 0); + /* This would better be handled via semaphore or condvar. */ + nn_sleep (100); + nn_assert (bytes == sz_msg); + nn_close (cli_sock); + } +} + +int main() +{ + int i; + struct nn_thread srv_thread; + struct nn_thread cli_threads[THREAD_COUNT]; + /* Stress the shutdown algorithm. */ + nn_thread_init(&srv_thread, server, NULL); + + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_init(&cli_threads[i], client, (void *)(intptr_t)i); + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_term(&cli_threads[i]); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/list.c b/node/node_modules/nanomsg/deps/nanomsg/tests/list.c new file mode 100644 index 0000000..9c5caa2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/list.c @@ -0,0 +1,197 @@ +/* + Copyright (c) 2013 Nir Soffer + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/utils/cont.h" + +#include "../src/utils/err.c" +#include "../src/utils/list.c" + +static struct nn_list_item sentinel; + +/* Typical object that can be added to a list. */ +struct item { + int value; + struct nn_list_item item; +}; + +/* Initializing list items statically so they can be inserted into a list. */ +static struct item that = {1, NN_LIST_ITEM_INITIALIZER}; +static struct item other = {2, NN_LIST_ITEM_INITIALIZER}; + +int main () +{ + int rc; + struct nn_list list; + struct nn_list_item *list_item; + struct item *item; + + /* List item life cycle. */ + + /* Initialize the item. Make sure it's not part of any list. */ + nn_list_item_init (&that.item); + nn_assert (!nn_list_item_isinlist (&that.item)); + + /* That may be part of some list, or uninitialized memory. */ + that.item.prev = &sentinel; + that.item.next = &sentinel; + nn_assert (nn_list_item_isinlist (&that.item)); + that.item.prev = NULL; + that.item.next = NULL; + nn_assert (nn_list_item_isinlist (&that.item)); + + /* Before termination, item must be removed from the list. */ + nn_list_item_init (&that.item); + nn_list_item_term (&that.item); + + /* Initializing a list. */ + + /* Uninitialized list has random content. */ + list.first = &sentinel; + list.last = &sentinel; + + nn_list_init (&list); + + nn_assert (list.first == NULL); + nn_assert (list.last == NULL); + + nn_list_term (&list); + + /* Empty list. */ + + nn_list_init (&list); + + rc = nn_list_empty (&list); + nn_assert (rc == 1); + + list_item = nn_list_begin (&list); + nn_assert (list_item == NULL); + + list_item = nn_list_end (&list); + nn_assert (list_item == NULL); + + nn_list_term (&list); + + /* Inserting and erasing items. */ + + nn_list_init (&list); + nn_list_item_init (&that.item); + + /* Item doesn'tt belong to list yet. */ + nn_assert (!nn_list_item_isinlist (&that.item)); + + nn_list_insert (&list, &that.item, nn_list_end (&list)); + + /* Item is now part of a list. */ + nn_assert (nn_list_item_isinlist (&that.item)); + + /* Single item does not have prev or next item. */ + nn_assert (that.item.prev == NULL); + nn_assert (that.item.next == NULL); + + /* Item is both first and list item. */ + nn_assert (list.first == &that.item); + nn_assert (list.last == &that.item); + + /* Removing an item. */ + nn_list_erase (&list, &that.item); + nn_assert (!nn_list_item_isinlist (&that.item)); + + nn_assert (list.first == NULL); + nn_assert (list.last == NULL); + + nn_list_item_term (&that.item); + nn_list_term (&list); + + /* Iterating items. */ + + nn_list_init (&list); + nn_list_item_init (&that.item); + + nn_list_insert (&list, &that.item, nn_list_end (&list)); + + list_item = nn_list_begin (&list); + nn_assert (list_item == &that.item); + + item = nn_cont (list_item, struct item, item); + nn_assert (item == &that); + + list_item = nn_list_end (&list); + nn_assert (list_item == NULL); + + list_item = nn_list_prev (&list, &that.item); + nn_assert (list_item == NULL); + + list_item = nn_list_next (&list, &that.item); + nn_assert (list_item == NULL); + + rc = nn_list_empty (&list); + nn_assert (rc == 0); + + nn_list_erase (&list, &that.item); + nn_list_item_term (&that.item); + nn_list_term (&list); + + /* Appending items. */ + + nn_list_init (&list); + nn_list_item_init (&that.item); + nn_list_item_init (&other.item); + + nn_list_insert (&list, &that.item, nn_list_end (&list)); + nn_list_insert (&list, &other.item, nn_list_end (&list)); + + list_item = nn_list_begin (&list); + nn_assert (list_item == &that.item); + + list_item = nn_list_next (&list, list_item); + nn_assert (list_item == &other.item); + + nn_list_erase (&list, &that.item); + nn_list_erase (&list, &other.item); + nn_list_item_term (&that.item); + nn_list_item_term (&other.item); + nn_list_term (&list); + + /* Prepending items. */ + + nn_list_init (&list); + nn_list_item_init (&that.item); + nn_list_item_init (&other.item); + + nn_list_insert (&list, &that.item, nn_list_begin (&list)); + nn_list_insert (&list, &other.item, nn_list_begin (&list)); + + list_item = nn_list_begin (&list); + nn_assert (list_item == &other.item); + + list_item = nn_list_next (&list, list_item); + nn_assert (list_item == &that.item); + + nn_list_erase (&list, &that.item); + nn_list_erase (&list, &other.item); + nn_list_item_term (&that.item); + nn_list_item_term (&other.item); + nn_list_term (&list); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/msg.c b/node/node_modules/nanomsg/deps/nanomsg/tests/msg.c new file mode 100644 index 0000000..d0d9530 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/msg.c @@ -0,0 +1,129 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "testutil.h" + +#include + +#define SOCKET_ADDRESS "inproc://a" + +char longdata[1 << 20]; + +int main (int argc, const char *argv[]) +{ + int rc; + int sb; + int sc; + unsigned char *buf1, *buf2; + int i; + struct nn_iovec iov; + struct nn_msghdr hdr; + char socket_address_tcp[128]; + + test_addr_from(socket_address_tcp, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + buf1 = nn_allocmsg (256, 0); + alloc_assert (buf1); + for (i = 0; i != 256; ++i) + buf1 [i] = (unsigned char) i; + rc = nn_send (sc, &buf1, NN_MSG, 0); + errno_assert (rc >= 0); + nn_assert (rc == 256); + + buf2 = NULL; + rc = nn_recv (sb, &buf2, NN_MSG, 0); + errno_assert (rc >= 0); + nn_assert (rc == 256); + nn_assert (buf2); + for (i = 0; i != 256; ++i) + nn_assert (buf2 [i] == (unsigned char) i); + rc = nn_freemsg (buf2); + errno_assert (rc == 0); + + buf1 = nn_allocmsg (256, 0); + alloc_assert (buf1); + for (i = 0; i != 256; ++i) + buf1 [i] = (unsigned char) i; + iov.iov_base = &buf1; + iov.iov_len = NN_MSG; + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + rc = nn_sendmsg (sc, &hdr, 0); + errno_assert (rc >= 0); + nn_assert (rc == 256); + + buf2 = NULL; + iov.iov_base = &buf2; + iov.iov_len = NN_MSG; + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + rc = nn_recvmsg (sb, &hdr, 0); + errno_assert (rc >= 0); + nn_assert (rc == 256); + nn_assert (buf2); + for (i = 0; i != 256; ++i) + nn_assert (buf2 [i] == (unsigned char) i); + rc = nn_freemsg (buf2); + errno_assert (rc == 0); + + test_close (sc); + test_close (sb); + + /* Test receiving of large message */ + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address_tcp); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address_tcp); + + for (i = 0; i < (int) sizeof (longdata); ++i) + longdata[i] = '0' + (i % 10); + longdata [sizeof (longdata) - 1] = 0; + test_send (sb, longdata); + + rc = nn_recv (sc, &buf2, NN_MSG, 0); + errno_assert (rc >= 0); + nn_assert (rc == sizeof (longdata) - 1); + nn_assert (buf2); + for (i = 0; i < (int) sizeof (longdata) - 1; ++i) + nn_assert (buf2 [i] == longdata [i]); + rc = nn_freemsg (buf2); + errno_assert (rc == 0); + + test_close (sc); + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/pair.c b/node/node_modules/nanomsg/deps/nanomsg/tests/pair.c new file mode 100644 index 0000000..51bce13 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/pair.c @@ -0,0 +1,50 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "testutil.h" + +#define SOCKET_ADDRESS "inproc://a" + +int main () +{ + int sb; + int sc; + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + test_send (sc, "ABC"); + test_recv (sb, "ABC"); + test_send (sb, "DEF"); + test_recv (sc, "DEF"); + + test_close (sc); + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/pipeline.c b/node/node_modules/nanomsg/deps/nanomsg/tests/pipeline.c new file mode 100644 index 0000000..6f1cda9 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/pipeline.c @@ -0,0 +1,81 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pipeline.h" +#include "testutil.h" + +#define SOCKET_ADDRESS "inproc://a" + +int main () +{ + int push1; + int push2; + int pull1; + int pull2; + + /* Test fan-out. */ + + push1 = test_socket (AF_SP, NN_PUSH); + test_bind (push1, SOCKET_ADDRESS); + pull1 = test_socket (AF_SP, NN_PULL); + test_connect (pull1, SOCKET_ADDRESS); + pull2 = test_socket (AF_SP, NN_PULL); + test_connect (pull2, SOCKET_ADDRESS); + + /* Wait till both connections are established to get messages spread + evenly between the two pull sockets. */ + nn_sleep (10); + + test_send (push1, "ABC"); + test_send (push1, "DEF"); + + test_recv (pull1, "ABC"); + test_recv (pull2, "DEF"); + + test_close (push1); + test_close (pull1); + test_close (pull2); + + /* Test fan-in. */ + + pull1 = test_socket (AF_SP, NN_PULL); + test_bind (pull1, SOCKET_ADDRESS); + push1 = test_socket (AF_SP, NN_PUSH); + test_connect (push1, SOCKET_ADDRESS); + push2 = test_socket (AF_SP, NN_PUSH); + test_connect (push2, SOCKET_ADDRESS); + + test_send (push1, "ABC"); + test_send (push2, "DEF"); + + test_recv (pull1, "ABC"); + test_recv (pull1, "DEF"); + + test_close (pull1); + test_close (push1); + test_close (push2); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/poll.c b/node/node_modules/nanomsg/deps/nanomsg/tests/poll.c new file mode 100644 index 0000000..aad87e5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/poll.c @@ -0,0 +1,194 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/inproc.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +#if defined NN_HAVE_WINDOWS +#include "../src/utils/win.h" +#else +#include +#endif + +/* Test of polling via NN_SNDFD/NN_RCVFD mechanism. */ + +#define SOCKET_ADDRESS "inproc://a" + +int sc; + +void routine1 (NN_UNUSED void *arg) +{ + nn_sleep (10); + test_send (sc, "ABC"); +} + +void routine2 (NN_UNUSED void *arg) +{ + nn_sleep (10); + nn_term (); +} + +#define NN_IN 1 +#define NN_OUT 2 + +int getevents (int s, int events, int timeout) +{ + int rc; + fd_set pollset; +#if defined NN_HAVE_WINDOWS + SOCKET rcvfd; + SOCKET sndfd; +#else + int rcvfd; + int sndfd; + int maxfd; +#endif + size_t fdsz; + struct timeval tv; + int revents; + +#if !defined NN_HAVE_WINDOWS + maxfd = 0; +#endif + FD_ZERO (&pollset); + + if (events & NN_IN) { + fdsz = sizeof (rcvfd); + rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_RCVFD, (char*) &rcvfd, &fdsz); + errno_assert (rc == 0); + nn_assert (fdsz == sizeof (rcvfd)); + FD_SET (rcvfd, &pollset); +#if !defined NN_HAVE_WINDOWS + if (rcvfd + 1 > maxfd) + maxfd = rcvfd + 1; +#endif + } + + if (events & NN_OUT) { + fdsz = sizeof (sndfd); + rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_SNDFD, (char*) &sndfd, &fdsz); + errno_assert (rc == 0); + nn_assert (fdsz == sizeof (sndfd)); + FD_SET (sndfd, &pollset); +#if !defined NN_HAVE_WINDOWS + if (sndfd + 1 > maxfd) + maxfd = sndfd + 1; +#endif + } + + if (timeout >= 0) { + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + } +#if defined NN_HAVE_WINDOWS + rc = select (0, &pollset, NULL, NULL, timeout < 0 ? NULL : &tv); + wsa_assert (rc != SOCKET_ERROR); +#else + rc = select (maxfd, &pollset, NULL, NULL, timeout < 0 ? NULL : &tv); + errno_assert (rc >= 0); +#endif + revents = 0; + if ((events & NN_IN) && FD_ISSET (rcvfd, &pollset)) + revents |= NN_IN; + if ((events & NN_OUT) && FD_ISSET (sndfd, &pollset)) + revents |= NN_OUT; + return revents; +} + +int main () +{ + int rc; + int sb; + char buf [3]; + struct nn_thread thread; + struct nn_pollfd pfd [2]; + + /* Test nn_poll() function. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + test_send (sc, "ABC"); + nn_sleep (100); + pfd [0].fd = sb; + pfd [0].events = NN_POLLIN | NN_POLLOUT; + pfd [1].fd = sc; + pfd [1].events = NN_POLLIN | NN_POLLOUT; + rc = nn_poll (pfd, 2, -1); + errno_assert (rc >= 0); + nn_assert (rc == 2); + nn_assert (pfd [0].revents == (NN_POLLIN | NN_POLLOUT)); + nn_assert (pfd [1].revents == NN_POLLOUT); + test_close (sc); + test_close (sb); + + /* Create a simple topology. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, SOCKET_ADDRESS); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + /* Check the initial state of the socket. */ + rc = getevents (sb, NN_IN | NN_OUT, 1000); + nn_assert (rc == NN_OUT); + + /* Poll for IN when there's no message available. The call should + time out. */ + rc = getevents (sb, NN_IN, 10); + nn_assert (rc == 0); + + /* Send a message and start polling. This time IN event should be + signaled. */ + test_send (sc, "ABC"); + rc = getevents (sb, NN_IN, 1000); + nn_assert (rc == NN_IN); + + /* Receive the message and make sure that IN is no longer signaled. */ + test_recv (sb, "ABC"); + rc = getevents (sb, NN_IN, 10); + nn_assert (rc == 0); + + /* Check signalling from a different thread. */ + nn_thread_init (&thread, routine1, NULL); + rc = getevents (sb, NN_IN, 1000); + nn_assert (rc == NN_IN); + test_recv (sb, "ABC"); + nn_thread_term (&thread); + + /* Check terminating the library from a different thread. */ + nn_thread_init (&thread, routine2, NULL); + rc = nn_recv (sb, buf, sizeof (buf), 0); + nn_assert (rc < 0 && nn_errno () == EBADF); + nn_thread_term (&thread); + + /* Clean up. */ + test_close (sc); + test_close (sb); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/prio.c b/node/node_modules/nanomsg/deps/nanomsg/tests/prio.c new file mode 100644 index 0000000..90a75b8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/prio.c @@ -0,0 +1,121 @@ +/* + Copyright (c) 2013-2014 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pipeline.h" + +#include "testutil.h" + +#define SOCKET_ADDRESS_A "inproc://a" +#define SOCKET_ADDRESS_B "inproc://b" + +int main () +{ + int rc; + int push1; + int push2; + int pull1; + int pull2; + int sndprio; + int rcvprio; + + /* Test send priorities. */ + + pull1 = test_socket (AF_SP, NN_PULL); + test_bind (pull1, SOCKET_ADDRESS_A); + pull2 = test_socket (AF_SP, NN_PULL); + test_bind (pull2, SOCKET_ADDRESS_B); + push1 = test_socket (AF_SP, NN_PUSH); + sndprio = 1; + rc = nn_setsockopt (push1, NN_SOL_SOCKET, NN_SNDPRIO, + &sndprio, sizeof (sndprio)); + errno_assert (rc == 0); + test_connect (push1, SOCKET_ADDRESS_A); + sndprio = 2; + rc = nn_setsockopt (push1, NN_SOL_SOCKET, NN_SNDPRIO, + &sndprio, sizeof (sndprio)); + errno_assert (rc == 0); + test_connect (push1, SOCKET_ADDRESS_B); + + test_send (push1, "ABC"); + test_send (push1, "DEF"); + test_recv (pull1, "ABC"); + test_recv (pull1, "DEF"); + + test_close (pull1); + test_close (push1); + test_close (pull2); + + /* Test receive priorities. */ + + push1 = test_socket (AF_SP, NN_PUSH); + test_bind (push1, SOCKET_ADDRESS_A); + push2 = test_socket (AF_SP, NN_PUSH); + test_bind (push2, SOCKET_ADDRESS_B); + pull1 = test_socket (AF_SP, NN_PULL); + rcvprio = 2; + rc = nn_setsockopt (pull1, NN_SOL_SOCKET, NN_RCVPRIO, + &rcvprio, sizeof (rcvprio)); + errno_assert (rc == 0); + test_connect (pull1, SOCKET_ADDRESS_A); + rcvprio = 1; + rc = nn_setsockopt (pull1, NN_SOL_SOCKET, NN_RCVPRIO, + &rcvprio, sizeof (rcvprio)); + errno_assert (rc == 0); + test_connect (pull1, SOCKET_ADDRESS_B); + + test_send (push1, "ABC"); + test_send (push2, "DEF"); + nn_sleep (100); + test_recv (pull1, "DEF"); + test_recv (pull1, "ABC"); + + test_close (pull1); + test_close (push2); + test_close (push1); + + /* Test removing a pipe from the list. */ + + push1 = test_socket (AF_SP, NN_PUSH); + test_bind (push1, SOCKET_ADDRESS_A); + pull1 = test_socket (AF_SP, NN_PULL); + test_connect (pull1, SOCKET_ADDRESS_A); + + test_send (push1, "ABC"); + test_recv (pull1, "ABC"); + test_close (pull1); + + rc = nn_send (push1, "ABC", 3, NN_DONTWAIT); + nn_assert (rc == -1 && nn_errno() == EAGAIN); + + pull1 = test_socket (AF_SP, NN_PULL); + test_connect (pull1, SOCKET_ADDRESS_A); + + test_send (push1, "ABC"); + test_recv (pull1, "ABC"); + test_close (pull1); + test_close (push1); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/pubsub.c b/node/node_modules/nanomsg/deps/nanomsg/tests/pubsub.c new file mode 100644 index 0000000..4f5b5d4 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/pubsub.c @@ -0,0 +1,88 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pubsub.h" + +#include "testutil.h" + +#define SOCKET_ADDRESS "inproc://a" + +int main () +{ + int rc; + int pub1; + int pub2; + int sub1; + int sub2; + char buf [8]; + size_t sz; + + pub1 = test_socket (AF_SP, NN_PUB); + test_bind (pub1, SOCKET_ADDRESS); + sub1 = test_socket (AF_SP, NN_SUB); + rc = nn_setsockopt (sub1, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + errno_assert (rc == 0); + sz = sizeof (buf); + rc = nn_getsockopt (sub1, NN_SUB, NN_SUB_SUBSCRIBE, buf, &sz); + nn_assert (rc == -1 && nn_errno () == ENOPROTOOPT); + test_connect (sub1, SOCKET_ADDRESS); + sub2 = test_socket (AF_SP, NN_SUB); + rc = nn_setsockopt (sub2, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + errno_assert (rc == 0); + test_connect (sub2, SOCKET_ADDRESS); + + /* Wait till connections are established to prevent message loss. */ + nn_sleep (10); + + test_send (pub1, "0123456789012345678901234567890123456789"); + test_recv (sub1, "0123456789012345678901234567890123456789"); + test_recv (sub2, "0123456789012345678901234567890123456789"); + + test_close (pub1); + test_close (sub1); + test_close (sub2); + + /* Check receiving messages from two publishers. */ + + sub1 = test_socket (AF_SP, NN_SUB); + rc = nn_setsockopt (sub1, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + errno_assert (rc == 0); + test_bind (sub1, SOCKET_ADDRESS); + pub1 = test_socket (AF_SP, NN_PUB); + test_connect (pub1, SOCKET_ADDRESS); + pub2 = test_socket (AF_SP, NN_PUB); + test_connect (pub2, SOCKET_ADDRESS); + nn_sleep (100); + + test_send (pub1, "0123456789012345678901234567890123456789"); + test_send (pub2, "0123456789012345678901234567890123456789"); + test_recv (sub1, "0123456789012345678901234567890123456789"); + test_recv (sub1, "0123456789012345678901234567890123456789"); + + test_close (pub2); + test_close (pub1); + test_close (sub1); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/reqrep.c b/node/node_modules/nanomsg/deps/nanomsg/tests/reqrep.c new file mode 100644 index 0000000..b4b0a4f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/reqrep.c @@ -0,0 +1,178 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/reqrep.h" + +#include "testutil.h" + +#define SOCKET_ADDRESS "inproc://test" + +int main () +{ + int rc; + int rep1; + int rep2; + int req1; + int req2; + int resend_ivl; + char buf [7]; + int timeo; + + /* Test req/rep with full socket types. */ + rep1 = test_socket (AF_SP, NN_REP); + test_bind (rep1, SOCKET_ADDRESS); + req1 = test_socket (AF_SP, NN_REQ); + test_connect (req1, SOCKET_ADDRESS); + req2 = test_socket (AF_SP, NN_REQ); + test_connect (req2, SOCKET_ADDRESS); + + /* Check invalid sequence of sends and recvs. */ + rc = nn_send (rep1, "ABC", 3, 0); + nn_assert (rc == -1 && nn_errno () == EFSM); + rc = nn_recv (req1, buf, sizeof (buf), 0); + nn_assert (rc == -1 && nn_errno () == EFSM); + + /* Check fair queueing the requests. */ + test_send (req2, "ABC"); + test_recv (rep1, "ABC"); + test_send (rep1, "ABC"); + test_recv (req2, "ABC"); + + test_send (req1, "ABC"); + test_recv (rep1, "ABC"); + test_send (rep1, "ABC"); + test_recv (req1, "ABC"); + + test_close (rep1); + test_close (req1); + test_close (req2); + + /* Check load-balancing of requests. */ + req1 = test_socket (AF_SP, NN_REQ); + test_bind (req1, SOCKET_ADDRESS); + rep1 = test_socket (AF_SP, NN_REP); + test_connect (rep1, SOCKET_ADDRESS); + rep2 = test_socket (AF_SP, NN_REP); + test_connect (rep2, SOCKET_ADDRESS); + + test_send (req1, "ABC"); + test_recv (rep1, "ABC"); + test_send (rep1, "ABC"); + test_recv (req1, "ABC"); + + test_send (req1, "ABC"); + test_recv (rep2, "ABC"); + test_send (rep2, "ABC"); + test_recv (req1, "ABC"); + + test_close (rep2); + test_close (rep1); + test_close (req1); + + /* Test re-sending of the request. */ + rep1 = test_socket (AF_SP, NN_REP); + test_bind (rep1, SOCKET_ADDRESS); + req1 = test_socket (AF_SP, NN_REQ); + test_connect (req1, SOCKET_ADDRESS); + resend_ivl = 100; + rc = nn_setsockopt (req1, NN_REQ, NN_REQ_RESEND_IVL, + &resend_ivl, sizeof (resend_ivl)); + errno_assert (rc == 0); + + test_send (req1, "ABC"); + test_recv (rep1, "ABC"); + /* The following waits for request to be resent */ + test_recv (rep1, "ABC"); + + test_close (req1); + test_close (rep1); + + /* Check sending a request when the peer is not available. (It should + be sent immediatelly when the peer comes online rather than relying + on the resend algorithm. */ + req1 = test_socket (AF_SP, NN_REQ); + test_connect (req1, SOCKET_ADDRESS); + test_send (req1, "ABC"); + + rep1 = test_socket (AF_SP, NN_REP); + test_bind (rep1, SOCKET_ADDRESS); + timeo = 200; + rc = nn_setsockopt (rep1, NN_SOL_SOCKET, NN_RCVTIMEO, + &timeo, sizeof (timeo)); + errno_assert (rc == 0); + test_recv (rep1, "ABC"); + + test_close (req1); + test_close (rep1); + + /* Check removing socket request sent to (It should + be sent immediatelly to other peer rather than relying + on the resend algorithm). */ + req1 = test_socket (AF_SP, NN_REQ); + test_bind (req1, SOCKET_ADDRESS); + rep1 = test_socket (AF_SP, NN_REP); + test_connect (rep1, SOCKET_ADDRESS); + rep2 = test_socket (AF_SP, NN_REP); + test_connect (rep2, SOCKET_ADDRESS); + + timeo = 200; + rc = nn_setsockopt (rep1, NN_SOL_SOCKET, NN_RCVTIMEO, + &timeo, sizeof (timeo)); + errno_assert (rc == 0); + rc = nn_setsockopt (rep2, NN_SOL_SOCKET, NN_RCVTIMEO, + &timeo, sizeof (timeo)); + errno_assert (rc == 0); + + test_send (req1, "ABC"); + /* We got request through rep1 */ + test_recv (rep1, "ABC"); + /* But instead replying we simulate crash */ + test_close (rep1); + /* The rep2 should get request immediately */ + test_recv (rep2, "ABC"); + /* Let's check it's delivered well */ + test_send (rep2, "REPLY"); + test_recv (req1, "REPLY"); + + + test_close (req1); + test_close (rep2); + + /* Test cancelling delayed request */ + + req1 = test_socket (AF_SP, NN_REQ); + test_connect (req1, SOCKET_ADDRESS); + test_send (req1, "ABC"); + test_send (req1, "DEF"); + + rep1 = test_socket (AF_SP, NN_REP); + test_bind (rep1, SOCKET_ADDRESS); + timeo = 100; + test_recv (rep1, "DEF"); + + test_close (req1); + test_close (rep1); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/reqttl.c b/node/node_modules/nanomsg/deps/nanomsg/tests/reqttl.c new file mode 100644 index 0000000..795b43e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/reqttl.c @@ -0,0 +1,155 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/reqrep.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +static char socket_address_a[128]; +static char socket_address_b[128]; +int dev0; +int dev1; + +void device (NN_UNUSED void *arg) +{ + int rc; + + /* Run the device. */ + rc = nn_device (dev0, dev1); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev0); + test_close (dev1); +} + +int main (int argc, const char *argv[]) +{ + int end0; + int end1; + struct nn_thread thread1; + int timeo; + int maxttl; + size_t sz; + int rc; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address_a, "tcp", "127.0.0.1", port); + test_addr_from(socket_address_b, "tcp", "127.0.0.1", port + 1); + + /* Intialise the device sockets. */ + dev0 = test_socket (AF_SP_RAW, NN_REP); + dev1 = test_socket (AF_SP_RAW, NN_REQ); + + test_bind (dev0, socket_address_a); + test_bind (dev1, socket_address_b); + + /* Start the device. */ + nn_thread_init (&thread1, device, NULL); + + end0 = test_socket (AF_SP, NN_REQ); + end1 = test_socket (AF_SP, NN_REP); + + /* Test the bi-directional device TTL */ + test_connect (end0, socket_address_a); + test_connect (end1, socket_address_b); + + /* Wait for TCP to establish. */ + nn_sleep (100); + + /* Pass a message between endpoints. */ + /* Set up max receive timeout. */ + timeo = 100; + test_setsockopt (end0, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof (timeo)); + timeo = 100; + test_setsockopt (end1, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof (timeo)); + + /* Test default TTL is 8. */ + sz = sizeof (maxttl); + maxttl = -1; + rc = nn_getsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, &sz); + nn_assert (rc == 0); + nn_assert (sz == sizeof (maxttl)); + nn_assert (maxttl == 8); + + /* Test to make sure option TTL cannot be set below 1. */ + maxttl = -1; + rc = nn_setsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + nn_assert (rc < 0 && nn_errno () == EINVAL); + nn_assert (maxttl == -1); + maxttl = 0; + rc = nn_setsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + nn_assert (rc < 0 && nn_errno () == EINVAL); + nn_assert (maxttl == 0); + + /* Test to set non-integer size */ + maxttl = 8; + rc = nn_setsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, 1); + nn_assert (rc < 0 && nn_errno () == EINVAL); + nn_assert (maxttl == 8); + + test_send (end0, "XYZ"); + + test_recv (end1, "XYZ"); + + /* Now send a reply. */ + test_send (end1, "REPLYXYZ\n"); + test_recv (end0, "REPLYXYZ\n"); + + /* Now set the max TTL. */ + maxttl = 1; + test_setsockopt (end0, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + test_setsockopt (end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + + test_send (end0, "DROPTHIS"); + test_drop (end1, ETIMEDOUT); + + /* Now set the max TTL up. */ + maxttl = 2; + test_setsockopt (end0, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + test_setsockopt (end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + + test_send (end0, "DONTDROP"); + test_recv (end1, "DONTDROP"); + + test_send (end1, "GOTIT"); + test_recv (end0, "GOTIT"); + + /* Clean up. */ + test_close (end0); + test_close (end1); + + /* Shut down the devices. */ + nn_term (); + + nn_thread_term (&thread1); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/separation.c b/node/node_modules/nanomsg/deps/nanomsg/tests/separation.c new file mode 100644 index 0000000..7545d4e --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/separation.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pipeline.h" +#include "../src/inproc.h" +#include "../src/ipc.h" +#include "../src/tcp.h" +#include "testutil.h" + +#define SOCKET_ADDRESS_INPROC "inproc://a" +#define SOCKET_ADDRESS_IPC "ipc://test-separation.ipc" + +/* This test checks whether the library prevents interconnecting sockets + between different non-compatible protocols. */ + +int main (int argc, const char *argv[]) +{ + int rc; + int pair; + int pull; + int timeo; + char socket_address_tcp[128]; + + test_addr_from(socket_address_tcp, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + /* Inproc: Bind first, connect second. */ + pair = test_socket (AF_SP, NN_PAIR); + test_bind (pair, SOCKET_ADDRESS_INPROC); + pull = test_socket (AF_SP, NN_PULL); + test_connect (pull, SOCKET_ADDRESS_INPROC); + timeo = 100; + test_setsockopt (pair, NN_SOL_SOCKET, NN_SNDTIMEO, + &timeo, sizeof (timeo)); + rc = nn_send (pair, "ABC", 3, 0); + errno_assert (rc < 0 && nn_errno () == ETIMEDOUT); + test_close (pull); + test_close (pair); + + /* Inproc: Connect first, bind second. */ + pull = test_socket (AF_SP, NN_PULL); + test_connect (pull, SOCKET_ADDRESS_INPROC); + pair = test_socket (AF_SP, NN_PAIR); + test_bind (pair, SOCKET_ADDRESS_INPROC); + timeo = 100; + test_setsockopt (pair, NN_SOL_SOCKET, NN_SNDTIMEO, + &timeo, sizeof (timeo)); + rc = nn_send (pair, "ABC", 3, 0); + errno_assert (rc < 0 && nn_errno () == ETIMEDOUT); + test_close (pull); + test_close (pair); + +#if !defined NN_HAVE_WINDOWS + + /* IPC */ + pair = test_socket (AF_SP, NN_PAIR); + test_bind (pair, SOCKET_ADDRESS_IPC); + pull = test_socket (AF_SP, NN_PULL); + test_connect (pull, SOCKET_ADDRESS_IPC); + timeo = 100; + test_setsockopt (pair, NN_SOL_SOCKET, NN_SNDTIMEO, + &timeo, sizeof (timeo)); + rc = nn_send (pair, "ABC", 3, 0); + errno_assert (rc < 0 && nn_errno () == ETIMEDOUT); + test_close (pull); + test_close (pair); + +#endif + + /* TCP */ + pair = test_socket (AF_SP, NN_PAIR); + test_bind (pair, socket_address_tcp); + pull = test_socket (AF_SP, NN_PULL); + test_connect (pull, socket_address_tcp); + timeo = 100; + test_setsockopt (pair, NN_SOL_SOCKET, NN_SNDTIMEO, + &timeo, sizeof (timeo)); + rc = nn_send (pair, "ABC", 3, 0); + errno_assert (rc < 0 && nn_errno () == ETIMEDOUT); + test_close (pull); + test_close (pair); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/shutdown.c b/node/node_modules/nanomsg/deps/nanomsg/tests/shutdown.c new file mode 100644 index 0000000..2dd4e4d --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/shutdown.c @@ -0,0 +1,49 @@ +/* + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/tcp.h" +#include "../src/reqrep.h" + +#include "testutil.h" + +int main (int argc, const char *argv[]) +{ + int s; + int rc; + int eid; + char socket_address[128]; + + test_addr_from(socket_address, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + /* Run endpoint shutdown and socket shutdown in parallel. */ + s = test_socket (AF_SP, NN_REQ); + eid = test_connect (s, socket_address); + rc = nn_shutdown (s, eid); + errno_assert (rc == 0); + test_close (s); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/stats.c b/node/node_modules/nanomsg/deps/nanomsg/tests/stats.c new file mode 100644 index 0000000..e5158d5 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/stats.c @@ -0,0 +1,99 @@ +/* + Copyright 2016 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/reqrep.h" + +#include "testutil.h" + +int main (int argc, const char *argv[]) +{ + int rep1; + int req1; + char socket_address[128]; + + test_addr_from(socket_address, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + /* Test req/rep with full socket types. */ + rep1 = test_socket (AF_SP, NN_REP); + test_bind (rep1, socket_address); + nn_sleep (100); + + req1 = test_socket (AF_SP, NN_REQ); + test_connect (req1, socket_address); + nn_sleep (200); + + nn_assert (nn_get_statistic(rep1, NN_STAT_ACCEPTED_CONNECTIONS) == 1); + nn_assert (nn_get_statistic(rep1, NN_STAT_ESTABLISHED_CONNECTIONS) == 0); + nn_assert (nn_get_statistic(rep1, NN_STAT_CURRENT_CONNECTIONS) == 1); + nn_assert (nn_get_statistic(rep1, NN_STAT_MESSAGES_SENT) == 0); + nn_assert (nn_get_statistic(rep1, NN_STAT_MESSAGES_RECEIVED) == 0); + + nn_assert (nn_get_statistic(req1, NN_STAT_ACCEPTED_CONNECTIONS) == 0); + nn_assert (nn_get_statistic(req1, NN_STAT_ESTABLISHED_CONNECTIONS) == 1); + nn_assert (nn_get_statistic(req1, NN_STAT_CURRENT_CONNECTIONS) == 1); + nn_assert (nn_get_statistic(req1, NN_STAT_MESSAGES_SENT) == 0); + nn_assert (nn_get_statistic(req1, NN_STAT_MESSAGES_RECEIVED) == 0); + + test_send (req1, "ABC"); + nn_sleep (100); + + nn_assert (nn_get_statistic(req1, NN_STAT_MESSAGES_SENT) == 1); + nn_assert (nn_get_statistic(req1, NN_STAT_BYTES_SENT) == 3); + nn_assert (nn_get_statistic(req1, NN_STAT_MESSAGES_RECEIVED) == 0); + nn_assert (nn_get_statistic(req1, NN_STAT_BYTES_RECEIVED) == 0); + + test_recv(rep1, "ABC"); + + nn_assert (nn_get_statistic(rep1, NN_STAT_MESSAGES_SENT) == 0); + nn_assert (nn_get_statistic(rep1, NN_STAT_BYTES_SENT) == 0); + nn_assert (nn_get_statistic(rep1, NN_STAT_MESSAGES_RECEIVED) == 1); + nn_assert (nn_get_statistic(rep1, NN_STAT_BYTES_RECEIVED) == 3); + + test_send (rep1, "OK"); + test_recv (req1, "OK"); + + nn_assert (nn_get_statistic(req1, NN_STAT_MESSAGES_SENT) == 1); + nn_assert (nn_get_statistic(req1, NN_STAT_BYTES_SENT) == 3); + nn_assert (nn_get_statistic(req1, NN_STAT_MESSAGES_RECEIVED) == 1); + nn_assert (nn_get_statistic(req1, NN_STAT_BYTES_RECEIVED) == 2); + + nn_assert (nn_get_statistic(rep1, NN_STAT_MESSAGES_SENT) == 1); + nn_assert (nn_get_statistic(rep1, NN_STAT_BYTES_SENT) == 2); + nn_assert (nn_get_statistic(rep1, NN_STAT_MESSAGES_RECEIVED) == 1); + nn_assert (nn_get_statistic(rep1, NN_STAT_BYTES_RECEIVED) == 3); + + test_close (req1); + + nn_sleep (100); + + nn_assert (nn_get_statistic(rep1, NN_STAT_ACCEPTED_CONNECTIONS) == 1); + nn_assert (nn_get_statistic(rep1, NN_STAT_ESTABLISHED_CONNECTIONS) == 0); + nn_assert (nn_get_statistic(rep1, NN_STAT_CURRENT_CONNECTIONS) == 0); + + test_close (rep1); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/survey.c b/node/node_modules/nanomsg/deps/nanomsg/tests/survey.c new file mode 100644 index 0000000..73cc193 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/survey.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/survey.h" + +#include "testutil.h" + +#define SOCKET_ADDRESS "inproc://test" + +int main () +{ + int rc; + int surveyor; + int respondent1; + int respondent2; + int respondent3; + int deadline; + char buf [7]; + + /* Test a simple survey with three respondents. */ + surveyor = test_socket (AF_SP, NN_SURVEYOR); + deadline = 500; + rc = nn_setsockopt (surveyor, NN_SURVEYOR, NN_SURVEYOR_DEADLINE, + &deadline, sizeof (deadline)); + errno_assert (rc == 0); + test_bind (surveyor, SOCKET_ADDRESS); + respondent1 = test_socket (AF_SP, NN_RESPONDENT); + test_connect (respondent1, SOCKET_ADDRESS); + respondent2 = test_socket (AF_SP, NN_RESPONDENT); + test_connect (respondent2, SOCKET_ADDRESS); + respondent3 = test_socket (AF_SP, NN_RESPONDENT); + test_connect (respondent3, SOCKET_ADDRESS); + + /* Check that attempt to recv with no survey pending is EFSM. */ + rc = nn_recv (surveyor, buf, sizeof (buf), 0); + errno_assert (rc == -1 && nn_errno () == EFSM); + + /* Send the survey. */ + test_send (surveyor, "ABC"); + + /* First respondent answers. */ + test_recv (respondent1, "ABC"); + test_send (respondent1, "DEF"); + + /* Second respondent answers. */ + test_recv (respondent2, "ABC"); + test_send (respondent2, "DEF"); + + /* Surveyor gets the responses. */ + test_recv (surveyor, "DEF"); + test_recv (surveyor, "DEF"); + + /* There are no more responses. Surveyor hits the deadline. */ + rc = nn_recv (surveyor, buf, sizeof (buf), 0); + errno_assert (rc == -1 && nn_errno () == ETIMEDOUT); + + /* Third respondent answers (it have already missed the deadline). */ + test_recv (respondent3, "ABC"); + test_send (respondent3, "GHI"); + + /* Surveyor initiates new survey. */ + test_send (surveyor, "ABC"); + + /* Check that stale response from third respondent is not delivered. */ + rc = nn_recv (surveyor, buf, sizeof (buf), 0); + errno_assert (rc == -1 && nn_errno () == ETIMEDOUT); + + /* Check that subsequent attempt to recv with no survey pending is EFSM. */ + rc = nn_recv (surveyor, buf, sizeof (buf), 0); + errno_assert (rc == -1 && nn_errno () == EFSM); + + test_close (surveyor); + test_close (respondent1); + test_close (respondent2); + test_close (respondent3); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/surveyttl.c b/node/node_modules/nanomsg/deps/nanomsg/tests/surveyttl.c new file mode 100644 index 0000000..625ed45 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/surveyttl.c @@ -0,0 +1,148 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright 2016 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/survey.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" + +static char socket_address_a[128]; +static char socket_address_b[128]; +int dev0; +int dev1; + +void device (NN_UNUSED void *arg) +{ + int rc; + + /* Run the device. */ + rc = nn_device (dev0, dev1); + nn_assert (rc < 0 && nn_errno () == EBADF); + + /* Clean up. */ + test_close (dev0); + test_close (dev1); +} + +int main (int argc, const char *argv[]) +{ + int end0; + int end1; + struct nn_thread thread1; + int timeo; + int maxttl; + size_t sz; + int rc; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address_a, "tcp", "127.0.0.1", port); + test_addr_from(socket_address_b, "tcp", "127.0.0.1", port + 1); + + /* Intialise the device sockets. */ + dev0 = test_socket (AF_SP_RAW, NN_RESPONDENT); + dev1 = test_socket (AF_SP_RAW, NN_SURVEYOR); + + test_bind (dev0, socket_address_a); + test_bind (dev1, socket_address_b); + + /* Start the device. */ + nn_thread_init (&thread1, device, NULL); + + end0 = test_socket (AF_SP, NN_SURVEYOR); + end1 = test_socket (AF_SP, NN_RESPONDENT); + + /* Test the bi-directional device TTL */ + test_connect (end0, socket_address_a); + test_connect (end1, socket_address_b); + + /* Wait for TCP to establish. */ + nn_sleep (100); + + /* Set up max receive timeout. */ + timeo = 100; + test_setsockopt (end0, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof (timeo)); + timeo = 100; + test_setsockopt (end1, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof (timeo)); + + /* Test default TTL is 8. */ + sz = sizeof (maxttl); + maxttl = -1; + rc = nn_getsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, &sz); + nn_assert (rc == 0); + nn_assert (sz == sizeof (maxttl)); + nn_assert (maxttl == 8); + + /* Test to make sure option TTL cannot be set below 1. */ + maxttl = -1; + rc = nn_setsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + nn_assert (rc < 0 && nn_errno () == EINVAL); + nn_assert (maxttl == -1); + maxttl = 0; + rc = nn_setsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + nn_assert (rc < 0 && nn_errno () == EINVAL); + nn_assert (maxttl == 0); + + /* Test to set non-integer size */ + maxttl = 8; + rc = nn_setsockopt(end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, 1); + nn_assert (rc < 0 && nn_errno () == EINVAL); + nn_assert (maxttl == 8); + + /* Pass a message between endpoints. */ + test_send (end0, "SURVEY"); + test_recv (end1, "SURVEY"); + + /* Now send a reply. */ + test_send (end1, "REPLYXYZ"); + test_recv (end0, "REPLYXYZ"); + + /* Now set the max TTL. */ + maxttl = 1; + test_setsockopt (end0, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + test_setsockopt (end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + + test_send (end0, "DROPTHIS"); + test_drop (end1, ETIMEDOUT); + + maxttl = 2; + test_setsockopt (end0, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + test_setsockopt (end1, NN_SOL_SOCKET, NN_MAXTTL, &maxttl, sizeof (maxttl)); + test_send (end0, "DONTDROP"); + test_recv (end1, "DONTDROP"); + + /* Clean up. */ + test_close (end0); + test_close (end1); + + /* Shut down the devices. */ + nn_term (); + nn_thread_term (&thread1); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/symbol.c b/node/node_modules/nanomsg/deps/nanomsg/tests/symbol.c new file mode 100644 index 0000000..d1bab24 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/symbol.c @@ -0,0 +1,58 @@ +/* + Copyright (c) 2013 Evan Wies + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/utils/err.c" + +int main () +{ + int i; + struct nn_symbol_properties sym; + int value; + + nn_assert (nn_symbol (-1, NULL) == NULL); + nn_assert (nn_errno () == EINVAL); + nn_assert (nn_symbol_info (-1, &sym, (int) sizeof (sym)) == 0); + + nn_assert (nn_symbol (2000, NULL) == NULL); + nn_assert (nn_errno () == EINVAL); + nn_assert (nn_symbol_info (2000, &sym, (int) sizeof (sym)) == 0); + + nn_assert (nn_symbol (6, &value) != NULL); + nn_assert (value != 0); + nn_assert (nn_symbol_info (6, &sym, (int) sizeof (sym)) == sizeof (sym)); + + for (i = 0; ; ++i) { + const char* name = nn_symbol (i, &value); + if (name == NULL) { + nn_assert (nn_errno () == EINVAL); + break; + } + } + + for (i = 0; ; ++i) { + if (nn_symbol_info (i, &sym, sizeof (sym)) == 0) + break; + } + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/tcp.c b/node/node_modules/nanomsg/deps/nanomsg/tests/tcp.c new file mode 100644 index 0000000..a5063a2 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/tcp.c @@ -0,0 +1,227 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/tcp.h" + +#include "testutil.h" + +/* Tests TCP transport. */ + +int sc; + +int main (int argc, const char *argv[]) +{ + int rc; + int sb; + int i; + int opt; + size_t sz; + int s1, s2; + void * dummy_buf; + char addr[128]; + char socket_address[128]; + + int port = get_test_port(argc, argv); + + test_addr_from(socket_address, "tcp", "127.0.0.1", port); + + /* Try closing bound but unconnected socket. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + test_close (sb); + + /* Try closing a TCP socket while it not connected. At the same time + test specifying the local address for the connection. */ + sc = test_socket (AF_SP, NN_PAIR); + test_addr_from(addr, "tcp", "127.0.0.1;127.0.0.1", port); + test_connect (sc, addr); + test_close (sc); + + /* Open the socket anew. */ + sc = test_socket (AF_SP, NN_PAIR); + + /* Check NODELAY socket option. */ + sz = sizeof (opt); + rc = nn_getsockopt (sc, NN_TCP, NN_TCP_NODELAY, &opt, &sz); + errno_assert (rc == 0); + nn_assert (sz == sizeof (opt)); + nn_assert (opt == 0); + opt = 2; + rc = nn_setsockopt (sc, NN_TCP, NN_TCP_NODELAY, &opt, sizeof (opt)); + nn_assert (rc < 0 && nn_errno () == EINVAL); + opt = 1; + rc = nn_setsockopt (sc, NN_TCP, NN_TCP_NODELAY, &opt, sizeof (opt)); + errno_assert (rc == 0); + sz = sizeof (opt); + rc = nn_getsockopt (sc, NN_TCP, NN_TCP_NODELAY, &opt, &sz); + errno_assert (rc == 0); + nn_assert (sz == sizeof (opt)); + nn_assert (opt == 1); + + /* Try using invalid address strings. */ + rc = nn_connect (sc, "tcp://*:"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://*:1000000"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://*:some_port"); + nn_assert (rc < 0); + rc = nn_connect (sc, "tcp://eth10000;127.0.0.1:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == ENODEV); + rc = nn_connect (sc, "tcp://127.0.0.1"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_bind (sc, "tcp://127.0.0.1:"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_bind (sc, "tcp://127.0.0.1:1000000"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_bind (sc, "tcp://eth10000:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == ENODEV); + rc = nn_connect (sc, "tcp://:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://-hostname:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://abc.123.---.#:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://[::1]:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://abc.123.:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://abc...123:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "tcp://.123:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + + /* Connect correctly. Do so before binding the peer socket. */ + test_connect (sc, socket_address); + + /* Leave enough time for at least on re-connect attempt. */ + nn_sleep (200); + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + + /* Ping-pong test. */ + for (i = 0; i != 100; ++i) { + + test_send (sc, "ABC"); + test_recv (sb, "ABC"); + + test_send (sb, "DEF"); + test_recv (sc, "DEF"); + } + + /* Batch transfer test. */ + for (i = 0; i != 100; ++i) { + test_send (sc, "0123456789012345678901234567890123456789"); + } + for (i = 0; i != 100; ++i) { + test_recv (sb, "0123456789012345678901234567890123456789"); + } + + test_close (sc); + test_close (sb); + + /* Test whether connection rejection is handled decently. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + s1 = test_socket (AF_SP, NN_PAIR); + test_connect (s1, socket_address); + s2 = test_socket (AF_SP, NN_PAIR); + test_connect (s2, socket_address); + nn_sleep (100); + test_close (s2); + test_close (s1); + test_close (sb); + + /* Test two sockets binding to the same address. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + s1 = test_socket (AF_SP, NN_PAIR); + + rc = nn_bind (s1, socket_address); + nn_assert (rc < 0); + errno_assert (nn_errno () == EADDRINUSE); + + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + nn_sleep (100); + test_send (sb, "ABC"); + test_recv (sc, "ABC"); + test_close (sb); + test_close (sc); + test_close (s1); + + /* Test NN_RCVMAXSIZE limit */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + s1 = test_socket (AF_SP, NN_PAIR); + test_connect (s1, socket_address); + opt = 4; + rc = nn_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc == 0); + nn_sleep (100); + test_send (s1, "ABC"); + test_recv (sb, "ABC"); + test_send (s1, "0123456789012345678901234567890123456789"); + rc = nn_recv (sb, &dummy_buf, NN_MSG, NN_DONTWAIT); + nn_assert (rc < 0); + errno_assert (nn_errno () == EAGAIN); + test_close (sb); + test_close (s1); + + /* Test that NN_RCVMAXSIZE can be -1, but not lower */ + sb = test_socket (AF_SP, NN_PAIR); + opt = -1; + rc = nn_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc >= 0); + opt = -2; + rc = nn_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + test_close (sb); + + /* Test closing a socket that is waiting to connect. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + nn_sleep (100); + test_close (sc); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/tcp_shutdown.c b/node/node_modules/nanomsg/deps/nanomsg/tests/tcp_shutdown.c new file mode 100644 index 0000000..79d2754 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/tcp_shutdown.c @@ -0,0 +1,134 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/pipeline.h" +#include "../src/tcp.h" + +#include "testutil.h" +#include "../src/utils/attr.h" +#include "../src/utils/thread.c" +#include "../src/utils/atomic.c" + +/* Stress test the TCP transport. */ + +#define THREAD_COUNT 100 +#define TEST2_THREAD_COUNT 10 +#define MESSAGES_PER_THREAD 10 +#define TEST_LOOPS 10 + +struct nn_atomic active; + +static char socket_address[128]; + +static void routine (NN_UNUSED void *arg) +{ + int s; + + s = nn_socket (AF_SP, NN_SUB); + if (s < 0 && nn_errno () == EMFILE) + return; + errno_assert (s >= 0); + test_connect (s, socket_address); + test_close (s); +} + +static void routine2 (NN_UNUSED void *arg) +{ + int s; + int i; + int ms; + + s = test_socket (AF_SP, NN_PULL); + + test_connect (s, socket_address); + + ms = 2000; + test_setsockopt (s, NN_SOL_SOCKET, NN_RCVTIMEO, &ms, sizeof (ms)); + + for (i = 0; i < MESSAGES_PER_THREAD; ++i) { + test_recv (s, "hello"); + } + + test_close (s); + nn_atomic_dec(&active, 1); +} + +int main (int argc, const char *argv[]) +{ + int sb; + int i; + int j; + struct nn_thread threads [THREAD_COUNT]; + + test_addr_from(socket_address, "tcp", "127.0.0.1", + get_test_port(argc, argv)); + + /* Stress the shutdown algorithm. */ + +#if defined(SIGPIPE) && defined(SIG_IGN) + signal (SIGPIPE, SIG_IGN); +#endif + + sb = test_socket (AF_SP, NN_PUB); + test_bind (sb, socket_address); + + for (j = 0; j != TEST_LOOPS; ++j) { + for (i = 0; i != THREAD_COUNT; ++i) + nn_thread_init (&threads [i], routine, NULL); + for (i = 0; i != THREAD_COUNT; ++i) { + nn_thread_term (&threads [i]); + } + } + + test_close (sb); + + /* Test race condition of sending message while socket shutting down */ + + sb = test_socket (AF_SP, NN_PUSH); + test_bind (sb, socket_address); + + for (j = 0; j != TEST_LOOPS; ++j) { + int ms; + nn_atomic_init(&active, TEST2_THREAD_COUNT); + for (i = 0; i != TEST2_THREAD_COUNT; ++i) + nn_thread_init (&threads [i], routine2, &threads[i]); + + nn_sleep(100); + ms = 200; + test_setsockopt (sb, NN_SOL_SOCKET, NN_SNDTIMEO, &ms, sizeof (ms)); + while (active.n) { + (void) nn_send (sb, "hello", 5, 0); + } + + for (i = 0; i != TEST2_THREAD_COUNT; ++i) + nn_thread_term (&threads [i]); + nn_atomic_term(&active); + } + + test_close (sb); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/term.c b/node/node_modules/nanomsg/deps/nanomsg/tests/term.c new file mode 100644 index 0000000..6cb37de --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/term.c @@ -0,0 +1,74 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "../src/utils/thread.c" +#include "testutil.h" + +static void worker (NN_UNUSED void *arg) +{ + int rc; + int s; + char buf [3]; + + /* Test socket. */ + s = test_socket (AF_SP, NN_PAIR); + + /* Launch blocking function to check that it will be unblocked once + nn_term() is called from the main thread. */ + rc = nn_recv (s, buf, sizeof (buf), 0); + nn_assert (rc == -1 && nn_errno () == EBADF); + + /* Check that all subsequent operations fail in synchronous manner. */ + rc = nn_recv (s, buf, sizeof (buf), 0); + nn_assert (rc == -1 && nn_errno () == EBADF); + test_close (s); +} + +int main () +{ + int rc; + int s; + struct nn_thread thread; + + /* Close the socket with no associated endpoints. */ + s = test_socket (AF_SP, NN_PAIR); + test_close (s); + + /* Test nn_term() before nn_close(). */ + nn_thread_init (&thread, worker, NULL); + nn_sleep (100); + nn_term (); + + /* Check that it's not possible to create new sockets after nn_term(). */ + rc = nn_socket (AF_SP, NN_PAIR); + nn_assert (rc == -1); + errno_assert (nn_errno () == ETERM); + + /* Wait till worker thread terminates. */ + nn_thread_term (&thread); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/testutil.h b/node/node_modules/nanomsg/deps/nanomsg/tests/testutil.h new file mode 100644 index 0000000..735399b --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/testutil.h @@ -0,0 +1,215 @@ +/* + Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef TESTUTIL_H_INCLUDED +#define TESTUTIL_H_INCLUDED + +#include "../src/utils/attr.h" +#include "../src/utils/err.c" +#include "../src/utils/sleep.c" + +static int test_socket_impl (char *file, int line, int family, int protocol); +static int test_connect_impl (char *file, int line, int sock, char *address); +static int test_bind_impl (char *file, int line, int sock, char *address); +static void test_close_impl (char *file, int line, int sock); +static void test_send_impl (char *file, int line, int sock, char *data); +static void test_recv_impl (char *file, int line, int sock, char *data); +static void test_drop_impl (char *file, int line, int sock, int err); +static int test_setsockopt_impl (char *file, int line, int sock, int level, + int option, const void *optval, size_t optlen); + +#define test_socket(f, p) test_socket_impl (__FILE__, __LINE__, (f), (p)) +#define test_connect(s, a) test_connect_impl (__FILE__, __LINE__, (s), (a)) +#define test_bind(s, a) test_bind_impl (__FILE__, __LINE__, (s), (a)) +#define test_send(s, d) test_send_impl (__FILE__, __LINE__, (s), (d)) +#define test_recv(s, d) test_recv_impl (__FILE__, __LINE__, (s), (d)) +#define test_drop(s, e) test_drop_impl (__FILE__, __LINE__, (s), (e)) +#define test_close(s) test_close_impl (__FILE__, __LINE__, (s)) +#define test_setsockopt(s, l, o, v, z) test_setsockopt_impl (__FILE__, \ + __LINE__, (s), (l), (o), (v), (z)) + +static int NN_UNUSED test_socket_impl (char *file, int line, int family, + int protocol) +{ + int sock; + + sock = nn_socket (family, protocol); + if (sock == -1) { + fprintf (stderr, "Failed create socket: %s [%d] (%s:%d)\n", + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } + + return sock; +} + +static int NN_UNUSED test_connect_impl (char *file, int line, + int sock, char *address) +{ + int rc; + + rc = nn_connect (sock, address); + if(rc < 0) { + fprintf (stderr, "Failed connect to \"%s\": %s [%d] (%s:%d)\n", + address, + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } + return rc; +} + +static int NN_UNUSED test_bind_impl (char *file, int line, + int sock, char *address) +{ + int rc; + + rc = nn_bind (sock, address); + if(rc < 0) { + fprintf (stderr, "Failed bind to \"%s\": %s [%d] (%s:%d)\n", + address, + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } + return rc; +} + +static int NN_UNUSED test_setsockopt_impl (char *file, int line, + int sock, int level, int option, const void *optval, size_t optlen) +{ + int rc; + + rc = nn_setsockopt (sock, level, option, optval, optlen); + if(rc < 0) { + fprintf (stderr, "Failed set option \"%d\": %s [%d] (%s:%d)\n", + option, + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } + return rc; +} + +static void NN_UNUSED test_close_impl (char *file, int line, int sock) +{ + int rc; + + rc = nn_close (sock); + if ((rc != 0) && (errno != EBADF && errno != ETERM)) { + fprintf (stderr, "Failed to close socket: %s [%d] (%s:%d)\n", + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } +} + +static void NN_UNUSED test_send_impl (char *file, int line, + int sock, char *data) +{ + size_t data_len; + int rc; + + data_len = strlen (data); + + rc = nn_send (sock, data, data_len, 0); + if (rc < 0) { + fprintf (stderr, "Failed to send: %s [%d] (%s:%d)\n", + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } + if (rc != (int)data_len) { + fprintf (stderr, "Data to send is truncated: %d != %d (%s:%d)\n", + rc, (int) data_len, + file, line); + nn_err_abort (); + } +} + +static void NN_UNUSED test_recv_impl (char *file, int line, int sock, char *data) +{ + size_t data_len; + int rc; + char *buf; + + data_len = strlen (data); + /* We allocate plus one byte so that we are sure that message received + has correct length and not truncated */ + buf = malloc (data_len+1); + alloc_assert (buf); + + rc = nn_recv (sock, buf, data_len+1, 0); + if (rc < 0) { + fprintf (stderr, "Failed to recv: %s [%d] (%s:%d)\n", + nn_err_strerror (errno), + (int) errno, file, line); + nn_err_abort (); + } + if (rc != (int)data_len) { + fprintf (stderr, "Received data has wrong length: %d != %d (%s:%d)\n", + rc, (int) data_len, + file, line); + nn_err_abort (); + } + if (memcmp (data, buf, data_len) != 0) { + /* We don't print the data as it may have binary garbage */ + fprintf (stderr, "Received data is wrong (%s:%d)\n", file, line); + nn_err_abort (); + } + + free (buf); +} + +static void NN_UNUSED test_drop_impl (char *file, int line, int sock, int err) +{ + int rc; + char buf[1024]; + + rc = nn_recv (sock, buf, sizeof (buf), 0); + if (rc < 0 && err != errno) { + fprintf (stderr, "Got wrong err to recv: %s [%d != %d] (%s:%d)\n", + nn_err_strerror (errno), + (int) errno, err, file, line); + nn_err_abort (); + } else if (rc >= 0) { + fprintf (stderr, "Did not drop message: [%d bytes] (%s:%d)\n", + rc, file, line); + nn_err_abort (); + } +} + +static int NN_UNUSED get_test_port (int argc, const char *argv[]) +{ + return atoi(argc < 2 ? "5555" : argv[1]); +} + +static void NN_UNUSED test_addr_from (char *out, const char *proto, + const char *ip, int port) +{ + sprintf(out, "%s://%s:%d", proto, ip, port); +} + +#endif diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/timeo.c b/node/node_modules/nanomsg/deps/nanomsg/tests/timeo.c new file mode 100644 index 0000000..49540b8 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/timeo.c @@ -0,0 +1,62 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" + +#include "testutil.h" +#include "../src/utils/stopwatch.c" + +int main () +{ + int rc; + int s; + int timeo; + char buf [3]; + struct nn_stopwatch stopwatch; + uint64_t elapsed; + + s = test_socket (AF_SP, NN_PAIR); + + timeo = 100; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof (timeo)); + errno_assert (rc == 0); + nn_stopwatch_init (&stopwatch); + rc = nn_recv (s, buf, sizeof (buf), 0); + elapsed = nn_stopwatch_term (&stopwatch); + errno_assert (rc < 0 && nn_errno () == ETIMEDOUT); + time_assert (elapsed, 100000); + + timeo = 100; + rc = nn_setsockopt (s, NN_SOL_SOCKET, NN_SNDTIMEO, &timeo, sizeof (timeo)); + errno_assert (rc == 0); + nn_stopwatch_init (&stopwatch); + rc = nn_send (s, "ABC", 3, 0); + elapsed = nn_stopwatch_term (&stopwatch); + errno_assert (rc < 0 && nn_errno () == ETIMEDOUT); + time_assert (elapsed, 100000); + + test_close (s); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/trie.c b/node/node_modules/nanomsg/deps/nanomsg/tests/trie.c new file mode 100644 index 0000000..a5aa382 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/trie.c @@ -0,0 +1,210 @@ +/* + Copyright (c) 2013 Martin Sustrik All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/protocols/pubsub/trie.c" +#include "../src/utils/alloc.c" +#include "../src/utils/err.c" + +#include + +int main () +{ + int rc; + struct nn_trie trie; + + /* Try matching with an empty trie. */ + nn_trie_init (&trie); + rc = nn_trie_match (&trie, (const uint8_t*) "", 0); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "ABC", 3); + nn_assert (rc == 0); + nn_trie_term (&trie); + + /* Try matching with "all" subscription. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "", 0); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "", 0); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "ABC", 3); + nn_assert (rc == 1); + nn_trie_term (&trie); + + /* Try some simple matching. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "ABC", 3); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "DEF", 3); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "AB", 2); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "ABC", 3); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "ABCDE", 5); + nn_assert (rc == 1); + nn_trie_term (&trie); + + /* Try a long subcsription. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, + (const uint8_t*) "01234567890123456789012345678901234", 35); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "", 0); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "012456789", 10); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "012345678901234567", 18); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, + (const uint8_t*) "01234567890123456789012345678901234", 35); + nn_assert (rc == 1); + nn_trie_term (&trie); + + /* Try matching with a sparse node involved. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "ABC", 3); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "ADE", 3); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "AD", 2); + nn_assert (rc == 0); + nn_trie_term (&trie); + + /* Try matching with a dense node involved. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "B", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "C", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "0", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "E", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "F", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "1", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "@", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "b", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "f", 1); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "0", 1); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "f", 1); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "000", 3); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "a", 1); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "c", 1); + nn_assert (rc == 0); + nn_trie_term (&trie); + + /* Check prefix splitting and compaction. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "ABCD", 4); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "AB", 2); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "AB", 2); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "AB", 2); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "ABCDEF", 6); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "ABEF", 4); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "ABCD", 4); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "ABCD", 4); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "ABEF", 4); + nn_assert (rc == 1); + nn_trie_term (&trie); + + /* Check whether there's no problem with removing all subscriptions. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 1); + rc = nn_trie_match (&trie, (const uint8_t*) "", 0); + nn_assert (rc == 0); + rc = nn_trie_match (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 0); + nn_trie_term (&trie); + + /* Check converting from sparse node to dense node and vice versa. */ + nn_trie_init (&trie); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "B", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "C", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "0", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "E", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "F", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "1", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "@", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "b", 1); + nn_assert (rc == 1); + rc = nn_trie_subscribe (&trie, (const uint8_t*) "f", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "0", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "f", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "E", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "B", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "A", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "1", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "@", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "F", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "C", 1); + nn_assert (rc == 1); + rc = nn_trie_unsubscribe (&trie, (const uint8_t*) "b", 1); + nn_assert (rc == 1); + nn_trie_term (&trie); + + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/win_sec_attr.c b/node/node_modules/nanomsg/deps/nanomsg/tests/win_sec_attr.c new file mode 100644 index 0000000..6bd4f54 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/win_sec_attr.c @@ -0,0 +1,144 @@ +/* + Copyright (c) 2015 Timothee "TTimo" Besset All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/pubsub.h" +#include "../src/ipc.h" + +#include "testutil.h" + +#include +#include +#include + +/* Windows only. Custom SECURITY_ATTRIBUTES on a socket. */ + +#define PIPE_NAME "win_sec_attr.ipc" +#define SOCKET_ADDRESS "ipc://" PIPE_NAME + +int main () +{ + int sb; + int sc; + SECURITY_ATTRIBUTES sec; + BOOL ret; + SID SIDAuthUsers; + DWORD SIDSize; + EXPLICIT_ACCESS xa; + PACL pACL; + DWORD ret2; + int ret3; + void *void_ret_value = NULL; + size_t void_ret_size = sizeof (void_ret_value); + HANDLE pipeHandle = NULL; + PSID pSidOwner = NULL; + + BOOL equal = FALSE; + BOOL bret = FALSE; + PACL dacl = NULL; + PACE_HEADER ace = NULL; + PACCESS_ALLOWED_ACE allowed_ace = NULL; + PSID the_sid = NULL; + PSECURITY_DESCRIPTOR sd = NULL; + + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, SOCKET_ADDRESS); + + sb = test_socket (AF_SP, NN_PAIR); + + memset (&sec, 0, sizeof (sec)); + sec.lpSecurityDescriptor = malloc (SECURITY_DESCRIPTOR_MIN_LENGTH); + ret = InitializeSecurityDescriptor (sec.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION); + nn_assert (ret); + + SIDSize = sizeof (SIDAuthUsers); + ret = CreateWellKnownSid (WinAuthenticatedUserSid, NULL, &SIDAuthUsers, &SIDSize); + nn_assert (ret); + + xa.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE; + xa.grfAccessMode = SET_ACCESS; + xa.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT; + xa.Trustee.TrusteeForm = TRUSTEE_IS_SID; + xa.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; + xa.Trustee.ptstrName = (LPSTR) &SIDAuthUsers; + ret2 = SetEntriesInAcl (1, &xa, NULL, &pACL); + nn_assert (ret2 == ERROR_SUCCESS); + + ret = SetSecurityDescriptorDacl (sec.lpSecurityDescriptor, TRUE, pACL, FALSE); + nn_assert (ret); + + sec.nLength = sizeof (sec); + sec.bInheritHandle = TRUE; + + ret3 = nn_setsockopt (sb, NN_IPC, NN_IPC_SEC_ATTR, &sec, sizeof (sec)); + nn_assert (ret3 == 0); + test_bind (sb, SOCKET_ADDRESS); + + nn_sleep (200); + + test_send (sc, "0123456789012345678901234567890123456789"); + test_recv (sb, "0123456789012345678901234567890123456789"); + + ret3 = nn_getsockopt (sb, NN_IPC, NN_IPC_SEC_ATTR, &void_ret_value, &void_ret_size); + nn_assert (ret3 == 0); + nn_assert (void_ret_value == &sec); + + + /* Verify that the pipe has the same security descriptor that we set by + comparing the ace of the kernel object to the one we created it with. */ + pipeHandle = CreateFileA ("\\\\.\\\\pipe\\" PIPE_NAME, READ_CONTROL, 0, NULL, + OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + + nn_assert (pipeHandle != INVALID_HANDLE_VALUE); + + ret2 = GetSecurityInfo (pipeHandle, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, + NULL, NULL, &dacl, NULL, &sd); + + nn_assert (ret2 == ERROR_SUCCESS); + nn_assert (1 == dacl->AceCount); + + bret = GetAce (dacl, 0, &ace); + + nn_assert (bret == TRUE); + nn_assert (ace->AceType == ACCESS_ALLOWED_ACE_TYPE); + + allowed_ace = (PACCESS_ALLOWED_ACE) ace; + the_sid = (PSID) &(allowed_ace->SidStart); + + nn_assert (IsValidSid (the_sid)); + + equal = EqualSid ((PSID) &(allowed_ace->SidStart), &SIDAuthUsers); + nn_assert (equal); + LocalFree (sd); + + test_close (sc); + test_close (sb); + + LocalFree (pACL); + + free (sec.lpSecurityDescriptor); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/ws.c b/node/node_modules/nanomsg/deps/nanomsg/tests/ws.c new file mode 100644 index 0000000..e8b8d9c --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/ws.c @@ -0,0 +1,253 @@ +/* + Copyright (c) 2012 250bpm s.r.o. All rights reserved. + Copyright (c) 2014-2016 Jack R. Dunaway. All rights reserved. + Copyright 2015 Garrett D'Amore + Copyright 2016 Franklin "Snaipe" Mathieu + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pair.h" +#include "../src/ws.h" + +#include "testutil.h" + +static char socket_address[128]; + +/* Basic tests for WebSocket transport. */ + +/* test_text() verifies that we drop messages properly when sending invalid + UTF-8, but not when we send valid data. */ +void test_text () +{ + int sb; + int sc; + int opt; + uint8_t bad[20]; + + /* Negative testing... bad UTF-8 data for text. */ + sb = test_socket (AF_SP, NN_PAIR); + sc = test_socket (AF_SP, NN_PAIR); + + opt = NN_WS_MSG_TYPE_TEXT; + test_setsockopt (sb, NN_WS, NN_WS_MSG_TYPE, &opt, sizeof (opt)); + opt = NN_WS_MSG_TYPE_TEXT; + test_setsockopt (sc, NN_WS, NN_WS_MSG_TYPE, &opt, sizeof (opt)); + opt = 500; + test_setsockopt (sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sizeof (opt)); + + test_bind (sb, socket_address); + test_connect (sc, socket_address); + + test_send (sc, "GOOD"); + test_recv (sb, "GOOD"); + + /* and the bad ... */ + strcpy ((char *)bad, "BAD."); + bad[2] = (char)0xDD; + test_send (sc, (char *)bad); + + /* Make sure we dropped the frame. */ + test_drop (sb, ETIMEDOUT); + + test_close (sb); + test_close (sc); + + return; +} + +int main (int argc, const char *argv[]) +{ + int rc; + int sb; + int sc; + int sb2; + int opt; + size_t sz; + int i; + char any_address[128]; + + test_addr_from (socket_address, "ws", "127.0.0.1", + get_test_port (argc, argv)); + + test_addr_from (any_address, "ws", "*", + get_test_port (argc, argv)); + + /* Try closing bound but unconnected socket. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, any_address); + test_close (sb); + + /* Try closing a TCP socket while it not connected. At the same time + test specifying the local address for the connection. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + test_close (sc); + + /* Open the socket anew. */ + sc = test_socket (AF_SP, NN_PAIR); + + /* Check socket options. */ + sz = sizeof (opt); + rc = nn_getsockopt (sc, NN_WS, NN_WS_MSG_TYPE, &opt, &sz); + errno_assert (rc == 0); + nn_assert (sz == sizeof (opt)); + nn_assert (opt == NN_WS_MSG_TYPE_BINARY); + + /* Default port 80 should be assumed if not explicitly declared. */ + rc = nn_connect (sc, "ws://127.0.0.1"); + errno_assert (rc >= 0); + + /* Try using invalid address strings. */ + rc = nn_connect (sc, "ws://*:"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://*:1000000"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://*:some_port"); + nn_assert (rc < 0); + rc = nn_connect (sc, "ws://eth10000;127.0.0.1:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == ENODEV); + + rc = nn_bind (sc, "ws://127.0.0.1:"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_bind (sc, "ws://127.0.0.1:1000000"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_bind (sc, "ws://eth10000:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == ENODEV); + + rc = nn_connect (sc, "ws://:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://-hostname:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://abc.123.---.#:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://[::1]:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://abc.123.:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://abc...123:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + rc = nn_connect (sc, "ws://.123:5555"); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + + test_close (sc); + + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + + /* Ping-pong test. */ + for (i = 0; i != 100; ++i) { + + test_send (sc, "ABC"); + test_recv (sb, "ABC"); + + test_send (sb, "DEF"); + test_recv (sc, "DEF"); + } + + /* Batch transfer test. */ + for (i = 0; i != 100; ++i) { + test_send (sc, "0123456789012345678901234567890123456789"); + } + for (i = 0; i != 100; ++i) { + test_recv (sb, "0123456789012345678901234567890123456789"); + } + + test_close (sc); + test_close (sb); + + /* Test two sockets binding to the same address. */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + sb2 = test_socket (AF_SP, NN_PAIR); + + rc = nn_bind (sb2, socket_address); + nn_assert (rc < 0); + errno_assert (nn_errno () == EADDRINUSE); + test_close(sb); + test_close(sb2); + + /* Test that NN_RCVMAXSIZE can be -1, but not lower */ + sb = test_socket (AF_SP, NN_PAIR); + opt = -1; + rc = nn_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc >= 0); + opt = -2; + rc = nn_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + nn_assert (rc < 0); + errno_assert (nn_errno () == EINVAL); + test_close (sb); + + /* Test NN_RCVMAXSIZE limit */ + sb = test_socket (AF_SP, NN_PAIR); + test_bind (sb, socket_address); + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + opt = 1000; + test_setsockopt (sc, NN_SOL_SOCKET, NN_SNDTIMEO, &opt, sizeof (opt)); + nn_assert (opt == 1000); + opt = 1000; + test_setsockopt (sb, NN_SOL_SOCKET, NN_RCVTIMEO, &opt, sizeof (opt)); + nn_assert (opt == 1000); + opt = 4; + test_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + test_send (sc, "ABC"); + test_recv (sb, "ABC"); + test_send (sc, "ABCD"); + test_recv (sb, "ABCD"); + test_send (sc, "ABCDE"); + test_drop (sb, ETIMEDOUT); + + /* Increase the size limit, reconnect, then try sending again. The reason a + reconnect is necessary is because after a protocol violation, the + connecting socket will not continue automatic reconnection attempts. */ + opt = 5; + test_setsockopt (sb, NN_SOL_SOCKET, NN_RCVMAXSIZE, &opt, sizeof (opt)); + test_connect (sc, socket_address); + test_send (sc, "ABCDE"); + test_recv (sb, "ABCDE"); + test_close (sb); + test_close (sc); + + test_text (); + + /* Test closing a socket that is waiting to connect. */ + sc = test_socket (AF_SP, NN_PAIR); + test_connect (sc, socket_address); + nn_sleep (100); + test_close (sc); + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/ws_async_shutdown.c b/node/node_modules/nanomsg/deps/nanomsg/tests/ws_async_shutdown.c new file mode 100644 index 0000000..cac4b3f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/ws_async_shutdown.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pubsub.h" + +#include "testutil.h" +#include "../src/utils/thread.c" + +static char socket_address [128]; + +/* Test condition of closing sockets that are blocking in another thread. */ + +#define TEST_LOOPS 10 +#define TEST_THREADS 10 + +static void routine (NN_UNUSED void *arg) +{ + int s; + int rc; + char msg[1]; + + nn_assert (arg); + + s = *(int *)arg; + + while (1) { + rc = nn_recv (s, &msg, sizeof(msg), 0); + if (rc == 0) { + continue; + } + + nn_assert (rc == -1); + + /* A timeout is OK since PUB/SUB is lossy. */ + if (nn_errno () == ETIMEDOUT) { + continue; + } + break; + } + /* Socket is expected to be closed by caller. */ + errno_assert (nn_errno () == EBADF); +} + +int main (int argc, const char *argv[]) +{ + int i; + int j; + int s; + int sb; + int rcvtimeo = 10; + int sndtimeo = 0; + int sockets [TEST_THREADS]; + struct nn_thread threads [TEST_THREADS]; + + test_addr_from (socket_address, "ws", "127.0.0.1", + get_test_port (argc, argv)); + + for (i = 0; i != TEST_LOOPS; ++i) { + + sb = test_socket (AF_SP, NN_PUB); + test_bind (sb, socket_address); + test_setsockopt (sb, NN_SOL_SOCKET, NN_SNDTIMEO, + &sndtimeo, sizeof (sndtimeo)); + + for (j = 0; j < TEST_THREADS; j++){ + s = test_socket (AF_SP, NN_SUB); + test_setsockopt (s, NN_SOL_SOCKET, NN_RCVTIMEO, + &rcvtimeo, sizeof (rcvtimeo)); + test_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + test_connect (s, socket_address); + sockets [j] = s; + nn_thread_init (&threads [j], routine, &sockets [j]); + } + + /* Allow all threads a bit of time to connect. */ + nn_sleep (100); + + test_send (sb, ""); + + for (j = 0; j < TEST_THREADS; j++) { + test_close (sockets [j]); + nn_thread_term (&threads [j]); + } + + test_close (sb); + } + + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tests/zerocopy.c b/node/node_modules/nanomsg/deps/nanomsg/tests/zerocopy.c new file mode 100644 index 0000000..3a61336 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tests/zerocopy.c @@ -0,0 +1,216 @@ +/* + Copyright (c) 2013 GoPivotal, Inc. All rights reserved. + Copyright (c) 2014 Achille Roussel. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pubsub.h" +#include "../src/reqrep.h" + +#include "testutil.h" + +/* + * Nanomsg never zero copies anymore - it used to be an attribute of + * the inproc transport, but frankly its a mistake for anyone to depend + * on that. The implementation must be free to copy, move data, etc. + * The only thing that should be guaranteed is that the "ownership" of the + * message on send is passed to libnanomsg. libnanomsg may give that message + * to an inproc receiver, or it can do something else (like copy the data) + * with it. + */ +#if 0 + +#include + +void test_allocmsg_reqrep () +{ + int rc; + int req; + void *p; + struct nn_iovec iov; + struct nn_msghdr hdr; + + /* Try to create an oversized message. */ + p = nn_allocmsg (-1, 0); + nn_assert (!p && nn_errno () == ENOMEM); + p = nn_allocmsg (-3, 0); + nn_assert (!p && nn_errno () == ENOMEM); + + /* Try to create a message of unknown type. */ + p = nn_allocmsg (100, 333); + nn_assert (!p && nn_errno () == EINVAL); + + /* Create a socket. */ + req = test_socket (AF_SP_RAW, NN_REQ); + + /* Make send fail and check whether the zero-copy buffer is left alone + rather than deallocated. */ + p = nn_allocmsg (100, 0); + nn_assert (p); + rc = nn_send (req, &p, NN_MSG, NN_DONTWAIT); + nn_assert (rc < 0); + errno_assert (nn_errno () == EAGAIN); + memset (p, 0, 100); + rc = nn_freemsg (p); + errno_assert (rc == 0); + + /* Same thing with nn_sendmsg(). */ + p = nn_allocmsg (100, 0); + nn_assert (p); + iov.iov_base = &p; + iov.iov_len = NN_MSG; + memset (&hdr, 0, sizeof (hdr)); + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + nn_sendmsg (req, &hdr, NN_DONTWAIT); + errno_assert (nn_errno () == EAGAIN); + memset (p, 0, 100); + rc = nn_freemsg (p); + errno_assert (rc == 0); + + /* Clean up. */ + test_close (req); +} + +void test_reallocmsg_reqrep () +{ + int rc; + int req; + int rep; + void *p; + void *p2; + + /* Create sockets. */ + req = nn_socket (AF_SP, NN_REQ); + rep = nn_socket (AF_SP, NN_REP); + rc = nn_bind (rep, "inproc://test"); + errno_assert (rc >= 0); + rc = nn_connect (req, "inproc://test"); + errno_assert (rc >= 0); + + /* Create message, make sure we handle overflow. */ + p = nn_allocmsg (100, 0); + nn_assert (p); + p2 = nn_reallocmsg (p, (size_t)-3); + errno_assert (nn_errno () == ENOMEM); + nn_assert (p2 == NULL); + + /* Realloc to fit data size. */ + memcpy (p, "Hello World!", 12); + p = nn_reallocmsg (p, 12); + nn_assert (p); + rc = nn_send (req, &p, NN_MSG, 0); + errno_assert (rc == 12); + + /* Receive request and send response. */ + rc = nn_recv (rep, &p, NN_MSG, 0); + errno_assert (rc == 12); + rc = nn_send (rep, &p, NN_MSG, 0); + errno_assert (rc == 12); + + /* Receive response and free message. */ + rc = nn_recv (req, &p, NN_MSG, 0); + errno_assert (rc == 12); + rc = memcmp (p, "Hello World!", 12); + nn_assert (rc == 0); + rc = nn_freemsg (p); + errno_assert (rc == 0); + + /* Clean up. */ + nn_close (req); + nn_close (rep); +} + +void test_reallocmsg_pubsub () +{ + int rc; + int pub; + int sub1; + int sub2; + void *p; + void *p1; + void *p2; + + /* Create sockets. */ + pub = nn_socket (AF_SP, NN_PUB); + sub1 = nn_socket (AF_SP, NN_SUB); + sub2 = nn_socket (AF_SP, NN_SUB); + rc = nn_bind (pub, "inproc://test"); + errno_assert (rc >= 0); + rc = nn_connect (sub1, "inproc://test"); + errno_assert (rc >= 0); + rc = nn_connect (sub2, "inproc://test"); + errno_assert (rc >= 0); + rc = nn_setsockopt (sub1, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + errno_assert (rc == 0); + rc = nn_setsockopt (sub2, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + errno_assert (rc == 0); + + /* Publish message. */ + p = nn_allocmsg (12, 0); + nn_assert (p); + memcpy (p, "Hello World!", 12); + rc = nn_send (pub, &p, NN_MSG, 0); + errno_assert (rc == 12); + + /* Receive messages, both messages are the same object with inproc. */ + rc = nn_recv (sub1, &p1, NN_MSG, 0); + errno_assert (rc == 12); + rc = nn_recv (sub2, &p2, NN_MSG, 0); + errno_assert (rc == 12); + nn_assert (p1 == p2); + rc = memcmp (p1, "Hello World!", 12); + nn_assert (rc == 0); + rc = memcmp (p2, "Hello World!", 12); + nn_assert (rc == 0); + + /* Reallocate one message, both messages shouldn't be the same object + anymore. */ + p1 = nn_reallocmsg (p1, 15); + errno_assert (p1); + nn_assert (p1 != p2); + memcpy (((char*) p1) + 12, " 42", 3); + rc = memcmp (p1, "Hello World! 42", 15); + nn_assert (rc == 0); + + /* Release messages. */ + rc = nn_freemsg (p1); + errno_assert (rc == 0); + rc = nn_freemsg (p2); + errno_assert (rc == 0); + + /* Clean up. */ + nn_close (sub2); + nn_close (sub1); + nn_close (pub); +} +#endif + +int main () +{ +#if 0 + test_allocmsg_reqrep (); + test_reallocmsg_reqrep (); + test_reallocmsg_pubsub (); +#endif + return 0; +} + diff --git a/node/node_modules/nanomsg/deps/nanomsg/tools/nanocat.c b/node/node_modules/nanomsg/deps/nanomsg/tools/nanocat.c new file mode 100644 index 0000000..4b5116f --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tools/nanocat.c @@ -0,0 +1,654 @@ +/* + Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. + Copyright 2016 Garrett D'Amore + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "../src/nn.h" +#include "../src/pubsub.h" +#include "../src/pipeline.h" +#include "../src/bus.h" +#include "../src/pair.h" +#include "../src/survey.h" +#include "../src/reqrep.h" + +#include "options.h" +#include "../src/utils/sleep.c" +#include "../src/utils/clock.c" + +#include +#include +#include +#include +#include +#include +#if !defined NN_HAVE_WINDOWS +#include +#endif + +enum echo_format { + NN_NO_ECHO, + NN_ECHO_RAW, + NN_ECHO_ASCII, + NN_ECHO_QUOTED, + NN_ECHO_MSGPACK, + NN_ECHO_HEX +}; + +typedef struct nn_options { + /* Global options */ + int verbose; + + /* Socket options */ + int socket_type; + struct nn_string_list bind_addresses; + struct nn_string_list connect_addresses; + float send_timeout; + float recv_timeout; + struct nn_string_list subscriptions; + char *socket_name; + + /* Output options */ + float send_delay; + float send_interval; + struct nn_blob data_to_send; + + /* Input options */ + enum echo_format echo_format; +} nn_options_t; + +/* Constants to get address of in option declaration */ +static const int nn_push = NN_PUSH; +static const int nn_pull = NN_PULL; +static const int nn_pub = NN_PUB; +static const int nn_sub = NN_SUB; +static const int nn_req = NN_REQ; +static const int nn_rep = NN_REP; +static const int nn_bus = NN_BUS; +static const int nn_pair = NN_PAIR; +static const int nn_surveyor = NN_SURVEYOR; +static const int nn_respondent = NN_RESPONDENT; + + +struct nn_enum_item socket_types[] = { + {"PUSH", NN_PUSH}, + {"PULL", NN_PULL}, + {"PUB", NN_PUB}, + {"SUB", NN_SUB}, + {"REQ", NN_REQ}, + {"REP", NN_REP}, + {"BUS", NN_BUS}, + {"PAIR", NN_PAIR}, + {"SURVEYOR", NN_SURVEYOR}, + {"RESPONDENT", NN_RESPONDENT}, + {NULL, 0}, +}; + + +/* Constants to get address of in option declaration */ +static const int nn_echo_raw = NN_ECHO_RAW; +static const int nn_echo_ascii = NN_ECHO_ASCII; +static const int nn_echo_quoted = NN_ECHO_QUOTED; +static const int nn_echo_msgpack = NN_ECHO_MSGPACK; +static const int nn_echo_hex = NN_ECHO_HEX; + +struct nn_enum_item echo_formats[] = { + {"no", NN_NO_ECHO}, + {"raw", NN_ECHO_RAW}, + {"ascii", NN_ECHO_ASCII}, + {"quoted", NN_ECHO_QUOTED}, + {"msgpack", NN_ECHO_MSGPACK}, + {"hex", NN_ECHO_HEX}, + {NULL, 0}, +}; + +/* Constants for conflict masks */ +#define NN_MASK_SOCK 1 +#define NN_MASK_WRITEABLE 2 +#define NN_MASK_READABLE 4 +#define NN_MASK_SOCK_SUB 8 +#define NN_MASK_DATA 16 +#define NN_MASK_ENDPOINT 32 +#define NN_NO_PROVIDES 0 +#define NN_NO_CONFLICTS 0 +#define NN_NO_REQUIRES 0 +#define NN_MASK_SOCK_WRITEABLE (NN_MASK_SOCK | NN_MASK_WRITEABLE) +#define NN_MASK_SOCK_READABLE (NN_MASK_SOCK | NN_MASK_READABLE) +#define NN_MASK_SOCK_READWRITE (NN_MASK_SOCK_WRITEABLE|NN_MASK_SOCK_READABLE) + +struct nn_option nn_options[] = { + /* Generic options */ + {"verbose", 'v', NULL, + NN_OPT_INCREMENT, offsetof (nn_options_t, verbose), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Generic", NULL, "Increase verbosity of the nanocat"}, + {"silent", 'q', NULL, + NN_OPT_DECREMENT, offsetof (nn_options_t, verbose), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Generic", NULL, "Decrease verbosity of the nanocat"}, + {"help", 'h', NULL, + NN_OPT_HELP, 0, NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Generic", NULL, "This help text"}, + + /* Socket types */ + {"push", 0, "nn_push", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_push, + NN_MASK_SOCK_WRITEABLE, NN_MASK_SOCK, NN_MASK_DATA, + "Socket Types", NULL, "Use NN_PUSH socket type"}, + {"pull", 0, "nn_pull", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_pull, + NN_MASK_SOCK_READABLE, NN_MASK_SOCK, NN_NO_REQUIRES, + "Socket Types", NULL, "Use NN_PULL socket type"}, + {"pub", 0, "nn_pub", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_pub, + NN_MASK_SOCK_WRITEABLE, NN_MASK_SOCK, NN_MASK_DATA, + "Socket Types", NULL, "Use NN_PUB socket type"}, + {"sub", 0, "nn_sub", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_sub, + NN_MASK_SOCK_READABLE|NN_MASK_SOCK_SUB, NN_MASK_SOCK, NN_NO_REQUIRES, + "Socket Types", NULL, "Use NN_SUB socket type"}, + {"req", 0, "nn_req", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_req, + NN_MASK_SOCK_READWRITE, NN_MASK_SOCK, NN_MASK_DATA, + "Socket Types", NULL, "Use NN_REQ socket type"}, + {"rep", 0, "nn_rep", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_rep, + NN_MASK_SOCK_READWRITE, NN_MASK_SOCK, NN_NO_REQUIRES, + "Socket Types", NULL, "Use NN_REP socket type"}, + {"surveyor", 0, "nn_surveyor", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_surveyor, + NN_MASK_SOCK_READWRITE, NN_MASK_SOCK, NN_MASK_DATA, + "Socket Types", NULL, "Use NN_SURVEYOR socket type"}, + {"respondent", 0, "nn_respondent", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_respondent, + NN_MASK_SOCK_READWRITE, NN_MASK_SOCK, NN_NO_REQUIRES, + "Socket Types", NULL, "Use NN_RESPONDENT socket type"}, + {"bus", 0, "nn_bus", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_bus, + NN_MASK_SOCK_READWRITE, NN_MASK_SOCK, NN_NO_REQUIRES, + "Socket Types", NULL, "Use NN_BUS socket type"}, + {"pair", 0, "nn_pair", + NN_OPT_SET_ENUM, offsetof (nn_options_t, socket_type), &nn_pair, + NN_MASK_SOCK_READWRITE, NN_MASK_SOCK, NN_NO_REQUIRES, + "Socket Types", NULL, "Use NN_PAIR socket type"}, + + /* Socket Options */ + {"bind", 0, NULL, + NN_OPT_LIST_APPEND, offsetof (nn_options_t, bind_addresses), NULL, + NN_MASK_ENDPOINT, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "ADDR", "Bind socket to the address ADDR"}, + {"connect", 0, NULL, + NN_OPT_LIST_APPEND, offsetof (nn_options_t, connect_addresses), NULL, + NN_MASK_ENDPOINT, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "ADDR", "Connect socket to the address ADDR"}, + {"bind-ipc", 'X' , NULL, NN_OPT_LIST_APPEND_FMT, + offsetof (nn_options_t, bind_addresses), "ipc://%s", + NN_MASK_ENDPOINT, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "PATH", "Bind socket to the ipc address " + "\"ipc://PATH\"."}, + {"connect-ipc", 'x' , NULL, NN_OPT_LIST_APPEND_FMT, + offsetof (nn_options_t, connect_addresses), "ipc://%s", + NN_MASK_ENDPOINT, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "PATH", "Connect socket to the ipc address " + "\"ipc://PATH\"."}, + {"bind-local", 'L' , NULL, NN_OPT_LIST_APPEND_FMT, + offsetof (nn_options_t, bind_addresses), "tcp://127.0.0.1:%s", + NN_MASK_ENDPOINT, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "PORT", "Bind socket to the tcp address " + "\"tcp://127.0.0.1:PORT\"."}, + {"connect-local", 'l' , NULL, NN_OPT_LIST_APPEND_FMT, + offsetof (nn_options_t, connect_addresses), "tcp://127.0.0.1:%s", + NN_MASK_ENDPOINT, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "PORT", "Connect socket to the tcp address " + "\"tcp://127.0.0.1:PORT\"."}, + {"recv-timeout", 0, NULL, + NN_OPT_FLOAT, offsetof (nn_options_t, recv_timeout), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Socket Options", "SEC", "Set timeout for receiving a message"}, + {"send-timeout", 0, NULL, + NN_OPT_FLOAT, offsetof (nn_options_t, send_timeout), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_WRITEABLE, + "Socket Options", "SEC", "Set timeout for sending a message"}, + {"socket-name", 0, NULL, + NN_OPT_STRING, offsetof (nn_options_t, socket_name), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Socket Options", "NAME", "Name of the socket for statistics"}, + + /* Pattern-specific options */ + {"subscribe", 0, NULL, + NN_OPT_LIST_APPEND, offsetof (nn_options_t, subscriptions), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_SOCK_SUB, + "SUB Socket Options", "PREFIX", "Subscribe to the prefix PREFIX. " + "Note: socket will be subscribed to everything (empty prefix) if " + "no prefixes are specified on the command-line."}, + + /* Input Options */ + {"format", 0, NULL, + NN_OPT_ENUM, offsetof (nn_options_t, echo_format), &echo_formats, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Input Options", "FORMAT", "Use echo format FORMAT " + "(same as the options below)"}, + {"raw", 0, NULL, + NN_OPT_SET_ENUM, offsetof (nn_options_t, echo_format), &nn_echo_raw, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Input Options", NULL, "Dump message as is " + "(Note: no delimiters are printed)"}, + {"ascii", 'A', NULL, + NN_OPT_SET_ENUM, offsetof (nn_options_t, echo_format), &nn_echo_ascii, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Input Options", NULL, "Print ASCII part of message delimited by newline. " + "All non-ascii characters replaced by dot."}, + {"quoted", 'Q', NULL, + NN_OPT_SET_ENUM, offsetof (nn_options_t, echo_format), &nn_echo_quoted, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Input Options", NULL, "Print each message on separate line in double " + "quotes with C-like character escaping"}, + {"msgpack", 0, NULL, + NN_OPT_SET_ENUM, offsetof (nn_options_t, echo_format), &nn_echo_msgpack, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Input Options", NULL, "Print each message as msgpacked string (raw type)." + " This is useful for programmatic parsing."}, + + {"hex", 0, NULL, + NN_OPT_SET_ENUM, offsetof (nn_options_t, echo_format), &nn_echo_hex, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_READABLE, + "Input Options", NULL, "Print each message on separate line in double " + "quotes with hex values"}, + /* Output Options */ + {"interval", 'i', NULL, + NN_OPT_FLOAT, offsetof (nn_options_t, send_interval), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_MASK_WRITEABLE, + "Output Options", "SEC", "Send message (or request) every SEC seconds"}, + {"delay", 'd', NULL, + NN_OPT_FLOAT, offsetof (nn_options_t, send_delay), NULL, + NN_NO_PROVIDES, NN_NO_CONFLICTS, NN_NO_REQUIRES, + "Output Options", "SEC", "Wait for SEC seconds before sending message" + " (useful for one-shot PUB sockets)"}, + {"data", 'D', NULL, + NN_OPT_BLOB, offsetof (nn_options_t, data_to_send), &echo_formats, + NN_MASK_DATA, NN_MASK_DATA, NN_MASK_WRITEABLE, + "Output Options", "DATA", "Send DATA to the socket and quit for " + "PUB, PUSH, PAIR, BUS socket. Use DATA to reply for REP or " + " RESPONDENT socket. Send DATA as request for REQ or SURVEYOR socket."}, + {"file", 'F', NULL, + NN_OPT_READ_FILE, offsetof (nn_options_t, data_to_send), &echo_formats, + NN_MASK_DATA, NN_MASK_DATA, NN_MASK_WRITEABLE, + "Output Options", "PATH", "Same as --data but get data from file PATH"}, + + /* Sentinel */ + {NULL, 0, NULL, + 0, 0, NULL, + 0, 0, 0, + NULL, NULL, NULL}, + }; + + +struct nn_commandline nn_cli = { + "A command-line interface to nanomsg", + "", + nn_options, + NN_MASK_SOCK | NN_MASK_ENDPOINT, +}; + + +void nn_assert_errno (int flag, char *description) +{ + int err; + + if (!flag) { + err = errno; + fprintf (stderr, "%s: %s\n", description, nn_strerror (err)); + exit (3); + } +} + +void nn_sub_init (nn_options_t *options, int sock) +{ + int i; + int rc; + + if (options->subscriptions.num) { + for (i = 0; i < options->subscriptions.num; ++i) { + rc = nn_setsockopt (sock, NN_SUB, NN_SUB_SUBSCRIBE, + options->subscriptions.items[i], + strlen (options->subscriptions.items[i])); + nn_assert_errno (rc == 0, "Can't subscribe"); + } + } else { + rc = nn_setsockopt (sock, NN_SUB, NN_SUB_SUBSCRIBE, "", 0); + nn_assert_errno (rc == 0, "Can't subscribe"); + } +} + +void nn_set_recv_timeout (int sock, int millis) +{ + int rc; + rc = nn_setsockopt (sock, NN_SOL_SOCKET, NN_RCVTIMEO, + &millis, sizeof (millis)); + nn_assert_errno (rc == 0, "Can't set recv timeout"); +} + +int nn_create_socket (nn_options_t *options) +{ + int sock; + int rc; + int millis; + + sock = nn_socket (AF_SP, options->socket_type); + nn_assert_errno (sock >= 0, "Can't create socket"); + + /* Generic initialization */ + if (options->send_timeout >= 0) { + millis = (int)(options->send_timeout * 1000); + rc = nn_setsockopt (sock, NN_SOL_SOCKET, NN_SNDTIMEO, + &millis, sizeof (millis)); + nn_assert_errno (rc == 0, "Can't set send timeout"); + } + if (options->recv_timeout >= 0) { + nn_set_recv_timeout (sock, (int) options->recv_timeout * 1000); + } + if (options->socket_name) { + rc = nn_setsockopt (sock, NN_SOL_SOCKET, NN_SOCKET_NAME, + options->socket_name, strlen(options->socket_name)); + nn_assert_errno (rc == 0, "Can't set socket name"); + } + + /* Specific initialization */ + switch (options->socket_type) { + case NN_SUB: + nn_sub_init (options, sock); + break; + } + + return sock; +} + +void nn_print_message (nn_options_t *options, char *buf, int buflen) +{ + switch (options->echo_format) { + case NN_NO_ECHO: + return; + case NN_ECHO_RAW: + fwrite (buf, 1, buflen, stdout); + break; + case NN_ECHO_ASCII: + for (; buflen > 0; --buflen, ++buf) { + if (isprint (*buf)) { + fputc (*buf, stdout); + } else { + fputc ('.', stdout); + } + } + fputc ('\n', stdout); + break; + case NN_ECHO_QUOTED: + fputc ('"', stdout); + for (; buflen > 0; --buflen, ++buf) { + switch (*buf) { + case '\n': + fprintf (stdout, "\\n"); + break; + case '\r': + fprintf (stdout, "\\r"); + break; + case '\\': + case '\"': + fprintf (stdout, "\\%c", *buf); + break; + default: + if (isprint (*buf)) { + fputc (*buf, stdout); + } else { + fprintf (stdout, "\\x%02x", (unsigned char)*buf); + } + } + } + fprintf (stdout, "\"\n"); + break; + case NN_ECHO_MSGPACK: + if (buflen < 256) { + fputc ('\xc4', stdout); + fputc (buflen, stdout); + fwrite (buf, 1, buflen, stdout); + } else if (buflen < 65536) { + fputc ('\xc5', stdout); + fputc (buflen >> 8, stdout); + fputc (buflen & 0xff, stdout); + fwrite (buf, 1, buflen, stdout); + } else { + fputc ('\xc6', stdout); + fputc (buflen >> 24, stdout); + fputc ((buflen >> 16) & 0xff, stdout); + fputc ((buflen >> 8) & 0xff, stdout); + fputc (buflen & 0xff, stdout); + fwrite (buf, 1, buflen, stdout); + } + break; + case NN_ECHO_HEX: + fputc ('"', stdout); + for (; buflen > 0; --buflen, ++buf) { + fprintf (stdout, "\\x%02x", (unsigned char)*buf); + } + fprintf (stdout, "\"\n"); + break; + + } + fflush (stdout); +} + +void nn_connect_socket (nn_options_t *options, int sock) +{ + int i; + int rc; + + for (i = 0; i < options->bind_addresses.num; ++i) { + rc = nn_bind (sock, options->bind_addresses.items[i]); + nn_assert_errno (rc >= 0, "Can't bind"); + } + for (i = 0; i < options->connect_addresses.num; ++i) { + rc = nn_connect (sock, options->connect_addresses.items[i]); + nn_assert_errno (rc >= 0, "Can't connect"); + } +} + +void nn_send_loop (nn_options_t *options, int sock) +{ + int rc; + uint64_t start_time; + int64_t time_to_sleep, interval; + + interval = (int)(options->send_interval*1000); + + for (;;) { + start_time = nn_clock_ms(); + rc = nn_send (sock, + options->data_to_send.data, options->data_to_send.length, + 0); + if (rc < 0 && errno == EAGAIN) { + fprintf (stderr, "Message not sent (EAGAIN)\n"); + } else { + nn_assert_errno (rc >= 0, "Can't send"); + } + if (interval >= 0) { + time_to_sleep = (start_time + interval) - nn_clock_ms(); + if (time_to_sleep > 0) { + nn_sleep ((int) time_to_sleep); + } + } else { + break; + } + } +} + +void nn_recv_loop (nn_options_t *options, int sock) +{ + int rc; + void *buf; + + for (;;) { + rc = nn_recv (sock, &buf, NN_MSG, 0); + if (rc < 0 && errno == EAGAIN) { + continue; + } else if (rc < 0 && (errno == ETIMEDOUT || errno == EFSM)) { + return; /* No more messages possible */ + } else { + nn_assert_errno (rc >= 0, "Can't recv"); + } + nn_print_message (options, buf, rc); + nn_freemsg (buf); + } +} + +void nn_rw_loop (nn_options_t *options, int sock) +{ + int rc; + void *buf; + uint64_t start_time; + int64_t time_to_sleep, interval, recv_timeout; + + interval = (int)(options->send_interval*1000); + recv_timeout = (int)(options->recv_timeout*1000); + + for (;;) { + start_time = nn_clock_ms(); + rc = nn_send (sock, + options->data_to_send.data, options->data_to_send.length, + 0); + if (rc < 0 && errno == EAGAIN) { + fprintf (stderr, "Message not sent (EAGAIN)\n"); + } else { + nn_assert_errno (rc >= 0, "Can't send"); + } + if (options->send_interval < 0) { /* Never send any more */ + nn_recv_loop (options, sock); + return; + } + + for (;;) { + time_to_sleep = (start_time + interval) - nn_clock_ms(); + if (time_to_sleep <= 0) { + break; + } + if (recv_timeout >= 0 && time_to_sleep > recv_timeout) + { + time_to_sleep = recv_timeout; + } + nn_set_recv_timeout (sock, (int) time_to_sleep); + rc = nn_recv (sock, &buf, NN_MSG, 0); + if (rc < 0) { + if (errno == EAGAIN) { + continue; + } else if (errno == ETIMEDOUT || errno == EFSM) { + time_to_sleep = (start_time + interval) - nn_clock_ms(); + if (time_to_sleep > 0) + nn_sleep ((int) time_to_sleep); + continue; + } + } + nn_assert_errno (rc >= 0, "Can't recv"); + nn_print_message (options, buf, rc); + nn_freemsg (buf); + } + } +} + +void nn_resp_loop (nn_options_t *options, int sock) +{ + int rc; + void *buf; + + for (;;) { + rc = nn_recv (sock, &buf, NN_MSG, 0); + if (rc < 0 && errno == EAGAIN) { + continue; + } else { + nn_assert_errno (rc >= 0, "Can't recv"); + } + nn_print_message (options, buf, rc); + nn_freemsg (buf); + rc = nn_send (sock, + options->data_to_send.data, options->data_to_send.length, + 0); + if (rc < 0 && errno == EAGAIN) { + fprintf (stderr, "Message not sent (EAGAIN)\n"); + } else { + nn_assert_errno (rc >= 0, "Can't send"); + } + } +} + +int main (int argc, char **argv) +{ + int sock; + nn_options_t options = { + /* verbose */ 0, + /* socket_type */ 0, + /* bind_addresses */ {NULL, NULL, 0, 0}, + /* connect_addresses */ {NULL, NULL, 0, 0}, + /* send_timeout */ -1.f, + /* recv_timeout */ -1.f, + /* subscriptions */ {NULL, NULL, 0, 0}, + /* socket_name */ NULL, + /* send_delay */ 0.f, + /* send_interval */ -1.f, + /* data_to_send */ {NULL, 0, 0}, + /* echo_format */ NN_NO_ECHO + }; + + nn_parse_options (&nn_cli, &options, argc, argv); + sock = nn_create_socket (&options); + nn_connect_socket (&options, sock); + nn_sleep((int)(options.send_delay*1000)); + switch (options.socket_type) { + case NN_PUB: + case NN_PUSH: + nn_send_loop (&options, sock); + break; + case NN_SUB: + case NN_PULL: + nn_recv_loop (&options, sock); + break; + case NN_BUS: + case NN_PAIR: + if (options.data_to_send.data) { + nn_rw_loop (&options, sock); + } else { + nn_recv_loop (&options, sock); + } + break; + case NN_SURVEYOR: + case NN_REQ: + nn_rw_loop (&options, sock); + break; + case NN_REP: + case NN_RESPONDENT: + if (options.data_to_send.data) { + nn_resp_loop (&options, sock); + } else { + nn_recv_loop (&options, sock); + } + break; + } + + nn_close (sock); + nn_free_options(&nn_cli, &options); + return 0; +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tools/options.c b/node/node_modules/nanomsg/deps/nanomsg/tools/options.c new file mode 100644 index 0000000..1ddf626 --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tools/options.c @@ -0,0 +1,821 @@ +/* + Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#include "options.h" + +#include "../src/utils/err.c" + +#include +#include +#include +#include +#include + +struct nn_parse_context { + /* Initial state */ + struct nn_commandline *def; + struct nn_option *options; + void *target; + int argc; + char **argv; + unsigned long requires; + + /* Current values */ + unsigned long mask; + int args_left; + char **arg; + char *data; + char **last_option_usage; +}; + +static int nn_has_arg (struct nn_option *opt) +{ + switch (opt->type) { + case NN_OPT_INCREMENT: + case NN_OPT_DECREMENT: + case NN_OPT_SET_ENUM: + case NN_OPT_HELP: + return 0; + case NN_OPT_ENUM: + case NN_OPT_STRING: + case NN_OPT_BLOB: + case NN_OPT_FLOAT: + case NN_OPT_INT: + case NN_OPT_LIST_APPEND: + case NN_OPT_LIST_APPEND_FMT: + case NN_OPT_READ_FILE: + return 1; + } + nn_assert (0); +} + +static void nn_print_usage (struct nn_parse_context *ctx, FILE *stream) +{ + int i; + int first; + struct nn_option *opt; + + fprintf (stream, " %s ", ctx->argv[0]); + + /* Print required options (long names) */ + first = 1; + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (opt->mask_set & ctx->requires) { + if (first) { + first = 0; + fprintf (stream, "{--%s", opt->longname); + } else { + fprintf (stream, "|--%s", opt->longname); + } + } + } + if (!first) { + fprintf (stream, "} "); + } + + /* Print flag short options */ + first = 1; + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (opt->mask_set & ctx->requires) + continue; /* already printed */ + if (opt->shortname && !nn_has_arg (opt)) { + if (first) { + first = 0; + fprintf (stream, "[-%c", opt->shortname); + } else { + fprintf (stream, "%c", opt->shortname); + } + } + } + if (!first) { + fprintf (stream, "] "); + } + + /* Print short options with arguments */ + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (opt->mask_set & ctx->requires) + continue; /* already printed */ + if (opt->shortname && nn_has_arg (opt) && opt->metavar) { + fprintf (stream, "[-%c %s] ", opt->shortname, opt->metavar); + } + } + + fprintf (stream, "[options] \n"); /* There may be long options too */ +} + +static char *nn_print_line (FILE *out, char *str, size_t width) +{ + size_t i; + if (strlen (str) < width) { + fprintf (out, "%s", str); + return ""; + } + for (i = width; i > 1; --i) { + if (isspace (str[i])) { + fprintf (out, "%.*s", (int) i, str); + return str + i + 1; + } + } /* no break points, just print as is */ + fprintf (out, "%s", str); + return ""; +} + +static void nn_print_help (struct nn_parse_context *ctx, FILE *stream) +{ + int i; + size_t optlen; + struct nn_option *opt; + char *last_group; + char *cursor; + + fprintf (stream, "Usage:\n"); + nn_print_usage (ctx, stream); + fprintf (stream, "\n%s\n", ctx->def->short_description); + + last_group = NULL; + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (!last_group || last_group != opt->group || + strcmp (last_group, opt->group)) + { + fprintf (stream, "\n"); + fprintf (stream, "%s:\n", opt->group); + last_group = opt->group; + } + fprintf (stream, " --%s", opt->longname); + optlen = 3 + strlen (opt->longname); + if (opt->shortname) { + fprintf (stream, ",-%c", opt->shortname); + optlen += 3; + } + if (nn_has_arg (opt)) { + if (opt->metavar) { + fprintf (stream, " %s", opt->metavar); + optlen += strlen (opt->metavar) + 1; + } else { + fprintf (stream, " ARG"); + optlen += 4; + } + } + if (optlen < 23) { + fputs (&" "[optlen], stream); + cursor = nn_print_line (stream, opt->description, 80-24); + } else { + cursor = opt->description; + } + while (*cursor) { + fprintf (stream, "\n "); + cursor = nn_print_line (stream, cursor, 80-24); + } + fprintf (stream, "\n"); + } +} + +static void nn_print_option (struct nn_parse_context *ctx, int opt_index, + FILE *stream) +{ + char *ousage; + char *oend; + size_t olen; + struct nn_option *opt; + + opt = &ctx->options[opt_index]; + ousage = ctx->last_option_usage[opt_index]; + if (*ousage == '-') { /* Long option */ + oend = strchr (ousage, '='); + if (!oend) { + olen = strlen (ousage); + } else { + olen = (oend - ousage); + } + if (olen != strlen (opt->longname)+2) { + fprintf (stream, " %.*s[%s] ", + (int)olen, ousage, opt->longname + (olen-2)); + } else { + fprintf (stream, " %s ", ousage); + } + } else if (ousage == ctx->argv[0]) { /* Binary name */ + fprintf (stream, " %s (executable) ", ousage); + } else { /* Short option */ + fprintf (stream, " -%c (--%s) ", + *ousage, opt->longname); + } +} + +static void nn_option_error (char *message, struct nn_parse_context *ctx, + int opt_index) +{ + fprintf (stderr, "%s: Option", ctx->argv[0]); + nn_print_option (ctx, opt_index, stderr); + fprintf (stderr, "%s\n", message); + exit (1); +} + + +static void nn_memory_error (struct nn_parse_context *ctx) { + fprintf (stderr, "%s: Memory error while parsing command-line", + ctx->argv[0]); + abort (); +} + +static void nn_invalid_enum_value (struct nn_parse_context *ctx, + int opt_index, char *argument) +{ + struct nn_option *opt; + struct nn_enum_item *items; + + opt = &ctx->options[opt_index]; + items = (struct nn_enum_item *)opt->pointer; + fprintf (stderr, "%s: Invalid value ``%s'' for", ctx->argv[0], argument); + nn_print_option (ctx, opt_index, stderr); + fprintf (stderr, ". Options are:\n"); + for (;items->name; ++items) { + fprintf (stderr, " %s\n", items->name); + } + exit (1); +} + +static void nn_option_conflict (struct nn_parse_context *ctx, + int opt_index) +{ + unsigned long mask; + int i; + int num_conflicts; + struct nn_option *opt; + + fprintf (stderr, "%s: Option", ctx->argv[0]); + nn_print_option (ctx, opt_index, stderr); + fprintf (stderr, "conflicts with the following options:\n"); + + mask = ctx->options[opt_index].conflicts_mask; + num_conflicts = 0; + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (i == opt_index) + continue; + if (ctx->last_option_usage[i] && opt->mask_set & mask) { + num_conflicts += 1; + fprintf (stderr, " "); + nn_print_option (ctx, i, stderr); + fprintf (stderr, "\n"); + } + } + if (!num_conflicts) { + fprintf (stderr, " "); + nn_print_option (ctx, opt_index, stderr); + fprintf (stderr, "\n"); + } + exit (1); +} + +static void nn_print_requires (struct nn_parse_context *ctx, unsigned long mask) +{ + int i; + struct nn_option *opt; + + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (opt->mask_set & mask) { + fprintf (stderr, " --%s\n", opt->longname); + if (opt->shortname) { + fprintf (stderr, " -%c\n", opt->shortname); + } + } + } + exit (1); +} + +static void nn_option_requires (struct nn_parse_context *ctx, int opt_index) { + fprintf (stderr, "%s: Option", ctx->argv[0]); + nn_print_option (ctx, opt_index, stderr); + fprintf (stderr, "requires at least one of the following options:\n"); + + nn_print_requires (ctx, ctx->options[opt_index].requires_mask); + exit (1); +} + +static void nn_append_string (struct nn_parse_context *ctx, + struct nn_option *opt, char *str) +{ + struct nn_string_list *lst; + + lst = (struct nn_string_list *)(((char *)ctx->target) + opt->offset); + nn_assert (lst); + if (lst->items) { + lst->num += 1; + lst->items = realloc (lst->items, sizeof (char *) * lst->num); + } else { + lst->items = malloc (sizeof (char *)); + lst->num = 1; + } + if (!lst->items) { + nn_memory_error (ctx); + } + + nn_assert (lst && lst->items); + lst->items [lst->num - 1] = str; +} + +static void nn_append_string_to_free (struct nn_parse_context *ctx, + struct nn_option *opt, char *str) +{ + struct nn_string_list *lst; + + lst = (struct nn_string_list *)( + ((char *)ctx->target) + opt->offset); + nn_assert (lst); + if (lst->to_free) { + lst->to_free_num += 1; + lst->to_free = realloc (lst->items, + sizeof (char *) * lst->to_free_num); + } else { + lst->to_free = malloc (sizeof (char *)); + lst->to_free_num = 1; + } + if (!lst->items) { + nn_memory_error (ctx); + } + nn_assert (lst->to_free); + lst->to_free [lst->to_free_num - 1] = str; +} + +static void nn_process_option (struct nn_parse_context *ctx, + int opt_index, char *argument) +{ + struct nn_option *opt; + struct nn_enum_item *items; + char *endptr; + struct nn_blob *blob; + FILE *file; + char *data; + size_t data_len; + size_t data_buf; + size_t bytes_read; + + opt = &ctx->options[opt_index]; + if (ctx->mask & opt->conflicts_mask) { + nn_option_conflict (ctx, opt_index); + } + ctx->mask |= opt->mask_set; + + switch (opt->type) { + case NN_OPT_HELP: + nn_print_help (ctx, stdout); + exit (0); + return; + case NN_OPT_INT: + *(long *)(((char *)ctx->target) + opt->offset) = strtol (argument, + &endptr, 0); + if (endptr == argument || *endptr != 0) { + nn_option_error ("requires integer argument", + ctx, opt_index); + } + return; + case NN_OPT_INCREMENT: + *(int *)(((char *)ctx->target) + opt->offset) += 1; + return; + case NN_OPT_DECREMENT: + *(int *)(((char *)ctx->target) + opt->offset) -= 1; + return; + case NN_OPT_ENUM: + items = (struct nn_enum_item *)opt->pointer; + for (;items->name; ++items) { + if (!strcmp (items->name, argument)) { + *(int *)(((char *)ctx->target) + opt->offset) = \ + items->value; + return; + } + } + nn_invalid_enum_value (ctx, opt_index, argument); + return; + case NN_OPT_SET_ENUM: + *(int *)(((char *)ctx->target) + opt->offset) = \ + *(int *)(opt->pointer); + return; + case NN_OPT_STRING: + *(char **)(((char *)ctx->target) + opt->offset) = argument; + return; + case NN_OPT_BLOB: + blob = (struct nn_blob *)(((char *)ctx->target) + opt->offset); + blob->data = argument; + blob->length = strlen (argument); + blob->need_free = 0; + return; + case NN_OPT_FLOAT: +#if defined NN_HAVE_WINDOWS + *(float *)(((char *)ctx->target) + opt->offset) = + (float) atof (argument); +#else + *(float *)(((char *)ctx->target) + opt->offset) = + strtof (argument, &endptr); + if (endptr == argument || *endptr != 0) { + nn_option_error ("requires float point argument", + ctx, opt_index); + } +#endif + return; + case NN_OPT_LIST_APPEND: + nn_append_string (ctx, opt, argument); + return; + case NN_OPT_LIST_APPEND_FMT: + data_buf = strlen (argument) + strlen (opt->pointer); + data = malloc (data_buf); +#if defined NN_HAVE_WINDOWS + data_len = _snprintf_s (data, data_buf, _TRUNCATE, opt->pointer, + argument); +#else + data_len = snprintf (data, data_buf, opt->pointer, argument); +#endif + assert (data_len < data_buf); + nn_append_string (ctx, opt, data); + nn_append_string_to_free (ctx, opt, data); + return; + case NN_OPT_READ_FILE: + if (!strcmp (argument, "-")) { + file = stdin; + } else { + file = fopen (argument, "r"); + if (!file) { + fprintf (stderr, "Error opening file ``%s'': %s\n", + argument, strerror (errno)); + exit (2); + } + } + data = malloc (4096); + if (!data) + nn_memory_error (ctx); + data_len = 0; + data_buf = 4096; + for (;;) { + bytes_read = fread (data + data_len, 1, data_buf - data_len, + file); + data_len += bytes_read; + if (feof (file)) + break; + if (data_buf - data_len < 1024) { + if (data_buf < (1 << 20)) { + data_buf *= 2; /* grow twice until not too big */ + } else { + data_buf += 1 << 20; /* grow 1 Mb each time */ + } + data = realloc (data, data_buf); + if (!data) + nn_memory_error (ctx); + } + } + if (data_len != data_buf) { + data = realloc (data, data_len); + assert (data); + } + if (ferror (file)) { +#if defined _MSC_VER +#pragma warning (push) +#pragma warning (disable:4996) +#endif + fprintf (stderr, "Error reading file ``%s'': %s\n", + argument, strerror (errno)); +#if defined _MSC_VER +#pragma warning (pop) +#endif + exit (2); + } + if (file != stdin) { + fclose (file); + } + blob = (struct nn_blob *)(((char *)ctx->target) + opt->offset); + blob->data = data; + blob->length = data_len; + blob->need_free = 1; + return; + } + abort (); +} + +static void nn_parse_arg0 (struct nn_parse_context *ctx) +{ + int i; + struct nn_option *opt; + char *arg0; + + arg0 = strrchr (ctx->argv[0], '/'); + if (arg0 == NULL) { + arg0 = ctx->argv[0]; + } else { + arg0 += 1; /* Skip slash itself */ + } + + + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + return; + if (opt->arg0name && !strcmp (arg0, opt->arg0name)) { + assert (!nn_has_arg (opt)); + ctx->last_option_usage[i] = ctx->argv[0]; + nn_process_option (ctx, i, NULL); + } + } +} + + +static void nn_error_ambiguous_option (struct nn_parse_context *ctx) +{ + struct nn_option *opt; + char *a, *b; + char *arg; + + arg = ctx->data+2; + fprintf (stderr, "%s: Ambiguous option ``%s'':\n", ctx->argv[0], ctx->data); + for (opt = ctx->options; opt->longname; ++opt) { + for (a = opt->longname, b = arg; ; ++a, ++b) { + if (*b == 0 || *b == '=') { /* End of option on command-line */ + fprintf (stderr, " %s\n", opt->longname); + break; + } else if (*b != *a) { + break; + } + } + } + exit (1); +} + +static void nn_error_unknown_long_option (struct nn_parse_context *ctx) +{ + fprintf (stderr, "%s: Unknown option ``%s''\n", ctx->argv[0], ctx->data); + exit (1); +} + +static void nn_error_unexpected_argument (struct nn_parse_context *ctx) +{ + fprintf (stderr, "%s: Unexpected argument ``%s''\n", + ctx->argv[0], ctx->data); + exit (1); +} + +static void nn_error_unknown_short_option (struct nn_parse_context *ctx) +{ + fprintf (stderr, "%s: Unknown option ``-%c''\n", ctx->argv[0], *ctx->data); + exit (1); +} + +static int nn_get_arg (struct nn_parse_context *ctx) +{ + if (!ctx->args_left) + return 0; + ctx->args_left -= 1; + ctx->arg += 1; + ctx->data = *ctx->arg; + return 1; +} + +static void nn_parse_long_option (struct nn_parse_context *ctx) +{ + struct nn_option *opt; + char *a, *b; + size_t longest_prefix; + size_t cur_prefix; + int best_match; + char *arg; + int i; + + arg = ctx->data+2; + longest_prefix = 0; + best_match = -1; + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + for (a = opt->longname, b = arg;; ++a, ++b) { + if (*b == 0 || *b == '=') { /* End of option on command-line */ + cur_prefix = a - opt->longname; + if (!*a) { /* Matches end of option name */ + best_match = i; + longest_prefix = cur_prefix; + goto finish; + } + if (cur_prefix == longest_prefix) { + best_match = -1; /* Ambiguity */ + } else if (cur_prefix > longest_prefix) { + best_match = i; + longest_prefix = cur_prefix; + } + break; + } else if (*b != *a) { + break; + } + } + } +finish: + if (best_match >= 0) { + opt = &ctx->options[best_match]; + ctx->last_option_usage[best_match] = ctx->data; + if (arg[longest_prefix] == '=') { + if (nn_has_arg (opt)) { + nn_process_option (ctx, best_match, arg + longest_prefix + 1); + } else { + nn_option_error ("does not accept argument", ctx, best_match); + } + } else { + if (nn_has_arg (opt)) { + if (nn_get_arg (ctx)) { + nn_process_option (ctx, best_match, ctx->data); + } else { + nn_option_error ("requires an argument", ctx, best_match); + } + } else { + nn_process_option (ctx, best_match, NULL); + } + } + } else if (longest_prefix > 0) { + nn_error_ambiguous_option (ctx); + } else { + nn_error_unknown_long_option (ctx); + } +} + +static void nn_parse_short_option (struct nn_parse_context *ctx) +{ + int i; + struct nn_option *opt; + + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (!opt->shortname) + continue; + if (opt->shortname == *ctx->data) { + ctx->last_option_usage[i] = ctx->data; + if (nn_has_arg (opt)) { + if (ctx->data[1]) { + nn_process_option (ctx, i, ctx->data+1); + } else { + if (nn_get_arg (ctx)) { + nn_process_option (ctx, i, ctx->data); + } else { + nn_option_error ("requires an argument", ctx, i); + } + } + ctx->data = ""; /* end of short options anyway */ + } else { + nn_process_option (ctx, i, NULL); + ctx->data += 1; + } + return; + } + } + nn_error_unknown_short_option (ctx); +} + + +static void nn_parse_arg (struct nn_parse_context *ctx) +{ + if (ctx->data[0] == '-') { /* an option */ + if (ctx->data[1] == '-') { /* long option */ + if (ctx->data[2] == 0) { /* end of options */ + return; + } + nn_parse_long_option (ctx); + } else { + ctx->data += 1; /* Skip minus */ + while (*ctx->data) { + nn_parse_short_option (ctx); + } + } + } else { + nn_error_unexpected_argument (ctx); + } +} + +void nn_check_requires (struct nn_parse_context *ctx) { + int i; + struct nn_option *opt; + + for (i = 0;; ++i) { + opt = &ctx->options[i]; + if (!opt->longname) + break; + if (!ctx->last_option_usage[i]) + continue; + if (opt->requires_mask && + (opt->requires_mask & ctx->mask) != opt->requires_mask) { + nn_option_requires (ctx, i); + } + } + + if ((ctx->requires & ctx->mask) != ctx->requires) { + fprintf (stderr, "%s: At least one of the following required:\n", + ctx->argv[0]); + nn_print_requires (ctx, ctx->requires & ~ctx->mask); + exit (1); + } +} + +void nn_parse_options (struct nn_commandline *cline, + void *target, int argc, char **argv) +{ + struct nn_parse_context ctx; + int num_options; + + ctx.def = cline; + ctx.options = cline->options; + ctx.target = target; + ctx.argc = argc; + ctx.argv = argv; + ctx.requires = cline->required_options; + + for (num_options = 0; ctx.options[num_options].longname; ++num_options); + ctx.last_option_usage = calloc (sizeof (char *), num_options); + if (!ctx.last_option_usage) + nn_memory_error (&ctx); + + ctx.mask = 0; + ctx.args_left = argc - 1; + ctx.arg = argv; + + nn_parse_arg0 (&ctx); + + while (nn_get_arg (&ctx)) { + nn_parse_arg (&ctx); + } + + nn_check_requires (&ctx); + + free (ctx.last_option_usage); + +} + +void nn_free_options (struct nn_commandline *cline, void *target) { + int i, j; + struct nn_option *opt; + struct nn_blob *blob; + struct nn_string_list *lst; + + for (i = 0;; ++i) { + opt = &cline->options[i]; + if (!opt->longname) + break; + switch(opt->type) { + case NN_OPT_LIST_APPEND: + case NN_OPT_LIST_APPEND_FMT: + lst = (struct nn_string_list *)(((char *)target) + opt->offset); + nn_assert (lst); + if(lst->items) { + free(lst->items); + lst->items = NULL; + } + if(lst->to_free) { + for(j = 0; j < lst->to_free_num; ++j) { + free(lst->to_free[j]); + } + free(lst->to_free); + lst->to_free = NULL; + } + break; + case NN_OPT_READ_FILE: + case NN_OPT_BLOB: + blob = (struct nn_blob *)(((char *)target) + opt->offset); + if(blob->need_free && blob->data) { + free(blob->data); + blob->need_free = 0; + } + break; + default: + break; + } + } +} diff --git a/node/node_modules/nanomsg/deps/nanomsg/tools/options.h b/node/node_modules/nanomsg/deps/nanomsg/tools/options.h new file mode 100644 index 0000000..0c865cf --- /dev/null +++ b/node/node_modules/nanomsg/deps/nanomsg/tools/options.h @@ -0,0 +1,96 @@ +/* + Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +#ifndef NN_OPTIONS_HEADER +#define NN_OPTIONS_HEADER + +#include + +enum nn_option_type { + NN_OPT_HELP, + NN_OPT_INT, + NN_OPT_INCREMENT, + NN_OPT_DECREMENT, + NN_OPT_ENUM, + NN_OPT_SET_ENUM, + NN_OPT_STRING, + NN_OPT_BLOB, + NN_OPT_FLOAT, + NN_OPT_LIST_APPEND, + NN_OPT_LIST_APPEND_FMT, + NN_OPT_READ_FILE +}; + +struct nn_option { + /* Option names */ + char *longname; + char shortname; + char *arg0name; + + /* Parsing specification */ + enum nn_option_type type; + int offset; /* offsetof() where to store the value */ + const void *pointer; /* type specific pointer */ + + /* Conflict mask for options */ + unsigned long mask_set; + unsigned long conflicts_mask; + unsigned long requires_mask; + + /* Group and description for --help */ + char *group; + char *metavar; + char *description; +}; + +struct nn_commandline { + char *short_description; + char *long_description; + struct nn_option *options; + int required_options; +}; + +struct nn_enum_item { + char *name; + int value; +}; + +struct nn_string_list { + char **items; + char **to_free; + int num; + int to_free_num; +}; + +struct nn_blob { + char *data; + size_t length; + int need_free; +}; + + +void nn_parse_options (struct nn_commandline *cline, + void *target, int argc, char **argv); +void nn_free_options (struct nn_commandline *cline, void *target); + + +#endif /* NN_OPTIONS_HEADER */ diff --git a/node/node_modules/nanomsg/deps/win.gypi b/node/node_modules/nanomsg/deps/win.gypi new file mode 100644 index 0000000..cb9f174 --- /dev/null +++ b/node/node_modules/nanomsg/deps/win.gypi @@ -0,0 +1,63 @@ +{ + # compiler settings to build the nanomsg library + 'defines': [ + '_WINDOWS', + '_CRT_SECURE_NO_WARNINGS', + 'NN_HAVE_WINDOWS', + 'WIN32', + '_WIN32', + 'NN_USE_LITERAL_IFADDR', + 'NN_SHARED_LIB', + 'NN_HAVE_STDINT', + 'NN_HAVE_WINSOCK', + 'NN_USE_WINSOCK', + ], + 'link_settings': { + 'libraries': [ + '-lws2_32.lib', + '-lmswsock.lib', + '-ladvapi32', + ], + }, + 'direct_dependent_settings': { + # build nanomsg hub with same compiler flags as the library + 'defines': [ + '_WINDOWS', + '_CRT_SECURE_NO_WARNINGS', + 'NN_HAVE_WINDOWS', + 'WIN32', + '_WIN32', + 'NN_USE_LITERAL_IFADDR', + 'NN_SHARED_LIB', + 'NN_HAVE_STDINT', + 'NN_HAVE_WINSOCK', + 'NN_USE_WINSOCK', + ], + }, + 'target_defaults': { + 'default_configuration': 'Debug', + 'configurations': { + 'Debug': { + 'defines': [ 'DEBUG', '_DEBUG' ], + 'msvs_settings': { + 'VCCLCompilerTool': { + 'RuntimeLibrary': 0, # shared debug + }, + }, + }, + 'Release': { + 'defines': [ 'NDEBUG' ], + 'msvs_settings': { + 'VCCLCompilerTool': { + 'RuntimeLibrary': 1, # shared release + }, + }, + } + }, + 'msvs_settings': { + 'VCLinkerTool': { + 'GenerateDebugInformation': 'true', + }, + }, + }, +} diff --git a/node/node_modules/nanomsg/examples/multisub.js b/node/node_modules/nanomsg/examples/multisub.js new file mode 100644 index 0000000..3bbfdca --- /dev/null +++ b/node/node_modules/nanomsg/examples/multisub.js @@ -0,0 +1,30 @@ +var nano = require('../'); + +var pub = nano.socket('pub'); +var sub1 = nano.socket('sub'); +var sub2 = nano.socket('sub'); +var sub3 = nano.socket('sub'); + +var addr = 'tcp://127.0.0.1:7789' +pub.bind(addr); +sub1.connect(addr); +sub2.connect(addr); +sub3.connect(addr); + +sub1.on('data', function (str) { + console.log('sub1 got: %s', str); + sub1.close(); +}); +sub2.on('data', function (str) { + console.log('sub2 got: %s', str); + sub2.close(); +}); +sub3.on('data', function (str) { + console.log('sub3 got: %s', str); + sub3.close(); +}); + +setTimeout(function () { + console.log("PUBLISHING..."); + pub.send("Hello from nanomsg!"); +}, 100); diff --git a/node/node_modules/nanomsg/examples/pipeline.js b/node/node_modules/nanomsg/examples/pipeline.js new file mode 100644 index 0000000..f15a9ad --- /dev/null +++ b/node/node_modules/nanomsg/examples/pipeline.js @@ -0,0 +1,16 @@ +var nano = require('..'); + +var pull = nano.socket('pull', {encoding:'utf8'} ); +var push = nano.socket('push'); + +var addr = 'tcp://127.0.0.1:7789'; +pull.connect(addr); +push.bind(addr); + +pull.on('data', console.log); + +setInterval( send, 100 ); + +function send(){ + push.send('hello from nanomsg stream api'); +} diff --git a/node/node_modules/nanomsg/examples/pubsub.js b/node/node_modules/nanomsg/examples/pubsub.js new file mode 100644 index 0000000..f6c00e7 --- /dev/null +++ b/node/node_modules/nanomsg/examples/pubsub.js @@ -0,0 +1,14 @@ +var nano = require('..'); +var pub = nano.socket('pub'); +var sub = nano.socket('sub'); + +var addr = 'tcp://127.0.0.1:7789' +pub.bind(addr); +sub.connect(addr); + +sub.pipe(process.stdout); +setInterval( send, 100 ); + +function send(){ + pub.send('hello from nanomsg stream api\n'); +} diff --git a/node/node_modules/nanomsg/examples/reqrep.js b/node/node_modules/nanomsg/examples/reqrep.js new file mode 100644 index 0000000..7f5aed9 --- /dev/null +++ b/node/node_modules/nanomsg/examples/reqrep.js @@ -0,0 +1,22 @@ +var nano = require('../'); + +var rep = nano.socket('rep'); +var req = nano.socket('req'); + +var addr = 'tcp://127.0.0.1:5555'; + +rep.bind(addr); +req.connect(addr); + +rep.on('data', function (buf) { + console.log('received request: ', buf.toString()); + rep.send('world'); +}); + +req.on('data', function (buf) { + console.log('received response: ', buf.toString()); + req.close(); + rep.close(); +}); + +req.send('hello'); diff --git a/node/node_modules/nanomsg/examples/transforms.js b/node/node_modules/nanomsg/examples/transforms.js new file mode 100644 index 0000000..404d9b5 --- /dev/null +++ b/node/node_modules/nanomsg/examples/transforms.js @@ -0,0 +1,40 @@ +var nano = require('..') + +var pub = nano.socket('pub'); +var sub = nano.socket('sub'); + +pub.bind('inproc://transform'); +sub.connect('inproc://transform'); + +/** + * minimal transform stream implementation + */ +require('util').inherits(thr, require('stream').Transform); +function thr(fn){ + this._transform = fn; + require('stream').Transform.call(this); +} + +/** + * pipe from a readable source to minimal transform streams + */ +var t = new thr(function (msg, _, cb){ + process.stdout.write('transformed: ' + msg + '\n'); //write to stdout stream + this.emit('destroy'); + cb(); +}); + +sub + .pipe(new thr(function (msg, _, cb){ + console.log('original: ' + msg); //original: hello from nanømsg + this.push(msg + ' and cheers!'); + return cb(); + })) + .pipe(t); + +pub.send('hello from nanømsg'); + +t.on('destroy', cleanup); //do some cleanup +function cleanup(){ + return sub.close(); +} diff --git a/node/node_modules/nanomsg/examples/writablepipe.js b/node/node_modules/nanomsg/examples/writablepipe.js new file mode 100644 index 0000000..1d85cdb --- /dev/null +++ b/node/node_modules/nanomsg/examples/writablepipe.js @@ -0,0 +1,16 @@ +var nano = require('..') +var pub = nano.socket('pub'), push = nano.socket('push'); +var sub = nano.socket('sub'), pull = nano.socket('pull'); +pub.bind('tcp://127.0.0.1:3333'); push.bind('tcp://127.0.0.1:4444'); +sub.connect('tcp://127.0.0.1:3333'); pull.connect('tcp://127.0.0.1:4444'); + +// setEncoding formats inbound message type +sub.setEncoding('utf8'); + +sub.on('data', function (msg) { + console.log(msg); //hello from a push socket! +}) + +pull.pipe(pub); //pipe readable sockets to any writable socket or stream + +setInterval( function(){ push.send('hello from a push socket!') }, 100 ); diff --git a/node/node_modules/nanomsg/examples/ws/index.html b/node/node_modules/nanomsg/examples/ws/index.html new file mode 100644 index 0000000..35e6670 --- /dev/null +++ b/node/node_modules/nanomsg/examples/ws/index.html @@ -0,0 +1,42 @@ + + + + +

nanomsg ws test: 

+ + + + + diff --git a/node/node_modules/nanomsg/examples/ws/server.js b/node/node_modules/nanomsg/examples/ws/server.js new file mode 100644 index 0000000..7cfd309 --- /dev/null +++ b/node/node_modules/nanomsg/examples/ws/server.js @@ -0,0 +1,12 @@ +var nano = require('../..'); +var pair = nano.socket('pair'); + +pair.bind('ws://127.0.0.1:7789'); +pair.on('data', function(msg){ + pair.send(msg+''); + console.log('msg recv\'d: '+msg); +}); + +require('http').createServer(function (req, res) { + require('fs').createReadStream('index.html').pipe(res); +}).listen(3000); diff --git a/node/node_modules/nanomsg/lib/index.js b/node/node_modules/nanomsg/lib/index.js new file mode 100644 index 0000000..339cff0 --- /dev/null +++ b/node/node_modules/nanomsg/lib/index.js @@ -0,0 +1,513 @@ +var nn = require('bindings')('node_nanomsg.node'); +var util = require('util'); +var EventEmitter = require('events').EventEmitter; +var Duplex = require('stream').Duplex; + +/** + * generic socket-level NN_SOL_SOCKET options + */ +var sol = { + linger : nn.NN_LINGER, + sndbuf : nn.NN_SNDBUF, + rcvbuf : nn.NN_RCVBUF, + sndtimeo : nn.NN_SNDTIMEO, + rcvtimeo : nn.NN_RCVTIMEO, + reconn : nn.NN_RECONNECT_IVL, + maxreconn : nn.NN_RECONNECT_IVL_MAX, + sndprio : nn.NN_SNDPRIO, + rcvprio : nn.NN_RCVPRIO, + rcvmaxsize : nn.NN_RCVMAXSIZE, + tcpnodelay : nn.NN_TCP_NODELAY, + ipv6 : nn.NN_IPV4ONLY, +} + +/** + * Socket implementation + */ + +function Socket (type, opts) { + + opts = opts || {}; + this.af_domain = opts.raw ? nn.AF_SP_RAW : nn.AF_SP; + this.type = type; + + switch(type) { + case 'req': + this.protocol = nn.NN_REQ; + this.sender=true; + this.receiver=true; + break; + + case 'rep': + this.protocol = nn.NN_REP; + this.sender = true; + this.receiver = true; + break; + + case 'pair': + this.protocol = nn.NN_PAIR; + this.sender = true; + this.receiver = true; + break; + + case 'push': + this.protocol = nn.NN_PUSH; + this.sender = true; + this.receiver = false; + // nndontwait otherwise defaults true, PUSH socket default is false + opts.dontwait = opts.dontwait || false; + break; + + case 'pull': + this.protocol = nn.NN_PULL; + this.sender = false; + this.receiver = true; + break; + + case 'pub': + this.protocol = nn.NN_PUB; + this.sender = true; + this.receiver = false; + break; + + case 'sub': + this.protocol = nn.NN_SUB; + this.sender = false; + this.receiver = true; + break; + + case 'bus': + this.protocol = nn.NN_BUS; + this.sender = true; + this.receiver = true; + break; + + case 'surveyor': + this.protocol = nn.NN_SURVEYOR; + this.sender = true; + this.receiver = false; + break; + + case 'respondent': + this.protocol = nn.NN_RESPONDENT; + this.sender = true; + this.receiver = true; + break; + + default: + throw new Error('unrecognised socket type ' + type); + break; + } + + this.binding = nn.Socket(this.af_domain, this.protocol); + this.bound = {}; + this.connected = {}; + this.queue = []; + + /* async I/O option */ + this.dontwait('dontwait' in opts ? opts.dontwait : true); + + /* subscription filter control */ + this.channels = {}; + + /* subscription handling at initialization */ + if (opts.hasOwnProperty('chan')) { + if (Array.isArray(opts.chan)) { + opts.chan.forEach(this._register.bind(this)); + } else { + throw new TypeError('chan requires an Array'); + } + } else if (type === 'sub') { + this._register(''); //default topic is an empty string + } + + /* sockopt api handling at initialization */ + for(var sokopt in sol){ + if(opts.hasOwnProperty(sokopt)) this[sokopt](opts[sokopt]); + } + + /* start listening for inbound messages */ + if (this.af_domain === nn.AF_SP && this.receiver) { + this._startPollReceive(); + } + + if (!opts.hasOwnProperty('objectMode')) { + // reduce the highwatermark from 16K msgs to 16msgs + // would be more useful if we have a backpressure mechanism + opts.objectMode = true; + } + + Duplex.call(this, opts); + +} + +util.inherits(Socket, Duplex); + +Socket.prototype._protect = function (ret, unwind) { + if(ret < 0) { + if (unwind) unwind.call(this); + this.emit('error', new Error(nn.Err())); + return null; + } + return ret; +}; + +/* like _protect, but ret is an array where the first element + * is the error code (0=good, <0=bad), and the second element + * is the value to return if there was no error. + */ +Socket.prototype._protectArray = function (ret, unwind) { + if(ret[0] < 0) { + if (unwind) unwind.call(this); + this.emit('error', new Error(nn.Err())); + return null; + } + return ret[1]; +}; + +Socket.prototype._send = function (msg, flags) { + if (this.closed) return; + + if(this.type === 'surveyor' || this.type === 'rep') { + this._startPollReceive(); + } + + if (this.transform && typeof this.transform === 'function') { + msg = this.transform(msg); + } + return this._protect(nn.Send(this.binding, msg, flags), function () { + this.queue.unshift([msg, flags]); + }); +}; + +Socket.prototype._receive = function () { + if (this.closed){ + this.push(null); + return; + } + + var msg = nn.Recv(this.binding, this.nndontwait); + + if(this.type === 'surveyor') { + if(msg < 0 && nn.Errno() === nn.EFSM) { + this._stopPollSend(); + this._stopPollReceive(); + return; + } + } else if(this.type === 'rep') { + this._stopPollReceive(); + } + if (msg === -1) return; + + if (this.restore && typeof this.restore === 'function') msg = this.restore(msg); + this.push(msg); +}; + +Socket.prototype._startPollSend = function () { + if (!this._pollSend) { + this._pollSend = nn.PollSocket(this.binding, true, function (events) { + if (events) this.flush(); + }.bind(this)); + } +} + +Socket.prototype._startPollReceive = function () { + if (!this._pollReceive) { + this._pollReceive = nn.PollSocket(this.binding, false, function (events) { + if (events) this._receive(); + }.bind(this)); + } +} + +Socket.prototype._stopPollSend = function () { + if (this._pollSend) nn.PollStop(this._pollSend); + this._pollSend = null; +} + +Socket.prototype._stopPollReceive = function () { + if (this._pollReceive) nn.PollStop(this._pollReceive); + this._pollReceive = null; +} + +Socket.prototype._register = function(chan){ + if (this.channels.hasOwnProperty('')) { + this.rmchan(''); + this._register(chan); + } else if (nn.Chan(this.binding, nn.NN_SUB_SUBSCRIBE, chan) !== -1) { + this.channels[chan] = true; + } else { + this.emit('error', new Error( nn.Err() + ' : ' + chan)); + } +}; + +Socket.prototype._write = function(buf, _, cb){ + this.send(buf, this.nndontwait); + cb(); +} + +Socket.prototype._read = function (n) {} + +/** + * Socket API + */ + +Socket.prototype.bind = function (addr) { + return this.bound[addr] = this._protect(nn.Bind( this.binding, addr )); +} + +Socket.prototype.connect = function (addr) { + return this.connected[addr] = this._protect(nn.Connect( this.binding, addr )); +} + +Socket.prototype.shutdown = function (addr) { + var eid; + if (this.bound.hasOwnProperty(addr)) { + eid = this.bound[addr]; + delete this.bound[addr]; + return this._protect(nn.Shutdown(this.binding, eid)); + } else if (this.connected.hasOwnProperty(addr)) { + eid = this.connected[addr]; + delete this.connected[addr]; + return this._protect(nn.Shutdown(this.binding, eid)); + } +}; + +Socket.prototype.flush = function () { + while(this.queue.length) { + var entry = this.queue.shift(); + this._send(entry[0], Number(entry[1]) || 0); + } + this._stopPollSend(); +}; + +Socket.prototype.close = function () { + if(!this.closed) { + // Prevent "Bad file descriptor" from recursively firing "error" event + this.closed_status = nn.Close(this.binding); + this.closed = true; + + this._stopPollSend(); + this._stopPollReceive(); + + this.emit('close'); + + return this.closed_status; + } + + // TODO: AJS: in the event of multiple close, we remember + // the return code from the first valid close, and return + // it for all subsequent close attempts. This appears to be + // in the spirit of the original author's intention, but + // perhaps it would be better to return EBADF or some other + // error? + return this.closed_status; +}; + +Socket.prototype.send = function (buf, flags) { + this.queue.push([buf, flags]); + this._startPollSend(); + return buf.length; +}; + +/* returns an int, a string, or throws EBADF, ENOPROTOOPT, ETERM */ +Socket.prototype.getsockopt = function (level, option) { + return this._protectArray(nn.Getsockopt(this.binding, level, option)); +}; + +Socket.prototype.setsockopt = function (level, option, value) { + return this._protect(nn.Setsockopt(this.binding, level, option, value)); +}; + +/** + * Device implementation + */ +function Device (sock1,sock2) { + var that = this; + this.sock1= sock1; + this.sock2 = sock2; + this.s1 = -1; + this.s2 = -1; + + if(sock1 instanceof Socket) { + this.s1 = sock1.binding; + + if(sock2 instanceof Socket) { + this.s2 = sock2.binding; + } + + this._timer = setImmediate(function () { + nn.DeviceWorker(that.s1, that.s2, function (err) { + that.emit('error', new Error('lib err: '+ err +'\n'+ nn.Err())); + }); + }); + + } else { + throw new Error('expected at least one Socket argument'); + } + + EventEmitter.call(this); +} + +util.inherits(Device, EventEmitter); + +/** + * sockopt API + */ +Socket.prototype.linger = opt('linger'); +Socket.prototype.sndbuf = opt('sndbuf'); +Socket.prototype.rcvbuf = opt('rcvbuf'); +Socket.prototype.sndtimeo = opt('sndtimeo'); +Socket.prototype.rcvtimeo = opt('rcvtimeo'); +Socket.prototype.reconn = opt('reconn'); +Socket.prototype.maxreconn = opt('maxreconn'); +Socket.prototype.sndprio = opt('sndprio'); +Socket.prototype.rcvprio = opt('rcvprio'); +Socket.prototype.rcvmaxsize = opt('rcvmaxsize'); + +/* ipv6 & tcpnodelay sockopt methods. these two opts are a little different */ +Socket.prototype.ipv6 = function (bool) { + if(arguments.length){ + if(bool){ + if(nn.Setopt(this.binding, nn.NN_SOL_SOCKET, sol.ipv6, 0) > -1) + return true; + throw new Error(nn.Err() + ': '+this.type + ' ipv6@activing\n'); + } else { + if(nn.Setopt(this.binding, nn.NN_SOL_SOCKET, sol.ipv6, 1) > -1) + return false; + throw new Error(nn.Err() + ': '+this.type+' ipv6@deactiving\n'); + } + } else { + switch(nn.Getopt(this.binding, nn.NN_SOL_SOCKET, sol.ipv6)){ + case 1: return false; + case 0: return true; + default: + throw new Error(nn.Err() +': '+this.type+' ipv6@getsockopt\n'); + } + } +} + +Socket.prototype.tcpnodelay = function (bool) { + if(arguments.length){ + if(bool){ + if(nn.Setopt(this.binding, nn.NN_TCP, nn.NN_TCP_NODELAY, 1) > -1) + return true; + throw new Error(nn.Err() + ': '+this.type + ' nodelay@activing\n'); + } else { + if(nn.Setopt(this.binding, nn.NN_TCP, nn.NN_TCP_NODELAY, 0) > -1) + return false; + throw new Error(nn.Err() + ': '+this.type+' nodelay@deactiving\n'); + } + } else { + switch(nn.Getopt(this.binding, nn.NN_TCP, nn.NN_TCP_NODELAY)){ + case 1: return true; + case 0: return false; + default: + throw new Error(nn.Err() +': '+this.type+' nodelay@getsockopt\n'); + } + } +} + +/* set binary or text websocket options */ +Socket.prototype.wsopt = function (str) { + if (arguments.length) { + var wsopt = { + text : nn.NN_WS_MSG_TYPE_TEXT, + binary : nn.NN_WS_MSG_TYPE_BINARY, + } + if (nn.Setopt(this.binding, nn.NN_WS, nn.NN_WS_MSG_TYPE, wsopt[str]) > -1) + return true; + throw new Error(nn.Err() + ': '+this.type + ' wsopt@'+ str + '\n'); + } else { + switch(nn.Getopt(this.binding, nn.NN_WS, nn.NN_WS_MSG_TYPE)){ + case 0x01: return 'text'; + case 0x02: return 'binary'; + default: + throw new Error(nn.Err() +': '+ this.type + ' wsopt@getsockopt\n'); + } + } +} + +/* sockopt API workhorse */ +function opt (option) { + return function (value) { + if (typeof value === 'undefined') { + return nn.Getopt(this.binding, nn.NN_SOL_SOCKET, sol[option]); + } + + if(nn.Setopt(this.binding, nn.NN_SOL_SOCKET, sol[option], value) > -1) { + return true; + } + + throw new Error(nn.Err() + ': ' + this.type + option + '@' + value + '\n'); + } +}; + +/* chan and rmchan sockopt methods. only relevant for subscription sockets */ +Socket.prototype.chan = function (list) { + if (Array.isArray(list)) { + list.forEach(this._register.bind(this)); + } else { + throw new TypeError('chan requires an Array'); + } +} + +Socket.prototype.rmchan = function() { + var i = arguments.length; + while(i--) { + if (this.channels[arguments[i]]) { + if (nn.Chan(this.binding, nn.NN_SUB_UNSUBSCRIBE, arguments[i]) > -1) { + delete this.channels[arguments[i]]; + } else { + this.emit('error', new Error( nn.Err() + ' : ' + chan)); + } + } + }; +} + +Socket.prototype.dontwait = function (bool) { + if (arguments.length) { + if(bool){ + this.nndontwait = nn.NN_DONTWAIT; + return true; + } else { + this.nndontwait = 0; + return false; + } + } else { + return Boolean(this.nndontwait); + } +} + +/** + * module API + */ +function createSocket (type, opts) { + return new Socket(type, opts); +} + +function symbolInfo (symbol) { + return nn.SymbolInfo(symbol); +} + +function symbol (symbol) { + return nn.Symbol(symbol); +} + +function term () { + return nn.Term(); +} + +function createDevice (sock1, sock2) { + return new Device(sock1, sock2); +} + +exports._bindings = nn; +exports.Socket = Socket; +exports.createSocket = createSocket; +exports.symbolInfo = symbolInfo; +exports.symbol = symbol; +exports.term = term; +exports.socket = createSocket; + +exports.createDevice = createDevice; +exports.device = createDevice; diff --git a/node/node_modules/nanomsg/package.json b/node/node_modules/nanomsg/package.json new file mode 100644 index 0000000..d6235e0 --- /dev/null +++ b/node/node_modules/nanomsg/package.json @@ -0,0 +1,122 @@ +{ + "_from": "nanomsg", + "_id": "nanomsg@3.3.0", + "_inBundle": false, + "_integrity": "sha1-ktlgsuWDQl3srIHovbjrnBTMIfY=", + "_location": "/nanomsg", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "nanomsg", + "name": "nanomsg", + "escapedName": "nanomsg", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/nanomsg/-/nanomsg-3.3.0.tgz", + "_shasum": "92d960b2e583425decac81e8bdb8eb9c14cc21f6", + "_spec": "nanomsg", + "_where": "/Users/hwwu/Git/ats-sessions/node", + "author": { + "name": "Nick Desaulniers", + "email": "ndesaulniers@mozilla.com", + "url": "http://nickdesaulniers.github.io" + }, + "bugs": { + "url": "https://github.com/nickdesaulniers/node-nanomsg/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "a0000778", + "url": "https://github.com/a0000778" + }, + { + "name": "Adam Biro", + "url": "https://github.com/sirudog" + }, + { + "name": "Ant Skelton", + "url": "https://github.com/blowback" + }, + { + "name": "Benjamin Byholm", + "url": "https://github.com/kkoopa" + }, + { + "name": "Bent Cardan", + "url": "https://github.com/reqshark" + }, + { + "name": "Deepak Prabhakara", + "url": "https://github.com/deepakprabhakara" + }, + { + "name": "Flynn Joffray", + "url": "https://github.com/nucleardreamer" + }, + { + "name": "m-ohuchi", + "url": "https://github.com/m-ohuchi" + }, + { + "name": "Michele Comignano", + "url": "https://github.com/comick" + }, + { + "name": "Nick Desaulniers", + "url": "https://github.com/nickdesaulniers" + }, + { + "name": "Tim Cameron Ryan", + "url": "https://github.com/tcr" + }, + { + "name": "Trygve Lie", + "url": "https://github.com/trygve-lie" + } + ], + "dependencies": { + "bindings": "1.2.1", + "nan": "2.4" + }, + "deprecated": false, + "description": "Node bindings for nanomsg", + "devDependencies": { + "buffer-equals-polyfill": "1.0.0", + "esformatter": "0.0.16", + "tap-difflet": "0.3.0", + "tap-nyan": "0.0.2", + "tape": "~2.12.0" + }, + "gypfile": true, + "homepage": "https://github.com/nickdesaulniers/node-nanomsg#readme", + "keywords": [ + "nanomsg", + "native", + "binding", + "addon", + "nn", + "nanømsg" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "nanomsg", + "repository": { + "type": "git", + "url": "git+https://github.com/nickdesaulniers/node-nanomsg.git" + }, + "scripts": { + "beaut": "find . -path ./node_modules -prune -or -name '*.js' -exec sh -c 'cp -a {} {}.tmp; esformatter {} >{}.tmp && mv {}.tmp {}' \\;", + "install": "node-gyp rebuild", + "symbols": "cd test && ruby mksymbols.rb > symbols.js", + "test": "find test/*.js test/standalone/*.js | xargs -n 1 node | node_modules/tap-nyan/bin/cmd.js" + }, + "version": "3.3.0" +} diff --git a/node/node_modules/nanomsg/perf/common.js b/node/node_modules/nanomsg/perf/common.js new file mode 100644 index 0000000..d08d6f5 --- /dev/null +++ b/node/node_modules/nanomsg/perf/common.js @@ -0,0 +1,18 @@ +'use strict'; + +exports.createMsg = function(msgType, sz) { + var buf; + switch (msgType) { + case '--buffer': + buf = new Buffer(sz); + buf.fill('o'); + break; + case '--string': + buf = new Array(sz + 1).join('o'); + break; + default: + console.err('Unspecified msg type not supported, please use --buffer or --string.'); + process.exit(1); + } + return buf; +} diff --git a/node/node_modules/nanomsg/perf/local_lat.js b/node/node_modules/nanomsg/perf/local_lat.js new file mode 100644 index 0000000..b4a7b4e --- /dev/null +++ b/node/node_modules/nanomsg/perf/local_lat.js @@ -0,0 +1,30 @@ +'use strict'; + +var nano = require('../'); +var assert = require('assert'); + +if (process.argv.length != 5) { + console.log('usage: node local_lat.js '); + process.exit(1); +} +var bind_to = process.argv[2]; +var sz = Number(process.argv[3]); +var rts = Number(process.argv[4]); + +var s = nano.socket('pair'); +assert(s.binding !== -1); +var rc = s.tcpnodelay(true); +assert(rc === true); +rc = s.bind(bind_to); +assert(rc >= 0); + +var i = 0; +s.on('data', function (data) { + assert.equal(data.length, sz); + var nbytes = s.send(data); + assert.equal(nbytes, sz); + if (++i === rts) { + s.flush(); + s.close(); + } +}); diff --git a/node/node_modules/nanomsg/perf/local_thr.js b/node/node_modules/nanomsg/perf/local_thr.js new file mode 100644 index 0000000..3650661 --- /dev/null +++ b/node/node_modules/nanomsg/perf/local_thr.js @@ -0,0 +1,43 @@ +'use strict'; + +var nano = require('../'); +var assert = require('assert'); + +if (process.argv.length != 5) { + console.log('usage: node local_thr.js '); + process.exit(1); +} +var bind_to = process.argv[2]; +var sz = Number(process.argv[3]); +var count = Number(process.argv[4]); + +var s = nano.socket('pair'); +assert(s.binding !== -1); +var rc = s.bind(bind_to); +assert(rc >= 0); + +var sw; + +function finish() { + sw = process.hrtime(sw); + var total = sw[0] + (sw[1] / 1e9); + var thr = count / total; + var mbs = (thr * sz * 8) / 1000000; + console.log('message size: %d [B]', sz); + console.log('message count: %d', count); + console.log('throughput: %d [msg/s]', thr.toFixed(0)); + console.log('throughput: %d [Mb/s]', mbs.toFixed(3)); + rc = s.close(); + assert(rc === 0); +} + +var i = 0; +s.on('data', function (data) { + assert(data.length === sz); + if (!sw) { + sw = process.hrtime(); + } + if (++i === count) { + finish(); + } +}); diff --git a/node/node_modules/nanomsg/perf/remote_lat.js b/node/node_modules/nanomsg/perf/remote_lat.js new file mode 100644 index 0000000..d754208 --- /dev/null +++ b/node/node_modules/nanomsg/perf/remote_lat.js @@ -0,0 +1,54 @@ +'use strict'; + +var nano = require('../'); +var assert = require('assert'); +var createMsg = require('./common').createMsg; + +if (process.argv.length < 5 || process.argv.length > 6) { + console.log('usage: node remote_lat.js [--buffer|--string]'); + process.exit(1); +} +var connect_to = process.argv[2]; +var sz = Number(process.argv[3]); +var rts = Number(process.argv[4]); +// Specific to node-nanomsg. +var msgType = process.argv[5] || '--buffer'; + +var s = nano.socket('pair'); +assert(s.binding !== -1); +var rc = s.tcpnodelay(true); +assert(rc === true); +rc = s.connect(connect_to); +assert(rc >= 0); + +var buf = createMsg(msgType, sz) + +var sw; + +function finish() { + sw = process.hrtime(sw); + var total = sw[0] * 1e6 + sw[1] / 1e3; + var lat = total / (rts * 2); + console.log('message size: %d [B]', sz); + console.log('roundtrip count: %d', rts); + console.log('average latency: %d [us]', lat.toFixed(3)); + s.close() +} + +function send() { + var nbytes = s.send(buf); + assert.equal(nbytes, sz); +} + +var i = 0; +s.on('data', function (data) { + assert.equal(data.length, sz); + if (++i === rts) { + finish(); + } else { + send(); + } +}); + +sw = process.hrtime(); +send(); diff --git a/node/node_modules/nanomsg/perf/remote_thr.js b/node/node_modules/nanomsg/perf/remote_thr.js new file mode 100644 index 0000000..6c48e40 --- /dev/null +++ b/node/node_modules/nanomsg/perf/remote_thr.js @@ -0,0 +1,31 @@ +'use strict'; + +var nano = require('../'); +var assert = require('assert'); +var createMsg = require('./common').createMsg; + +if (process.argv.length < 5 || process.argv.length > 6) { + console.log('usage: node remote_thr.js [--string|--buffer]'); + process.exit(1); +} + +var connect_to = process.argv[2]; +var sz = Number(process.argv[3]); +var count = Number(process.argv[4]); +// Specific to node-nanomsg. +var msgType = process.argv[5] || '--buffer'; + +var s = nano.socket('pair'); +assert(s.binding !== -1); +var rc = s.connect(connect_to); +assert(rc >= 0); + +var buf = createMsg(msgType, sz); + +for (var i = 0; i != count; i++) { + var nbytes = s.send(buf); + assert(nbytes === sz); +} + +s.flush(); +s.close(); diff --git a/node/node_modules/nanomsg/src/node_nanomsg.cc b/node/node_modules/nanomsg/src/node_nanomsg.cc new file mode 100644 index 0000000..01e6cf1 --- /dev/null +++ b/node/node_modules/nanomsg/src/node_nanomsg.cc @@ -0,0 +1,291 @@ +#include "bus.h" +#include "inproc.h" +#include "ipc.h" +#include "nn.h" +#include "pair.h" +#include "pipeline.h" +#include "poll_ctx.h" +#include "pubsub.h" +#include "reqrep.h" +#include "survey.h" +#include "tcp.h" +#include "ws.h" + +using v8::Function; +using v8::FunctionTemplate; +using v8::Local; +using v8::Number; +using v8::Object; +using v8::String; +using v8::Value; + +NAN_METHOD(Socket) { + int domain = Nan::To(info[0]).FromJust(); + int protocol = Nan::To(info[1]).FromJust(); + + info.GetReturnValue().Set(Nan::New(nn_socket(domain, protocol))); +} + +NAN_METHOD(Close) { + int s = Nan::To(info[0]).FromJust(); + int rc = 0; + + do { + rc = nn_close(s); + } while (rc < 0 && errno == EINTR); + + info.GetReturnValue().Set(Nan::New(rc)); +} + +NAN_METHOD(Setopt) { + int s = Nan::To(info[0]).FromJust(); + int level = Nan::To(info[1]).FromJust(); + int option = Nan::To(info[2]).FromJust(); + int optval = Nan::To(info[3]).FromJust(); + + info.GetReturnValue().Set(Nan::New( + nn_setsockopt(s, level, option, &optval, sizeof(optval)))); +} + +NAN_METHOD(Getopt) { + int s = Nan::To(info[0]).FromJust(); + int level = Nan::To(info[1]).FromJust(); + int option = Nan::To(info[2]).FromJust(); + int optval; + size_t optsize = sizeof(optval); + + // check if the function succeeds + if (nn_getsockopt(s, level, option, &optval, &optsize) == 0) { + info.GetReturnValue().Set(Nan::New(optval)); + } +} + +NAN_METHOD(Chan) { + int s = Nan::To(info[0]).FromJust(); + int level = NN_SUB; + int option = Nan::To(info[1]).FromJust(); + String::Utf8Value str(info[2]); + + info.GetReturnValue().Set( + Nan::New(nn_setsockopt(s, level, option, *str, str.length()))); +} + +NAN_METHOD(Bind) { + int s = Nan::To(info[0]).FromJust(); + String::Utf8Value addr(info[1]); + + info.GetReturnValue().Set(Nan::New(nn_bind(s, *addr))); +} + +NAN_METHOD(Connect) { + int s = Nan::To(info[0]).FromJust(); + String::Utf8Value addr(info[1]); + + info.GetReturnValue().Set(Nan::New(nn_connect(s, *addr))); +} + +NAN_METHOD(Shutdown) { + int s = Nan::To(info[0]).FromJust(); + int how = Nan::To(info[1]).FromJust(); + + info.GetReturnValue().Set(Nan::New(nn_shutdown(s, how))); +} + +NAN_METHOD(Send) { + int s = Nan::To(info[0]).FromJust(); + int flags = Nan::To(info[2]).FromJust(); + + if (node::Buffer::HasInstance(info[1])) { + info.GetReturnValue().Set(Nan::New(nn_send( + s, node::Buffer::Data(info[1]), node::Buffer::Length(info[1]), flags))); + } else { + String::Utf8Value str(info[1]); + info.GetReturnValue().Set( + Nan::New(nn_send(s, *str, str.length(), flags))); + } +} + +static void fcb(char *data, void *) { + nn_freemsg(data); +} + +NAN_METHOD(Recv) { + int s = Nan::To(info[0]).FromJust(); + int flags = Nan::To(info[1]).FromJust(); + + // Invoke nanomsg function. + char *buf = NULL; + int len = nn_recv(s, &buf, NN_MSG, flags); + + if (len > -1) { + Local h = Nan::NewBuffer(buf, len, fcb, 0).ToLocalChecked(); + info.GetReturnValue().Set(h); + } else { + info.GetReturnValue().Set(Nan::New(len)); + } +} + +NAN_METHOD(SymbolInfo) { + int s = Nan::To(info[0]).FromJust(); + struct nn_symbol_properties prop; + int ret = nn_symbol_info(s, &prop, sizeof(prop)); + + if (ret > 0) { + Local obj = Nan::New(); + Nan::Set(obj, Nan::New("value").ToLocalChecked(), + Nan::New(prop.value)); + Nan::Set(obj, Nan::New("ns").ToLocalChecked(), Nan::New(prop.ns)); + Nan::Set(obj, Nan::New("type").ToLocalChecked(), + Nan::New(prop.type)); + Nan::Set(obj, Nan::New("unit").ToLocalChecked(), + Nan::New(prop.unit)); + Nan::Set(obj, Nan::New("name").ToLocalChecked(), + Nan::New(prop.name).ToLocalChecked()); + info.GetReturnValue().Set(obj); + } else if (ret != 0) { + Nan::ThrowError(nn_strerror(nn_errno())); + } +} + +NAN_METHOD(Symbol) { + int s = Nan::To(info[0]).FromJust(); + int val; + const char *ret = nn_symbol(s, &val); + + if (ret) { + Local obj = Nan::New(); + Nan::Set(obj, Nan::New("value").ToLocalChecked(), Nan::New(val)); + Nan::Set(obj, Nan::New("name").ToLocalChecked(), + Nan::New(ret).ToLocalChecked()); + info.GetReturnValue().Set(obj); + } else { + // symbol index out of range + // this behaviour seems inconsistent with SymbolInfo() above + // but we are faithfully following the libnanomsg API, warta and all + Nan::ThrowError(nn_strerror(nn_errno())); // EINVAL + } +} + +NAN_METHOD(Term) { nn_term(); } + +// Pass in two sockets, or (socket, -1) or (-1, socket) for loopback +NAN_METHOD(Device) { + int s1 = Nan::To(info[0]).FromJust(); + int s2 = Nan::To(info[1]).FromJust(); + + // nn_device only returns when it encounters an error + nn_device(s1, s2); + Nan::ThrowError(nn_strerror(nn_errno())); +} + +NAN_METHOD(Errno) { info.GetReturnValue().Set(Nan::New(nn_errno())); } + +NAN_METHOD(Err) { + info.GetReturnValue().Set(Nan::New(nn_strerror(nn_errno())).ToLocalChecked()); +} + +NAN_METHOD(PollSocket) { + const int s = Nan::To(info[0]).FromJust(); + const bool is_sender = Nan::To(info[1]).FromJust(); + const Local cb = info[2].As(); + PollCtx *context = new PollCtx(s, is_sender, cb); + info.GetReturnValue().Set(PollCtx::WrapPointer(context, sizeof context)); +} + +static void close_cb(uv_handle_t *handle) { + const PollCtx* const context = static_cast(handle->data); + delete context; +} + +NAN_METHOD(PollStop) { + PollCtx* const context = PollCtx::UnwrapPointer(info[0]); + if (context != NULL) { + uv_close(reinterpret_cast(&context->poll_handle), close_cb); + } + // TODO: the else case should never happen. Maybe add an assert or + // something. +} + +class NanomsgDeviceWorker : public Nan::AsyncWorker { +public: + NanomsgDeviceWorker(Nan::Callback *callback, int s1, int s2) + : Nan::AsyncWorker(callback), s1(s1), s2(s2) {} + ~NanomsgDeviceWorker() {} + + // Executed inside the worker-thread. + // It is not safe to access V8, or V8 data structures + // here, so everything we need for input and output + // should go on `this`. + void Execute() { + // nn_errno() only returns on error + nn_device(s1, s2); + err = nn_errno(); + } + + // Executed when the async work is complete + // this function will be run inside the main event loop + // so it is safe to use V8 again + void HandleOKCallback() { + Nan::HandleScope scope; + + Local argv[] = { Nan::New(err) }; + + callback->Call(1, argv); + }; + +private: + int s1; + int s2; + int err; +}; + +// Asynchronous access to the `nn_device()` function +NAN_METHOD(DeviceWorker) { + int s1 = Nan::To(info[0]).FromJust(); + int s2 = Nan::To(info[1]).FromJust(); + Nan::Callback *callback = new Nan::Callback(info[2].As()); + + Nan::AsyncQueueWorker(new NanomsgDeviceWorker(callback, s1, s2)); +} + +#define EXPORT_METHOD(C, S) \ + Nan::Set(C, Nan::New(#S).ToLocalChecked(), \ + Nan::GetFunction(Nan::New(S)).ToLocalChecked()); + +NAN_MODULE_INIT(InitAll) { + Nan::HandleScope scope; + + // Export functions. + EXPORT_METHOD(target, Socket); + EXPORT_METHOD(target, Close); + EXPORT_METHOD(target, Chan); + EXPORT_METHOD(target, Bind); + EXPORT_METHOD(target, Connect); + EXPORT_METHOD(target, Shutdown); + EXPORT_METHOD(target, Send); + EXPORT_METHOD(target, Recv); + EXPORT_METHOD(target, Errno); + EXPORT_METHOD(target, PollSocket); + EXPORT_METHOD(target, PollStop); + EXPORT_METHOD(target, DeviceWorker); + EXPORT_METHOD(target, SymbolInfo); + EXPORT_METHOD(target, Symbol); + EXPORT_METHOD(target, Term); + + EXPORT_METHOD(target, Getopt); + EXPORT_METHOD(target, Setopt); + EXPORT_METHOD(target, Err); + + // Export symbols. + for (int i = 0;; ++i) { + int value; + const char *symbol_name = nn_symbol(i, &value); + if (symbol_name == NULL) { + break; + } + Nan::Set(target, Nan::New(symbol_name).ToLocalChecked(), + Nan::New(value)); + } +} + +NODE_MODULE(node_nanomsg, InitAll) diff --git a/node/node_modules/nanomsg/src/poll_ctx.cc b/node/node_modules/nanomsg/src/poll_ctx.cc new file mode 100644 index 0000000..084864d --- /dev/null +++ b/node/node_modules/nanomsg/src/poll_ctx.cc @@ -0,0 +1,53 @@ +#include "nn.h" +#include "poll_ctx.h" + +using v8::Function; +using v8::Local; +using v8::Number; +using v8::Value; + +static void NanomsgReadable(uv_poll_t* req, int /* status */, int events) { + const PollCtx* const context = static_cast(req->data); + if (events & UV_READABLE) { + context->invoke_callback(events); + } +} + +void PollCtx::begin_poll (const int s, const bool is_sender) { + size_t siz = sizeof(uv_os_sock_t); + nn_getsockopt(s, NN_SOL_SOCKET, is_sender ? NN_SNDFD : NN_RCVFD, &sockfd, + &siz); + if (sockfd != 0) { + uv_poll_init_socket(uv_default_loop(), &poll_handle, sockfd); + uv_poll_start(&poll_handle, UV_READABLE, NanomsgReadable); + } +} + +PollCtx::PollCtx (const int s, const bool is_sender, + const Local cb): callback(cb) { + // TODO: maybe container_of can be used instead? + // that would save us this assignment, and ugly static_cast hacks. + poll_handle.data = this; + begin_poll(s, is_sender); +} + +void PollCtx::invoke_callback (const int events) const { + Nan::HandleScope scope; + Local argv[] = { Nan::New(events) }; + callback.Call(1, argv); +} + +// Nan will invoke this once it's done with the Buffer, in case we wanted to +// free ptr. In this case, ptr is a PollCtx that we're not done with and don't +// want to free yet (not until PollStop is invoked), so we do nothing. +static void wrap_pointer_cb(char * /* data */, void * /* hint */) {} + +Local PollCtx::WrapPointer (void* ptr, size_t length) { + return Nan::NewBuffer(static_cast(ptr), length, wrap_pointer_cb, 0) + .ToLocalChecked(); +} + +PollCtx* PollCtx::UnwrapPointer (v8::Local buffer) { + return reinterpret_cast(node::Buffer::HasInstance(buffer) ? + node::Buffer::Data(buffer.As()) : NULL); +} diff --git a/node/node_modules/nanomsg/src/poll_ctx.h b/node/node_modules/nanomsg/src/poll_ctx.h new file mode 100644 index 0000000..ec0da33 --- /dev/null +++ b/node/node_modules/nanomsg/src/poll_ctx.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +class PollCtx { + private: + const Nan::Callback callback; + uv_os_sock_t sockfd; // for libnanomsg + void begin_poll (const int s, const bool is_sender); + public: + uv_poll_t poll_handle; // for libuv + PollCtx (const int s, const bool is_sender, + const v8::Local cb); + void invoke_callback (const int events) const; + static v8::Local WrapPointer (void* ptr, size_t length); + static PollCtx* UnwrapPointer (v8::Local buffer); +}; diff --git a/node/node_modules/nanomsg/test/README.md b/node/node_modules/nanomsg/test/README.md new file mode 100644 index 0000000..26145b7 --- /dev/null +++ b/node/node_modules/nanomsg/test/README.md @@ -0,0 +1,28 @@ +# Test suite for node-nanomsg + +## Tests that can share a process +Most of the tests in this top-level directory can co-exist within the same process, therefore they can be run +by eg a single instance of `tape`. + +## Tests that **cannot** share a single process +Some tests need to make use of the `nano.Term()` method, which causes the underlying libnanomsg C library to +shutdown, irretrievably. + +Obviously, this will cause any following tests to fail. + +To mitigate against this, any test that requires this functionality must exist as a separate file in the +*standalone* directory. + +These tests may be run individually using `tape`, but they will not play nicely with other tests. + + +## I just want to run all the tests + +Use a TAP compatible test harness, such as *faucet* or *tapper*. We use *tapper* by default, so you can +run the entire test suite from the project directory with: + +``` +npm test +``` + + diff --git a/node/node_modules/nanomsg/test/bind.js b/node/node_modules/nanomsg/test/bind.js new file mode 100644 index 0000000..65d59ee --- /dev/null +++ b/node/node_modules/nanomsg/test/bind.js @@ -0,0 +1,148 @@ +var nano = require('..'); +var test = require('tape'); + +test('map bind address eid for valid INPROC address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.bind('inproc://some_address'); + + if (sock.bound['inproc://some_address'] > -1) { + t.pass('valid INPROC bind'); + } else { + t.pass('INPROC bind fail'); + } + + sock.close(); +}); + +test('map bind address eid for valid IPC address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.bind('ipc://some_address'); + + if (sock.bound['ipc://some_address'] > -1) { + t.pass('valid IPC bind'); + } else { + t.pass('IPC bind fail'); + } + + sock.close(); +}); + +test('map bind address eid for valid TCP address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.bind('tcp://127.0.0.1:5555'); + + if (sock.bound['tcp://127.0.0.1:5555'] > -1) { + t.pass('valid TCP bind'); + } else { + t.pass('TCP bind fail'); + } + + sock.close(); +}); + +test('bind exception: invalid INPROC address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.bind('inproc:/missing_first_slash'); + +}); + + +test('bind exception: invalid INPROC address (too long)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'File name too long'); + sock.close(); + }); + + var addr = new Array(nano._bindings.NN_SOCKADDR_MAX + 1).join('a'); + sock.bind('inproc://' + addr); +}); + +test('bind exception: invalid TCP address (missing)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.bind('tcp://'); +}); + +test('bind exception: invalid TCP address (non-numeric port)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.bind('tcp://127.0.0.1:port'); +}); + +test('bind exception: invalid TCP address (port out of range)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.bind('tcp://127.0.0.1:65536'); +}); + +test('bind exception: unsupported transport', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Protocol not supported', err.message); + sock.close(); + }); + + sock.bind('zmq://127.0.0.1:6000'); +}); + +test('bind exception: TCP on non-existent device', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.ok(err, 'Operation not supported by device: tcp://eth99:555'); + sock.close(); + }); + + sock.bind('tcp://eth99:555'); +}); diff --git a/node/node_modules/nanomsg/test/bug105.js b/node/node_modules/nanomsg/test/bug105.js new file mode 100644 index 0000000..9f1b70c --- /dev/null +++ b/node/node_modules/nanomsg/test/bug105.js @@ -0,0 +1,45 @@ +var nano = require('..') +var test = require('tape'); + +// see: https://github.com/nickdesaulniers/node-nanomsg/issues/105 +test('multiple req sockets should not throw', function (t) { + t.plan(1); + + var tcp = 'tcp://127.0.0.1:9080'; + var server = nano.socket('rep'); + + var counter = 10; + + server.setEncoding('utf8'); + server.bind(tcp); + + server.on('data', function (data) { + server.send(data); + if (!(--counter)) { + clearInterval(int1); + clearInterval(int2); + client.close(); + clientb.close(); + server.close(); + t.pass('no crashes'); + } + }) + + var client = nano.socket('req'); + + client.setEncoding('utf8'); + client.connect(tcp); + + var int1 = setInterval(function () { + client.send('3'); + }); + + var clientb = nano.socket('req'); + clientb.setEncoding('utf8'); + clientb.connect(tcp); + + var int2 = setInterval(function () { + clientb.send('3'); + }); +}); + diff --git a/node/node_modules/nanomsg/test/chan.js b/node/node_modules/nanomsg/test/chan.js new file mode 100644 index 0000000..de9f34a --- /dev/null +++ b/node/node_modules/nanomsg/test/chan.js @@ -0,0 +1,247 @@ +var nano = require('..'); +var test = require('tape'); + +test('adding and removing subscription channels', function (t) { + + t.plan(7); + + var pub = nano.socket('pub'); + + //register some channels: hello, foo, bar + var sub = nano.socket('sub', { + chan: ['hello', 'foo', 'bar'] + }); + + pub.bind('inproc://filter'); + sub.connect('inproc://filter'); + + //the main array we'll use to test channel registration and removal + var msgs = ['hello world','hello world','hello world','bar world','foo world']; + var msgqty = -1; //starting here so first msg counted can be zero + var sent = 0; + + sub.on('data', function (buf) { + + var msg = String(buf); + + //increment msgqty when a msg is received (happening about every 100ms) + //we'll call finish() on the 5th msg received + switch(++msgqty){ + case 0: return t.equal(msg, msgs[msgqty]); //msgs[0], 'hello world' + case 1: return t.equal(msg, msgs[msgqty]); //msgs[1], 'hello world' + case 2: return t.equal(msg, msgs[msgqty]); //msgs[2], 'hello world' + case 3: return t.equal(msg, msgs[msgqty]); //msgs[3], 'bar world' + case 4: return finish (msg); + } + + }); + + setTimeout(send, 0); //send msgs[0], 'hello world' + setTimeout(send, 100); //send msgs[1], 'hello world' + setTimeout(send, 200); //send msgs[2], 'hello world' + setTimeout(removeHello, 300); //send msgs[3], 'bar world' and remove hello + setTimeout(send, 400); //send msgs[4], 'foo world' + + function send(){ + pub.send(msgs[sent++]); //lazy incrementing + } + + function removeHello(){ + + //stop listening for msg prefix: hello + sub.rmchan('hello'); + + //publish about 10 extra hello worlds to see if we can increment msgqty + var i = 0; + while(i++ < 10) pub.send('hello world'); + + send(); // send something with a registered prefix: 'bar world' + } + + function finish(msg){ + t.equal(msg, msgs[msgqty]); //'foo world' + t.equal(msg, msgs[4]); //msgqty count + t.equal(msg, 'foo world'); //prove case 4, the fifth msg + sub.close(); + pub.close(); + } +}); + +test('without explicitly registering any channels, socket recvs 2+ msgs of different prefixes', function(t){ + t.plan(2); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var msgs = 0; + var msg1 = 'foo world'; + var msg2 = 'bar world'; + var addr = 'inproc://default'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + + var msg = String(buf); + + if(++msgs < 2){ + t.equal(msg, 'foo world'); + } else { + t.equal(msg, 'bar world'); + sub.close(); + pub.close(); + } + }); + + pub.send(msg1); + + setTimeout(function () { + pub.send(msg2); + }, 100); + +}); + +test('registration after socket creation: chan receives correctly prefixed messages but not others', function(t){ + t.plan(2); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var msgs = 0; + var msg1 = 'foo world'; + var msg2 = 'bar world'; + var msg3 = 'hi world'; + var msg4 = 'hello world'; + var addr = 'inproc://prefixed'; + + pub.bind(addr); + sub.connect(addr); + + sub.chan(['foo','hello']); + + sub.on('data', function (buf) { + + var msg = String(buf); + + if(++msgs < 2){ + t.equal(msg, 'foo world'); + } else { + t.equal(msg, 'hello world'); + sub.close(); + pub.close(); + } + }); + + pub.send(msg1); + pub.send(msg2); + pub.send(msg3); + process.nextTick(function(){ + pub.send(msg4); + }) +}); + +test('channels registered by constructor get appropriately prefixed messages but not others', function(t){ + t.plan(2); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub',{ + chan: ['foo','hello'] + }); + + var msgs = 0; + var msg1 = 'foo world'; + var msg2 = 'bar world'; + var msg3 = 'hi world'; + var msg4 = 'hello world'; + var addr = 'inproc://prefixed'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + + var msg = String(buf); + + if(++msgs < 2){ + t.equal(msg, 'foo world'); + } else { + t.equal(msg, 'hello world'); + sub.close(); + pub.close(); + } + }); + + pub.send(msg1); + pub.send(msg2); + pub.send(msg3); + process.nextTick(function(){ + pub.send(msg4); + }) +}); + +test('multi-topic registration followed by calls to rmchan on all but one stops all channels no longer registerd', function(t){ + t.plan(5); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub',{ + chan: ['foo','bar','hi','hello'] + }); + + var msgs = 0; + var msg1 = 'foo world'; + var msg2 = 'bar world'; + var msg3 = 'hi world'; + var msg4 = 'hello world'; + var addr = 'inproc://prefixed'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + + var msg = String(buf); + + if(++msgs === 1) { + t.equal(msg, 'foo world'); + sub.rmchan('foo') + } else if(msgs === 2) { + t.equal(msg, 'bar world'); + sub.rmchan('bar'); + } else if (msgs === 3) { + t.equal(msg, 'hi world'); + sub.rmchan('hi'); + } else if (msgs === 4) { + t.equal(msg, 'hello world'); + } else if (msgs === 5) { + t.equal(msg, 'hello world'); + sub.close(); + pub.close(); + } + }); + + pub.send(msg1); // 1st msg + process.nextTick(function(){ + pub.send(msg2); // 2nd msg + pub.send(msg1); + process.nextTick(function(){ + pub.send(msg3); // 3rd msg + pub.send(msg2); + pub.send(msg1); + process.nextTick(function(){ + pub.send(msg4); // 4th msg + pub.send(msg3); + pub.send(msg2); + pub.send(msg1); + process.nextTick(function(){ + pub.send(msg3); + pub.send(msg2); + pub.send(msg1); + process.nextTick(function(){ + pub.send(msg4); //5th msg recv'd ends test + }); + }); + }); + }); + }); +}); diff --git a/node/node_modules/nanomsg/test/close.js b/node/node_modules/nanomsg/test/close.js new file mode 100644 index 0000000..d84c9c5 --- /dev/null +++ b/node/node_modules/nanomsg/test/close.js @@ -0,0 +1,33 @@ +// https://github.com/chuckremes/nn-core/blob/master/spec/nn_close_spec.rb + +var nano = require('../'); +var test = require('tape'); + +test('close a valid socket', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + var rc = sock.close(); + t.equal(rc, 0); +}); + +test('throw exception when closing invalid socket', function (t) { + // we can't test a close on an arbitrary fd as per the original test, + // because in our world close() is a method on a Socket object. + // We can test a double close on the same socket tho. + // Currently this is rigged so that the second (and any subsequent) + // close returns the same value as the first. + t.plan(2); + + var sock = nano.socket('pub'); + + sock.on('close', function (){ + t.ok(true, 'socket emitted close event'); + }) + + var rc = sock.close(); + var rc2 = sock.close(); + + t.equal(rc, rc2); +}); + diff --git a/node/node_modules/nanomsg/test/connect.js b/node/node_modules/nanomsg/test/connect.js new file mode 100644 index 0000000..c20278d --- /dev/null +++ b/node/node_modules/nanomsg/test/connect.js @@ -0,0 +1,135 @@ +var nano = require('..'); +var test = require('tape'); + +test('map connect address eid for valid INPROC address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.connect('inproc://some_address'); + + if (sock.connected['inproc://some_address'] > -1) { + t.pass('valid INPROC connect'); + } else { + t.pass('INPROC connect fail'); + } + + sock.close(); +}); + +test('map connect address eid for valid IPC address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.connect('ipc://some_address'); + + if (sock.connected['ipc://some_address'] > -1) { + t.pass('valid IPC connect'); + } else { + t.pass('IPC connect fail'); + } + + sock.close(); + require('fs').unlink('some_address'); +}); + +test('map connect address eid for valid TCP address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.connect('tcp://127.0.0.1:5555'); + + if (sock.connected['tcp://127.0.0.1:5555'] > -1) { + t.pass('valid TCP connect'); + } else { + t.pass('TCP connect fail'); + } + + sock.close(); +}); + +test('connect exception: invalid INPROC address', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.connect('inproc:/missing_first_slash'); + +}); + + +test('connect exception: invalid INPROC address (too long)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'File name too long'); + sock.close(); + }); + + var addr = new Array(nano._bindings.NN_SOCKADDR_MAX + 1).join('a'); + sock.connect('inproc://' + addr); +}); + +test('connect exception: invalid TCP address (missing)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.connect('tcp://'); +}); + +test('connect exception: invalid TCP address (non-numeric port)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.connect('tcp://127.0.0.1:port'); +}); + +test('connect exception: invalid TCP address (port out of range)', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Invalid argument', err.message); + sock.close(); + }); + + sock.connect('tcp://127.0.0.1:65536'); +}); + +test('connect exception: unsupported transport', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + + sock.on('error', function (err) { + t.equal(err.message, + 'Protocol not supported', err.message); + sock.close(); + }); + + sock.connect('zmq://127.0.0.1:6000'); +}); diff --git a/node/node_modules/nanomsg/test/inproc.js b/node/node_modules/nanomsg/test/inproc.js new file mode 100644 index 0000000..47cd522 --- /dev/null +++ b/node/node_modules/nanomsg/test/inproc.js @@ -0,0 +1,247 @@ +// http://tim.dysinger.net/posts/2013-09-16-getting-started-with-nanomsg.html + +var nano = require('../'); +var test = require('tape'); + +test('inproc socket pub sub', function (t) { + t.plan(1); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var addr = 'inproc://pubsub'; + var msg = 'hello world'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + t.equal(buf.toString(), msg); + + pub.close(); + sub.close(); + }); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); + + +test('inproc socket pairs', function (t) { + t.plan(1); + + var s1 = nano.socket('pair'); + var s2 = nano.socket('pair'); + + var addr = 'inproc://pairs'; + var msg = 'hello world'; + + s1.bind(addr); + s2.connect(addr); + + s1.on('data', function (buf) { + t.equal(buf.toString(), msg); + + s1.close(); + s2.close(); + }); + + setTimeout(function () { + s2.send(msg); + }, 100); +}); + + +test('inproc socket req rep', function (t) { + t.plan(2); + + var req = nano.socket('req'); + var rep = nano.socket('rep'); + + var addr = 'inproc://reqrep'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + rep.bind(addr); + req.connect(addr); + + rep.on('data', function (buf) { + t.equal(buf.toString(), msg1, 'request received'); + rep.send(msg2); + }); + + req.on('data', function (buf) { + t.equal(buf.toString(), msg2, 'reply received'); + req.close(); + rep.close(); + }); + + setTimeout(function () { + req.send(msg1); + }, 100); +}); + +test('inproc socket survey', function (t) { + t.plan(3); + + var sur = nano.socket('surveyor'); + var rep1 = nano.socket('respondent'); + var rep2 = nano.socket('respondent'); + var rep3 = nano.socket('respondent'); + + var addr = 'inproc://survey'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + sur.bind(addr); + rep1.connect(addr); + rep2.connect(addr); + rep3.connect(addr); + + function answer (buf) { + this.send(msg2); + } + + rep1.on('data', answer); + rep2.on('data', answer); + rep3.on('data', answer); + + var count = 0; + sur.on('data', function (buf) { + t.ok(buf.toString() == msg2, buf.toString() + ' == ' + msg2); + + if (++count == 3) { + sur.close(); + rep1.close(); + rep2.close(); + rep3.close(); + } + }); + + setTimeout(function () { + sur.send(msg1); + }, 100); +}); + +test('inproc socket bus', function (t) { + // http://250bpm.com/blog:17 + + // Number of buses to create. + var count = 3; + var total = count * (count-1), current = 0; + t.plan(count); + + // Create buses. + var buses = {}; + for (var i = 0; i < count; i++) { + (function (i) { + var bus = nano.socket('bus'); + var addr = 'inproc://bus' + i; + bus.bind(addr); + buses[addr] = bus; + + // Add a "response count" for each bus. + // We want this to equal the number of other buses. + bus.responseCount = 0; + + // Tally messages from other buses. + bus.on('data', function (msg) { + //console.error('#', 'received data from', msg.toString(), 'on', addr) + this.responseCount++; + current++; + + if (this.responseCount == count - 1) { + // All set! bus received all messages. + t.ok(true, 'all messages received on ' + addr); + } + + if (current == total) { + // close all buses. + Object.keys(buses).forEach(function (addr) { + buses[addr].close(); + }) + } + }); + })(i); + } + + // Connect all possible pairs of buses. + setTimeout(function () { + var keys = Object.keys(buses); + + for (var i = 0; i < keys.length; i++) { + for (var j = i+1; j < keys.length; j++) { + //console.error('#', 'connecting', keys[i], 'to', keys[j]); + buses[keys[i]].connect(keys[j]); + } + } + }, 500); + + // Send messages on every bus. + setTimeout(function () { + Object.keys(buses).forEach(function (addr) { + //console.error('#', 'writing on', addr, addr); + buses[addr].send(addr); + }); + }, 1000); +}); + + +test('inproc multiple binds on same address', function (t) { + t.plan(1); + + var s1 = nano.socket('pair'); + var s2 = nano.socket('pair'); + + var addr = 'inproc://multiplebinds'; + + s2.on('error', function (err) { + t.ok(err, 'error was thrown on multiple binds.'); + s1.close(); + s2.close(); + }); + + s1.bind(addr); + s2.bind(addr); +}); + +test('inproc multiple socket pub sub', function (t) { + t.plan(3); + + var pub = nano.socket('pub'); + var sub1 = nano.socket('sub'); + var sub2 = nano.socket('sub'); + var sub3 = nano.socket('sub'); + + var addr = 'inproc://pubsub'; + var msg = 'hello world'; + + pub.bind(addr); + sub1.connect(addr); + sub2.connect(addr); + sub3.connect(addr); + + var responses = 0; + + var resp_handler = function (buf) { + t.equal(buf.toString(), msg); + + responses++; + + if(responses == 3) { + pub.close(); + sub1.close(); + sub2.close(); + sub3.close(); + } + }; + + sub1.on('data', resp_handler); + sub2.on('data', resp_handler); + sub3.on('data', resp_handler); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); diff --git a/node/node_modules/nanomsg/test/ipc.js b/node/node_modules/nanomsg/test/ipc.js new file mode 100644 index 0000000..b2dc8e4 --- /dev/null +++ b/node/node_modules/nanomsg/test/ipc.js @@ -0,0 +1,238 @@ +// http://tim.dysinger.net/posts/2013-09-16-getting-started-with-nanomsg.html + +// This test suite is a duplicate of inproc.js, but using the ipc +// transport. + +var nano = require('..') +var test = require('tape') +var unlink = require('fs').unlink + +test('ipc socket pub sub', function (t) { + t.plan(1); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var addr = 'ipc:///tmp/pubsub.ipc'; + var msg = 'hello world'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + t.equal(buf.toString(), msg); + + pub.close(); + sub.close(); + unlink('/tmp/pubsub.ipc') + }); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); + +test('ipc socket pairs', function (t) { + t.plan(1); + + var s1 = nano.socket('pair'); + var s2 = nano.socket('pair'); + + var addr = 'ipc:///tmp/pairs.ipc'; + var msg = 'hello world'; + + s1.bind(addr); + s2.connect(addr); + + s1.on('data', function (buf) { + t.equal(buf.toString(), msg); + + s1.close(); + s2.close(); + unlink('/tmp/pairs.ipc') + }); + + setTimeout(function () { + s2.send(msg); + }, 100); +}); + +test('ipc socket req rep', function (t) { + t.plan(2); + + var req = nano.socket('req'); + var rep = nano.socket('rep'); + + var addr = 'ipc:///tmp/reqrep.ipc'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + rep.bind(addr); + req.connect(addr); + + rep.on('data', function (buf) { + t.equal(buf.toString(), msg1, 'request received'); + rep.send(msg2); + }); + + req.on('data', function (buf) { + t.equal(buf.toString(), msg2, 'reply received'); + + req.close(); + rep.close(); + unlink('/tmp/reqrep.ipc') + }); + + setTimeout(function () { + req.send(msg1); + }, 100); +}); + +test('ipc socket survey', function (t) { + t.plan(3); + + var sur = nano.socket('surveyor'); + var rep1 = nano.socket('respondent'); + var rep2 = nano.socket('respondent'); + var rep3 = nano.socket('respondent'); + + var addr = 'ipc:///tmp/survey.ipc'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + sur.bind(addr); + rep1.connect(addr); + rep2.connect(addr); + rep3.connect(addr); + + function answer (buf) { + this.send(msg2); + } + + rep1.on('data', answer); + rep2.on('data', answer); + rep3.on('data', answer); + + var count = 0; + sur.on('data', function (buf) { + t.ok(buf.toString() == msg2, buf.toString() + ' == ' + msg2); + + if (++count == 3) { + sur.close(); + rep1.close(); + rep2.close(); + rep3.close(); + unlink('/tmp/survey.ipc') + } + }); + + setTimeout(function () { + sur.send(msg1); + }, 100); +}); + +test('ipc socket bus', function (t) { + // http://250bpm.com/blog:17 + + // Number of buses to create. + var count = 3; + var total = count * (count-1), current = 0; + t.plan(count); + + // Create buses. + var buses = {}; + + for (var i = 0; i < count; i++) { + (function (i) { + var bus = nano.socket('bus'); + var addr = 'ipc:///tmp/bus' + i + '.ipc'; + bus.bind(addr); + buses[addr] = bus; + + // Add a "response count" for each bus. + // We want this to equal the number of other buses. + bus.responseCount = 0; + + // Tally messages from other buses. + bus.on('data', function (msg) { + //console.error('#', 'received data from', msg.toString(), 'on', addr); + this.responseCount++; + current++; + + if (this.responseCount == count - 1) { + // All set! bus received all messages. + t.ok(true, 'all messages received on ' + addr); + } + + if (current == total) { + // close all buses. + Object.keys(buses).forEach(function (addr) { + buses[addr].close(); + unlink(addr.split(/:\/\//)[1]) + }); + } + }); + })(i); + } + + // Connect all possible pairs of buses. + setTimeout(function () { + var keys = Object.keys(buses); + + for (var i = 0; i < keys.length; i++) { + for (var j = i+1; j < keys.length; j++) { + //console.error('#', 'connecting', keys[i], 'to', keys[j]); + buses[keys[i]].connect(keys[j]); + } + } + }, 500); + + // Send messages on every bus. + setTimeout(function () { + Object.keys(buses).forEach(function (addr) { + //console.error('#', 'writing on', addr, addr); + buses[addr].send(addr); + }); + }, 1000); +}); + +test('ipc multiple socket pub sub', function (t) { + t.plan(3); + + var pub = nano.socket('pub'); + var sub1 = nano.socket('sub'); + var sub2 = nano.socket('sub'); + var sub3 = nano.socket('sub'); + + var addr = 'ipc:///tmp/multisub.ipc'; + var msg = 'hello world'; + + pub.bind(addr); + sub1.connect(addr); + sub2.connect(addr); + sub3.connect(addr); + + var responses = 0; + + var resp_handler = function (buf) { + t.equal(buf.toString(), msg); + + responses++; + + if(responses == 3) { + pub.close(); + sub1.close(); + sub2.close(); + sub3.close(); + unlink('/tmp/multisub.ipc') + } + }; + + sub1.on('data', resp_handler); + sub2.on('data', resp_handler); + sub3.on('data', resp_handler); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); diff --git a/node/node_modules/nanomsg/test/mksymbols.rb b/node/node_modules/nanomsg/test/mksymbols.rb new file mode 100755 index 0000000..462c2a4 --- /dev/null +++ b/node/node_modules/nanomsg/test/mksymbols.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby +# this script builds symbols.js (required for the symbolinfo.js test) +# from the internal symbol table in libnanomsg. +# +# Regenerate the symbols each time a new major release of libnanomsg +# is incorporated, with: +# +# ./mksymbols >symbols.js +# +src = '../deps/nanomsg/src/core/symbol.c' +opts = [] + +s = File.open(src) {|f| f.read } + +if m = s.match(/static\s+const\s+struct\s+nn_symbol_properties\s+ + sym_value_names\s+\[\]\s+=\s+{\s+ + (.*?)\s+};/mx) + + m[1].scan(/{([^}]+)}/s) do |n| + a = n.first.split(/[ ,\n]+/) + + if a.length == 5 + opts.push(<<-FOO) + 'value': nn.#{a[0]}, + 'name': #{a[1].strip}, + 'ns': nn.#{a[2]}, + 'type': nn.#{a[3].strip}, + 'unit': nn.#{a[4]} + FOO + end + end +end + +o = opts.map {|t| "{\n" + t + "\n}"}.join(",\n") + +puts < 0) sub.connect( addr + i); + + //verify connection addresses known by publishers + while(++i <= 5) t.ok(has(pubs['p'+i],'bound'),'pub p'+i+' \'eid\' property check'); + while(i-- > 1) t.ok(has(pubs['p'+i].bound, addr+i ),'pub p'+i+' addr: '+ addr+i); + + t.end(); + +}) + +test('shutdown the sub\'s connections',function(t){ + + t.equal(Object.keys(sub.connected).length, 5, 'subscriber connections: 5'); + + function checkThenCleanUp (previousSubs, newSubs, msg) { + // After every shutdown, we should have decremented the number of + // subscribers. + t.equal(newSubs, previousSubs - 1, msg); + // It's only safe to clean up after the number of subscribers has hit zero. + if (newSubs !== 0) { + return; + } + clearInterval(pubInterval); + for(var p in pubs) pubs[p].close(); + sub.close(); + t.end(); + }; + + function numSubs (sub) { return Object.keys(sub.connected).length; } + var i = 0; + + sub.on('data', function(msg){ + + switch (String(msg)) { + + // After 10 messages from p1, shutdown everyone + case 'hello from p1': if (++i == 10) { + + var previousSubs = numSubs(sub); + t.ok(sub.shutdown(addr+1) != -1, + 'shutting down connection to endpoint: tcp://127.0.0.1:44451\n'); + var newSubs = numSubs(sub); + checkThenCleanUp(previousSubs, newSubs, 'shutting down p1'); + + } break; + + case 'hello from p2': if (i == 10) { + + var previousSubs = numSubs(sub); + t.ok(sub.shutdown(addr+2) != -1, + Object.keys(sub.connected).length+1, + 'shutting down connection to endpoint: tcp://127.0.0.1:44452\n'); + var newSubs = numSubs(sub); + checkThenCleanUp(previousSubs, newSubs, 'shutting down p2'); + + } break; + + case 'hello from p3': if (i == 10) { + + var previousSubs = numSubs(sub); + t.ok(sub.shutdown(addr+3) != -1, + Object.keys(sub.connected).length+1, + 'shutting down connection to endpoint: tcp://127.0.0.1:44453\n'); + var newSubs = numSubs(sub); + checkThenCleanUp(previousSubs, newSubs, 'shutting down p3'); + + } break; + + case 'hello from p4': if (i == 10) { + + var previousSubs = numSubs(sub); + t.ok(sub.shutdown(addr+4) != -1, + Object.keys(sub.connected).length+1, + 'shutting down connection to endpoint: tcp://127.0.0.1:44454\n'); + var newSubs = numSubs(sub); + checkThenCleanUp(previousSubs, newSubs, 'shutting down p4'); + + } break; + + case 'hello from p5': if (i == 10) { + + var previousSubs = numSubs(sub); + t.ok(sub.shutdown(addr+5) != -1, + Object.keys(sub.connected).length+1, + 'shutting down connection to endpoint: tcp://127.0.0.1:44455'); + var newSubs = numSubs(sub); + checkThenCleanUp(previousSubs, newSubs, 'shutting down p5'); + + } break; + } + + }) + + // Publish another five hellos after 5ms. + var pubInterval = setInterval(hellos, 5); + + function hellos(){ + pubs.p1.send('hello from p1'); + pubs.p2.send('hello from p2'); + pubs.p3.send('hello from p3'); + pubs.p4.send('hello from p4'); + pubs.p5.send('hello from p5'); + } + +}); + + +function has (obj, prop) { + return Object.hasOwnProperty.call(obj, prop); +} diff --git a/node/node_modules/nanomsg/test/sockoptapi.js b/node/node_modules/nanomsg/test/sockoptapi.js new file mode 100644 index 0000000..3946f55 --- /dev/null +++ b/node/node_modules/nanomsg/test/sockoptapi.js @@ -0,0 +1,116 @@ +var nano = require('..'); +var test = require('tape'); + +test('sockopt api methods', function(t){ + + //set sockopts when starting the socket + var sock = nano.socket('push', { + tcpnodelay:true, + linger: 3000, + sndbuf: 202400 + }); + t.equal( sock.tcpnodelay(), true, 'sock.tcpnodelay() gets: true'); + t.equal( sock.linger(), 3000, 'sock.linger() gets: 3000'); + t.equal( sock.sndbuf(), 202400, 'sock.sndbuf() gets: 202400'); + sock.tcpnodelay(false); + + + //`socket.tcpnodelay()` method + t.equal( sock.tcpnodelay(), false, 'sock.tcpnodelay(): false'); + t.equal( sock.tcpnodelay(true), true, 'sock.tcpnodelay(true) set: true'); + t.equal( sock.tcpnodelay(), true, 'sock.tcpnodelay() gets: true'); + t.equal( sock.tcpnodelay(false), false,'sock.tcpnodelay(false) set: false'); + t.equal( sock.tcpnodelay(), false, 'sock.tcpnodelay() gets: false'); + + //linger + t.equal( sock.linger(5000), true, 'sock.linger(5000) sets: 5000ms'); + t.equal( sock.linger(), 5000, 'sock.linger() gets: 5000'); + + //sndbuf + t.equal( sock.sndbuf(1024), true, 'sock.sndbuf(1024) sets: 1024 bytes'); + t.equal( sock.sndbuf(), 1024, 'sock.sndbuf() gets: 1024'); + + //rcvbuf + t.equal( sock.rcvbuf(102400), true, 'sock.rcvbuf(102400) sets: 102400 bytes'); + t.equal( sock.rcvbuf(), 102400, 'sock.rcvbuf() gets: 102400'); + + //sndtimeo + t.equal( sock.sndtimeo(500), true, 'sock.sndtimeo(500) sets: 500ms'); + t.equal( sock.sndtimeo(), 500, 'sock.sndtimeo() gets: 500'); + + //rcvtimeo + t.equal( sock.rcvtimeo(200), true, 'sock.rcvtimeo(200) sets: 200ms'); + t.equal( sock.rcvtimeo(), 200, 'sock.rcvtimeo() gets: 200'); + + //reconn + t.equal( sock.reconn(500), true, 'sock.reconn(500) sets: 500ms'); + t.equal( sock.reconn(), 500, 'sock.reconn() gets: 500'); + + //maxreconn + t.equal( sock.maxreconn(100000), true, 'sock.maxreconn(100000) sets: 100000ms'); + t.equal( sock.maxreconn(), 100000, 'sock.maxreconn() gets: 100000'); + + //sndprio + t.equal( sock.sndprio(3), true, 'sock.sndprio(3) sets: 3 priority'); + t.equal( sock.sndprio(), 3, 'sock.sndprio() gets: 3'); + + //rcvprio + t.equal( sock.rcvprio(10), true, 'sock.rcvprio(10) sets: 10 priority'); + t.equal( sock.rcvprio(), 10, 'sock.rcvprio() gets: 10'); + + //rcvmaxsize + t.equal( sock.rcvmaxsize(), 1048576, 'rcvmaxsize default: 1048576 bytes'); + t.equal( sock.rcvmaxsize(10000000), true, 'rcvmaxsize sets: 1M bytes'); + t.equal( sock.rcvmaxsize(), 10000000, 'rcvmaxsize gets: 1M bytes'); + + //ipv6 + t.equal( sock.ipv6(), false, 'sock.ipv6() gets: false'); + t.equal( sock.ipv6(true), true, 'sock.ipv6(true) gets: true'); + t.equal( sock.ipv6(), true, 'sock.ipv6() gets: true'); + + //set WS socket msg type + t.equal( sock.wsopt(), 'binary', 'sock.wsopt() gets: binary'); + t.equal( sock.wsopt('text'), true, 'sock.wsopt(text) sets: text'); + t.equal( sock.wsopt(), 'text', 'sock.wsopt() gets: text'); + t.equal( sock.wsopt('binary'), true, 'sock.wsopt(binary) sets: binary'); + t.equal( sock.wsopt(), 'binary', 'sock.wsopt() gets: binary'); + + //get default dontwait option for push + t.equal( sock.dontwait(), false, 'sock.dontwait() gets: false'); + + //set dontwait option + t.equal( sock.dontwait(true), true, 'sock.dontwait(true) sets: true'); + t.equal( sock.dontwait(), true, 'sock.dontwait(1) gets: true'); + + //get default dontwait option for pull + var pull = nano.socket('pull'); + t.equal( pull.dontwait(), true, 'sock.dontwait() gets: true'); + pull.close(); + + sock.close(); + t.end(); +}); + +test('ipv6 socket msg delivery', function (t) { + t.plan(1); + + var pub = nano.socket('pub', { ipv6: true }); + var sub = nano.socket('sub', { ipv6: true }); + + var addr = 'tcp://::1:6000'; + var msg = 'hello world'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + t.equal(buf.toString(), msg); + + pub.close(); + sub.close(); + }); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); diff --git a/node/node_modules/nanomsg/test/standalone/device.js b/node/node_modules/nanomsg/test/standalone/device.js new file mode 100644 index 0000000..d3c5a3b --- /dev/null +++ b/node/node_modules/nanomsg/test/standalone/device.js @@ -0,0 +1,57 @@ +// https://github.com/nanomsg/nanomsg/blob/master/tests/device.c +// test nn_device() with two PAIR sockets (ie BIDIRECTIONAL device) +// +// *NB* this is a standalone script because it calls nn_term() and therefore +// cannot coexist with any other nanomsg tests in the same process. + +var nano = require('../../'); +var test = require('tape'); + +test('create bidirectional device with two sockets', function (t) { + t.plan(3); + + var r1 = nano.socket('pair', { raw: 1 }); + var r2 = nano.socket('pair', { raw: 1 }); + + var addr1 = 'inproc://device01'; + var addr2 = 'inproc://device02'; + var msg1 = "Hello"; + var msg2 = "World"; + + r1.bind(addr1); + r2.bind(addr2); + + var d = nano.device(r1, r2); + + d.on('error', function (err) { + t.ok(err, 'error was thrown when device collapsed:' + err); + r1.close(); + r2.close(); + }); + + + var s1 = nano.socket('pair'); + var s2 = nano.socket('pair'); + + s1.connect(addr1); + s2.connect(addr2); + + s1.on('data', function (buf) { + t.equal(buf.toString(), msg2); + s1.close(); + s2.close(); + + // nano.term() is the only way to shutdown a nano.device() ! + nano.term(); + }); + + s2.on('data', function (buf) { + t.equal(buf.toString(), msg1); + s2.send(msg2); + }); + + setTimeout(function () { + s1.send(msg1); + }, 100); + +}); diff --git a/node/node_modules/nanomsg/test/standalone/device2.js b/node/node_modules/nanomsg/test/standalone/device2.js new file mode 100644 index 0000000..38b3ea0 --- /dev/null +++ b/node/node_modules/nanomsg/test/standalone/device2.js @@ -0,0 +1,51 @@ +// https://github.com/nanomsg/nanomsg/blob/master/tests/device.c +// test nn_device() with a PULLand PUSH socket (ie UNIDIRECTIONAL device) +// +// *NB* this is a standalone script because it calls nn_term() and therefore +// cannot coexist with any other nanomsg tests in the same process. + +var nano = require('../../'); +var test = require('tape'); + +test('create unidirectional device with two sockets', function (t) { + t.plan(2); + + var r1 = nano.socket('pull', { raw: true }); + var r2 = nano.socket('push', { raw: true }); + + var addr1 = 'inproc://device1'; + var addr2 = 'inproc://device2'; + var msg = "Hello"; + + r1.bind(addr1); + r2.bind(addr2); + + var d = nano.device(r1, r2); + + d.on('error', function (err) { + t.ok(err, 'error was thrown when device collapsed:' + err); + r1.close(); + r2.close(); + }); + + + var s1 = nano.socket('push'); + var s2 = nano.socket('pull'); + + s1.connect(addr1); + s2.connect(addr2); + + s2.on('data', function (buf) { + t.equal(buf.toString(), msg); + s1.close(); + s2.close(); + + // nano.term() is the only way to shutdown a nano.device() ! + nano.term(); + }); + + setTimeout(function () { + s1.send(msg); + }, 100); + +}); diff --git a/node/node_modules/nanomsg/test/standalone/device3.js b/node/node_modules/nanomsg/test/standalone/device3.js new file mode 100644 index 0000000..a45308b --- /dev/null +++ b/node/node_modules/nanomsg/test/standalone/device3.js @@ -0,0 +1,47 @@ +// https://github.com/nanomsg/nanomsg/blob/master/tests/device.c +// test nn_device() with a single BUS socket (ie LOOPBACK device) +// +// *NB* this is a standalone script because it calls nn_term() and therefore +// cannot coexist with any other nanomsg tests in the same process. + +var nano = require('../../'); +var test = require('tape'); + +test('create loopback device with one socket', function (t) { + t.plan(2); + + var r1 = nano.socket('bus', { raw: true }); + + var addr = 'inproc://device1'; + var msg = "Hello"; + + r1.bind(addr); + + var d = nano.device(r1); + + d.on('error', function (err) { + t.ok(err, 'error was thrown when device collapsed:' + err); + r1.close(); + }); + + + var s1 = nano.socket('bus'); + var s2 = nano.socket('bus'); + + s1.connect(addr); + s2.connect(addr); + + s2.on('data', function (buf) { + t.equal(buf.toString(), msg); + s1.close(); + s2.close(); + + // nano.term() is the only way to shutdown a nano.device() ! + nano.term(); + }); + + setTimeout(function () { + s1.send(msg); + }, 100); + +}); diff --git a/node/node_modules/nanomsg/test/standalone/term.js b/node/node_modules/nanomsg/test/standalone/term.js new file mode 100644 index 0000000..0b66808 --- /dev/null +++ b/node/node_modules/nanomsg/test/standalone/term.js @@ -0,0 +1,21 @@ +// https://github.com/chuckremes/nn-core/blob/master/spec/nn_term_spec.rb + +var nano = require('../../'); +var test = require('tape'); + +test('no longer throw exception when sending on socket after term() called', function (t) { + t.plan(1); + + var sock = nano.socket('pub'); + sock.bind('tcp://127.0.0.1:9999') + + sock.send("Hello"); + nano.term(); + + setTimeout(function(){ + + t.ok('library exit', 'exits cleanly now and sockets are closed.') + sock.close() + }, 100) + +}); diff --git a/node/node_modules/nanomsg/test/streams.js b/node/node_modules/nanomsg/test/streams.js new file mode 100644 index 0000000..3a8cba7 --- /dev/null +++ b/node/node_modules/nanomsg/test/streams.js @@ -0,0 +1,38 @@ +var nano = require('..'); +var test = require('tape'); + +test('pipe a thousand msgs between incompatible socket types', function(t){ + + var sent = 0, recv = 0; + + var pub = nano.socket('pub', { tcpnodelay: true }); + var sub = nano.socket('sub', { tcpnodelay: true }); + + var push = nano.socket('push'); + var pull = nano.socket('pull'); + pull.setEncoding('utf8'); //should also be able to do in `socket(type, opts)` + + pub.bind('tcp://127.0.0.1:64999'); + sub.connect('tcp://127.0.0.1:64999'); + + pull.bind('tcp://127.0.0.1:65000'); + push.connect('tcp://127.0.0.1:65000'); + + sub.pipe(push); + pull.on('data', pullsocket); + + setTimeout(function(){ + while(sent++ < 1001) pub.send('hello from nanomsg pub socket!'); + }, 200); + + function pullsocket(msg){ + if(recv++ > 999){ + t.equal( msg, 'hello from nanomsg pub socket!', 'piped a pub/pull combo'); + pub.close(); + push.close(); + pull.close(); + sub.close(); + t.end(); + } + } +}); diff --git a/node/node_modules/nanomsg/test/symbol.js b/node/node_modules/nanomsg/test/symbol.js new file mode 100644 index 0000000..ae075e2 --- /dev/null +++ b/node/node_modules/nanomsg/test/symbol.js @@ -0,0 +1,35 @@ +// https://github.com/chuckremes/nn-core/blob/master/spec/nn_symbol_spec.rb + +var nano = require('../'); +var test = require('tape'); +var symbols = require('./symbols'); + +test('retrieve symbol name/value', function (t) { + var n = symbols.symbols.length; + + // useful for debugging the test + //for(var j = 0; j < n; j++) { + //var s = symbols.symbols[j]; + //console.log("LUT: %j", s); + //} + + for(var i = 0; i < n; i++) { + var ret = nano.symbol(i); + t.ok(ret, 'symbol retrieved ok'); + //console.log("iDX %d, RET: %j", i, ret); + + for(var j = 0; j < n; j++) { + var s = symbols.symbols[j]; + + if(s.name == ret.name) { + t.equal(s.value, ret.value); + break; + } + } + + if(j == n) { + t.fail("symbol not in LUT"); + } + } + t.end(); +}); diff --git a/node/node_modules/nanomsg/test/symbolinfo.js b/node/node_modules/nanomsg/test/symbolinfo.js new file mode 100644 index 0000000..c93e9bf --- /dev/null +++ b/node/node_modules/nanomsg/test/symbolinfo.js @@ -0,0 +1,38 @@ +// https://github.com/chuckremes/nn-core/blob/master/spec/nn_symbol_info_spec.rb + +var nano = require('../'); +var test = require('tape'); +var symbols = require('./symbols'); + +test('retrieve symbol info', function (t) { + var n = symbols.symbols.length; + + // useful for debugging the test + //for(var j = 0; j < n; j++) { + //var s = symbols.symbols[j]; + //console.log("LUT: %j", s); + //} + + for(var i = 0; i < n; i++) { + var ret = nano.symbolInfo(i); + t.ok(ret, 'symbol retrieved ok'); + //console.log("iDX %d, RET: %j", i, ret); + + for(var j = 0; j < n; j++) { + var s = symbols.symbols[j]; + + if(s.name == ret.name) { + t.equal(s.value, ret.value); + t.equal(s.ns, ret.ns); + t.equal(s.type, ret.type); + t.equal(s.unit, ret.unit); + break; + } + } + + if(j == n) { + t.fail("symbol not in LUT"); + } + } + t.end(); +}); diff --git a/node/node_modules/nanomsg/test/symbols.js b/node/node_modules/nanomsg/test/symbols.js new file mode 100644 index 0000000..ee06ad8 --- /dev/null +++ b/node/node_modules/nanomsg/test/symbols.js @@ -0,0 +1,741 @@ +// autogenerated from ../deps/nanomsg/src/core/symbol.c - manual edits inadvisable! +var nano = require('../'); +var nn = nano._bindings; + +exports.symbols = [ +{ + 'value': nn.NN_NS_NAMESPACE, + 'name': "NN_NS_NAMESPACE", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_VERSION, + 'name': "NN_NS_VERSION", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_DOMAIN, + 'name': "NN_NS_DOMAIN", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_TRANSPORT, + 'name': "NN_NS_TRANSPORT", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_PROTOCOL, + 'name': "NN_NS_PROTOCOL", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_OPTION_LEVEL, + 'name': "NN_NS_OPTION_LEVEL", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_SOCKET_OPTION, + 'name': "NN_NS_SOCKET_OPTION", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_TRANSPORT_OPTION, + 'name': "NN_NS_TRANSPORT_OPTION", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_OPTION_TYPE, + 'name': "NN_NS_OPTION_TYPE", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_OPTION_UNIT, + 'name': "NN_NS_OPTION_UNIT", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_FLAG, + 'name': "NN_NS_FLAG", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_ERROR, + 'name': "NN_NS_ERROR", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_LIMIT, + 'name': "NN_NS_LIMIT", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_EVENT, + 'name': "NN_NS_EVENT", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_NS_STATISTIC, + 'name': "NN_NS_STATISTIC", + 'ns': nn.NN_NS_NAMESPACE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_TYPE_NONE, + 'name': "NN_TYPE_NONE", + 'ns': nn.NN_NS_OPTION_TYPE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_TYPE_INT, + 'name': "NN_TYPE_INT", + 'ns': nn.NN_NS_OPTION_TYPE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_TYPE_STR, + 'name': "NN_TYPE_STR", + 'ns': nn.NN_NS_OPTION_TYPE, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_NONE, + 'name': "NN_UNIT_NONE", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_BYTES, + 'name': "NN_UNIT_BYTES", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_MILLISECONDS, + 'name': "NN_UNIT_MILLISECONDS", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_PRIORITY, + 'name': "NN_UNIT_PRIORITY", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_BOOLEAN, + 'name': "NN_UNIT_BOOLEAN", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_COUNTER, + 'name': "NN_UNIT_COUNTER", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_UNIT_MESSAGES, + 'name': "NN_UNIT_MESSAGES", + 'ns': nn.NN_NS_OPTION_UNIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_VERSION_CURRENT, + 'name': "NN_VERSION_CURRENT", + 'ns': nn.NN_NS_VERSION, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_VERSION_REVISION, + 'name': "NN_VERSION_REVISION", + 'ns': nn.NN_NS_VERSION, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_VERSION_AGE, + 'name': "NN_VERSION_AGE", + 'ns': nn.NN_NS_VERSION, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.AF_SP, + 'name': "AF_SP", + 'ns': nn.NN_NS_DOMAIN, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.AF_SP_RAW, + 'name': "AF_SP_RAW", + 'ns': nn.NN_NS_DOMAIN, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_INPROC, + 'name': "NN_INPROC", + 'ns': nn.NN_NS_TRANSPORT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_IPC, + 'name': "NN_IPC", + 'ns': nn.NN_NS_TRANSPORT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_TCP, + 'name': "NN_TCP", + 'ns': nn.NN_NS_TRANSPORT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_WS, + 'name': "NN_WS", + 'ns': nn.NN_NS_TRANSPORT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_PAIR, + 'name': "NN_PAIR", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_PUB, + 'name': "NN_PUB", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_SUB, + 'name': "NN_SUB", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_REP, + 'name': "NN_REP", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_REQ, + 'name': "NN_REQ", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_PUSH, + 'name': "NN_PUSH", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_PULL, + 'name': "NN_PULL", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_SURVEYOR, + 'name': "NN_SURVEYOR", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_RESPONDENT, + 'name': "NN_RESPONDENT", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_BUS, + 'name': "NN_BUS", + 'ns': nn.NN_NS_PROTOCOL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_SOCKADDR_MAX, + 'name': "NN_SOCKADDR_MAX", + 'ns': nn.NN_NS_LIMIT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_SOL_SOCKET, + 'name': "NN_SOL_SOCKET", + 'ns': nn.NN_NS_OPTION_LEVEL, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_LINGER, + 'name': "NN_LINGER", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_SNDBUF, + 'name': "NN_SNDBUF", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_BYTES +}, +{ + 'value': nn.NN_RCVBUF, + 'name': "NN_RCVBUF", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_BYTES +}, +{ + 'value': nn.NN_RCVMAXSIZE, + 'name': "NN_RCVMAXSIZE", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_BYTES +}, +{ + 'value': nn.NN_SNDTIMEO, + 'name': "NN_SNDTIMEO", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_RCVTIMEO, + 'name': "NN_RCVTIMEO", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_RECONNECT_IVL, + 'name': "NN_RECONNECT_IVL", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_RECONNECT_IVL_MAX, + 'name': "NN_RECONNECT_IVL_MAX", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_SNDPRIO, + 'name': "NN_SNDPRIO", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_PRIORITY +}, +{ + 'value': nn.NN_RCVPRIO, + 'name': "NN_RCVPRIO", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_PRIORITY +}, +{ + 'value': nn.NN_SNDFD, + 'name': "NN_SNDFD", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_RCVFD, + 'name': "NN_RCVFD", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_DOMAIN, + 'name': "NN_DOMAIN", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_PROTOCOL, + 'name': "NN_PROTOCOL", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_IPV4ONLY, + 'name': "NN_IPV4ONLY", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_BOOLEAN +}, +{ + 'value': nn.NN_SOCKET_NAME, + 'name': "NN_SOCKET_NAME", + 'ns': nn.NN_NS_SOCKET_OPTION, + 'type': nn.NN_TYPE_STR, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_SUB_SUBSCRIBE, + 'name': "NN_SUB_SUBSCRIBE", + 'ns': nn.NN_NS_TRANSPORT_OPTION, + 'type': nn.NN_TYPE_STR, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_SUB_UNSUBSCRIBE, + 'name': "NN_SUB_UNSUBSCRIBE", + 'ns': nn.NN_NS_TRANSPORT_OPTION, + 'type': nn.NN_TYPE_STR, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_REQ_RESEND_IVL, + 'name': "NN_REQ_RESEND_IVL", + 'ns': nn.NN_NS_TRANSPORT_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_SURVEYOR_DEADLINE, + 'name': "NN_SURVEYOR_DEADLINE", + 'ns': nn.NN_NS_TRANSPORT_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_MILLISECONDS +}, +{ + 'value': nn.NN_TCP_NODELAY, + 'name': "NN_TCP_NODELAY", + 'ns': nn.NN_NS_TRANSPORT_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_BOOLEAN +}, +{ + 'value': nn.NN_WS_MSG_TYPE, + 'name': "NN_WS_MSG_TYPE", + 'ns': nn.NN_NS_TRANSPORT_OPTION, + 'type': nn.NN_TYPE_INT, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_DONTWAIT, + 'name': "NN_DONTWAIT", + 'ns': nn.NN_NS_FLAG, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_WS_MSG_TYPE_TEXT, + 'name': "NN_WS_MSG_TYPE_TEXT", + 'ns': nn.NN_NS_FLAG, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_WS_MSG_TYPE_BINARY, + 'name': "NN_WS_MSG_TYPE_BINARY", + 'ns': nn.NN_NS_FLAG, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_POLLIN, + 'name': "NN_POLLIN", + 'ns': nn.NN_NS_EVENT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.NN_POLLOUT, + 'name': "NN_POLLOUT", + 'ns': nn.NN_NS_EVENT, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EADDRINUSE, + 'name': "EADDRINUSE", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EADDRNOTAVAIL, + 'name': "EADDRNOTAVAIL", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EAFNOSUPPORT, + 'name': "EAFNOSUPPORT", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EAGAIN, + 'name': "EAGAIN", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EBADF, + 'name': "EBADF", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ECONNREFUSED, + 'name': "ECONNREFUSED", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EFAULT, + 'name': "EFAULT", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EFSM, + 'name': "EFSM", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EINPROGRESS, + 'name': "EINPROGRESS", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EINTR, + 'name': "EINTR", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EINVAL, + 'name': "EINVAL", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EMFILE, + 'name': "EMFILE", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENAMETOOLONG, + 'name': "ENAMETOOLONG", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENETDOWN, + 'name': "ENETDOWN", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENOBUFS, + 'name': "ENOBUFS", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENODEV, + 'name': "ENODEV", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENOMEM, + 'name': "ENOMEM", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENOPROTOOPT, + 'name': "ENOPROTOOPT", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENOTSOCK, + 'name': "ENOTSOCK", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENOTSUP, + 'name': "ENOTSUP", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EPROTO, + 'name': "EPROTO", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EPROTONOSUPPORT, + 'name': "EPROTONOSUPPORT", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ETERM, + 'name': "ETERM", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ETIMEDOUT, + 'name': "ETIMEDOUT", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EACCES, + 'name': "EACCES", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ECONNABORTED, + 'name': "ECONNABORTED", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ECONNRESET, + 'name': "ECONNRESET", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EHOSTUNREACH, + 'name': "EHOSTUNREACH", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.EMSGSIZE, + 'name': "EMSGSIZE", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENETRESET, + 'name': "ENETRESET", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENETUNREACH, + 'name': "ENETUNREACH", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +}, +{ + 'value': nn.ENOTCONN, + 'name': "ENOTCONN", + 'ns': nn.NN_NS_ERROR, + 'type': nn.NN_TYPE_NONE, + 'unit': nn.NN_UNIT_NONE +} +]; diff --git a/node/node_modules/nanomsg/test/tcp.js b/node/node_modules/nanomsg/test/tcp.js new file mode 100644 index 0000000..20a5bc4 --- /dev/null +++ b/node/node_modules/nanomsg/test/tcp.js @@ -0,0 +1,229 @@ +// http://tim.dysinger.net/posts/2013-09-16-getting-started-with-nanomsg.html + +// This test suite is a duplicate of inproc.js, but using the tcp +// transport. + +var nano = require('../'); +var test = require('tape'); + +test('tcp socket pub sub', function (t) { + t.plan(1); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var addr = 'tcp://127.0.0.1:6000'; + var msg = 'hello world'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + t.equal(buf.toString(), msg); + + pub.close(); + sub.close(); + }); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); + +test('tcp socket pairs', function (t) { + t.plan(1); + + var s1 = nano.socket('pair'); + var s2 = nano.socket('pair'); + + var addr = 'tcp://127.0.0.1:6000'; + var msg = 'hello world'; + + s1.bind(addr); + s2.connect(addr); + + s1.on('data', function (buf) { + t.equal(buf.toString(), msg); + + s1.close(); + s2.close(); + }); + + setTimeout(function () { + s2.send(msg); + }, 100); +}); + +test('tcp socket req rep', function (t) { + t.plan(2); + + var req = nano.socket('req'); + var rep = nano.socket('rep'); + + var addr = 'tcp://127.0.0.1:6000'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + rep.bind(addr); + req.connect(addr); + + rep.on('data', function (buf) { + t.equal(buf.toString(), msg1, 'request received'); + rep.send(msg2); + }); + + req.on('data', function (buf) { + t.equal(buf.toString(), msg2, 'reply received'); + + req.close(); + rep.close(); + }); + + setTimeout(function () { + req.send(msg1); + }, 100); +}); + +test('tcp socket survey', function (t) { + t.plan(3); + + var sur = nano.socket('surveyor'); + var rep1 = nano.socket('respondent'); + var rep2 = nano.socket('respondent'); + var rep3 = nano.socket('respondent'); + + var addr = 'tcp://127.0.0.1:6000'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + sur.bind(addr); + rep1.connect(addr); + rep2.connect(addr); + rep3.connect(addr); + + function answer (buf) { + this.send(msg2); + } + rep1.on('data', answer); + rep2.on('data', answer); + rep3.on('data', answer); + + var count = 0; + sur.on('data', function (buf) { + t.ok(buf.toString() == msg2, buf.toString() + ' == ' + msg2); + + if (++count == 3) { + sur.close(); + rep1.close(); + rep2.close(); + rep3.close(); + } + }); + + setTimeout(function () { + sur.send(msg1); + }, 100); +}); + +test('tcp socket bus', function (t) { + // http://250bpm.com/blog:17 + + // Number of buses to create. + var count = 3; + var total = count * (count-1), current = 0; + t.plan(count); + + // Create buses. + var buses = {}; + for (var i = 0; i < count; i++) { + (function (i) { + var bus = nano.socket('bus'); + var addr = 'tcp://127.0.0.1:' + (6000 + i); + bus.bind(addr); + buses[addr] = bus; + + // Add a "response count" for each bus. + // We want this to equal the number of other buses. + bus.responseCount = 0; + + // Tally messages from other buses. + bus.on('data', function (msg) { + //console.error('#', 'received data from', msg.toString(), 'on', addr) + this.responseCount++; + current++; + + if (this.responseCount == count - 1) { + // All set! bus received all messages. + t.ok(true, 'all messages received on ' + addr); + } + + if (current == total) { + // close all buses. + Object.keys(buses).forEach(function (addr) { + buses[addr].close(); + }) + } + }); + })(i); + } + + // Connect all possible pairs of buses. + setTimeout(function () { + var keys = Object.keys(buses); + + for (var i = 0; i < keys.length; i++) { + for (var j = i+1; j < keys.length; j++) { + //console.error('#', 'connecting', keys[i], 'to', keys[j]); + buses[keys[i]].connect(keys[j]); + } + } + }, 500); + + // Send messages on every bus. + setTimeout(function () { + Object.keys(buses).forEach(function (addr) { + //console.error('#', 'writing on', addr, addr); + buses[addr].send(addr); + }); + }, 1000); +}); + +test('tcp multiple socket pub sub', function (t) { + t.plan(3); + + var pub = nano.socket('pub'); + var sub1 = nano.socket('sub'); + var sub2 = nano.socket('sub'); + var sub3 = nano.socket('sub'); + + var addr = 'tcp://127.0.0.1:6000'; + var msg = 'hello world'; + + pub.bind(addr); + sub1.connect(addr); + sub2.connect(addr); + sub3.connect(addr); + + var responses = 0; + + var resp_handler = function (buf) { + t.equal(buf.toString(), msg); + + responses++; + + if(responses == 3) { + pub.close(); + sub1.close(); + sub2.close(); + sub3.close(); + } + }; + + sub1.on('data', resp_handler); + sub2.on('data', resp_handler); + sub3.on('data', resp_handler); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); diff --git a/node/node_modules/nanomsg/test/test.js b/node/node_modules/nanomsg/test/test.js new file mode 100644 index 0000000..418f0d0 --- /dev/null +++ b/node/node_modules/nanomsg/test/test.js @@ -0,0 +1,14 @@ +// http://tim.dysinger.net/posts/2013-09-16-getting-started-with-nanomsg.html + +var nano = require('../'); +var test = require('tape'); + +test('bindings should exist', function (t) { + t.plan(2); + + t.equal(typeof nano._bindings.AF_SP, 'number', 'AF_SP is a number') + t.equal(typeof nano._bindings.NN_PAIR, 'number', 'NN_PAIR is a number'); +}); + + + diff --git a/node/node_modules/nanomsg/test/transform.js b/node/node_modules/nanomsg/test/transform.js new file mode 100644 index 0000000..01fdbb4 --- /dev/null +++ b/node/node_modules/nanomsg/test/transform.js @@ -0,0 +1,40 @@ +// Use Socket::transform and Socket::restore for message passing. +// http://tim.dysinger.net/posts/2013-09-16-getting-started-with-nanomsg.html + +var nano = require('../'); +var test = require('tape'); + +nano.Socket.prototype.transform = function (buf) { + if (!Buffer.isBuffer(buf)) buf = new Buffer(buf); + return Buffer.concat([new Buffer([0x00]), buf]); +} + +nano.Socket.prototype.restore = function (buf) { + return Buffer.concat([new Buffer([0xFF]), buf]); +} + +test('inproc socket pub sub', function (t) { + t.plan(3); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var addr = 'inproc://pubsub'; + var msg = 'hello world'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + t.equal(buf.slice(2).toString(), msg); + t.equal(buf[0], 0xFF); + t.equal(buf[1], 0x00); + + pub.close(); + sub.close(); + }); + + setTimeout(function () { + pub.send(msg); + }, 100); +}); diff --git a/node/node_modules/nanomsg/test/ws.js b/node/node_modules/nanomsg/test/ws.js new file mode 100644 index 0000000..cc54f13 --- /dev/null +++ b/node/node_modules/nanomsg/test/ws.js @@ -0,0 +1,214 @@ +// This test suite is a duplicate of inproc.js, but using the ws transport. + +var nano = require('../'); +var test = require('tape'); + +test('ws socket pub sub', function (t) { + t.plan(1); + + var pub = nano.socket('pub'); + var sub = nano.socket('sub'); + + var addr = 'ws://127.0.0.1:6004'; + var msg = 'hello world'; + + pub.bind(addr); + sub.connect(addr); + + sub.on('data', function (buf) { + t.equal(buf.toString(), msg); + + pub.close(); + sub.close(); + }); + + setTimeout(function () { + pub.send(msg); + }, 300); +}); + +test('ws socket pairs', function (t) { + t.plan(1); + + var s1 = nano.socket('pair'); + var s2 = nano.socket('pair'); + + var addr = 'ws://127.0.0.1:6005'; + var msg = 'hello world'; + + s1.bind(addr); + s2.connect(addr); + + s1.on('data', function (buf) { + t.equal(buf.toString(), msg); + + s1.close(); + s2.close(); + }); + + setTimeout(function () { + s2.send(msg); + }, 300); +}); + +test('ws socket req rep', function (t) { + t.plan(2); + + var req = nano.socket('req'); + var rep = nano.socket('rep'); + + var addr = 'ws://127.0.0.1:6006'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + rep.bind(addr); + req.connect(addr); + + rep.on('data', function (buf) { + t.equal(buf.toString(), msg1, 'request received'); + rep.send(msg2); + }); + + req.on('data', function (buf) { + t.equal(buf.toString(), msg2, 'reply received'); + + req.close(); + rep.close(); + }); + + setTimeout(function () { + req.send(msg1); + }, 300); +}); + +test('ws socket survey', function (t) { + t.plan(3); + + var sur = nano.socket('surveyor'); + var rep1 = nano.socket('respondent'); + var rep2 = nano.socket('respondent'); + var rep3 = nano.socket('respondent'); + + var addr = 'ws://127.0.0.1:6007'; + var msg1 = 'knock knock'; + var msg2 = "who's there?"; + + sur.bind(addr); + rep1.connect(addr); + rep2.connect(addr); + rep3.connect(addr); + + function answer (buf) { + this.send(msg2); + } + rep1.on('data', answer); + rep2.on('data', answer); + rep3.on('data', answer); + + var count = 0; + sur.on('data', function (buf) { + t.ok(buf.toString() == msg2, buf.toString() + ' == ' + msg2); + + if (++count == 3) { + sur.close(); + rep1.close(); + rep2.close(); + rep3.close(); + } + }); + + setTimeout(function () { + sur.send(msg1); + }, 300); +}); + +test('ws socket bus', function (t) { + // http://250bpm.com/blog:17 + + // Number of buses to create. + var count = 3; + var total = count * (count-1), current = 0; + t.plan(count); + + // Create buses. + var buses = {}; + for (var i = 0; i < count; i++) { + (function (i) { + var bus = nano.socket('bus'); + var addr = 'ws://127.0.0.1:' + (6008 + i); + bus.bind(addr); + bus.connect(addr); + buses[addr] = bus; + + // Add a "response count" for each bus. + // We want this to equal the number of other buses. + bus.responseCount = 0; + + // Tally messages from other buses. + bus.on('data', function (msg) { + //console.error('#', 'received data from', msg.toString(), 'on', addr) + this.responseCount++; + current++; + + if (this.responseCount == count - 1) { + // All set! bus received all messages. + t.ok(true, 'all messages received on ' + addr); + } + + if (current == total) { + // close all buses. + Object.keys(buses).forEach(function (addr) { + buses[addr].close(); + }) + } + }); + })(i); + } + + // Send messages on every bus. + setTimeout(function () { + Object.keys(buses).forEach(function (addr) { + //console.error('#', 'writing on', addr, addr); + buses[addr].send(addr); + }); + }, 1500); +}); + +test('ws multiple socket pub sub', function (t) { + t.plan(3); + + var pub = nano.socket('pub'); + var sub1 = nano.socket('sub'); + var sub2 = nano.socket('sub'); + var sub3 = nano.socket('sub'); + + var addr = 'ws://127.0.0.1:6011'; + var msg = 'hello world'; + + pub.bind(addr); + sub1.connect(addr); + sub2.connect(addr); + sub3.connect(addr); + + var responses = 0; + + sub1.on('data', resp_handler); + sub2.on('data', resp_handler); + sub3.on('data', resp_handler); + + function resp_handler(buf) { + + if(++responses == 3) { + pub.close(); + sub1.close(); + sub2.close(); + sub3.close(); + } + + t.equal(buf.toString(), msg); + }; + + setTimeout(function () { + pub.send(msg); + }, 300); +}); diff --git a/node/node_modules/uuid/.eslintrc.json b/node/node_modules/uuid/.eslintrc.json new file mode 100644 index 0000000..638b0a5 --- /dev/null +++ b/node/node_modules/uuid/.eslintrc.json @@ -0,0 +1,46 @@ +{ + "root": true, + "env": { + "browser": true, + "commonjs": true, + "node": true, + "mocha": true + }, + "extends": ["eslint:recommended"], + "installedESLint": true, + "rules": { + "array-bracket-spacing": ["warn", "never"], + "arrow-body-style": ["warn", "as-needed"], + "arrow-parens": ["warn", "as-needed"], + "arrow-spacing": "warn", + "brace-style": "warn", + "camelcase": "warn", + "comma-spacing": ["warn", {"after": true}], + "dot-notation": "warn", + "indent": ["warn", 2, { + "SwitchCase": 1, + "FunctionDeclaration": {"parameters": 1}, + "MemberExpression": 1, + "CallExpression": {"arguments": 1} + }], + "key-spacing": ["warn", {"beforeColon": false, "afterColon": true, "mode": "minimum"}], + "keyword-spacing": "warn", + "no-console": "off", + "no-empty": "off", + "no-multi-spaces": "warn", + "no-redeclare": "off", + "no-restricted-globals": ["warn", "Promise"], + "no-trailing-spaces": "warn", + "no-undef": "error", + "no-unused-vars": ["warn", {"args": "none"}], + "padded-blocks": ["warn", "never"], + "object-curly-spacing": ["warn", "never"], + "quotes": ["warn", "single"], + "react/prop-types": "off", + "react/jsx-no-bind": "off", + "semi": ["warn", "always"], + "space-before-blocks": ["warn", "always"], + "space-before-function-paren": ["warn", "never"], + "space-in-parens": ["warn", "never"] + } +} diff --git a/node/node_modules/uuid/AUTHORS b/node/node_modules/uuid/AUTHORS new file mode 100644 index 0000000..5a10523 --- /dev/null +++ b/node/node_modules/uuid/AUTHORS @@ -0,0 +1,5 @@ +Robert Kieffer +Christoph Tavan +AJ ONeal +Vincent Voyer +Roman Shtylman diff --git a/node/node_modules/uuid/HISTORY.md b/node/node_modules/uuid/HISTORY.md new file mode 100644 index 0000000..c6050ec --- /dev/null +++ b/node/node_modules/uuid/HISTORY.md @@ -0,0 +1,28 @@ +# 3.0.1 (2016-11-28) + + * split uuid versions into separate files + +# 3.0.0 (2016-11-17) + + * remove .parse and .unparse + +# 2.0.0 + + * Removed uuid.BufferClass + +# 1.4.0 + + * Improved module context detection + * Removed public RNG functions + +# 1.3.2 + + * Improve tests and handling of v1() options (Issue #24) + * Expose RNG option to allow for perf testing with different generators + +# 1.3.0 + + * Support for version 1 ids, thanks to [@ctavan](https://github.com/ctavan)! + * Support for node.js crypto API + * De-emphasizing performance in favor of a) cryptographic quality PRNGs where available and b) more manageable code + diff --git a/node/node_modules/uuid/LICENSE.md b/node/node_modules/uuid/LICENSE.md new file mode 100644 index 0000000..8c84e39 --- /dev/null +++ b/node/node_modules/uuid/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2010-2016 Robert Kieffer and other contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node/node_modules/uuid/README.md b/node/node_modules/uuid/README.md new file mode 100644 index 0000000..5adaa8f --- /dev/null +++ b/node/node_modules/uuid/README.md @@ -0,0 +1,227 @@ +# uuid [![Build Status](https://secure.travis-ci.org/kelektiv/node-uuid.svg?branch=master)](http://travis-ci.org/kelektiv/node-uuid) # + +Simple, fast generation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDS. + +Features: + +* Support for version 1, 4 and 5 UUIDs +* Cross-platform +* Uses cryptographically-strong random number APIs (when available) +* Zero-dependency, small footprint (... but not [this small](https://gist.github.com/982883)) + +## Quickstart - CommonJS (Recommended) + +```shell +npm install uuid +``` + +Then generate your uuid version of choice ... + +Version 1 (timestamp): + +```javascript +const uuidv1 = require('uuid/v1'); +uuidv1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' +``` + +Version 4 (random): + +```javascript +const uuidv4 = require('uuid/v4'); +uuidv4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' +``` + +Version 5 (namespace): + +```javascript +const uuidv5 = require('uuid/v5'); + +// ... using predefined DNS namespace (for domain names) +uuidv5('hello.example.com', uuidv5.DNS)); // -> 'fdda765f-fc57-5604-a269-52a7df8164ec' + +// ... using predefined URL namespace (for, well, URLs) +uuidv5('http://example.com/hello', uuidv5.URL); // -> '3bbcee75-cecc-5b56-8031-b6641c1ed1f1' + +// ... using a custom namespace +const MY_NAMESPACE = ''; +uuidv5('Hello, World!', MY_NAMESPACE); // -> '90123e1c-7512-523e-bb28-76fab9f2f73d' +``` + +## Quickstart - Browser-ready Versions + +Browser-ready versions of this module are available via [wzrd.in](https://github.com/jfhbrook/wzrd.in). + +For version 1 uuids: + +```html + + +``` + +For version 4 uuids: + +```html + + +``` + +For version 5 uuids: + +```html + + +``` + +## API + +### Version 1 + +```javascript +const uuidv1 = require('uuid/v1'); + +// Allowed arguments +uuidv1(); +uuidv1(options); +uuidv1(options, buffer, offset); +``` + +Generate and return a RFC4122 v1 (timestamp-based) UUID. + +* `options` - (Object) Optional uuid state to apply. Properties may include: + + * `node` - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1. + * `clockseq` - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used. + * `msecs` - (Number | Date) Time in milliseconds since unix Epoch. Default: The current time is used. + * `nsecs` - (Number between 0-9999) additional time, in 100-nanosecond units. Ignored if `msecs` is unspecified. Default: internal uuid counter is used, as per 4.2.1.2. + +* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written. +* `offset` - (Number) Starting index in `buffer` at which to begin writing. + +Returns `buffer`, if specified, otherwise the string form of the UUID + +Note: The id is generated guaranteed to stay constant for the lifetime of the current JS runtime. (Future versions of this module may use persistent storage mechanisms to extend this guarantee.) + +Example: Generate string UUID with fully-specified options + +```javascript +uuidv1({ + node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], + clockseq: 0x1234, + msecs: new Date('2011-11-01').getTime(), + nsecs: 5678 +}); // -> "710b962e-041c-11e1-9234-0123456789ab" +``` + +Example: In-place generation of two binary IDs + +```javascript +// Generate two ids in an array +const arr = new Array(32); // -> [] +uuidv1(null, arr, 0); // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15] +uuidv1(null, arr, 16); // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15 02 a3 1c b0 14 32 11 e1 85 58 0b 48 8e 4f c1 15] +``` + +### Version 4 + +```javascript +const uuidv4 = require('uuid/v4') + +// Allowed arguments +uuidv4(); +uuidv4(options); +uuidv4(options, buffer, offset); +``` + +Generate and return a RFC4122 v4 UUID. + +* `options` - (Object) Optional uuid state to apply. Properties may include: + * `random` - (Number[16]) Array of 16 numbers (0-255) to use in place of randomly generated values + * `rng` - (Function) Random # generator function that returns an Array[16] of byte values (0-255) +* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written. +* `offset` - (Number) Starting index in `buffer` at which to begin writing. + +Returns `buffer`, if specified, otherwise the string form of the UUID + +Example: Generate string UUID with fully-specified options + +```javascript +uuid.v4({ + random: [ + 0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea, + 0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36 + ] +}); +// -> "109156be-c4fb-41ea-b1b4-efe1671c5836" +``` + +Example: Generate two IDs in a single buffer + +```javascript +const buffer = new Array(32); // (or 'new Buffer' in node.js) +uuid.v4(null, buffer, 0); +uuid.v4(null, buffer, 16); +``` + +### Version 5 + +```javascript +const uuidv5 = require('uuid/v4'); + +// Allowed arguments +uuidv5(name, namespace); +uuidv5(name, namespace, buffer); +uuidv5(name, namespace, buffer, offset); +``` + +Generate and return a RFC4122 v4 UUID. + +* `name` - (String | Array[]) "name" to create UUID with +* `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values +* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written. +* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0 + +Returns `buffer`, if specified, otherwise the string form of the UUID + +Example: + +```javascript +// Generate a unique namespace (typically you would do this once, outside of +// your project, then bake this value into your code) +const uuidv4 = require('uuid/v4'); +const MY_NAMESPACE = uuidv4(); // + +// Generate a couple namespace uuids +const uuidv5 = require('uuid/v5'); +uuidv5('hello', MY_NAMESPACE); +uuidv5('world', MY_NAMESPACE); +``` + +## Testing + +```shell +npm test +``` + +## Deprecated / Browser-ready API + +The API below is available for legacy purposes and is not expected to be available post-3.X + +```javascript +const uuid = require('uuid'); + +uuid.v1(...); // alias of uuid/v1 +uuid.v4(...); // alias of uuid/v4 +uuid(...); // alias of uuid/v4 + +// uuid.v5() is not supported in this API +``` + +## Legacy node-uuid package + +The code for the legacy node-uuid package is available in the `node-uuid` branch. diff --git a/node/node_modules/uuid/bin/uuid b/node/node_modules/uuid/bin/uuid new file mode 100755 index 0000000..2fd26d7 --- /dev/null +++ b/node/node_modules/uuid/bin/uuid @@ -0,0 +1,50 @@ +#!/usr/bin/env node +var assert = require('assert'); + +function usage() { + console.log('Usage:'); + console.log(' uuid'); + console.log(' uuid v1'); + console.log(' uuid v4'); + console.log(' uuid v5 '); + console.log(' uuid --help'); + console.log('\nNote: may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC4122'); +} + +var args = process.argv.slice(2); + +if (args.indexOf('--help') >= 0) { + usage(); + process.exit(0); +} +var version = args.shift() || 'v4'; + +switch (version) { + case 'v1': + var uuidV1 = require('../v1'); + console.log(uuidV1()); + break; + + case 'v4': + var uuidV4 = require('../v4'); + console.log(uuidV4()); + break; + + case 'v5': + var uuidV5 = require('../v5'); + + var name = args.shift(); + var namespace = args.shift(); + assert(name != null, 'v5 name not specified'); + assert(namespace != null, 'v5 namespace not specified'); + + if (namespace == 'URL') namespace = uuidV5.URL; + if (namespace == 'DNS') namespace = uuidV5.DNS; + + console.log(uuidV5(name, namespace)); + break; + + default: + usage(); + process.exit(1); +} diff --git a/node/node_modules/uuid/index.js b/node/node_modules/uuid/index.js new file mode 100644 index 0000000..e96791a --- /dev/null +++ b/node/node_modules/uuid/index.js @@ -0,0 +1,8 @@ +var v1 = require('./v1'); +var v4 = require('./v4'); + +var uuid = v4; +uuid.v1 = v1; +uuid.v4 = v4; + +module.exports = uuid; diff --git a/node/node_modules/uuid/lib/bytesToUuid.js b/node/node_modules/uuid/lib/bytesToUuid.js new file mode 100644 index 0000000..2c9a223 --- /dev/null +++ b/node/node_modules/uuid/lib/bytesToUuid.js @@ -0,0 +1,23 @@ +/** + * Convert array of 16 byte values to UUID string format of the form: + * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX + */ +var byteToHex = []; +for (var i = 0; i < 256; ++i) { + byteToHex[i] = (i + 0x100).toString(16).substr(1); +} + +function bytesToUuid(buf, offset) { + var i = offset || 0; + var bth = byteToHex; + return bth[buf[i++]] + bth[buf[i++]] + + bth[buf[i++]] + bth[buf[i++]] + '-' + + bth[buf[i++]] + bth[buf[i++]] + '-' + + bth[buf[i++]] + bth[buf[i++]] + '-' + + bth[buf[i++]] + bth[buf[i++]] + '-' + + bth[buf[i++]] + bth[buf[i++]] + + bth[buf[i++]] + bth[buf[i++]] + + bth[buf[i++]] + bth[buf[i++]]; +} + +module.exports = bytesToUuid; diff --git a/node/node_modules/uuid/lib/rng-browser.js b/node/node_modules/uuid/lib/rng-browser.js new file mode 100644 index 0000000..ac39b12 --- /dev/null +++ b/node/node_modules/uuid/lib/rng-browser.js @@ -0,0 +1,33 @@ +// Unique ID creation requires a high quality random # generator. In the +// browser this is a little complicated due to unknown quality of Math.random() +// and inconsistent support for the `crypto` API. We do the best we can via +// feature-detection +var rng; + +var crypto = global.crypto || global.msCrypto; // for IE 11 +if (crypto && crypto.getRandomValues) { + // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto + var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef + rng = function whatwgRNG() { + crypto.getRandomValues(rnds8); + return rnds8; + }; +} + +if (!rng) { + // Math.random()-based (RNG) + // + // If all else fails, use Math.random(). It's fast, but is of unspecified + // quality. + var rnds = new Array(16); + rng = function() { + for (var i = 0, r; i < 16; i++) { + if ((i & 0x03) === 0) r = Math.random() * 0x100000000; + rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; + } + + return rnds; + }; +} + +module.exports = rng; diff --git a/node/node_modules/uuid/lib/rng.js b/node/node_modules/uuid/lib/rng.js new file mode 100644 index 0000000..4a0182f --- /dev/null +++ b/node/node_modules/uuid/lib/rng.js @@ -0,0 +1,10 @@ +// Unique ID creation requires a high quality random # generator. In node.js +// this is pretty straight-forward - we use the crypto API. + +var rb = require('crypto').randomBytes; + +function rng() { + return rb(16); +} + +module.exports = rng; diff --git a/node/node_modules/uuid/lib/sha1-browser.js b/node/node_modules/uuid/lib/sha1-browser.js new file mode 100644 index 0000000..dbc3184 --- /dev/null +++ b/node/node_modules/uuid/lib/sha1-browser.js @@ -0,0 +1,85 @@ +// Adapted from Chris Veness' SHA1 code at +// http://www.movable-type.co.uk/scripts/sha1.html +'use strict'; + +function f(s, x, y, z) { + switch (s) { + case 0: return (x & y) ^ (~x & z); + case 1: return x ^ y ^ z; + case 2: return (x & y) ^ (x & z) ^ (y & z); + case 3: return x ^ y ^ z; + } +} + +function ROTL(x, n) { + return (x << n) | (x>>> (32 - n)); +} + +function sha1(bytes) { + var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]; + var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]; + + if (typeof(bytes) == 'string') { + var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape + bytes = new Array(msg.length); + for (var i = 0; i < msg.length; i++) bytes[i] = msg.charCodeAt(i); + } + + bytes.push(0x80); + + var l = bytes.length/4 + 2; + var N = Math.ceil(l/16); + var M = new Array(N); + + for (var i=0; i>> 0; + e = d; + d = c; + c = ROTL(b, 30) >>> 0; + b = a; + a = T; + } + + H[0] = (H[0] + a) >>> 0; + H[1] = (H[1] + b) >>> 0; + H[2] = (H[2] + c) >>> 0; + H[3] = (H[3] + d) >>> 0; + H[4] = (H[4] + e) >>> 0; + } + + return [ + H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, + H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, + H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, + H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, + H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff + ]; +} + +module.exports = sha1; diff --git a/node/node_modules/uuid/lib/sha1.js b/node/node_modules/uuid/lib/sha1.js new file mode 100644 index 0000000..e8771ce --- /dev/null +++ b/node/node_modules/uuid/lib/sha1.js @@ -0,0 +1,21 @@ +'use strict'; + +var crypto = require('crypto'); + +function sha1(bytes) { + // support modern Buffer API + if (typeof Buffer.from === 'function') { + if (Array.isArray(bytes)) bytes = Buffer.from(bytes); + else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8'); + } + + // support pre-v4 Buffer API + else { + if (Array.isArray(bytes)) bytes = new Buffer(bytes); + else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8'); + } + + return crypto.createHash('sha1').update(bytes).digest(); +} + +module.exports = sha1; diff --git a/node/node_modules/uuid/package.json b/node/node_modules/uuid/package.json new file mode 100644 index 0000000..4c9b790 --- /dev/null +++ b/node/node_modules/uuid/package.json @@ -0,0 +1,80 @@ +{ + "_from": "uuid", + "_id": "uuid@3.1.0", + "_inBundle": false, + "_integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==", + "_location": "/uuid", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "uuid", + "name": "uuid", + "escapedName": "uuid", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "_shasum": "3dd3d3e790abc24d7b0d3a034ffababe28ebbc04", + "_spec": "uuid", + "_where": "/Users/hwwu/Git/ats-sessions/node", + "bin": { + "uuid": "./bin/uuid" + }, + "browser": { + "./lib/rng.js": "./lib/rng-browser.js", + "./lib/sha1.js": "./lib/sha1-browser.js" + }, + "bugs": { + "url": "https://github.com/kelektiv/node-uuid/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Robert Kieffer", + "email": "robert@broofa.com" + }, + { + "name": "Christoph Tavan", + "email": "dev@tavan.de" + }, + { + "name": "AJ ONeal", + "email": "coolaj86@gmail.com" + }, + { + "name": "Vincent Voyer", + "email": "vincent@zeroload.net" + }, + { + "name": "Roman Shtylman", + "email": "shtylman@gmail.com" + } + ], + "deprecated": false, + "description": "RFC4122 (v1, v4, and v5) UUIDs", + "devDependencies": { + "mocha": "3.1.2" + }, + "homepage": "https://github.com/kelektiv/node-uuid#readme", + "keywords": [ + "uuid", + "guid", + "rfc4122" + ], + "license": "MIT", + "name": "uuid", + "repository": { + "type": "git", + "url": "git+https://github.com/kelektiv/node-uuid.git" + }, + "scripts": { + "test": "mocha test/test.js" + }, + "version": "3.1.0" +} diff --git a/node/node_modules/uuid/v1.js b/node/node_modules/uuid/v1.js new file mode 100644 index 0000000..613f67e --- /dev/null +++ b/node/node_modules/uuid/v1.js @@ -0,0 +1,100 @@ +var rng = require('./lib/rng'); +var bytesToUuid = require('./lib/bytesToUuid'); + +// **`v1()` - Generate time-based UUID** +// +// Inspired by https://github.com/LiosK/UUID.js +// and http://docs.python.org/library/uuid.html + +// random #'s we need to init node and clockseq +var _seedBytes = rng(); + +// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1) +var _nodeId = [ + _seedBytes[0] | 0x01, + _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5] +]; + +// Per 4.2.2, randomize (14 bit) clockseq +var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff; + +// Previous uuid creation time +var _lastMSecs = 0, _lastNSecs = 0; + +// See https://github.com/broofa/node-uuid for API details +function v1(options, buf, offset) { + var i = buf && offset || 0; + var b = buf || []; + + options = options || {}; + + var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; + + // UUID timestamps are 100 nano-second units since the Gregorian epoch, + // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so + // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs' + // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00. + var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime(); + + // Per 4.2.1.2, use count of uuid's generated during the current clock + // cycle to simulate higher resolution clock + var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; + + // Time since last uuid creation (in msecs) + var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000; + + // Per 4.2.1.2, Bump clockseq on clock regression + if (dt < 0 && options.clockseq === undefined) { + clockseq = clockseq + 1 & 0x3fff; + } + + // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new + // time interval + if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) { + nsecs = 0; + } + + // Per 4.2.1.2 Throw error if too many uuids are requested + if (nsecs >= 10000) { + throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec'); + } + + _lastMSecs = msecs; + _lastNSecs = nsecs; + _clockseq = clockseq; + + // Per 4.1.4 - Convert from unix epoch to Gregorian epoch + msecs += 12219292800000; + + // `time_low` + var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; + b[i++] = tl >>> 24 & 0xff; + b[i++] = tl >>> 16 & 0xff; + b[i++] = tl >>> 8 & 0xff; + b[i++] = tl & 0xff; + + // `time_mid` + var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff; + b[i++] = tmh >>> 8 & 0xff; + b[i++] = tmh & 0xff; + + // `time_high_and_version` + b[i++] = tmh >>> 24 & 0xf | 0x10; // include version + b[i++] = tmh >>> 16 & 0xff; + + // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant) + b[i++] = clockseq >>> 8 | 0x80; + + // `clock_seq_low` + b[i++] = clockseq & 0xff; + + // `node` + var node = options.node || _nodeId; + for (var n = 0; n < 6; ++n) { + b[i + n] = node[n]; + } + + return buf ? buf : bytesToUuid(b); +} + +module.exports = v1; diff --git a/node/node_modules/uuid/v4.js b/node/node_modules/uuid/v4.js new file mode 100644 index 0000000..38b6f76 --- /dev/null +++ b/node/node_modules/uuid/v4.js @@ -0,0 +1,29 @@ +var rng = require('./lib/rng'); +var bytesToUuid = require('./lib/bytesToUuid'); + +function v4(options, buf, offset) { + var i = buf && offset || 0; + + if (typeof(options) == 'string') { + buf = options == 'binary' ? new Array(16) : null; + options = null; + } + options = options || {}; + + var rnds = options.random || (options.rng || rng)(); + + // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` + rnds[6] = (rnds[6] & 0x0f) | 0x40; + rnds[8] = (rnds[8] & 0x3f) | 0x80; + + // Copy bytes to buffer, if provided + if (buf) { + for (var ii = 0; ii < 16; ++ii) { + buf[i + ii] = rnds[ii]; + } + } + + return buf || bytesToUuid(rnds); +} + +module.exports = v4; diff --git a/node/node_modules/uuid/v5.js b/node/node_modules/uuid/v5.js new file mode 100644 index 0000000..39cc35e --- /dev/null +++ b/node/node_modules/uuid/v5.js @@ -0,0 +1,42 @@ +var sha1 = require('./lib/sha1-browser'); +var bytesToUuid = require('./lib/bytesToUuid'); + +function uuidToBytes(uuid) { + // Note: We assume we're being passed a valid uuid string + var bytes = []; + uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) { + bytes.push(parseInt(hex, 16)); + }); + + return bytes; +} + +function stringToBytes(str) { + str = unescape(encodeURIComponent(str)); // UTF8 escape + var bytes = new Array(str.length); + for (var i = 0; i < str.length; i++) { + bytes[i] = str.charCodeAt(i); + } + return bytes; +} + +function v5(name, namespace, buf, offset) { + if (typeof(name) == 'string') name = stringToBytes(name); + if (typeof(namespace) == 'string') namespace = uuidToBytes(namespace); + + if (!Array.isArray(name)) throw TypeError('name must be an array of bytes'); + if (!Array.isArray(namespace) || namespace.length != 16) throw TypeError('namespace must be uuid string or an Array of 16 byte values'); + + // Per 4.3 + var bytes = sha1(namespace.concat(name)); + bytes[6] = (bytes[6] & 0x0f) | 0x50; + bytes[8] = (bytes[8] & 0x3f) | 0x80; + + return buf || bytesToUuid(bytes); +} + +// Pre-defined namespaces, per Appendix C +v5.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; +v5.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'; + +module.exports = v5; diff --git a/node/package-lock.json b/node/package-lock.json new file mode 100644 index 0000000..4f22873 --- /dev/null +++ b/node/package-lock.json @@ -0,0 +1,30 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "bindings": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", + "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=" + }, + "nan": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.4.0.tgz", + "integrity": "sha1-+zxZ1F/k7/4hXwuJD4rfbrMtIjI=" + }, + "nanomsg": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/nanomsg/-/nanomsg-3.3.0.tgz", + "integrity": "sha1-ktlgsuWDQl3srIHovbjrnBTMIfY=", + "requires": { + "bindings": "1.2.1", + "nan": "2.4.0" + } + }, + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" + } + } +} diff --git a/node/socket.js b/node/socket.js new file mode 100644 index 0000000..9575d18 --- /dev/null +++ b/node/socket.js @@ -0,0 +1,51 @@ +"use strict" + +let nanomsg = require("nanomsg") + +class Socket { + constructor(proto) { + this.sock = nanomsg.socket(proto) + this.sock.setEncoding("utf8") + this.handler = null + } + + bind(addr) { + try { + this.sock.bind(addr) + } catch(e) { + console.log(e) + } + } + + connect(addr) { + try { + this.sock.connect(addr) + } catch(e) { + console.log(e) + } + } + + close() { + this.sock.close() + } + + set onmessage(handler) { + this.sock.removeAllListeners("data") + this.handler = handler + this.sock.on("data", msg => { + console.log(`recv: ${msg}`) + this.handler(JSON.parse(msg)) + }) + } + + get onmessage() { + return this.handler + } + + send(payload) { + console.log(`send: ${JSON.stringify(payload)}`) + this.sock.send(JSON.stringify(payload)) + } +} + +module.exports = Socket \ No newline at end of file