StreamSocketSource.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file StreamSocketSource.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 StreamRecvInterface} source which receives data from a stream socket.
  25. */
  26. #ifndef BADVPN_FLOW_STREAMSOCKETSOURCE_H
  27. #define BADVPN_FLOW_STREAMSOCKETSOURCE_H
  28. #include <stdint.h>
  29. #include <misc/dead.h>
  30. #include <system/DebugObject.h>
  31. #include <system/BSocket.h>
  32. #include <flow/StreamRecvInterface.h>
  33. #include <flow/error.h>
  34. #define STREAMSOCKETSOURCE_ERROR_CLOSED 0
  35. #define STREAMSOCKETSOURCE_ERROR_BSOCKET 1
  36. /**
  37. * A {@link StreamRecvInterface} source which receives data from a stream socket.
  38. */
  39. typedef struct {
  40. FlowErrorReporter rep;
  41. BSocket *bsock;
  42. StreamRecvInterface output;
  43. int out_avail;
  44. uint8_t *out;
  45. DebugObject d_obj;
  46. #ifndef NDEBUG
  47. dead_t d_dead;
  48. #endif
  49. } StreamSocketSource;
  50. /**
  51. * Initializes the source.
  52. *
  53. * @param s the object
  54. * @param rep error reporting data. Error code is an int. Possible error codes:
  55. * - STREAMSOCKETSOURCE_ERROR_CLOSED: {@link BSocket_Recv} returned 0
  56. * - STREAMSOCKETSOURCE_ERROR_BSOCKET: {@link BSocket_Recv} failed
  57. * with an unhandled error code
  58. * The object must be freed from the error handler.
  59. * @param bsock stream socket to read data from. Registers a BSOCKET_READ handler which
  60. * must not be registered.
  61. * @param pg pending group
  62. */
  63. void StreamSocketSource_Init (StreamSocketSource *s, FlowErrorReporter rep, BSocket *bsock, BPendingGroup *pg);
  64. /**
  65. * Frees the source.
  66. *
  67. * @param s the object
  68. */
  69. void StreamSocketSource_Free (StreamSocketSource *s);
  70. /**
  71. * Returns the output interface.
  72. *
  73. * @param s the object
  74. * @return output interface
  75. */
  76. StreamRecvInterface * StreamSocketSource_GetOutput (StreamSocketSource *s);
  77. #endif