1 #ifndef IOLOOP_PRIVATE_H 2 #define IOLOOP_PRIVATE_H 3 4 #include "priorityq.h" 5 #include "ioloop.h" 6 #include "array-decl.h" 7 8 #ifndef IOLOOP_INITIAL_FD_COUNT 9 # define IOLOOP_INITIAL_FD_COUNT 128 10 #endif 11 12 struct ioloop { 13 struct ioloop *prev; 14 15 struct ioloop_context *cur_ctx; 16 17 struct io_file *io_files; 18 struct io_file *next_io_file; 19 struct priorityq *timeouts; 20 ARRAY(struct timeout *) timeouts_new; 21 struct io_wait_timer *wait_timers; 22 23 struct ioloop_handler_context *handler_context; 24 struct ioloop_notify_handler_context *notify_handler_context; 25 unsigned int max_fd_count; 26 27 io_loop_time_moved_callback_t *time_moved_callback; 28 struct timeval next_max_time; 29 uint64_t ioloop_wait_usecs; 30 struct timeval wait_started; 31 32 unsigned int io_pending_count; 33 34 bool running:1; 35 bool iolooping:1; 36 bool stop_after_run_loop:1; 37 }; 38 39 struct io { 40 enum io_condition condition; 41 const char *source_filename; 42 unsigned int source_linenum; 43 /* trigger I/O callback even if OS doesn't think there is input 44 pending */ 45 bool pending; 46 /* This IO event shouldn't be the only thing being waited on, because 47 it would just result in infinite wait. */ 48 bool never_wait_alone; 49 50 io_callback_t *callback; 51 void *context; 52 53 struct ioloop *ioloop; 54 struct ioloop_context *ctx; 55 }; 56 57 struct io_file { 58 struct io io; 59 60 /* use a doubly linked list so that io_remove() is quick */ 61 struct io_file *prev, *next; 62 63 int refcount; 64 int fd; 65 66 /* only for io_add_istream(), a bit kludgy to be here.. */ 67 struct istream *istream; 68 }; 69 70 struct timeout { 71 struct priorityq_item item; 72 const char *source_filename; 73 unsigned int source_linenum; 74 75 unsigned int msecs; 76 struct timeval next_run; 77 78 timeout_callback_t *callback; 79 void *context; 80 81 struct ioloop *ioloop; 82 struct ioloop_context *ctx; 83 84 bool one_shot:1; 85 }; 86 87 struct io_wait_timer { 88 struct io_wait_timer *prev, *next; 89 const char *source_filename; 90 unsigned int source_linenum; 91 92 struct ioloop *ioloop; 93 uint64_t usecs; 94 }; 95 96 struct ioloop_context_callback { 97 io_callback_t *activate; 98 io_callback_t *deactivate; 99 void *context; 100 bool activated; 101 }; 102 103 struct ioloop_context { 104 int refcount; 105 struct ioloop *ioloop; 106 ARRAY(struct ioloop_context_callback) callbacks; 107 }; 108 109 int io_loop_run_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r); 110 void io_loop_handle_timeouts(struct ioloop *ioloop); 111 void io_loop_call_io(struct io *io); 112 113 void io_loop_handler_run_internal(struct ioloop *ioloop); 114 115 /* I/O handler calls */ 116 void io_loop_handle_add(struct io_file *io); 117 void io_loop_handle_remove(struct io_file *io, bool closed); 118 119 void io_loop_handler_init(struct ioloop *ioloop, unsigned int initial_fd_count); 120 void io_loop_handler_deinit(struct ioloop *ioloop); 121 122 void io_loop_notify_remove(struct io *io); 123 void io_loop_notify_handler_deinit(struct ioloop *ioloop); 124 125 #endif 126