Skip to content

Commit 8339c96

Browse files
committed
Merge pull request socketio#596 from einaros/nodenext
Node v0.5+ compatibility
2 parents abd0326 + a125fcb commit 8339c96

20 files changed

+137
-241
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ run-tests:
66
@./node_modules/.bin/expresso \
77
-t 3000 \
88
-I support \
9-
-I lib \
109
--serial \
1110
$(TESTFLAGS) \
1211
$(TESTS)
1312

1413
test:
15-
@$(MAKE) TESTS="$(ALL_TESTS)" run-tests
14+
@$(MAKE) NODE_PATH=lib TESTS="$(ALL_TESTS)" run-tests
1615

1716
test-cov:
1817
@TESTFLAGS=--cov $(MAKE) test

examples/chat/app.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
2-
/**
3-
* Bootstrap app.
4-
*/
5-
6-
require.paths.unshift(__dirname + '/../../lib/');
7-
81
/**
92
* Module dependencies.
103
*/
114

125
var express = require('express')
136
, stylus = require('stylus')
147
, nib = require('nib')
15-
, sio = require('socket.io');
8+
, sio = require('../../lib/socket.io');
169

1710
/**
1811
* App.

examples/chat/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
, "description": "example chat application with socket.io"
44
, "version": "0.0.1"
55
, "dependencies": {
6-
"express": "2.3.11"
7-
, "jade": "0.12.1"
8-
, "stylus": "0.13.3"
9-
, "nib": "0.0.8"
6+
"express": "2.5.0"
7+
, "jade": "0.16.4"
8+
, "stylus": "0.19.0"
9+
, "nib": "0.2.0"
1010
}
1111
}

examples/irc-output/app.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
2-
/**
3-
* Bootstrap app.
4-
*/
5-
6-
require.paths.unshift(__dirname + '/../../lib/');
7-
81
/**
92
* Module dependencies.
103
*/
114

125
var express = require('express')
136
, stylus = require('stylus')
147
, nib = require('nib')
15-
, sio = require('socket.io')
8+
, sio = require('../../lib/socket.io')
169
, irc = require('./irc');
1710

1811
/**

examples/irc-output/irc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* From https://github.com/felixge/nodelog/
33
*/
44

5-
var sys = require('sys');
5+
var sys = require('util');
66
var tcp = require('net');
77
var irc = exports;
88

examples/irc-output/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "socket.io-irc"
33
, "version": "0.0.1"
44
, "dependencies": {
5-
"express": "2.3.11"
6-
, "jade": "0.12.1"
7-
, "stylus": "0.13.3"
8-
, "nib": "0.0.8"
5+
"express": "2.5.0"
6+
, "jade": "0.16.4"
7+
, "stylus": "0.19.0"
8+
, "nib": "0.2.0"
99
}
1010
}

lib/manager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ function Manager (server, options) {
9393

9494
var self = this;
9595

96+
// default error handler
97+
server.on('error', function(err) {
98+
self.log.warn('error raised: ' + err);
99+
});
100+
96101
this.initStore();
97102

98103
this.on('set:store', function() {

lib/transports/flashsocket.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ FlashSocket.prototype.name = 'flashsocket';
4949
* @api private
5050
*/
5151

52-
var server;
5352

5453
FlashSocket.init = function (manager) {
54+
var server;
5555
function create () {
5656
server = require('policyfile').createServer({
5757
log: function(msg){
@@ -80,10 +80,15 @@ FlashSocket.init = function (manager) {
8080
// destory the server and create a new server
8181
manager.on('set:flash policy port', function (value, key) {
8282
var transports = manager.get('transports');
83-
84-
if (server && server.port !== value && ~transports.indexOf('flashsocket')) {
85-
// destroy the server and rebuild it on a new port
86-
server.close();
83+
if (~transports.indexOf('flashsocket')) {
84+
if (server) {
85+
if (server.port === value) return;
86+
// destroy the server and rebuild it on a new port
87+
try {
88+
server.close();
89+
}
90+
catch (e) { /* ignore exception. could e.g. be that the server isn't started yet */ }
91+
}
8792
create();
8893
}
8994
});
@@ -94,7 +99,6 @@ FlashSocket.init = function (manager) {
9499
create();
95100
}
96101
});
97-
98102
// check if we need to initialize at start
99103
if (~manager.get('transports').indexOf('flashsocket')){
100104
create();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
, "redis": "0.6.7"
2222
}
2323
, "devDependencies": {
24-
"expresso": "0.7.7"
24+
"expresso": "0.9.2"
2525
, "should": "0.0.4"
2626
, "assertvanish": "0.0.3-1"
2727
, "benchmark": "0.2.2"

support/node-websocket-client/lib/websocket.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var events = require('events');
55
var http = require('http');
66
var net = require('net');
77
var urllib = require('url');
8-
var sys = require('sys');
8+
var sys = require('util');
99

1010
var FRAME_NO = 0;
1111
var FRAME_LO = 1;
@@ -347,7 +347,6 @@ var WebSocket = function(url, proto, opts) {
347347
// that we've closed.
348348
var finishClose = self.finishClose = function() {
349349
readyState = CLOSED;
350-
351350
if (stream) {
352351
stream.end();
353352
stream.destroy();
@@ -469,29 +468,45 @@ var WebSocket = function(url, proto, opts) {
469468
// that http.Client passes its constructor arguments through,
470469
// un-inspected to net.Stream.connect(). The latter accepts a
471470
// string as its first argument to connect to a UNIX socket.
472-
var httpClient = undefined;
471+
var opt = {};
472+
var agent = null;
473473
switch (getUrlScheme(url)) {
474474
case 'ws':
475475
var u = urllib.parse(url);
476-
httpClient = http.createClient(u.port || 80, u.hostname);
477-
httpPath = (u.pathname || '/') + (u.search || '');
478-
httpHeaders.Host = u.hostname + (u.port ? (":" + u.port) : "");
476+
agent = new http.Agent({
477+
host: u.hostname,
478+
port: u.port || 80
479+
});
480+
opt.agent = agent;
481+
opt.host = u.hostname;
482+
opt.port = u.port || 80;
483+
opt.path = (u.pathname || '/') + (u.search || '');
484+
opt.headers = httpHeaders;
479485
break;
480486

481487
case 'ws+unix':
482488
var sockPath = url.substring('ws+unix://'.length, url.length);
483-
httpClient = http.createClient(sockPath);
484-
httpHeaders.Host = 'localhost';
489+
var u = urllib.parse(url);
490+
agent = new http.Agent({
491+
host: 'localhost',
492+
port: sockPath
493+
});
494+
opt.agent = agent;
495+
opt.host = 'localhost';
496+
opt.path = sockPath;
497+
opt.headers = httpHeaders;
485498
break;
486499

487500
default:
488501
throw new Error('Invalid URL scheme \'' + urlScheme + '\' specified.');
489502
}
490503

491-
httpClient.on('upgrade', (function() {
504+
var httpReq = http.request(opt, function() { });
505+
var upgradeHandler = (function() {
492506
var data = undefined;
493507

494508
return function(req, s, head) {
509+
req.socket.setNoDelay(true);
495510
stream = s;
496511

497512
if (readyState == CLOSED) {
@@ -554,7 +569,7 @@ var WebSocket = function(url, proto, opts) {
554569
//
555570
// XXX: This is lame. We should only remove the listeners
556571
// that we added.
557-
httpClient.removeAllListeners('upgrade');
572+
httpReq.removeAllListeners('upgrade');
558573
stream.removeAllListeners('data');
559574
stream.on('data', dataListener);
560575

@@ -582,13 +597,9 @@ var WebSocket = function(url, proto, opts) {
582597

583598
stream.emit('data', head);
584599
};
585-
})());
586-
httpClient.on('error', function(e) {
587-
httpClient.end();
588-
errorListener(e);
589-
});
590-
591-
var httpReq = httpClient.request(httpPath, httpHeaders);
600+
})();
601+
agent.on('upgrade', upgradeHandler); // node v0.4
602+
httpReq.on('upgrade', upgradeHandler); // node v0.5+
592603

593604
httpReq.write(challenge, 'binary');
594605
httpReq.end();

0 commit comments

Comments
 (0)