@@ -35,15 +35,11 @@ const {
3535 newHandle,
3636} = require ( 'internal/dgram' ) ;
3737const { guessHandleType } = internalBinding ( 'util' ) ;
38- const {
39- isLegalPort,
40- } = require ( 'internal/net' ) ;
4138const {
4239 ERR_INVALID_ARG_TYPE ,
4340 ERR_MISSING_ARGS ,
4441 ERR_SOCKET_ALREADY_BOUND ,
4542 ERR_SOCKET_BAD_BUFFER_SIZE ,
46- ERR_SOCKET_BAD_PORT ,
4743 ERR_SOCKET_BUFFER_SIZE ,
4844 ERR_SOCKET_DGRAM_IS_CONNECTED ,
4945 ERR_SOCKET_DGRAM_NOT_CONNECTED ,
@@ -53,7 +49,8 @@ const {
5349const {
5450 isInt32,
5551 validateString,
56- validateNumber
52+ validateNumber,
53+ validatePort,
5754} = require ( 'internal/validators' ) ;
5855const { Buffer } = require ( 'buffer' ) ;
5956const { deprecate } = require ( 'internal/util' ) ;
@@ -351,21 +348,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
351348 return this ;
352349} ;
353350
354-
355- function validatePort ( port ) {
356- const legal = isLegalPort ( port ) ;
357- if ( legal )
358- port = port | 0 ;
359-
360- if ( ! legal || port === 0 )
361- throw new ERR_SOCKET_BAD_PORT ( port ) ;
362-
363- return port ;
364- }
365-
366-
367351Socket . prototype . connect = function ( port , address , callback ) {
368- port = validatePort ( port ) ;
352+ port = validatePort ( port , 'Port' , { allowZero : false } ) ;
369353 if ( typeof address === 'function' ) {
370354 callback = address ;
371355 address = '' ;
@@ -610,7 +594,7 @@ Socket.prototype.send = function(buffer,
610594 }
611595
612596 if ( ! connected )
613- port = validatePort ( port ) ;
597+ port = validatePort ( port , 'Port' , { allowZero : false } ) ;
614598
615599 // Normalize callback so it's either a function or undefined but not anything
616600 // else.
0 commit comments