Lines Matching refs:reactor
29 #include "reactor.h"
40 static reactor_status_t run_reactor(reactor_t *reactor, int iterations, struct timeval *tv);
66 void reactor_free(reactor_t *reactor) {
67 if (!reactor)
70 list_free(reactor->objects);
71 close(reactor->event_fd);
72 free(reactor);
75 reactor_status_t reactor_start(reactor_t *reactor) {
76 assert(reactor != NULL);
77 return run_reactor(reactor, 0, NULL);
80 reactor_status_t reactor_run_once(reactor_t *reactor) {
81 assert(reactor != NULL);
82 return run_reactor(reactor, 1, NULL);
85 reactor_status_t reactor_run_once_timeout(reactor_t *reactor, timeout_t timeout_ms) {
86 assert(reactor != NULL);
91 return run_reactor(reactor, 1, &tv);
94 void reactor_stop(reactor_t *reactor) {
95 assert(reactor != NULL);
97 eventfd_write(reactor->event_fd, 1);
100 void reactor_register(reactor_t *reactor, reactor_object_t *obj) {
101 assert(reactor != NULL);
104 list_append(reactor->objects, obj);
107 void reactor_unregister(reactor_t *reactor, reactor_object_t *obj) {
108 assert(reactor != NULL);
111 list_remove(reactor->objects, obj);
114 // Runs the reactor loop for a maximum of |iterations| with the given timeout, |tv|.
117 // |reactor| may not be NULL.
118 static reactor_status_t run_reactor(reactor_t *reactor, int iterations, struct timeval *tv) {
119 assert(reactor != NULL);
126 FD_SET(reactor->event_fd, &read_set);
128 int max_fd = reactor->event_fd;
129 for (const list_node_t *iter = list_begin(reactor->objects); iter != list_end(reactor->objects); iter = list_next(iter)) {
154 if (FD_ISSET(reactor->event_fd, &read_set)) {
156 eventfd_read(reactor->event_fd, &value);
160 for (const list_node_t *iter = list_begin(reactor->objects); ret > 0 && iter != list_end(reactor->objects); iter = list_next(iter)) {