PacketRecvConnector.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @file PacketRecvConnector.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. * @section DESCRIPTION
  23. *
  24. * A {@link PacketRecvInterface} layer which allows the input to be
  25. * connected and disconnected on the fly.
  26. */
  27. #ifndef BADVPN_FLOW_PACKETRECVCONNECTOR_H
  28. #define BADVPN_FLOW_PACKETRECVCONNECTOR_H
  29. #include <stdint.h>
  30. #include <system/DebugObject.h>
  31. #include <flow/PacketRecvInterface.h>
  32. /**
  33. * A {@link PacketRecvInterface} layer which allows the input to be
  34. * connected and disconnected on the fly.
  35. */
  36. typedef struct {
  37. PacketRecvInterface output;
  38. int output_mtu;
  39. int out_have;
  40. uint8_t *out;
  41. PacketRecvInterface *input;
  42. int in_blocking;
  43. DebugObject d_obj;
  44. } PacketRecvConnector;
  45. /**
  46. * Initializes the object.
  47. * The object is initialized in not connected state.
  48. *
  49. * @param o the object
  50. * @param mtu maximum output packet size. Must be >=0.
  51. * @param pg pending group
  52. */
  53. void PacketRecvConnector_Init (PacketRecvConnector *o, int mtu, BPendingGroup *pg);
  54. /**
  55. * Frees the object.
  56. *
  57. * @param o the object
  58. */
  59. void PacketRecvConnector_Free (PacketRecvConnector *o);
  60. /**
  61. * Returns the output interface.
  62. * The MTU of the interface will be as in {@link PacketRecvConnector_Init}.
  63. *
  64. * @param o the object
  65. * @return output interface
  66. */
  67. PacketRecvInterface * PacketRecvConnector_GetOutput (PacketRecvConnector *o);
  68. /**
  69. * Connects input.
  70. * The object must be in not connected state.
  71. * The object enters connected state.
  72. *
  73. * @param o the object
  74. * @param output input to connect. Its MTU must be <= MTU specified in
  75. * {@link PacketRecvConnector_Init}.
  76. */
  77. void PacketRecvConnector_ConnectInput (PacketRecvConnector *o, PacketRecvInterface *input);
  78. /**
  79. * Disconnects input.
  80. * The object must be in connected state.
  81. * The object enters not connected state.
  82. *
  83. * @param o the object
  84. */
  85. void PacketRecvConnector_DisconnectInput (PacketRecvConnector *o);
  86. #endif