ApacheStream.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // ApacheStream.h
  3. //
  4. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
  5. // and Contributors.
  6. //
  7. // SPDX-License-Identifier: BSL-1.0
  8. //
  9. #ifndef ApacheConnector_ApacheStream_INCLUDED
  10. #define ApacheConnector_ApacheStream_INCLUDED
  11. #include "ApacheConnector.h"
  12. #include "Poco/BufferedStreamBuf.h"
  13. #include <istream>
  14. #include <ostream>
  15. class ApacheStreamBuf: public Poco::BufferedStreamBuf
  16. /// This is the streambuf class used for reading from and writing to a socket.
  17. {
  18. public:
  19. ApacheStreamBuf(ApacheRequestRec* pApacheRequest, bool haveData = false);
  20. /// Creates a ApacheStreamBuf with the given socket.
  21. ~ApacheStreamBuf();
  22. /// Destroys the SocketStreamBuf.
  23. protected:
  24. int readFromDevice(char* buffer, std::streamsize length);
  25. int writeToDevice(const char* buffer, std::streamsize length);
  26. private:
  27. enum
  28. {
  29. STREAM_BUFFER_SIZE = 1024
  30. };
  31. ApacheRequestRec* _pApacheRequest;
  32. bool _haveData;
  33. };
  34. class ApacheIOS: public virtual std::ios
  35. /// The base class for ApacheStream, ApacheInputStream and
  36. /// ApacheOutputStream.
  37. ///
  38. /// This class is needed to ensure the correct initialization
  39. /// order of the stream buffer and base classes.
  40. {
  41. public:
  42. ApacheIOS(ApacheRequestRec* pApacheRequest, bool haveData = false);
  43. /// Creates the ApacheIOS with the given socket.
  44. ~ApacheIOS();
  45. /// Destroys the ApacheIOS.
  46. ///
  47. /// Flushes the buffer, but does not close the socket.
  48. ApacheStreamBuf* rdbuf();
  49. /// Returns a pointer to the internal ApacheStreamBuf.
  50. void close();
  51. /// Flushes the stream.
  52. protected:
  53. ApacheStreamBuf _buf;
  54. };
  55. class ApacheOutputStream: public ApacheIOS, public std::ostream
  56. /// An output stream for writing to an Apache response.
  57. {
  58. public:
  59. ApacheOutputStream(ApacheRequestRec* pApacheRequest);
  60. /// Creates the ApacheOutputStream with the given socket.
  61. ~ApacheOutputStream();
  62. /// Destroys the ApacheOutputStream.
  63. ///
  64. /// Flushes the buffer.
  65. };
  66. class ApacheInputStream: public ApacheIOS, public std::istream
  67. /// An input stream for reading from an Apache request.
  68. ///
  69. /// Using formatted input from a ApacheInputStream
  70. /// is not recommended, due to the read-ahead behavior of
  71. /// istream with formatted reads.
  72. {
  73. public:
  74. ApacheInputStream(ApacheRequestRec* pApacheRequest);
  75. /// Creates the ApacheInputStream with the given socket.
  76. ~ApacheInputStream();
  77. /// Destroys the ApacheInputStream.
  78. };
  79. #endif // ApacheConnector_ApacheStream_INCLUDED