| 574 | |
| 575 | |
| 576 | function doConnect(ex, self, ip, address, port, callback) { |
| 577 | const state = self[kStateSymbol]; |
| 578 | if (!state.handle) |
| 579 | return; |
| 580 | if (!ex && state.sendBlockList?.check(ip, `ipv${isIP(ip)}`)) { |
| 581 | ex = new ERR_IP_BLOCKED(ip); |
| 582 | } |
| 583 | if (!ex) { |
| 584 | const err = state.handle.connect(ip, port); |
| 585 | if (err) { |
| 586 | ex = new ExceptionWithHostPort(err, 'connect', address, port); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | if (ex) { |
| 591 | state.connectState = CONNECT_STATE_DISCONNECTED; |
| 592 | return process.nextTick(() => { |
| 593 | if (callback) { |
| 594 | self.removeListener('connect', callback); |
| 595 | callback(ex); |
| 596 | } else { |
| 597 | self.emit('error', ex); |
| 598 | } |
| 599 | }); |
| 600 | } |
| 601 | |
| 602 | state.connectState = CONNECT_STATE_CONNECTED; |
| 603 | process.nextTick(() => self.emit('connect')); |
| 604 | } |
| 605 | |
| 606 | |
| 607 | Socket.prototype.disconnect = function() { |