aboutsummaryrefslogtreecommitdiff
path: root/src/pq/pq_event.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2021-07-25 16:05:56 +0200
committerChristian Grothoff <grothoff@gnunet.org>2021-07-25 16:13:23 +0200
commitb1a0dcd618befbbef049d1c2ce262c97f1c70a6f (patch)
treeb6e45449f5b4e7b68fc84a20995fab5d8f46ecd7 /src/pq/pq_event.c
parentaaeebebf670a2019a7ac8accb40e23cd923d396b (diff)
downloadgnunet-b1a0dcd618befbbef049d1c2ce262c97f1c70a6f.tar.gz
gnunet-b1a0dcd618befbbef049d1c2ce262c97f1c70a6f.zip
-complete new PQ event implementation, alas undertested
Diffstat (limited to 'src/pq/pq_event.c')
-rw-r--r--src/pq/pq_event.c87
1 files changed, 85 insertions, 2 deletions
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)
235} 235}
236 236
237 237
238/**
239 * Function called when the Postgres FD changes and we need
240 * to update the scheduler event loop task.
241 *
242 * @param cls a `struct GNUNET_PQ_Context *`
243 * @param fd the file descriptor, possibly -1
244 */
245static void
246scheduler_fd_cb (void *cls,
247 int fd);
248
249
250/**
251 * The GNUnet scheduler notifies us that we need to
252 * trigger the DB event poller.
253 *
254 * @param cls a `struct GNUNET_PQ_Context *`
255 */
256static void
257do_scheduler_notify (void *cls)
258{
259 struct GNUNET_PQ_Context *db = cls;
260
261 GNUNET_assert (db->scheduler_on);
262 GNUNET_assert (NULL != db->rfd);
263 GNUNET_PQ_event_do_poll (db);
264 db->event_task
265 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO,
266 db->rfd,
267 &do_scheduler_notify,
268 db);
269}
270
271
272/**
273 * Function called when the Postgres FD changes and we need
274 * to update the scheduler event loop task.
275 *
276 * @param cls a `struct GNUNET_PQ_Context *`
277 * @param fd the file descriptor, possibly -1
278 */
279static void
280scheduler_fd_cb (void *cls,
281 int fd)
282{
283 struct GNUNET_PQ_Context *db = cls;
284
285 if (NULL != db->event_task)
286 {
287 GNUNET_SCHEDULER_cancel (db->event_task);
288 db->event_task = NULL;
289 }
290 GNUNET_free (db->rfd);
291 if (-1 == fd)
292 return;
293 if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
294 return;
295 db->rfd = GNUNET_NETWORK_socket_box_native (fd);
296 db->event_task
297 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO,
298 db->rfd,
299 &do_scheduler_notify,
300 db);
301}
302
303
238void 304void
239GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) 305GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db)
240{ 306{
241 GNUNET_break (0); // FIXME: not implemented 307 int fd;
308
309 GNUNET_assert (! db->scheduler_on);
310 GNUNET_assert (NULL == db->sc);
311 db->scheduler_on = true;
312 db->sc = &scheduler_fd_cb;
313 db->sc_cls = db;
314 fd = PQsocket (db->conn);
315 scheduler_fd_cb (db,
316 fd);
242} 317}
243 318
244 319
245void 320void
246GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db) 321GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db)
247{ 322{
248 GNUNET_break (0); // FIXME: not implemented 323 GNUNET_assert (db->scheduler_on);
324 GNUNET_free (db->rfd);
325 db->sc = NULL;
326 db->scheduler_on = false;
327 if (NULL != db->event_task)
328 {
329 GNUNET_SCHEDULER_cancel (db->event_task);
330 db->event_task = NULL;
331 }
249} 332}
250 333
251 334