Permalink
Browse files

fixed connection close issue

  • Loading branch information...
1 parent 7cc94ff commit a76a988765ef80fd946056219721a6a5f7f983c2 andris Reinman committed Jul 4, 2012
Showing with 44 additions and 18 deletions.
  1. +16 −1 lib/client.js
  2. +1 −1 package.json
  3. +27 −16 tools/proxy.js
View
@@ -458,6 +458,8 @@ IMAPClient.prototype._onClose = function(){
if(this.debug){
console.log("EVENT: CLOSE");
}
+
+ this.close();
};
/**
@@ -470,6 +472,8 @@ IMAPClient.prototype._onEnd = function(){
if(this.debug){
console.log("EVENT: END");
}
+
+ this.close();
};
/**
@@ -645,7 +649,7 @@ IMAPClient.prototype._send = function(data, callback, prewrite){
*/
IMAPClient.prototype._processCommandQueue = function(){
- if(!this._commandQueue.length){
+ if(!this._commandQueue.length || !this._connection){
return;
}
@@ -1573,8 +1577,19 @@ IMAPClient.prototype.idle = function(){
* // FIXME - should LOGOUT first!
*/
IMAPClient.prototype.close = function(){
+ if(!this._connection){
+ return;
+ }
+
var socket = this._connection.socket || this._connection;
+
if(socket && !socket.destroyed){
socket.destroy();
}
+
+ this._connection = false;
+ this._commandQueue = [];
+ clearTimeout(this._shouldIdleTimer);
+ clearTimeout(this._idleTimer);
+ this.emit("close");
};
View
@@ -1,6 +1,6 @@
{
"name": "inbox",
- "version": "0.1.6",
+ "version": "0.1.7",
"author" : "Andris Reinman",
"maintainers":[
{
View
@@ -40,22 +40,33 @@ var sessionCounter = 0,
socket.end();
}
});
-
- var target = (targetSecure?tls:net).connect(targetPort, targetHost, function() {
-
- console.log("Server connected");
-
- socket = targetSecure ? target.socket : target;
-
- socket.setKeepAlive(true);
-
- if(client && !client.destroyed){
- client.pipe(target);
- }else{
- socket.end();
- }
-
- });
+ console.log(targetPort, targetHost)
+ var params = [targetPort, targetHost, function() {
+
+ console.log("Server connected");
+
+ socket = targetSecure ? target.socket : target;
+
+ socket.setKeepAlive(true);
+
+ if(client && !client.destroyed){
+ client.pipe(target);
+ }else{
+ socket.end();
+ }
+
+ }];
+
+ if(targetSecure){
+ params.shift();
+ params.shift();
+ params.unshift({
+ port: targetPort,
+ host: targetHost
+ });
+ }
+
+ var target = (targetSecure?tls:net).connect.apply((targetSecure?tls:net), params);
target.on('data', function(chunk) {
var str = (chunk || "").toString("utf-8").trim();

0 comments on commit a76a988

Please sign in to comment.