Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Allow "socket" option to pass existing socket (e.g. for SOCKS5 proxying) #784

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function Client (options) {

this._socket = null
this.connected = false
this.connect()
this.connect(options.socket)
}
util.inherits(Client, EventEmitter)
module.exports = Client
Expand Down Expand Up @@ -785,7 +785,7 @@ Client.prototype.destroy = function destroy (err) {
/**
* Initiate LDAP connection.
*/
Client.prototype.connect = function connect () {
Client.prototype.connect = function connect (__socket) {
if (this.connecting || this.connected) {
return
}
Expand Down Expand Up @@ -833,7 +833,12 @@ Client.prototype.connect = function connect () {
socket = tls.connect(port, host, self.tlsOptions)
socket.once('secureConnect', onConnect)
} else {
socket = net.connect(port, host)
if (__socket) {
socket = __socket;
setImmediate(() => { socket.emit('connect') }); // This is for the socket.once('connect', ...) below
} else {
socket = net.connect(port, host);
}
socket.once('connect', onConnect)
}
socket.once('error', onResult)
Expand Down