Comparing version 9.0.1 to 9.1.0
@@ -61,6 +61,10 @@ 'use strict'; | ||
fs.unlink( | ||
this.path, | ||
startServer.bind(this) | ||
); | ||
if(this.config.unlink){ | ||
fs.unlink( | ||
this.path, | ||
startServer.bind(this) | ||
); | ||
}else{ | ||
startServer.bind(this)(); | ||
} | ||
} | ||
@@ -299,3 +303,3 @@ } | ||
); | ||
} | ||
}.bind(this) | ||
); | ||
@@ -302,0 +306,0 @@ |
@@ -31,2 +31,3 @@ 'use strict'; | ||
this.sync=false; | ||
this.unlink=true; | ||
@@ -38,2 +39,3 @@ this.delimiter='\f'; | ||
this.logInColor=true; | ||
this.logger=console.log.bind(console); | ||
@@ -40,0 +42,0 @@ this.maxConnections=100; |
{ | ||
"name": "node-ipc", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.", | ||
@@ -18,6 +18,5 @@ "main": "node-ipc.js", | ||
"devDependencies": { | ||
"codacy-coverage": "1.1.3", | ||
"codacy-coverage": "2.0.0", | ||
"jasmine": "2.4.1", | ||
"istanbul": "0.4.1", | ||
"codacy-coverage": "2.0.0", | ||
"node-cmd": "2.0.0" | ||
@@ -32,3 +31,3 @@ }, | ||
"pre-commit": [ | ||
"cover" | ||
"cover" | ||
], | ||
@@ -35,0 +34,0 @@ "keywords": [ |
@@ -105,2 +105,3 @@ node-ipc | ||
logDepth : 5, | ||
logger : console.log, | ||
maxConnections : 100, | ||
@@ -110,2 +111,3 @@ retry : 500, | ||
stopRetrying : false, | ||
unlink : true, | ||
interfaces : { | ||
@@ -135,2 +137,3 @@ localAddress: false, | ||
| logDepth | set the depth for util.inspect during ipc.log | | ||
| logger | the function which receives the output from ipc.log; should take a single string argument | | ||
| maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. | | ||
@@ -140,2 +143,3 @@ | retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. | | ||
| stopRetrying| Defaults to false meaning clients will continue to retry to connect to servers indefinitely at the retry interval. If set to any number the client will stop retrying when that number is exceeded after each disconnect. If set to true in real time it will immediately stop trying to connect regardless of maxRetries. If set to 0, the client will ***NOT*** try to reconnect. | | ||
| unlink| Defaults to true meaning that the module will take care of deleting the IPC socket prior to startup. If you use `node-ipc` in a clustered environment where there will be multiple listeners on the same socket, you must set this to `false` and then take care of deleting the socket in your own code. | | ||
| interfaces| primarily used when specifying which interface a client should connect through. see the [socket.connect documentation in the node.js api](https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener) | | ||
@@ -155,3 +159,3 @@ | ||
The log also uses util.inspect You can control if it should log in color as well as the log depth via ` ipc.config ` | ||
The log also uses util.inspect You can control if it should log in color, the log depth, and the destination via ` ipc.config ` | ||
@@ -162,2 +166,3 @@ ```javascript | ||
ipc.config.logDepth=5; //default | ||
ipc.config.logger=console.log.bind(console); // default | ||
@@ -796,3 +801,83 @@ ``` | ||
#### Server with the `cluster` Module | ||
`node-ipc` can be used with Node.js' [cluster module](https://nodejs.org/api/cluster.html) to provide the ability to have multiple readers for a single socket. Doing so simply requires you to set the `unlink` property in the config to `false` and take care of unlinking the socket path in the master process: | ||
##### Server | ||
```javascript | ||
const fs = require('fs'); | ||
const ipc=require('../../../node-ipc'); | ||
const cpuCount = require('os').cpus().length; | ||
const cluster = require('cluster'); | ||
const socketPath = '/tmp/ipc.sock'; | ||
ipc.config.unlink = false; | ||
if (cluster.isMaster) { | ||
if (fs.existsSync(socketPath)) { | ||
fs.unlinkSync(socketPath); | ||
} | ||
for (let i = 0; i < cpuCount; i++) { | ||
cluster.fork(); | ||
} | ||
}else{ | ||
ipc.serve( | ||
socketPath, | ||
function() { | ||
ipc.server.on( | ||
'currentDate', | ||
function(data,socket) { | ||
console.log(`pid ${process.pid} got: `, data); | ||
} | ||
); | ||
} | ||
); | ||
ipc.server.start(); | ||
console.log(`pid ${process.pid} listening on ${socketPath}`); | ||
} | ||
``` | ||
##### Client | ||
```javascript | ||
const fs = require('fs'); | ||
const ipc = require('../../node-ipc'); | ||
const socketPath = '/tmp/ipc.sock'; | ||
//loop forever so you can see the pid of the cluster sever change in the logs | ||
setInterval( | ||
function() { | ||
ipc.connectTo( | ||
'world', | ||
socketPath, | ||
connecting | ||
); | ||
}, | ||
2000 | ||
); | ||
function connecting(socket) { | ||
ipc.of.world.on( | ||
'connect', | ||
function() { | ||
ipc.of.world.emit( | ||
'currentDate', | ||
{ | ||
message: new Date().toISOString() | ||
} | ||
); | ||
ipc.disconnect('world'); | ||
} | ||
); | ||
} | ||
``` | ||
#### Licensed under DBAD license | ||
See the [DBAD license](https://github.com/philsturgeon/dbad) in your language or our [licence.md](https://github.com/RIAEvangelist/node-phidget-API/blob/master/license.md) file. |
@@ -64,3 +64,3 @@ 'use strict'; | ||
function log(){ | ||
function log(...args){ | ||
if(this.config.silent){ | ||
@@ -70,4 +70,2 @@ return; | ||
const args=Array.prototype.slice.call(arguments); | ||
for(let i=0, count=args.length; i<count; i++){ | ||
@@ -87,3 +85,3 @@ if(typeof args[i] != 'object'){ | ||
console.log( | ||
this.config.logger( | ||
args.join(' ') | ||
@@ -117,5 +115,5 @@ ); | ||
this.log( | ||
'Server path not specified, so defaulting to'.notice, | ||
'ipc.config.socketRoot + ipc.config.appspace + ipc.config.id'.variable, | ||
(this.config.socketRoot+this.config.appspace+this.config.id).data | ||
'Server path not specified, so defaulting to', | ||
'ipc.config.socketRoot + ipc.config.appspace + ipc.config.id', | ||
this.config.socketRoot+this.config.appspace+this.config.id | ||
); | ||
@@ -160,5 +158,5 @@ path=this.config.socketRoot+this.config.appspace+this.config.id; | ||
this.log( | ||
'Server host not specified, so defaulting to'.notice, | ||
'ipc.config.networkHost'.variable, | ||
this.config.networkHost.data | ||
'Server host not specified, so defaulting to', | ||
'ipc.config.networkHost', | ||
this.config.networkHost | ||
); | ||
@@ -186,4 +184,4 @@ host=this.config.networkHost; | ||
this.log( | ||
'Server port not specified, so defaulting to'.notice, | ||
'ipc.config.networkPort'.variable, | ||
'Server port not specified, so defaulting to', | ||
'ipc.config.networkPort', | ||
this.config.networkPort | ||
@@ -236,4 +234,4 @@ ); | ||
this.log( | ||
'Service id required'.warn, | ||
'Requested service connection without specifying service id. Aborting connection attempt'.notice | ||
'Service id required', | ||
'Requested service connection without specifying service id. Aborting connection attempt' | ||
); | ||
@@ -245,4 +243,4 @@ return; | ||
this.log( | ||
'Service path not specified, so defaulting to'.notice, | ||
'ipc.config.socketRoot + ipc.config.appspace + id'.variable, | ||
'Service path not specified, so defaulting to', | ||
'ipc.config.socketRoot + ipc.config.appspace + id', | ||
(this.config.socketRoot+this.config.appspace+id).data | ||
@@ -256,5 +254,5 @@ ); | ||
this.log( | ||
'Already Connected to'.notice, | ||
id.variable, | ||
'- So executing success without connection'.notice | ||
'Already Connected to', | ||
id, | ||
'- So executing success without connection' | ||
); | ||
@@ -279,4 +277,4 @@ callback(); | ||
this.log( | ||
'Service id required'.warn, | ||
'Requested service connection without specifying service id. Aborting connection attempt'.notice | ||
'Service id required', | ||
'Requested service connection without specifying service id. Aborting connection attempt' | ||
); | ||
@@ -297,5 +295,5 @@ return; | ||
this.log( | ||
'Server host not specified, so defaulting to'.notice, | ||
'ipc.config.networkHost'.variable, | ||
this.config.networkHost.data | ||
'Server host not specified, so defaulting to', | ||
'ipc.config.networkHost', | ||
this.config.networkHost | ||
); | ||
@@ -311,4 +309,4 @@ host=this.config.networkHost; | ||
this.log( | ||
'Server port not specified, so defaulting to'.notice, | ||
'ipc.config.networkPort'.variable, | ||
'Server port not specified, so defaulting to', | ||
'ipc.config.networkPort', | ||
this.config.networkPort | ||
@@ -329,6 +327,7 @@ ); | ||
if(!this.of[id].socket.destroyed){ | ||
this.log( | ||
'Already Connected to'.notice, | ||
id.variable, | ||
'- So executing success without connection'.notice | ||
'Already Connected to', | ||
id, | ||
'- So executing success without connection' | ||
); | ||
@@ -335,0 +334,0 @@ callback(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130165
65
2694
877
4