ioloop.h revision 4c096615cb86a826fda377b87df22c579bfe5525
#ifndef IOLOOP_H
#define IOLOOP_H
#include <time.h>
struct io;
struct timeout;
struct ioloop;
struct istream;
enum io_condition {
IO_READ = 0x01,
IO_WRITE = 0x02,
/* IO_ERROR can be used to check when writable pipe's reader side
closes the pipe. For other uses IO_READ should work just as well. */
IO_ERROR = 0x04,
/* internal */
IO_NOTIFY = 0x08
};
enum io_notify_result {
/* Notify added successfully */
/* Specified file doesn't exist, can't wait on it */
/* Can't add notify for specified file. Main reasons for this:
a) No notify support at all, b) Only directory notifies supported */
};
typedef void io_callback_t(void *context);
typedef void timeout_callback_t(void *context);
/* Time when the I/O loop started calling handlers.
Can be used instead of time(NULL). */
extern time_t ioloop_time;
extern struct timeval ioloop_timeval;
extern struct ioloop *current_ioloop;
/* You can create different handlers for IO_READ and IO_WRITE. IO_READ and
IO_ERROR can't use different handlers (and there's no point anyway).
Don't try to add multiple handlers for the same type. It's not checked and
the behavior will be undefined. */
unsigned int source_linenum,
enum io_notify_result
io_add_notify(path + \
/* Remove I/O handler, and set io pointer to NULL. */
/* Like io_remove(), but assume that the file descriptor is already closed.
With some backends this simply frees the memory. */
/* Make sure the I/O callback is called by io_loop_run() even if there isn't
any input actually pending currently as seen by the OS. This may be useful
if some of the input has already read into some internal buffer and the
caller wants to handle it the same way as if the fd itself had input. */
/* Timeout handlers */
struct timeout *
struct timeout *
/* Remove timeout handler, and set timeout pointer to NULL. */
/* Reset timeout so it's next run after now+msecs. */
/* Refresh ioloop_time and ioloop_timeval variables. */
void io_loop_time_refresh(void);
/* call these if you wish to run the iteration only once */
struct ioloop *io_loop_create(void);
/* Specify the maximum number of fds we're expecting to use. */
/* Destroy I/O loop and set ioloop pointer to NULL. */
/* If time moves backwards or jumps forwards call the callback. */
/* Change the current_ioloop. */
/* Call the callback whenever ioloop is changed. */
/* This context is used for all further I/O and timeout callbacks that are
added until returning to ioloop. When a callback is called, this context is
again activated. */
/* Call the activate callback when this context is activated (I/O callback is
about to be called), and the deactivate callback when the context is
deactivated (I/O callback has returned). You can add multiple callbacks. */
/* Remove callbacks with the given callbacks and context. */
/* Returns the current context set to ioloop. */
/* Move the given I/O into the current I/O loop if it's not already
there. New I/O is returned, while the old one is freed. */
/* Like io_loop_move_io(), but for timeouts. */
/* Returns TRUE if any IOs have been added to the ioloop. */
/* Returns TRUE if there is a pending timeout that is going to be run
immediately. */
#endif