FastPacketSource.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @file FastPacketSource.h
  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. #ifndef _FASTPACKETSOURCE_H
  23. #define _FASTPACKETSOURCE_H
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include <misc/debug.h>
  27. #include <system/DebugObject.h>
  28. #include <flow/PacketPassInterface.h>
  29. typedef struct {
  30. PacketPassInterface *output;
  31. int psize;
  32. uint8_t *data;
  33. int data_len;
  34. DebugObject d_obj;
  35. } FastPacketSource;
  36. static void _FastPacketSource_output_handler_done (FastPacketSource *s)
  37. {
  38. DebugObject_Access(&s->d_obj);
  39. PacketPassInterface_Sender_Send(s->output, s->data, s->data_len);
  40. }
  41. static void FastPacketSource_Init (FastPacketSource *s, PacketPassInterface *output, uint8_t *data, int data_len, BPendingGroup *pg)
  42. {
  43. ASSERT(data_len >= 0)
  44. ASSERT(data_len <= PacketPassInterface_GetMTU(output));
  45. // init arguments
  46. s->output = output;
  47. s->data = data;
  48. s->data_len = data_len;
  49. // init output
  50. PacketPassInterface_Sender_Init(s->output, (PacketPassInterface_handler_done)_FastPacketSource_output_handler_done, s);
  51. // schedule send
  52. PacketPassInterface_Sender_Send(s->output, s->data, s->data_len);
  53. DebugObject_Init(&s->d_obj);
  54. }
  55. static void FastPacketSource_Free (FastPacketSource *s)
  56. {
  57. DebugObject_Free(&s->d_obj);
  58. }
  59. #endif