Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

libev_helper.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 timeout;
  34. };
  35. /**
  36. * Initialize watcher similar to event_init
  37. * @param ev
  38. * @param fd
  39. * @param what
  40. * @param cb
  41. * @param ud
  42. */
  43. void rspamd_ev_watcher_init (struct rspamd_io_ev *ev,
  44. int fd, short what, rspamd_ev_cb cb, void *ud);
  45. /**
  46. * Start watcher with the specific timeout
  47. * @param loop
  48. * @param ev
  49. * @param timeout
  50. */
  51. void rspamd_ev_watcher_start (struct ev_loop *loop,
  52. struct rspamd_io_ev *ev,
  53. ev_tstamp timeout);
  54. /**
  55. * Stops watcher and clean it up
  56. * @param loop
  57. * @param ev
  58. */
  59. void rspamd_ev_watcher_stop (struct ev_loop *loop,
  60. struct rspamd_io_ev *ev);
  61. /**
  62. * Convenience function to reschedule watcher with different events
  63. * @param loop
  64. * @param ev
  65. * @param what
  66. */
  67. void rspamd_ev_watcher_reschedule (struct ev_loop *loop,
  68. struct rspamd_io_ev *ev,
  69. short what);
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif