GeezerVison is showing github.com — net: ensure Socket reported address is current · nodejs/node@6f89de9
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/net.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,6 +93,7 @@ function initSocketHandle(self) { |
93 | 93 | self.destroyed = false; |
94 | 94 | self.bytesRead = 0; |
95 | 95 | self._bytesDispatched = 0; |
| 96 | + self._sockname = null; |
96 | 97 |
|
97 | 98 | // Handle creation may be deferred to bind() or connect() time. |
98 | 99 | if (self._handle) { |
@@ -469,6 +470,7 @@ Socket.prototype._destroy = function(exception, cb) { |
469 | 470 | }); |
470 | 471 | this._handle.onread = noop; |
471 | 472 | this._handle = null; |
| 473 | + this._sockname = null; |
472 | 474 | } |
473 | 475 |
|
474 | 476 | // we set destroyed to true before firing error callbacks in order |
@@ -871,6 +873,7 @@ Socket.prototype.connect = function(options, cb) { |
871 | 873 | this.destroyed = false; |
872 | 874 | this._handle = null; |
873 | 875 | this._peername = null; |
| 876 | + this._sockname = null; |
874 | 877 | } |
875 | 878 |
|
876 | 879 | var self = this; |
@@ -1032,6 +1035,7 @@ function afterConnect(status, handle, req, readable, writable) { |
1032 | 1035 |
|
1033 | 1036 | assert.ok(self._connecting); |
1034 | 1037 | self._connecting = false; |
| 1038 | + self._sockname = null; |
1035 | 1039 |
|
1036 | 1040 | if (status == 0) { |
1037 | 1041 | self.readable = readable; |
|
Collapse file
Copy file name to clipboard +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +var common = require('../common'); |
| 3 | +var assert = require('assert'); |
| 4 | +var net = require('net'); |
| 5 | + |
| 6 | +var conns = 0; |
| 7 | +var clientLocalPorts = []; |
| 8 | +var serverRemotePorts = []; |
| 9 | + |
| 10 | +var server = net.createServer(function(socket) { |
| 11 | + serverRemotePorts.push(socket.remotePort); |
| 12 | + conns++; |
| 13 | +}); |
| 14 | + |
| 15 | +var client = new net.Socket(); |
| 16 | + |
| 17 | +server.on('close', function() { |
| 18 | + assert.deepEqual(clientLocalPorts, serverRemotePorts, |
| 19 | + 'client and server should agree on the ports used'); |
| 20 | + assert.equal(2, conns); |
| 21 | +}); |
| 22 | + |
| 23 | +server.listen(common.PORT, common.localhostIPv4, testConnect); |
| 24 | + |
| 25 | +function testConnect() { |
| 26 | + if (conns == 2) { |
| 27 | + return server.close(); |
| 28 | + } |
| 29 | + client.connect(common.PORT, common.localhostIPv4, function() { |
| 30 | + clientLocalPorts.push(this.localPort); |
| 31 | + this.once('close', testConnect); |
| 32 | + this.destroy(); |
| 33 | + }); |
| 34 | +} |