Skip to content
Browse files

make socket 'end' and 'close' handlers more DRY

  • Loading branch information...
1 parent 8b236a9 commit ff09045060673886fa82c977b59625b32171279f @mscdex committed Dec 16, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 ftp.js
View
19 ftp.js
@@ -209,21 +209,24 @@ FTP.prototype.connect = function(options) {
var hasReset = false;
this._socket.once('end', function() {
- clearTimeout(timer);
- self.connected = false;
- self._reset();
- hasReset = true;
+ ondone();
self.emit('end');
});
this._socket.once('close', function(had_err) {
- clearTimeout(timer);
- self.connected = false;
- if (!hasReset)
- self._reset();
+ ondone();
self.emit('close', had_err);
});
+ function ondone() {
+ if (!hasReset) {
+ hasReset = true;
+ clearTimeout(timer);
+ self.connected = false;
+ self._reset();
+ }
+ }
+
this._socket.connect(this.options.port, this.options.host);
};

0 comments on commit ff09045

Please sign in to comment.
Something went wrong with that request. Please try again.