fixed problem with `destroy` in socksv5 server
This commit is contained in:
parent
2ffd846352
commit
b361c0cd53
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
module.exports.create = function () {
|
module.exports.create = function () {
|
||||||
var PromiseA = require('bluebird');
|
var PromiseA = require('bluebird');
|
||||||
var enableDestroy = require('server-destroy');
|
|
||||||
var server;
|
var server;
|
||||||
|
|
||||||
function curState() {
|
function curState() {
|
||||||
if (!server) {
|
var addr = server && server.address();
|
||||||
|
if (!addr) {
|
||||||
return PromiseA.resolve({running: false});
|
return PromiseA.resolve({running: false});
|
||||||
}
|
}
|
||||||
return PromiseA.resolve({
|
return PromiseA.resolve({
|
||||||
running: true
|
running: true
|
||||||
, port: server.address().port
|
, port: addr.port
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ module.exports.create = function () {
|
||||||
accept();
|
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.on('close', function () {
|
||||||
server = null;
|
server = null;
|
||||||
});
|
});
|
||||||
|
@ -51,11 +53,7 @@ module.exports.create = function () {
|
||||||
return curState();
|
return curState();
|
||||||
}
|
}
|
||||||
return new PromiseA(function (resolve, reject) {
|
return new PromiseA(function (resolve, reject) {
|
||||||
var timeoutId = setTimeout(function () {
|
|
||||||
server.destroy();
|
|
||||||
}, 1000);
|
|
||||||
server.close(function (err) {
|
server.close(function (err) {
|
||||||
clearTimeout(timeoutId);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue