Connection: make end() more graceful, add destroy() for more forceful

fork
mscdex 11 years ago
parent 332dfc7435
commit dff2ff4a90

@ -396,7 +396,9 @@ Connection Instance Methods
* **connect**() - _(void)_ - Attempts to connect and authenticate with the IMAP server.
* **end**() - _(void)_ - Closes the connection to the server.
* **end**() - _(void)_ - Closes the connection to the server after all requests in the queue have been sent.
* **destroy**() - _(void)_ - Immediately destroys the connection to the server.
* **openBox**(< _string_ >mailboxName[, < _boolean_ >openReadOnly=false[, < _object_ >modifiers]], < _function_ >callback) - _(void)_ - Opens a specific mailbox that exists on the server. `mailboxName` should include any necessary prefix/path. `modifiers` is used by IMAP extensions. `callback` has 2 parameters: < _Error_ >err, < _Box_ >mailbox.

@ -67,6 +67,7 @@ function Connection(config) {
this._idle = {};
this._parser = undefined;
this._curReq = undefined;
this._ending = false;
this.delimiter = undefined;
this.namespaces = undefined;
this.state = 'disconnected';
@ -80,6 +81,17 @@ Connection.prototype.connect = function() {
socket = new Socket();
socket.setKeepAlive(true);
socket.setTimeout(0);
this._sock = undefined;
this._tagcount = 0;
this._tmrConn = undefined;
this._queue = [];
this._box = undefined;
this._idle = {};
this._parser = undefined;
this._curReq = undefined;
this._ending = false;
this.delimiter = undefined;
this.namespaces = undefined;
this.state = 'disconnected';
if (config.tls) {
@ -159,7 +171,6 @@ Connection.prototype.connect = function() {
stream.resume(); // a body we didn't ask for?
});
parser.on('continue', function(info) {
// only needed for IDLE and APPEND
var type = self._curReq.type;
if (type === 'IDLE') {
// now idling
@ -217,10 +228,19 @@ Connection.prototype.serverSupports = function(cap) {
return (this._caps && this._caps.indexOf(cap) > -1);
};
Connection.prototype.end = function() {
Connection.prototype.destroy = function() {
this._queue = [];
this._curReq = undefined;
this._sock.end();
};
Connection.prototype.end = function() {
var self = this;
this._enqueue('LOGOUT', function() {
self.destroy();
});
};
Connection.prototype.append = function(data, options, cb) {
if (typeof options === 'function') {
cb = options;
@ -1498,7 +1518,7 @@ Connection.prototype._starttls = function() {
};
Connection.prototype._processQueue = function() {
if (this._curReq || !this._queue.length || !this._sock.writable)
if (this._curReq || !this._queue.length || !this._sock || !this._sock.writable)
return;
this._curReq = this._queue.shift();

Loading…
Cancel
Save