ioloop-internal.h revision 90da11b31d498cd653ec7232b334b6057198ab46
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef __IOLOOP_INTERNAL_H
1d4f710106fb498750456724628da6063e012e6dTimo Sirainen#define __IOLOOP_INTERNAL_H
46552a931924c2d743f045e95b08c3ce6beda91aTimo Sirainen
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen#include "ioloop.h"
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainen
d3d769026fae5d21c2d29614d3bc4579e8d79e81Timo Sirainenstruct ioloop {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct ioloop *prev;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
baebb412a9a5a44b1756e01cfa3b99f5d8a846b6Timo Sirainen pool_t pool;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
b55f914c0ade77252cfd798ea8eb9a84bda56315Timo Sirainen struct io *ios;
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainen struct io *notifys, *event_io;
b55f914c0ade77252cfd798ea8eb9a84bda56315Timo Sirainen struct io *next_io;
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainen struct timeout *timeouts; /* sorted by next_run */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainen struct ioloop_handler_data *handler_data;
92c49f3005f4dff1a6f576fffa8112ef6d1cae7fTimo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen unsigned int running:1;
1d2c463d23f09f15727edae9c78b07ec6a7a27daTimo Sirainen};
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct io {
de754cb78f75e8b3b994cddafe41c9ed1467c33dTimo Sirainen struct io *prev, *next;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
4ead43ecc06d10047998966c4dc0b142ecce4b66Timo Sirainen int fd;
1d4f710106fb498750456724628da6063e012e6dTimo Sirainen enum io_condition condition;
1d4f710106fb498750456724628da6063e012e6dTimo Sirainen
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainen io_callback_t *callback;
0b3e92b6043435c5aa9f1cf1d04b632f3e19abd9Phil Carmody void *context;
0b3e92b6043435c5aa9f1cf1d04b632f3e19abd9Phil Carmody};
ab0d9eecd85f74acae18fe88529302e0776cc500Timo Sirainen
ad004e44be109684521494b5af2ad1da39b8bb27Timo Sirainenstruct timeout {
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen struct timeout *next;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen struct timeval next_run;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen unsigned int msecs;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen unsigned int run_now:1;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen unsigned int destroyed:1;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen timeout_callback_t *callback;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen void *context;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen};
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainenint io_loop_get_wait_time(struct timeout *timeout, struct timeval *tv,
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen struct timeval *tv_now);
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainenvoid io_loop_handle_timeouts(struct ioloop *ioloop);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* call only when timeout->destroyed is TRUE */
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenvoid timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen/* I/O handler calls */
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenvoid io_loop_handle_add(struct ioloop *ioloop, struct io *io);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenvoid io_loop_handle_remove(struct ioloop *ioloop, struct io *io);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenvoid io_loop_handler_init(struct ioloop *ioloop);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenvoid io_loop_handler_deinit(struct ioloop *ioloop);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenstruct io *io_loop_notify_add(struct ioloop *ioloop, int fd,
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen enum io_condition condition,
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen io_callback_t *callback, void *context);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainenvoid io_loop_notify_remove(struct ioloop *ioloop, struct io *io);
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen#endif
7a94f950fd1dcc81537acfc8adb030b5e703d722Timo Sirainen