File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -780,9 +780,10 @@ Socket.prototype._getpeername = function() {
780
780
if ( ! this . _handle || ! this . _handle . getpeername || this . connecting ) {
781
781
return this . _peername || { } ;
782
782
} else if ( ! this . _peername ) {
783
- this . _peername = { } ;
784
- // FIXME(bnoordhuis) Throw when the return value is not 0?
785
- this . _handle . getpeername ( this . _peername ) ;
783
+ const out = { } ;
784
+ const err = this . _handle . getpeername ( out ) ;
785
+ if ( err ) return out ;
786
+ this . _peername = out ;
786
787
}
787
788
return this . _peername ;
788
789
} ;
Original file line number Diff line number Diff line change
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
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments