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: fix socket._getpeername · nodejs/node@29bcd47

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • net.js
  • test/parallel
    • test-net-remote-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
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,10 @@ Socket.prototype._getpeername = function() {
785785
if (!this._handle || !this._handle.getpeername || this.connecting) {
786786
return this._peername || {};
787787
} else if (!this._peername) {
788-
this._peername = {};
789-
// FIXME(bnoordhuis) Throw when the return value is not 0?
790-
this._handle.getpeername(this._peername);
788+
const out = {};
789+
const err = this._handle.getpeername(out);
790+
if (err) return out;
791+
this._peername = out;
791792
}
792793
return this._peername;
793794
};
Collapse file

‎test/parallel/test-net-remote-address.js‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const net = require('net');
5+
const { strictEqual } = require('assert');
6+
7+
const server = net.createServer();
8+
9+
server.listen(common.mustCall(function() {
10+
const socket = net.connect({ port: server.address().port });
11+
12+
strictEqual(socket.connecting, true);
13+
strictEqual(socket.remoteAddress, undefined);
14+
15+
socket.on('connect', common.mustCall(function() {
16+
strictEqual(socket.remoteAddress !== undefined, true);
17+
socket.end();
18+
}));
19+
20+
socket.on('end', common.mustCall(function() {
21+
server.close();
22+
}));
23+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.