Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
#!/usr/local/bin/node | ||
|
||
var path = require('path'); | ||
var bridgePath = path.resolve(process.argv[2]); | ||
|
||
console.log('connecting to ' + bridgePath) | ||
require('dnode').connect(bridgePath, function (client, conn) { | ||
console.log('connected'); | ||
|
||
carapace = client; | ||
plugins = client.plugins; | ||
emit = client.emit.bind(client); | ||
on = client.on.bind(client); | ||
|
||
console.log(''); | ||
console.log('REPL started'); | ||
console.log(' use carapace.*, plugins.*, on(..), and emit(..) to communicate with the carapace'); | ||
console.log(''); | ||
require('repl').start('carapace>'); | ||
|
||
conn.on('end', function () { | ||
console.log('carapace connection had ended.'); | ||
process.exit(0); | ||
}); | ||
var hookio = require('hook.io'); | ||
var Hook = hookio.Hook; | ||
|
||
new Hook().connect({ | ||
name: "carapace-client", | ||
"hook-port": process.argv[2] | ||
}, function () { | ||
console.dir(arguments) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,10 @@ carapace.servers = {} | |
// done(carapace.proxy.ports); | ||
// }); | ||
|
||
net.Server.prototype._doListen = function() { | ||
// | ||
// Separate since net.Server uses a cached bind function | ||
// | ||
net.Server.prototype._doListen = function () { | ||
var self = this, | ||
desired = toPort(arguments[0]), | ||
actual; | ||
|
@@ -52,13 +55,18 @@ net.Server.prototype._doListen = function() { | |
getDummyFD(); | ||
|
||
try { | ||
// | ||
// Don't allow listening on the hook-port, hook may be restarting | ||
// | ||
if(desired === carapace['hook-port']) { | ||
return this._doListen.call(this, nextPort(desired), arguments[1]); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bmeck
via email
Author
Contributor
|
||
binding.bind(self.fd, arguments[0], arguments[1]); | ||
} | ||
catch (err) { | ||
if (err.code !== 'EADDRINUSE' || desired === carapace['hook-port']) { | ||
catch (err) { | ||
if (err.code !== 'EADDRINUSE') { | ||
self.close(); | ||
self.emit('error', err); | ||
return; | ||
return self.emit('error', err); | ||
} | ||
|
||
return this._doListen.call(this, nextPort(desired), arguments[1]); | ||
|
@@ -73,7 +81,7 @@ net.Server.prototype._doListen = function() { | |
// Need to the listening in the nextTick so that people potentially have | ||
// time to register 'listening' listeners. | ||
// | ||
process.nextTick(function() { | ||
return process.nextTick(function() { | ||
// | ||
// It could be that server.close() was called between the time the | ||
// original listen command was issued and this. Bail if that's the case. | ||
|
@@ -88,7 +96,7 @@ net.Server.prototype._doListen = function() { | |
// Remark: How does this work with multi-server programs? | ||
// | ||
carapace.servers[desired] = self; | ||
carapace.emit('*::port', desired); | ||
carapace.emit('*::carapace::port', carapace.id, desired, actual); | ||
} | ||
catch (err) { | ||
self.close(); | ||
|
@@ -108,4 +116,4 @@ function getDummyFD () { | |
dummyFD = null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@bmeck This is wrong. We should allow listening on
hook-port
, but we should not auto-increment the port on error. This is used by hook.io in.start()
to determine if it can start a hook server or not. With this here, the carapace will always be a hook server, and not a hook-client.