From b1a0dcd618befbbef049d1c2ce262c97f1c70a6f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Jul 2021 16:05:56 +0200 Subject: -complete new PQ event implementation, alas undertested --- src/pq/pq_event.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) (limited to 'src/pq/pq_event.c') diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c index b87aa6c5a..879caf842 100644 --- a/src/pq/pq_event.c +++ b/src/pq/pq_event.c @@ -235,17 +235,100 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db) } +/** + * Function called when the Postgres FD changes and we need + * to update the scheduler event loop task. + * + * @param cls a `struct GNUNET_PQ_Context *` + * @param fd the file descriptor, possibly -1 + */ +static void +scheduler_fd_cb (void *cls, + int fd); + + +/** + * The GNUnet scheduler notifies us that we need to + * trigger the DB event poller. + * + * @param cls a `struct GNUNET_PQ_Context *` + */ +static void +do_scheduler_notify (void *cls) +{ + struct GNUNET_PQ_Context *db = cls; + + GNUNET_assert (db->scheduler_on); + GNUNET_assert (NULL != db->rfd); + GNUNET_PQ_event_do_poll (db); + db->event_task + = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, + db->rfd, + &do_scheduler_notify, + db); +} + + +/** + * Function called when the Postgres FD changes and we need + * to update the scheduler event loop task. + * + * @param cls a `struct GNUNET_PQ_Context *` + * @param fd the file descriptor, possibly -1 + */ +static void +scheduler_fd_cb (void *cls, + int fd) +{ + struct GNUNET_PQ_Context *db = cls; + + if (NULL != db->event_task) + { + GNUNET_SCHEDULER_cancel (db->event_task); + db->event_task = NULL; + } + GNUNET_free (db->rfd); + if (-1 == fd) + return; + if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)) + return; + db->rfd = GNUNET_NETWORK_socket_box_native (fd); + db->event_task + = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, + db->rfd, + &do_scheduler_notify, + db); +} + + void GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) { - GNUNET_break (0); // FIXME: not implemented + int fd; + + GNUNET_assert (! db->scheduler_on); + GNUNET_assert (NULL == db->sc); + db->scheduler_on = true; + db->sc = &scheduler_fd_cb; + db->sc_cls = db; + fd = PQsocket (db->conn); + scheduler_fd_cb (db, + fd); } void GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db) { - GNUNET_break (0); // FIXME: not implemented + GNUNET_assert (db->scheduler_on); + GNUNET_free (db->rfd); + db->sc = NULL; + db->scheduler_on = false; + if (NULL != db->event_task) + { + GNUNET_SCHEDULER_cancel (db->event_task); + db->event_task = NULL; + } } -- cgit v1.2.3