Permalink
Browse files

hz

  • Loading branch information...
1 parent 5da20ea commit ccdc6828936766dee0f26a4337eeb69a24100ef0 @dvv committed Mar 15, 2011
Showing with 26 additions and 25 deletions.
  1. +2 −2 Readme.md
  2. +10 −11 index.coffee
  3. +12 −10 index.js
  4. +2 −2 test.js
View
@@ -8,7 +8,7 @@
server.js:
- var server = require('stereo')({
+ var server = require('stereo')(null, {
port: 3000,
repl: true,
workers: 4
@@ -20,7 +20,7 @@ server.js:
process.on('message', function(message){...});
} else { // master process
// broadcast a message
- process.publish({sos: 'to all, all, all'});
+ setTimeout(function(){process.publish({sos: 'to all, all, all'});}, 2000);
}
## Authors
View
@@ -68,7 +68,7 @@ options.ssl.cert
options.ssl.caCerts
###
-module.exports = (options = {}) ->
+module.exports = (server, options = {}) ->
net = require 'net'
fs = require 'fs'
@@ -96,18 +96,17 @@ module.exports = (options = {}) ->
#
# setup HTTP(S) server
- #
- if options.ssl
- credentials =
- key: fs.readFileSync options.ssl.key, 'utf8'
- cert: fs.readFileSync options.ssl.cert, 'utf8'
- #ca: options.ssl.caCerts.map (fname) -> fs.readFileSync fname, 'utf8'
- server = require('https').createServer credentials
- else
- server = require('http').createServer()
- #
# N.B. request handler to be attached elsewhere
#
+ unless server
+ if options.ssl
+ credentials =
+ key: fs.readFileSync options.ssl.key, 'utf8'
+ cert: fs.readFileSync options.ssl.cert, 'utf8'
+ #ca: options.ssl.caCerts.map (fname) -> fs.readFileSync fname, 'utf8'
+ server = require('https').createServer credentials
+ else
+ server = require('http').createServer()
#
# setup signals
View
@@ -66,8 +66,8 @@ options.ssl.cert
options.ssl.caCerts
*/
-module.exports = function(options) {
- var REPL, args, cmd, comm, credentials, env, fs, ipc, k, net, netBinding, nworkers, server, socket, spawnWorker, v, watch, workers, _ref, _ref2, _ref3, _ref4, _ref5;
+module.exports = function(server, options) {
+ var REPL, args, cmd, comm, credentials, env, fs, ipc, k, net, netBinding, nworkers, socket, spawnWorker, v, watch, workers, _ref, _ref2, _ref3, _ref4, _ref5;
if (options == null) {
options = {};
}
@@ -84,14 +84,16 @@ module.exports = function(options) {
args[0] = ("" + (Date.now()) + " WORKER " + process.pid + ": ") + args[0];
return console.error.apply(console, args);
};
- if (options.ssl) {
- credentials = {
- key: fs.readFileSync(options.ssl.key, 'utf8'),
- cert: fs.readFileSync(options.ssl.cert, 'utf8')
- };
- server = require('https').createServer(credentials);
- } else {
- server = require('http').createServer();
+ if (!server) {
+ if (options.ssl) {
+ credentials = {
+ key: fs.readFileSync(options.ssl.key, 'utf8'),
+ cert: fs.readFileSync(options.ssl.cert, 'utf8')
+ };
+ server = require('https').createServer(credentials);
+ } else {
+ server = require('http').createServer();
+ }
}
if (options.workerShutdownTimeout) {
process.on('SIGQUIT', function() {
View
@@ -1,4 +1,4 @@
-var server = require('./')({
+var server = require('./')(null, {
port: 3000,
repl: true,
workers: 4
@@ -15,5 +15,5 @@ if (server) { // worker process
});
} else { // master process
// broadcast a message
- process.publish({sos: 'to all, all, all'});
+ setTimeout(function(){process.publish({sos: 'to all, all, all'});}, 2000);
}

0 comments on commit ccdc682

Please sign in to comment.