select()-able timers

后端 未结 4 1004
长发绾君心
长发绾君心 2021-02-14 03:20

select() is a great system call. You can pack any number of file descriptors, socket descriptors, pipes, etc. and get notified in a synchronous fashion when input becomes availa

4条回答
  •  难免孤独
    2021-02-14 04:10

    Building on @MarkR, using a sorted structure to store callback+closure with an int and a pointer to an int. If the two ints have the same value then the event is active otherwise it was discarded.

    This way events can be discarded simply by increasing an int. Perhaps not the most straightforward solution but it was all I could think of.

    https://github.com/cheako/tor2web/tree/6ac67f80daaea01d14a5d07e6026e1af4258dc96/src

    hextree.c contains the code for the data structure used.
    schedule.c:156 is where the int is changed.
    gnutls.c:197 is where the timers are created.
    

提交回复
热议问题