Comparing version 0.1.23 to 0.1.24
@@ -14,3 +14,2 @@ var net = require('net'); | ||
connect(options) { | ||
var buf = Buffer.concat([]); | ||
this.opts = options; | ||
@@ -24,8 +23,15 @@ | ||
this.client = this.srv.connect(this.opts, () => { | ||
var socket = this.srv.connect(this.opts, () => { | ||
console.log('open connection:'+JSON.stringify(this.opts)); | ||
}) | ||
this.client.on('data', async (data) => { | ||
this.client.pause(); | ||
this.spawn(socket); | ||
} | ||
spawn(socket) { | ||
this.socket = socket; | ||
var buf = Buffer.concat([]); | ||
this.socket.on('data', async (data) => { | ||
this.socket.pause(); | ||
data = Buffer.concat([buf, data], buf.length + data.length); | ||
@@ -40,11 +46,11 @@ var leftover = await this.consumer.read({data, options: this.opts}); | ||
this.client.resume(); | ||
this.socket.resume(); | ||
}) | ||
this.client.on('end', (...args) => { | ||
this.socket.on('end', (...args) => { | ||
this.emit('end', ...args) | ||
// this.client.destroy(); | ||
// this.socket.destroy(); | ||
}) | ||
this.client.on('error', error => { | ||
this.socket.on('error', error => { | ||
console.log('client error: '+error); | ||
@@ -60,3 +66,3 @@ this.emit('error', error) | ||
write(data) { | ||
this.client.write(data); | ||
this.socket.write(data); | ||
} | ||
@@ -67,3 +73,3 @@ | ||
for (let data of trans.tx) { | ||
this.client.write(data); | ||
this.socket.write(data); | ||
} | ||
@@ -73,5 +79,5 @@ } | ||
end() { | ||
if(this.client) { | ||
this.client.unref(); | ||
this.client.end(); | ||
if(this.socket) { | ||
this.socket.unref(); | ||
this.socket.end(); | ||
} | ||
@@ -78,0 +84,0 @@ } |
@@ -60,3 +60,3 @@ { | ||
"optionalDependencies": {}, | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"directories": { | ||
@@ -63,0 +63,0 @@ "lib": "lib" |
58009
662