fixed problem with `destroy` in socksv5 server
This commit is contained in:
parent
2ffd846352
commit
b361c0cd53
|
@ -2,16 +2,16 @@
|
|||
|
||||
module.exports.create = function () {
|
||||
var PromiseA = require('bluebird');
|
||||
var enableDestroy = require('server-destroy');
|
||||
var server;
|
||||
|
||||
function curState() {
|
||||
if (!server) {
|
||||
var addr = server && server.address();
|
||||
if (!addr) {
|
||||
return PromiseA.resolve({running: false});
|
||||
}
|
||||
return PromiseA.resolve({
|
||||
running: true
|
||||
, port: server.address().port
|
||||
, port: addr.port
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,9 @@ module.exports.create = function () {
|
|||
accept();
|
||||
});
|
||||
|
||||
enableDestroy(server);
|
||||
// It would be nice if we could use `server-destroy` here, but we can't because
|
||||
// the socksv5 library will not give us access to any sockets it actually
|
||||
// handles, so we have no way of keeping track of them or closing them.
|
||||
server.on('close', function () {
|
||||
server = null;
|
||||
});
|
||||
|
@ -51,11 +53,7 @@ module.exports.create = function () {
|
|||
return curState();
|
||||
}
|
||||
return new PromiseA(function (resolve, reject) {
|
||||
var timeoutId = setTimeout(function () {
|
||||
server.destroy();
|
||||
}, 1000);
|
||||
server.close(function (err) {
|
||||
clearTimeout(timeoutId);
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue