SeqPacketSocketSource.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @file SeqPacketSocketSource.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} source which receives packets from a seqpacket socket.
  25. */
  26. #ifndef BADVPN_FLOW_SEQPACKETSOCKETSOURCE_H
  27. #define BADVPN_FLOW_SEQPACKETSOCKETSOURCE_H
  28. #include <misc/dead.h>
  29. #include <system/DebugObject.h>
  30. #include <system/BSocket.h>
  31. #include <flow/error.h>
  32. #include <flow/PacketRecvInterface.h>
  33. #define SEQPACKETSOCKETSOURCE_ERROR_BSOCKET 1
  34. /**
  35. * A {@link PacketRecvInterface} source which receives packets from a seqpacket socket.
  36. */
  37. typedef struct {
  38. DebugObject d_obj;
  39. dead_t dead;
  40. FlowErrorReporter rep;
  41. BSocket *bsock;
  42. int mtu;
  43. PacketRecvInterface output;
  44. int out_have;
  45. uint8_t *out;
  46. #ifndef NDEBUG
  47. int in_error;
  48. #endif
  49. } SeqPacketSocketSource;
  50. /**
  51. * Initializes the object.
  52. *
  53. * @param s the object
  54. * @param rep error reporting data. Error code is an int. Possible error codes:
  55. * - SEQPACKETSOCKETSOURCE_ERROR_BSOCKET: {@link BSocket_Recv} failed
  56. * with an unhandled error code
  57. * The object must be freed from the error handler.
  58. * @param bsock socket to read data from. The BSOCKET_READ event must be disabled.
  59. * * Takes over reading on the socket.
  60. * @param mtu maximum packet size. Must be >=0.
  61. */
  62. void SeqPacketSocketSource_Init (SeqPacketSocketSource *s, FlowErrorReporter rep, BSocket *bsock, int mtu);
  63. /**
  64. * Frees the object.
  65. *
  66. * @param s the object
  67. */
  68. void SeqPacketSocketSource_Free (SeqPacketSocketSource *s);
  69. /**
  70. * Returns the output interface.
  71. * The MTU of the interface will be as in {@link SeqPacketSocketSource_Init}.
  72. *
  73. * @param s the object
  74. * @return output interface
  75. */
  76. PacketRecvInterface * SeqPacketSocketSource_GetOutput (SeqPacketSocketSource *s);
  77. #endif