-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: ensure Socket reported address is current
Any time the connection state or the underlying handle itself changes, the socket's name (aka, local address) can change. To deal with this we need to reset the cached sockname any time we set or unset the internal handle or an existing handle establishes a connection. PR-URL: #2095 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
- Loading branch information
1 parent
c8282de
commit 6f89de9
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
|
||
var conns = 0; | ||
var clientLocalPorts = []; | ||
var serverRemotePorts = []; | ||
|
||
var server = net.createServer(function(socket) { | ||
serverRemotePorts.push(socket.remotePort); | ||
conns++; | ||
}); | ||
|
||
var client = new net.Socket(); | ||
|
||
server.on('close', function() { | ||
assert.deepEqual(clientLocalPorts, serverRemotePorts, | ||
'client and server should agree on the ports used'); | ||
assert.equal(2, conns); | ||
}); | ||
|
||
server.listen(common.PORT, common.localhostIPv4, testConnect); | ||
|
||
function testConnect() { | ||
if (conns == 2) { | ||
return server.close(); | ||
} | ||
client.connect(common.PORT, common.localhostIPv4, function() { | ||
clientLocalPorts.push(this.localPort); | ||
this.once('close', testConnect); | ||
this.destroy(); | ||
}); | ||
} |