Permalink
Browse files

Reorganised socket connect code to allow event handlers to attach bef…

…ore connection
  • Loading branch information...
1 parent a138edc commit eb3463d65b8f0638e7f35da2d8b9a700293de8df @argon argon committed Nov 30, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/connection.js
View
@@ -3,6 +3,7 @@ var Errors = require('./errors');
var fs = require('fs');
var q = require('q');
var tls = require('tls');
+var net = require('net');
var sysu = require('util');
var util = require('./util');
var events = require('events');
@@ -173,7 +174,8 @@ Connection.prototype.connect = function () {
}
socketOptions.passphrase = this.options.passphrase;
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized;
-
+ socketOptions.socket = new net.Stream();
+
this.socket = tls.connect(
this.options['port'],
this.options['gateway'],
@@ -195,6 +197,8 @@ Connection.prototype.connect = function () {
this.socket.on("clientError", this.errorOccurred.bind(this));
this.socket.on("end", this.destroyConnection.bind(this));
this.socket.once("close", this.restartConnection.bind(this));
+
+ this.socket.socket.connect(this.options['port'], this.options['gateway']);
}.bind(this)).fail(function (error) {
debug("Module initialisation error:", error);
this.emit('error', error);

0 comments on commit eb3463d

Please sign in to comment.