connection termination

This commit is contained in:
brianc 2011-02-20 19:20:13 -06:00
parent 93c1135389
commit 67e56fe832
2 changed files with 19 additions and 0 deletions

View File

@ -35,6 +35,7 @@ public:
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
NODE_SET_PROTOTYPE_METHOD(t, "end", End);
target->Set(String::NewSymbol("Connection"), t->GetFunction());
LOG("created class");
@ -83,6 +84,15 @@ public:
return Undefined();
}
static Handle<Value>
End(const Arguments& args)
{
HandleScope scope;
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
self->End();
}
ev_io read_watcher_;
ev_io write_watcher_;
PGconn *connection_;
@ -257,6 +267,11 @@ protected:
}
}
}
void End()
{
PQfinish(connection_);
}
private:
void HandleConnectionIO()

View File

@ -17,6 +17,7 @@ test('connecting with wrong parameters', function() {
con.connect("user=asldfkj hostaddr=127.0.0.1 port=5432 dbname=asldkfj");
assert.emits(con, 'error', function(error) {
console.log(error);
})
});
@ -26,5 +27,8 @@ test('connects', function() {
con.connect("user=brian hostaddr=127.0.0.1 port=5432 dbname=postgres");
assert.emits(con, 'connect', function() {
con._sendQuery("SELECT NOW()");
test('ends connection', function() {
con.end();
})
});
})