ioloop-private.h revision bd3f036fda5cf08d7b23e2681ecc759ad71843f5
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch#ifndef IOLOOP_PRIVATE_H
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#define IOLOOP_PRIVATE_H
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#include "priorityq.h"
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#include "ioloop.h"
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#include "array-decl.h"
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#ifndef IOLOOP_INITIAL_FD_COUNT
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen# define IOLOOP_INITIAL_FD_COUNT 128
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#endif
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainenstruct ioloop {
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct ioloop *prev;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct ioloop_context *cur_ctx;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct io_file *io_files;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct io_file *next_io_file;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct priorityq *timeouts;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen ARRAY(struct timeout *) timeouts_new;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct ioloop_handler_context *handler_context;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct ioloop_notify_handler_context *notify_handler_context;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen unsigned int max_fd_count;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
8b2cf1c1bd8ddcea0525b62fd35ba76e136828a1Timo Sirainen io_loop_time_moved_callback_t *time_moved_callback;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen time_t next_max_time;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen uint64_t ioloop_wait_usecs;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct timeval wait_started;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen unsigned int io_pending_count;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen bool running:1;
bool iolooping:1;
};
struct io {
enum io_condition condition;
const char *source_filename;
unsigned int source_linenum;
/* trigger I/O callback even if OS doesn't think there is input
pending */
bool pending;
io_callback_t *callback;
void *context;
struct ioloop *ioloop;
struct ioloop_context *ctx;
};
struct io_file {
struct io io;
/* use a doubly linked list so that io_remove() is quick */
struct io_file *prev, *next;
int refcount;
int fd;
/* only for io_add_istream(), a bit kludgy to be here.. */
struct istream *istream;
};
struct timeout {
struct priorityq_item item;
const char *source_filename;
unsigned int source_linenum;
unsigned int msecs;
struct timeval next_run;
timeout_callback_t *callback;
void *context;
struct ioloop *ioloop;
struct ioloop_context *ctx;
bool one_shot:1;
};
struct ioloop_context_callback {
io_callback_t *activate;
io_callback_t *deactivate;
void *context;
bool activated;
};
struct ioloop_context {
int refcount;
struct ioloop *ioloop;
ARRAY(struct ioloop_context_callback) callbacks;
};
int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r);
void io_loop_handle_timeouts(struct ioloop *ioloop);
void io_loop_call_io(struct io *io);
void io_loop_handler_run_internal(struct ioloop *ioloop);
/* I/O handler calls */
void io_loop_handle_add(struct io_file *io);
void io_loop_handle_remove(struct io_file *io, bool closed);
void io_loop_handler_init(struct ioloop *ioloop, unsigned int initial_fd_count);
void io_loop_handler_deinit(struct ioloop *ioloop);
void io_loop_notify_remove(struct io *io);
void io_loop_notify_handler_deinit(struct ioloop *ioloop);
void io_loop_context_activate(struct ioloop_context *ctx);
void io_loop_context_deactivate(struct ioloop_context *ctx);
#endif