diff --git a/Makefile b/Makefile index b9c1b5d..dd7f459 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ endif ifneq ("$(PGSQL)", "") S_SRC+=contrib/postgres/kore_pgsql.c - LDFLAGS+=-lpq + LDFLAGS+=-L$(shell pg_config --libdir) -lpq CFLAGS+=-I$(shell pg_config --includedir) -DKORE_USE_PGSQL endif diff --git a/src/bsd.c b/src/bsd.c index 2a0c8fd..e1cf9de 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -23,6 +23,10 @@ #include "kore.h" +#if defined(KORE_USE_PGSQL) +#include "contrib/postgres/kore_pgsql.h" +#endif + static int kfd = -1; static struct kevent *events; static u_int32_t nchanges; @@ -107,12 +111,20 @@ kore_platform_event_wait(void) if (type == KORE_TYPE_LISTENER) fatal("error on server socket"); +#if defined(KORE_USE_PGSQL) + if (type == KORE_TYPE_PGSQL_CONN) { + kore_pgsql_handle(events[i].udata, 1); + continue; + } +#endif + c = (struct connection *)events[i].udata; kore_connection_disconnect(c); continue; } - if (type == KORE_TYPE_LISTENER) { + switch (type) { + case KORE_TYPE_LISTENER: l = (struct listener *)events[i].udata; while ((worker->accepted < worker->accept_treshold) && @@ -128,7 +140,8 @@ kore_platform_event_wait(void) kore_platform_event_schedule(c->fd, EVFILT_WRITE, EV_ADD | EV_ONESHOT, c); } - } else { + break; + case KORE_TYPE_CONNECTION: c = (struct connection *)events[i].udata; if (events[i].filter == EVFILT_READ && !(c->flags & CONN_READ_BLOCK)) @@ -146,6 +159,14 @@ kore_platform_event_wait(void) c); } } + break; +#if defined(KORE_USE_PGSQL) + case KORE_TYPE_PGSQL_CONN: + kore_pgsql_handle(events[i].udata, 0); + break; +#endif + default: + fatal("wrong type in event %d", type); } } } @@ -180,6 +201,18 @@ kore_platform_disable_accept(void) kore_platform_event_schedule(l->fd, EVFILT_READ, EV_DISABLE, l); } +void +kore_platform_schedule_read(int fd, void *data) +{ + kore_platform_event_schedule(fd, EVFILT_READ, EV_ADD, data); +} + +void +kore_platform_disable_read(int fd) +{ + kore_platform_event_schedule(fd, EVFILT_READ, EV_DELETE, NULL); +} + void kore_platform_proctitle(char *title) {