SinglePacketSender.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @file SinglePacketSender.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 <misc/debug.h>
  23. #include <flow/SinglePacketSender.h>
  24. static void call_handler (SinglePacketSender *o)
  25. {
  26. DEBUGERROR(&o->d_err, o->handler(o->user));
  27. }
  28. static void output_handler_done (SinglePacketSender *o)
  29. {
  30. DebugObject_Access(&o->d_obj);
  31. // notify user
  32. call_handler(o);
  33. return;
  34. }
  35. void SinglePacketSender_Init (SinglePacketSender *o, uint8_t *packet, int packet_len, PacketPassInterface *output, SinglePacketSender_handler handler, void *user, BPendingGroup *pg)
  36. {
  37. ASSERT(packet_len >= 0)
  38. ASSERT(packet_len <= PacketPassInterface_GetMTU(output))
  39. // init arguments
  40. o->output = output;
  41. o->handler = handler;
  42. o->user = user;
  43. // init output
  44. PacketPassInterface_Sender_Init(o->output, (PacketPassInterface_handler_done)output_handler_done, o);
  45. // schedule send
  46. PacketPassInterface_Sender_Send(o->output, packet, packet_len);
  47. DebugObject_Init(&o->d_obj);
  48. DebugError_Init(&o->d_err, pg);
  49. }
  50. void SinglePacketSender_Free (SinglePacketSender *o)
  51. {
  52. DebugError_Free(&o->d_err);
  53. DebugObject_Free(&o->d_obj);
  54. }