PacketPassInterface.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @file PacketPassInterface.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <flow/PacketPassInterface.h>
  23. void _PacketPassInterface_job_operation (PacketPassInterface *i)
  24. {
  25. ASSERT(i->d_user_busy)
  26. ASSERT(i->buf_len >= 0)
  27. ASSERT(i->buf_len <= i->mtu)
  28. ASSERT(i->handler_done)
  29. DebugObject_Access(&i->d_obj);
  30. #ifndef NDEBUG
  31. DebugIn_AmOut(&i->d_in_operation);
  32. DebugIn_AmOut(&i->d_in_cancel);
  33. DebugIn_AmOut(&i->d_in_done);
  34. #endif
  35. // call operation handler
  36. #ifndef NDEBUG
  37. DebugIn_GoIn(&i->d_in_operation);
  38. DEAD_ENTER(i->d_dead)
  39. #endif
  40. i->handler_operation(i->user_provider, i->buf, i->buf_len);
  41. #ifndef NDEBUG
  42. if (DEAD_LEAVE(i->d_dead)) {
  43. return;
  44. }
  45. DebugIn_GoOut(&i->d_in_operation);
  46. #endif
  47. }
  48. void _PacketPassInterface_job_done (PacketPassInterface *i)
  49. {
  50. ASSERT(i->d_user_busy)
  51. ASSERT(i->buf_len >= 0)
  52. ASSERT(i->buf_len <= i->mtu)
  53. ASSERT(i->handler_done)
  54. DebugObject_Access(&i->d_obj);
  55. #ifndef NDEBUG
  56. DebugIn_AmOut(&i->d_in_operation);
  57. DebugIn_AmOut(&i->d_in_cancel);
  58. DebugIn_AmOut(&i->d_in_done);
  59. #endif
  60. #ifndef NDEBUG
  61. i->d_user_busy = 0;
  62. #endif
  63. // call done handler
  64. #ifndef NDEBUG
  65. DebugIn_GoIn(&i->d_in_done);
  66. DEAD_ENTER(i->d_dead)
  67. #endif
  68. i->handler_done(i->user_user);
  69. #ifndef NDEBUG
  70. if (DEAD_LEAVE(i->d_dead)) {
  71. return;
  72. }
  73. DebugIn_GoOut(&i->d_in_done);
  74. #endif
  75. }