Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move multi-available test logic into .peer()

  • Loading branch information...
commit 81c3870cbd764093c6b3c0e7eb18574480617878 1 parent 28bfb1d
James Halliday authored
Showing with 22 additions and 11 deletions.
  1. +21 −0 index.js
  2. +1 −11 test/multi.js
21 index.js
View
@@ -1,5 +1,6 @@
var net = require('net');
var seaport = require('./lib/seaport');
+var version = require('./package.json').version;
exports = module.exports = function () {
return seaport.apply(this, arguments);
@@ -81,6 +82,26 @@ exports.createServer = function (opts) {
s.listen = s.server.listen.bind(s.server);
s.address = s.server.address.bind(s.server);
+ s.peer = function () {
+ if (!s.address()) {
+ var args = arguments;
+ s.once('listening', function () {
+ s.peer.apply(s, args);
+ });
+ return;
+ }
+
+ var stream = s.createStream();
+ var c = exports.connect.apply(this, arguments);
+ s.on('close', c.close.bind(c));
+ stream.pipe(c.createStream()).pipe(stream);
+
+ c.register({
+ role : 'seaport@' + version,
+ port : s.address().port
+ });
+ };
+
s.on('close', function () {
s.server.close();
});
12 test/multi.js
View
@@ -15,17 +15,7 @@ test('multi-availability', function (t) {
server0.listen(0);
server1.listen(0);
- (function () {
- var s = server1.createStream();
- var c = seaport.connect(server0.address().port);
- server1.on('close', c.close.bind(c));
- s.pipe(c.createStream()).pipe(s);
-
- c.register({
- role : 'seaport',
- port : server1.address().port
- });
- })();
+ server1.peer(server0.address().port);
var ports = seaport.connect(server0.address().port);
var wport = ports.register('woo');
Please sign in to comment.
Something went wrong with that request. Please try again.