PRStreamSource.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file PRStreamSource.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 for a NSPR file descriptor (PRFileDesc) via {@link BPRFileDesc}.
  25. */
  26. #ifndef BADVPN_NSPRSUPPORT_PRSTREAMSOURCE_H
  27. #define BADVPN_NSPRSUPPORT_PRSTREAMSOURCE_H
  28. #include <stdint.h>
  29. #include <misc/debugerror.h>
  30. #include <base/DebugObject.h>
  31. #include <flow/StreamRecvInterface.h>
  32. #include <flow/FlowError.h>
  33. #include <nspr_support/BPRFileDesc.h>
  34. #define PRSTREAMSOURCE_ERROR_CLOSED 0
  35. #define PRSTREAMSOURCE_ERROR_NSPR 1
  36. /**
  37. * A {@link StreamRecvInterface} source for a NSPR file descriptor (PRFileDesc) via {@link BPRFileDesc}.
  38. */
  39. typedef struct {
  40. FlowErrorReporter rep;
  41. BPRFileDesc *bprfd;
  42. StreamRecvInterface output;
  43. int out_avail;
  44. uint8_t *out;
  45. DebugObject d_obj;
  46. DebugError d_err;
  47. } PRStreamSource;
  48. /**
  49. * Initializes the object.
  50. *
  51. * @param s the object
  52. * @param rep error reporting data. Error code is an int. Possible error codes:
  53. * - PRSTREAMSOURCE_ERROR_CLOSED: {@link PR_Read} returned 0
  54. * - PRSTREAMSOURCE_ERROR_NSPR: {@link PR_Read} failed
  55. * with an unhandled error code
  56. * The object must be freed from the error handler.
  57. * @param bprfd the {@link BPRFileDesc} object to read data from. Registers a
  58. * PR_POLL_READ handler which must not be registered.
  59. * @param pg pending group
  60. */
  61. void PRStreamSource_Init (PRStreamSource *s, FlowErrorReporter rep, BPRFileDesc *bprfd, BPendingGroup *pg);
  62. /**
  63. * Frees the object.
  64. *
  65. * @param s the object
  66. */
  67. void PRStreamSource_Free (PRStreamSource *s);
  68. /**
  69. * Returns the output interface.
  70. *
  71. * @param s the object
  72. * @return output interface
  73. */
  74. StreamRecvInterface * PRStreamSource_GetOutput (PRStreamSource *s);
  75. #endif