Merge pull request #149 from booo/c++

additional changes for the native binding
This commit is contained in:
Brian Carlson 2012-07-11 20:38:51 -07:00
commit 0d78763066
3 changed files with 18 additions and 26 deletions

View File

@ -30,7 +30,6 @@ p.connect = function(cb) {
if(err) {
return cb ? cb(err) : self.emit('error', err);
}
nativeConnect.call(self, conString);
if(cb) {
var errCallback;
var connectCallback = function() {
@ -46,6 +45,7 @@ p.connect = function(cb) {
self.once('connect', connectCallback);
self.once('error', errCallback);
}
nativeConnect.call(self, conString);
})
}

View File

@ -234,18 +234,17 @@ public:
uv_poll_t read_watcher_;
uv_poll_t write_watcher_;
PGconn *connection_;
bool connecting_;
bool ioInitialized_;
Connection () : ObjectWrap ()
{
connection_ = NULL;
connecting_ = false;
ioInitialized_ = false;
TRACE("Initializing ev watchers");
//ev_init(&read_watcher_, io_event);
read_watcher_.data = this;
//ev_init(&write_watcher_, io_event);
write_watcher_.data = this;
}
@ -308,7 +307,7 @@ protected:
{
if(PQflush(connection_) == 1) {
TRACE("Flushing");
//ev_io_start(EV_DEFAULT_ &write_watcher_);
uv_poll_start(&write_watcher_, UV_WRITABLE, io_event);
}
}
@ -331,15 +330,14 @@ protected:
LOG("Connection couldn't be created");
}
if (PQsetnonblocking(connection_, 1) == -1) {
LOG("Unable to set connection to non-blocking");
return false;
}
ConnStatusType status = PQstatus(connection_);
if(CONNECTION_BAD == status) {
LOG("Bad connection status");
return false;
}
if (PQsetnonblocking(connection_, 1) == -1) {
LOG("Unable to set connection to non-blocking");
return false;
}
@ -353,13 +351,11 @@ protected:
PQsetNoticeProcessor(connection_, NoticeReceiver, this);
TRACE("Setting watchers to socket");
uv_poll_init(uv_default_loop(), &read_watcher_, fd);
uv_poll_init(uv_default_loop(), &write_watcher_, fd);
TRACE("Setting watchers to socket");
//uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb)
//ev_io_set(&read_watcher_, fd, EV_READ);
//ev_io_set(&write_watcher_, fd, EV_WRITE);
ioInitialized_ = true;
connecting_ = true;
StartWrite();
@ -623,28 +619,28 @@ private:
void StopWrite()
{
TRACE("Stoping write watcher");
//ev_io_stop(EV_DEFAULT_ &write_watcher_);
if(ioInitialized_) {
uv_poll_stop(&write_watcher_);
}
}
void StartWrite()
{
TRACE("Starting write watcher");
uv_poll_start(&write_watcher_, UV_WRITABLE, io_event);
//ev_io_start(EV_DEFAULT_ &write_watcher_);
}
void StopRead()
{
TRACE("Stoping read watcher");
//ev_io_stop(EV_DEFAULT_ &read_watcher_);
if(ioInitialized_) {
uv_poll_stop(&read_watcher_);
}
}
void StartRead()
{
TRACE("Starting read watcher");
//ev_io_start(EV_DEFAULT_ &read_watcher_);
uv_poll_start(&read_watcher_, UV_READABLE, io_event);
}
//Converts a v8 array to an array of cstrings

View File

@ -80,7 +80,6 @@ test('error handling', function(){
});
test('non-query error', function() {
return false;
var client = new Client({
user:'asldkfjsadlfkj'
@ -90,7 +89,6 @@ test('error handling', function(){
});
test('non-query error with callback', function() {
return false;
var client = new Client({
user:'asldkfjsadlfkj'
});
@ -117,7 +115,6 @@ test('non-error calls supplied callback', function() {
});
test('when connecting to invalid host', function() {
return false;
var client = new Client({
user: 'brian',
password: '1234',
@ -128,7 +125,6 @@ test('when connecting to invalid host', function() {
});
test('when connecting to invalid host with callback', function() {
return false;
var client = new Client({
user: 'brian',
password: '1234',