Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refactor Socket._getpeername and Socket._getsockname #32969

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 8 additions & 14 deletions lib/net.js
Expand Up @@ -669,14 +669,11 @@ Socket.prototype._destroy = function(exception, cb) {
};

Socket.prototype._getpeername = function() {
if (!this._peername) {
if (!this._handle || !this._handle.getpeername) {
return {};
}
const out = {};
const err = this._handle.getpeername(out);
if (err) return {}; // FIXME(bnoordhuis) Throw?
this._peername = out;
if (!this._handle || !this._handle.getpeername) {
return {};
} else if (!this._peername) {
// FIXME(bnoordhuis) Throws when returns not 0?
himself65 marked this conversation as resolved.
Show resolved Hide resolved
this._handle.getpeername(this._peername = {});
}
return this._peername;
};
Expand Down Expand Up @@ -709,12 +706,9 @@ protoGetter('remotePort', function remotePort() {
Socket.prototype._getsockname = function() {
if (!this._handle || !this._handle.getsockname) {
return {};
}
if (!this._sockname) {
const out = {};
const err = this._handle.getsockname(out);
if (err) return {}; // FIXME(bnoordhuis) Throw?
this._sockname = out;
} else if (!this._sockname) {
// FIXME(bnoordhuis) Throws when returns not 0?
this._handle.getsockname(this._sockname = {});
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
}
return this._sockname;
};
Expand Down