Skip to content

Instantly share code, notes, and snippets.

View gitresetsoft's full-sized avatar
🎯
Locked-In-Maybe-Trying-Vibing-Perhaps

Amr gitresetsoft

🎯
Locked-In-Maybe-Trying-Vibing-Perhaps
View GitHub Profile
@gitresetsoft
gitresetsoft / net.Stream.setConnTimeout.hack.js
Created November 27, 2020 19:50 — forked from DanBUK/net.Stream.setConnTimeout.hack.js
This hack enables node.js to handle connection timeouts.
var net = require('net');
var sys = require('sys');
// START setConnTimeout hack
net.Stream.prototype._orig_connect = net.Stream.prototype.connect;
net.Stream.prototype.connect = function () {
var self = this;
if (typeof self.conn_timeout !== 'undefined' && self.conn_timeout > 0) {
self.addListener('connect', function () {
clearTimeout(self.conn_timer);