2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2019-05-30 04:30:10 +02:00
|
|
|
#include <ccan/io/io.h>
|
|
|
|
#include <common/timeout.h>
|
2022-01-03 19:45:35 +01:00
|
|
|
#include <db/exec.h>
|
2021-12-04 12:23:56 +01:00
|
|
|
#include <lightningd/io_loop_with_timers.h>
|
2019-05-30 04:30:10 +02:00
|
|
|
#include <lightningd/lightningd.h>
|
|
|
|
|
|
|
|
void *io_loop_with_timers(struct lightningd *ld)
|
|
|
|
{
|
|
|
|
void *retval = NULL;
|
|
|
|
struct timer *expired;
|
|
|
|
|
|
|
|
while (!retval) {
|
|
|
|
/* ~ccan/io's io_loop() continuously calls
|
|
|
|
* io_poll_lightningd() for all file descriptors registered
|
|
|
|
* with it, then calls their callbacks or closes them if they
|
|
|
|
* fail, as appropriate.
|
|
|
|
*
|
|
|
|
* It will only exit if there's an expired timer, *or* someone
|
|
|
|
* calls io_break, or if there are no more file descriptors
|
|
|
|
* (which never happens in our code). */
|
2019-06-14 05:49:23 +02:00
|
|
|
retval = io_loop(ld->timers, &expired);
|
2019-05-30 04:30:10 +02:00
|
|
|
|
|
|
|
/*~ Notice that timers are called here in the event loop like
|
|
|
|
* anything else, so there are no weird concurrency issues. */
|
|
|
|
if (expired) {
|
2019-07-24 06:58:53 +02:00
|
|
|
/* This routine is legal in early startup, too. */
|
|
|
|
if (ld->wallet)
|
|
|
|
db_begin_transaction(ld->wallet->db);
|
2021-12-06 15:45:50 +01:00
|
|
|
timer_expired(expired);
|
2019-07-24 06:58:53 +02:00
|
|
|
if (ld->wallet)
|
|
|
|
db_commit_transaction(ld->wallet->db);
|
2019-05-30 04:30:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|