Skip to content

Commit 175d18d

Browse files
committed
Fix for issue brianc#165. Use libuv events instead of libev events.
1 parent 9341efe commit 175d18d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/binding.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,18 @@ class Connection : public ObjectWrap {
7878
TRACE("created class");
7979
}
8080

81-
//static function called by libev as callback entrypoint
81+
//static function called by libuv as callback entrypoint
8282
static void
8383
io_event(uv_poll_t* w, int status, int revents)
8484
{
85+
8586
TRACE("Received IO event");
87+
88+
if(status == -1) {
89+
LOG("Connection error.");
90+
return;
91+
}
92+
8693
Connection *connection = static_cast<Connection*>(w->data);
8794
connection->HandleIOEvent(revents);
8895
}
@@ -379,30 +386,26 @@ class Connection : public ObjectWrap {
379386
Emit("notice", &notice);
380387
}
381388

382-
//called to process io_events from libev
389+
//called to process io_events from libuv
383390
void HandleIOEvent(int revents)
384391
{
385-
if(revents & EV_ERROR) {
386-
LOG("Connection error.");
387-
return;
388-
}
389392

390393
if(connecting_) {
391394
TRACE("Processing connecting_ io");
392395
HandleConnectionIO();
393396
return;
394397
}
395398

396-
if(revents & EV_READ) {
397-
TRACE("revents & EV_READ");
399+
if(revents & UV_READABLE) {
400+
TRACE("revents & UV_READABLE");
398401
if(PQconsumeInput(connection_) == 0) {
399402
End();
400403
EmitLastError();
401404
LOG("Something happened, consume input is 0");
402405
return;
403406
}
404407

405-
//declare handlescope as this method is entered via a libev callback
408+
//declare handlescope as this method is entered via a libuv callback
406409
//and not part of the public v8 interface
407410
HandleScope scope;
408411

@@ -432,8 +435,8 @@ class Connection : public ObjectWrap {
432435

433436
}
434437

435-
if(revents & EV_WRITE) {
436-
TRACE("revents & EV_WRITE");
438+
if(revents & UV_WRITABLE) {
439+
TRACE("revents & UV_WRITABLE");
437440
if (PQflush(connection_) == 0) {
438441
StopWrite();
439442
}

0 commit comments

Comments
 (0)