net_uv: throw if Server.prototype.close() is called twice

Follows net_legacy behaviour.
This commit is contained in:
Ben Noordhuis
2011-07-22 01:23:50 +02:00
parent 345df289eb
commit 984dc057e3
2 changed files with 11 additions and 4 deletions

View File

@@ -631,10 +631,13 @@ function onconnection(clientHandle) {
Server.prototype.close = function() {
if (this._handle != null) {
this._handle.close();
this._handle = null;
if (!this._handle) {
// Throw error. Follows net_legacy behaviour.
throw new Error('Not running');
}
this._handle.close();
this._handle = null;
this.emit('close');
};

View File

@@ -75,8 +75,12 @@ server.listen(common.PIPE, function() {
});
process.on('exit', function() {
server.close();
assert.ok(status_ok);
assert.ok(headers_ok);
assert.ok(body_ok);
// Double close should throw. Follows net_legacy behaviour.
assert.throws(function() {
server.close();
});
});