Permalink
Browse files

cathing up with origin

  • Loading branch information...
utvara committed Mar 15, 2012
2 parents 2d5b40c + b04e212 commit 1be129526cd089dfe0b8fa7ca023fc07555b59b1
View
@@ -6,3 +6,8 @@ build
binding.node
examples/stress-test-client
node_modules
+Makefile.gyp
+binding.Makefile
+binding.target.gyp.mk
+gyp-mac-tool
+out/
View
@@ -1,4 +1,9 @@
+2.0.3 / 2012-03-14
+==================
+
+ * Removed -Wall (libuv unused vars caused the build to fail...)
+
2.0.2 / 2012-02-16
==================
View
@@ -3,17 +3,14 @@ TESTS = $(wildcard test/test.*.js)
DOX = ./node_modules/.bin/dox
JADE = ./node_modules/.bin/jade
-binding.node: build binding.cc
- node-waf build
-
-build:
- node-waf configure
+build/Release/binding.node: binding.cc binding.gyp
+ npm install
test:
@node test/run $(TESTS)
clean:
- node-waf clean
+ rm -fr build
docs:
$(DOX) < lib/index.js > docs/index.json
View
@@ -0,0 +1,18 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'binding',
+ 'sources': [ 'binding.cc' ],
+ 'libraries': ['-lzmq'],
+ 'cflags!': ['-fno-exceptions'],
+ 'cflags_cc!': ['-fno-exceptions'],
+ 'conditions': [
+ ['OS=="mac"', {
+ 'xcode_settings': {
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
+ }
+ }]
+ ]
+ }
+ ]
+}
View
@@ -4,6 +4,7 @@
*
*/
+<<<<<<< HEAD
var cluster = require('cluster'),
zeromq = require('zmq'),
port = 'tcp://127.0.0.1:12345';
@@ -54,4 +55,53 @@ if (cluster.isMaster) {
console.log(socket.identity + ': received ' + envelope + ' - ' + data.toString());
socket.send([envelope, data * 2]);
});
+=======
+var cluster = require('cluster')
+ , zmq = require('../')
+ , port = 'tcp://127.0.0.1:12345';
+
+if (cluster.isMaster) {
+ for (var i = 0; i < 2; i++) cluster.fork();
+
+ cluster.on('death', function(worker) {
+ console.log('worker ' + worker.pid + ' died');
+ });
+
+ //dealer = client
+
+ var socket = zmq.socket('dealer');
+
+ socket.identity = 'client' + process.pid;
+
+ socket.bind(port, function(err) {
+ if (err) throw err;
+ console.log('bound!');
+
+ setInterval(function() {
+ var value = Math.floor(Math.random()*100);
+
+ console.log(socket.identity + ': asking ' + value);
+ socket.send(value);
+ }, 100);
+
+
+ socket.on('message', function(data) {
+ console.log(socket.identity + ': answer data ' + data);
+ });
+ });
+} else {
+ //router = server
+
+ var socket = zmq.socket('router');
+
+ socket.identity = 'server' + process.pid;
+
+ socket.connect(port);
+ console.log('connected!');
+
+ socket.on('message', function(envelope, data) {
+ console.log(socket.identity + ': received ' + envelope + ' - ' + data.toString());
+ socket.send([envelope, data * 2]);
+ });
+>>>>>>> upstream/master
}
View
@@ -0,0 +1,76 @@
+
+var zmq = require('../../')
+ , sock = zmq.socket('dealer')
+ , http = require('http')
+ , Stream = require('stream')
+
+var server = http.createServer(function(req, res){
+ // res.writeHead(200, req.headers);
+ // req.on('data', function(chunk){
+ // res.write(chunk);
+ // }).on('end', function(){
+ // res.end();
+ // });
+
+ console.log(req.method, req.url);
+ var body = 'Hello';
+ res.writeHead(200, { 'Content-Length': body.length });
+ res.write(body);
+ res.end();
+});
+
+var socks = {};
+
+sock.on('message', function(envelope, id, type, data){
+ var id = id.toString()
+ , type = type.toString()
+ , req
+ , res;
+
+ console.log('%s %s', id, type);
+
+ switch (type) {
+ case 'request':
+ req = new Stream;
+ res = new Stream;
+ res.socket = req;
+
+ res.writeHead = function(status, headers){
+ var obj = JSON.stringify({ status: status, header: headers });
+ sock.send([envelope, id, 'response', obj]);
+ };
+
+ res.write = function(data){
+ sock.send([envelope, id, 'data', data]);
+ };
+
+ res.end = function(){
+ sock.send([envelope, id, 'end']);
+ };
+
+ socks[id] = req;
+ data = JSON.parse(data.toString());
+ req.url = data.url;
+ req.method = data.method;
+ req.headers = data.header;
+ // console.log('%s : %s "%s"', id, req.method, req.url);
+ server.emit('request', req, res);
+ break;
+ case 'data':
+ // console.log();
+ // console.log('data');
+ // console.log(data.toString());
+ req = socks[id];
+ req.emit('data', data);
+ break;
+ case 'end':
+ // console.log('end');
+ req = socks[id];
+ req.emit('end');
+ delete socks[id];
+ break;
+ }
+});
+
+sock.connect('tcp://127.0.0.1:5001');
+console.log('app connected to :5001');
View
@@ -0,0 +1,19 @@
+
+var zmq = require('../../')
+ , router = zmq.socket('router')
+ , dealer = zmq.socket('dealer');
+
+router.on('message', function(envelope, id){
+ var args = Array.apply(null, arguments);
+ dealer.send(args);
+});
+
+dealer.on('message', function(envelope, id){
+ var args = Array.apply(null, arguments);
+ router.send(args);
+});
+
+router.bind('tcp://127.0.0.1:5000');
+dealer.bind('tcp://127.0.0.1:5001');
+console.log('router bound to :5000');
+console.log('dealer bound to :5001');
View
@@ -0,0 +1,18 @@
+
+var http = require('http');
+
+var server = http.createServer(function(req, res){
+ // res.writeHead(200, req.headers);
+ // req.on('data', function(chunk){
+ // res.write(chunk);
+ // }).on('end', function(){
+ // res.end();
+ // });
+
+ var body = 'Hello';
+ res.writeHead(200, { 'Content-Length': body.length });
+ res.write(body);
+ res.end();
+});
+
+server.listen(3001);
View
@@ -0,0 +1,56 @@
+
+var http = require('http')
+ , zmq = require('../../')
+ , sock = zmq.socket('dealer');
+
+var requests = {};
+
+http.createServer(function(req, res){
+ var id = Date.now() + Math.random();
+ // console.log('%s : %s "%s"', id, req.method, req.url);
+
+ requests[id] = res;
+
+ var obj = {
+ method: req.method,
+ url: req.url,
+ header: req.headers
+ };
+
+ var json = JSON.stringify(obj);
+
+ sock.send([id, 'request', json]);
+
+ req.on('data', function(chunk){
+ sock.send([id, 'data', chunk]);
+ });
+
+ req.on('end', function(){
+ sock.send([id, 'end']);
+ });
+}).listen(3000);
+
+sock.on('message', function(id, type, data){
+ var id = id.toString()
+ , type = type.toString()
+ , res = requests[id];
+
+ switch (type) {
+ case 'response':
+ data = JSON.parse(data);
+ res.writeHead(data.status, data.header);
+ break;
+ case 'data':
+ res.write(data);
+ break;
+ case 'end':
+ res.end();
+ delete requests[id];
+ break;
+ }
+});
+
+sock.connect('tcp://127.0.0.1:5000');
+
+console.log('HTTP server listening on :3000');
+console.log('dealer connected to :5000');
View
@@ -4,6 +4,7 @@
*
*/
+<<<<<<< HEAD
var cluster = require('cluster'),
zeromq = require('zmq'),
port = 'tcp://127.0.0.1:12345';
@@ -55,4 +56,54 @@ if (cluster.isMaster) {
socket.on('message', function(data) {
console.log(socket.identity + ': received data ' + data.toString());
});
+=======
+var cluster = require('cluster')
+ , zmq = require('../')
+ , port = 'tcp://127.0.0.1:12345';
+
+if (cluster.isMaster) {
+ for (var i = 0; i < 2; i++) cluster.fork();
+
+ cluster.on('death', function(worker) {
+ console.log('worker ' + worker.pid + ' died');
+ });
+
+ //publisher = send only
+
+ var socket = zmq.socket('pub');
+
+ socket.identity = 'publisher' + process.pid;
+
+ var stocks = ['AAPL', 'GOOG', 'YHOO', 'MSFT', 'INTC'];
+
+ socket.bind(port, function(err) {
+ if (err) throw err;
+ console.log('bound!');
+
+ setInterval(function() {
+ var symbol = stocks[Math.floor(Math.random()*stocks.length)]
+ , value = Math.random()*1000;
+
+ console.log(socket.identity + ': sent ' + symbol + ' ' + value);
+ socket.send(symbol + ' ' + value);
+ }, 100);
+ });
+} else {
+ //subscriber = receive only
+
+ var socket = zmq.socket('sub');
+
+ socket.identity = 'subscriber' + process.pid;
+
+ socket.connect(port);
+
+ socket.subscribe('AAPL');
+ socket.subscribe('GOOG');
+
+ console.log('connected!');
+
+ socket.on('message', function(data) {
+ console.log(socket.identity + ': received data ' + data.toString());
+ });
+>>>>>>> upstream/master
}
Oops, something went wrong.

0 comments on commit 1be1295

Please sign in to comment.