You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libev_helper.h 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * Copyright 2019 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RSPAMD_LIBEV_HELPER_H
  17. #define RSPAMD_LIBEV_HELPER_H
  18. #include "config.h"
  19. #include "contrib/libev/ev.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /*
  24. * This module is a little helper to simplify libevent->libev transition
  25. * It allows to create timed IO watchers utilising both
  26. */
  27. typedef void (*rspamd_ev_cb) (int fd, short what, void *ud);
  28. struct rspamd_io_ev {
  29. ev_io io;
  30. ev_timer tm;
  31. rspamd_ev_cb cb;
  32. void *ud;
  33. ev_tstamp last_activity;
  34. ev_tstamp timeout;
  35. };
  36. /**
  37. * Initialize watcher similar to event_init
  38. * @param ev
  39. * @param fd
  40. * @param what
  41. * @param cb
  42. * @param ud
  43. */
  44. void rspamd_ev_watcher_init (struct rspamd_io_ev *ev,
  45. int fd, short what, rspamd_ev_cb cb, void *ud);
  46. /**
  47. * Start watcher with the specific timeout
  48. * @param loop
  49. * @param ev
  50. * @param timeout
  51. */
  52. void rspamd_ev_watcher_start (struct ev_loop *loop,
  53. struct rspamd_io_ev *ev,
  54. ev_tstamp timeout);
  55. /**
  56. * Stops watcher and clean it up
  57. * @param loop
  58. * @param ev
  59. */
  60. void rspamd_ev_watcher_stop (struct ev_loop *loop,
  61. struct rspamd_io_ev *ev);
  62. /**
  63. * Convenience function to reschedule watcher with different events
  64. * @param loop
  65. * @param ev
  66. * @param what
  67. */
  68. void rspamd_ev_watcher_reschedule (struct ev_loop *loop,
  69. struct rspamd_io_ev *ev,
  70. short what);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif