event.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Copyright (c) 2003-2006 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. extern struct timeval current_time;
  20. extern struct timeval null_time;
  21. extern int diskIsClean;
  22. typedef struct _TimeEventHandler {
  23. struct timeval time;
  24. struct _TimeEventHandler *previous, *next;
  25. int (*handler)(struct _TimeEventHandler*);
  26. char data[1];
  27. } TimeEventHandlerRec, *TimeEventHandlerPtr;
  28. typedef struct _FdEventHandler {
  29. short fd;
  30. short poll_events;
  31. struct _FdEventHandler *previous, *next;
  32. int (*handler)(int, struct _FdEventHandler*);
  33. char data[1];
  34. } FdEventHandlerRec, *FdEventHandlerPtr;
  35. typedef struct _ConditionHandler {
  36. struct _Condition *condition;
  37. struct _ConditionHandler *previous, *next;
  38. int (*handler)(int, struct _ConditionHandler*);
  39. char data[1];
  40. } ConditionHandlerRec, *ConditionHandlerPtr;
  41. typedef struct _Condition {
  42. ConditionHandlerPtr handlers;
  43. } ConditionRec, *ConditionPtr;
  44. void initEvents(void);
  45. void uninitEvents(void);
  46. #ifdef HAVE_FORK
  47. void interestingSignals(sigset_t *ss);
  48. #endif
  49. TimeEventHandlerPtr scheduleTimeEvent(int seconds,
  50. int (*handler)(TimeEventHandlerPtr),
  51. int dsize, void *data);
  52. int timeval_minus_usec(const struct timeval *s1, const struct timeval *s2)
  53. ATTRIBUTE((pure));
  54. void cancelTimeEvent(TimeEventHandlerPtr);
  55. int allocateFdEventNum(int fd);
  56. void deallocateFdEventNum(int i);
  57. void timeToSleep(struct timeval *);
  58. void runTimeEventQueue(void);
  59. FdEventHandlerPtr makeFdEvent(int fd, int poll_events,
  60. int (*handler)(int, FdEventHandlerPtr),
  61. int dsize, void *data);
  62. FdEventHandlerPtr registerFdEvent(int fd, int poll_events,
  63. int (*handler)(int, FdEventHandlerPtr),
  64. int dsize, void *data);
  65. FdEventHandlerPtr registerFdEventHelper(FdEventHandlerPtr event);
  66. void unregisterFdEvent(FdEventHandlerPtr event);
  67. void pokeFdEvent(int fd, int status, int what);
  68. int workToDo(void);
  69. void eventLoop(void);
  70. ConditionPtr makeCondition(void);
  71. void initCondition(ConditionPtr);
  72. void signalCondition(ConditionPtr condition);
  73. ConditionHandlerPtr
  74. conditionWait(ConditionPtr condition,
  75. int (*handler)(int, ConditionHandlerPtr),
  76. int dsize, void *data);
  77. void unregisterConditionHandler(ConditionHandlerPtr);
  78. void abortConditionHandler(ConditionHandlerPtr);
  79. void polipoExit(void);