From 75181492f2069b00df87750fab7d95e5ba6383cb Mon Sep 17 00:00:00 2001 From: bmc Date: Sun, 30 Jun 2013 12:03:58 -0700 Subject: [PATCH] Fix native quick disconnect hang Do not initialize connection if connection has been ended --- src/binding.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/binding.cc b/src/binding.cc index e0b087e0..0ad0cdb1 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -6,7 +6,7 @@ #include #define LOG(msg) printf("%s\n",msg); -#define TRACE(msg) //printf(%s\n, msg); +#define TRACE(msg) //printf("%s\n", msg); #define THROW(msg) return ThrowException(Exception::Error(String::New(msg))); @@ -251,6 +251,7 @@ public: bool copyInMode_; bool reading_; bool writing_; + bool ended_; Connection () : ObjectWrap () { connection_ = NULL; @@ -260,6 +261,7 @@ public: copyInMode_ = false; reading_ = false; writing_ = false; + ended_ = false; TRACE("Initializing ev watchers"); read_watcher_.data = this; write_watcher_.data = this; @@ -369,6 +371,7 @@ protected: //and hands off control to libev bool Connect(const char* conninfo) { + if(ended_) return true; connection_ = PQconnectStart(conninfo); if (!connection_) { @@ -660,6 +663,7 @@ protected: StopWrite(); DestroyConnection(); Emit("_end"); + ended_ = true; } private: