Merge pull request #388 from brianc/issues/320

Issues/320
This commit is contained in:
Brian C 2013-07-01 12:43:36 -07:00
commit 300e70c630
2 changed files with 12 additions and 1 deletions

View File

@ -6,7 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#define LOG(msg) printf("%s\n",msg); #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))); #define THROW(msg) return ThrowException(Exception::Error(String::New(msg)));
@ -251,6 +251,7 @@ public:
bool copyInMode_; bool copyInMode_;
bool reading_; bool reading_;
bool writing_; bool writing_;
bool ended_;
Connection () : ObjectWrap () Connection () : ObjectWrap ()
{ {
connection_ = NULL; connection_ = NULL;
@ -260,6 +261,7 @@ public:
copyInMode_ = false; copyInMode_ = false;
reading_ = false; reading_ = false;
writing_ = false; writing_ = false;
ended_ = false;
TRACE("Initializing ev watchers"); TRACE("Initializing ev watchers");
read_watcher_.data = this; read_watcher_.data = this;
write_watcher_.data = this; write_watcher_.data = this;
@ -369,6 +371,7 @@ protected:
//and hands off control to libev //and hands off control to libev
bool Connect(const char* conninfo) bool Connect(const char* conninfo)
{ {
if(ended_) return true;
connection_ = PQconnectStart(conninfo); connection_ = PQconnectStart(conninfo);
if (!connection_) { if (!connection_) {
@ -660,6 +663,7 @@ protected:
StopWrite(); StopWrite();
DestroyConnection(); DestroyConnection();
Emit("_end"); Emit("_end");
ended_ = true;
} }
private: private:

View File

@ -0,0 +1,7 @@
//test for issue #320
//
var helper = require('./test-helper');
var client = new helper.pg.Client(helper.config);
client.connect();
client.end();