Merge pull request #424 from mercmobily/master

Added socketTimeout option to ensure that OS-level timeouts are handled by node-imap
fork
Brian White 10 years ago
commit c35e79803d

@ -56,6 +56,7 @@ function Connection(config) {
this._config = {
socket: config.socket,
socketTimeout: config.socketTimeout || 0,
host: config.host || 'localhost',
port: config.port || 143,
tls: config.tls,
@ -98,7 +99,6 @@ Connection.prototype.connect = function() {
socket = config.socket || new Socket();
socket.setKeepAlive(true);
socket.setTimeout(0);
this._sock = undefined;
this._tagcount = 0;
this._tmrConn = undefined;
@ -150,6 +150,21 @@ Connection.prototype.connect = function() {
};
this._sock.on('error', this._onError);
this._onSocketTimeout = function() {
clearTimeout(self._tmrConn);
clearTimeout(self._tmrAuth);
clearTimeout(self._tmrKeepalive);
self.state = 'disconnected';
self.debug && self.debug('[connection] Socket timeout');
var err = new Error('Socket timed out while talking to server');
err.source = 'socket-timeout';
self.emit('error', err);
socket.destroy();
};
this._sock.on('timeout', this._onSocketTimeout);
socket.setTimeout(config.socketTimeout);
socket.once('close', function(had_err) {
clearTimeout(self._tmrConn);
clearTimeout(self._tmrAuth);
@ -1675,6 +1690,9 @@ Connection.prototype._starttls = function() {
});
self._sock.on('error', self._onError);
self._sock.on('timeout', this._onSocketTimeout);
self._sock.setTimeout(config.socketTimeout);
self._parser.setStream(self._sock);
});
};

Loading…
Cancel
Save