net: fix Socket.pause null reference when called on a closed Stream

Fixes #1980.
This commit is contained in:
koichik
2011-12-28 15:13:57 +09:00
parent e1c043f43a
commit a848a3efbf
2 changed files with 59 additions and 2 deletions

View File

@@ -166,7 +166,10 @@ Socket.prototype.setKeepAlive = function(setting, msecs) {
Socket.prototype.address = function() {
return this._handle.getsockname();
if (this._handle && this._handle.getsockname) {
return this._handle.getsockname();
}
return null;
};
@@ -189,7 +192,9 @@ Object.defineProperty(Socket.prototype, 'readyState', {
Object.defineProperty(Socket.prototype, 'bufferSize', {
get: function() {
return this._handle.writeQueueSize + this._connectQueueSize;
if (this._handle) {
return this._handle.writeQueueSize + this._connectQueueSize;
}
}
});

View File

@@ -0,0 +1,52 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var net = require('net');
var closed = false;
var server = net.createServer(function(s) {
s.end();
});
server.listen(common.PORT, function() {
var c = net.createConnection(common.PORT);
c.on('close', function() {
assert.strictEqual(c._handle, null);
closed = true;
assert.doesNotThrow(function() {
c.setNoDelay();
c.setKeepAlive();
c.bufferSize;
c.pause();
c.resume();
c.address();
c.remoteAddress;
c.remotePort;
});
server.close();
});
});
process.on('exit', function() {
assert(closed);
});