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