updated close function for safety

This commit is contained in:
John Catron 2014-08-14 20:12:20 +00:00
parent a3d02196c5
commit 8be9d945d0

View File

@ -134,8 +134,16 @@ ProxyServer.prototype.listen = function(port, hostname) {
ProxyServer.prototype.close = function(callback) { ProxyServer.prototype.close = function(callback) {
if (this._server) { if (this._server) {
this._server.close(callback); // Wrap callback to nullify server after all open connections are closed.
var callback_wrapper = function() {
this._server = null; this._server = null;
if (callback) {
callback(arguments);
}
};
this._server.close(callback_wrapper);
} }
}; };