From 5b4e3cbb2e2f3a5cee75d64d0deba8fbc93c2d6b Mon Sep 17 00:00:00 2001 From: "Angus.Fenying" Date: Mon, 28 May 2018 12:08:14 +0800 Subject: [PATCH] Fixed the method `close` for TCP connection provider. --- CHANGES.md | 1 + src/samples/redis.ts | 6 ++++++ src/tcp.ts | 5 ++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e59c322..6d1afcd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,3 +3,4 @@ ## v0.1.1 - Added option `connectTimeout` for TCP connection provider. +- Fixed the method `close` for TCP connection provider. \ No newline at end of file diff --git a/src/samples/redis.ts b/src/samples/redis.ts index 0e7a9c1..d1f5a78 100644 --- a/src/samples/redis.ts +++ b/src/samples/redis.ts @@ -32,6 +32,10 @@ connector.on("connected", function() { c.on("data", function(data) { console.log(data.toString()); + + }).on("end", function() { + + console.log("Ended."); }); c.write("AUTH redis-passwd\r\n"); @@ -46,6 +50,8 @@ connector.on("connected", function() { c.write("MGET d b\r\n"); + setTimeout(() => connector.close(), 5000); + }).on("error", function(e) { console.error(e); diff --git a/src/tcp.ts b/src/tcp.ts index 05873d4..9a2d686 100644 --- a/src/tcp.ts +++ b/src/tcp.ts @@ -83,10 +83,9 @@ implements ConnectionProvider<$Net.Socket, NodeJS.ErrnoException> { public close(): void { - if (this._conn && !this._conn.destroyed) { + if (this._conn && this._conn.writable) { - this._conn.destroy(); - delete this._conn; + this._conn.end(); } }