PRStreamSink.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @file PRStreamSink.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 StreamPassInterface} sink for a NSPR file descriptor (PRFileDesc) via {@link BPRFileDesc}.
  25. */
  26. #ifndef BADVPN_NSPRSUPPORT_PRSTREAMSINK_H
  27. #define BADVPN_NSPRSUPPORT_PRSTREAMSINK_H
  28. #include <stdint.h>
  29. #include <misc/debugerror.h>
  30. #include <system/DebugObject.h>
  31. #include <flow/StreamPassInterface.h>
  32. #include <flow/FlowError.h>
  33. #include <nspr_support/BPRFileDesc.h>
  34. #define PRSTREAMSINK_ERROR_NSPR 1
  35. /**
  36. * A {@link StreamPassInterface} sink for a NSPR file descriptor (PRFileDesc) via {@link BPRFileDesc}.
  37. */
  38. typedef struct {
  39. FlowErrorReporter rep;
  40. BPRFileDesc *bprfd;
  41. StreamPassInterface input;
  42. int in_len;
  43. uint8_t *in;
  44. DebugObject d_obj;
  45. DebugError d_err;
  46. } PRStreamSink;
  47. /**
  48. * Initializes the object.
  49. *
  50. * @param s the object
  51. * @param rep error reporting data. Error code is an int. Possible error codes:
  52. * - PRSTREAMSINK_ERROR_NSPR: {@link PR_Write} failed
  53. * with an unhandled error code
  54. * The object must be freed from the error handler.
  55. * @param bprfd the {@link BPRFileDesc} object to write data to. Registers a
  56. * PR_POLL_WRITE handler which must not be registered.
  57. * @param pg pending group
  58. */
  59. void PRStreamSink_Init (PRStreamSink *s, FlowErrorReporter rep, BPRFileDesc *bprfd, BPendingGroup *pg);
  60. /**
  61. * Frees the object.
  62. *
  63. * @param s the object
  64. */
  65. void PRStreamSink_Free (PRStreamSink *s);
  66. /**
  67. * Returns the input interface.
  68. *
  69. * @param s the object
  70. * @return input interface
  71. */
  72. StreamPassInterface * PRStreamSink_GetInput (PRStreamSink *s);
  73. #endif