@@ -304,55 +304,54 @@ function Socket(options) {
304304 if ( options . handle ) {
305305 this . _handle = options . handle ; // private
306306 this [ async_id_symbol ] = getNewAsyncId ( this . _handle ) ;
307- } else {
308- const onread = options . onread ;
309- if ( onread !== null && typeof onread === 'object' &&
310- ( isUint8Array ( onread . buffer ) || typeof onread . buffer === 'function' ) &&
311- typeof onread . callback === 'function' ) {
312- if ( typeof onread . buffer === 'function' ) {
313- this [ kBuffer ] = true ;
314- this [ kBufferGen ] = onread . buffer ;
315- } else {
316- this [ kBuffer ] = onread . buffer ;
317- }
318- this [ kBufferCb ] = onread . callback ;
319- }
320- if ( options . fd !== undefined ) {
321- const { fd } = options ;
322- let err ;
307+ } else if ( options . fd !== undefined ) {
308+ const { fd } = options ;
309+ let err ;
323310
324- // createHandle will throw ERR_INVALID_FD_TYPE if `fd` is not
325- // a valid `PIPE` or `TCP` descriptor
326- this . _handle = createHandle ( fd , false ) ;
311+ // createHandle will throw ERR_INVALID_FD_TYPE if `fd` is not
312+ // a valid `PIPE` or `TCP` descriptor
313+ this . _handle = createHandle ( fd , false ) ;
314+
315+ err = this . _handle . open ( fd ) ;
316+
317+ // While difficult to fabricate, in some architectures
318+ // `open` may return an error code for valid file descriptors
319+ // which cannot be opened. This is difficult to test as most
320+ // un-openable fds will throw on `createHandle`
321+ if ( err )
322+ throw errnoException ( err , 'open' ) ;
327323
328- err = this . _handle . open ( fd ) ;
324+ this [ async_id_symbol ] = this . _handle . getAsyncId ( ) ;
329325
330- // While difficult to fabricate, in some architectures
331- // `open` may return an error code for valid file descriptors
332- // which cannot be opened. This is difficult to test as most
333- // un-openable fds will throw on `createHandle`
326+ if ( ( fd === 1 || fd === 2 ) &&
327+ ( this . _handle instanceof Pipe ) && isWindows ) {
328+ // Make stdout and stderr blocking on Windows
329+ err = this . _handle . setBlocking ( true ) ;
334330 if ( err )
335- throw errnoException ( err , 'open' ) ;
336-
337- this [ async_id_symbol ] = this . _handle . getAsyncId ( ) ;
338-
339- if ( ( fd === 1 || fd === 2 ) &&
340- ( this . _handle instanceof Pipe ) && isWindows ) {
341- // Make stdout and stderr blocking on Windows
342- err = this . _handle . setBlocking ( true ) ;
343- if ( err )
344- throw errnoException ( err , 'setBlocking' ) ;
345-
346- this . _writev = null ;
347- this . _write = makeSyncWrite ( fd ) ;
348- // makeSyncWrite adjusts this value like the original handle would, so
349- // we need to let it do that by turning it into a writable, own
350- // property.
351- ObjectDefineProperty ( this . _handle , 'bytesWritten' , {
352- value : 0 , writable : true
353- } ) ;
354- }
331+ throw errnoException ( err , 'setBlocking' ) ;
332+
333+ this . _writev = null ;
334+ this . _write = makeSyncWrite ( fd ) ;
335+ // makeSyncWrite adjusts this value like the original handle would, so
336+ // we need to let it do that by turning it into a writable, own
337+ // property.
338+ ObjectDefineProperty ( this . _handle , 'bytesWritten' , {
339+ value : 0 , writable : true
340+ } ) ;
341+ }
342+ }
343+
344+ const onread = options . onread ;
345+ if ( onread !== null && typeof onread === 'object' &&
346+ ( isUint8Array ( onread . buffer ) || typeof onread . buffer === 'function' ) &&
347+ typeof onread . callback === 'function' ) {
348+ if ( typeof onread . buffer === 'function' ) {
349+ this [ kBuffer ] = true ;
350+ this [ kBufferGen ] = onread . buffer ;
351+ } else {
352+ this [ kBuffer ] = onread . buffer ;
355353 }
354+ this [ kBufferCb ] = onread . callback ;
356355 }
357356
358357 // Shut down the socket when we're finished with it.
0 commit comments