GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — net: ensure Socket reported address is current · nodejs/node@1738c96

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • net.js
  • test/parallel
    • test-net-socket-local-address.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function initSocketHandle(self) {
9393
self.destroyed = false;
9494
self.bytesRead = 0;
9595
self._bytesDispatched = 0;
96+
self._sockname = null;
9697

9798
// Handle creation may be deferred to bind() or connect() time.
9899
if (self._handle) {
@@ -469,6 +470,7 @@ Socket.prototype._destroy = function(exception, cb) {
469470
});
470471
this._handle.onread = noop;
471472
this._handle = null;
473+
this._sockname = null;
472474
}
473475

474476
// we set destroyed to true before firing error callbacks in order
@@ -871,6 +873,7 @@ Socket.prototype.connect = function(options, cb) {
871873
this.destroyed = false;
872874
this._handle = null;
873875
this._peername = null;
876+
this._sockname = null;
874877
}
875878

876879
var self = this;
@@ -1032,6 +1035,7 @@ function afterConnect(status, handle, req, readable, writable) {
10321035

10331036
assert.ok(self._connecting);
10341037
self._connecting = false;
1038+
self._sockname = null;
10351039

10361040
if (status == 0) {
10371041
self.readable = readable;
Collapse file

‎test/parallel/test-net-socket-local-address.js‎

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.