MGStreamAdapter.h 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <iostream>
  3. #include <ostream>
  4. #include <cstring>
  5. #include "civetweb.h"
  6. const size_t BUF_SIZE = 1024;
  7. // Custom streambuf
  8. class mg_buf : public std::streambuf {
  9. private:
  10. struct mg_connection* conn;
  11. char buffer[BUF_SIZE];
  12. public:
  13. mg_buf(struct mg_connection* _conn);
  14. protected:
  15. virtual int_type overflow(int_type c);
  16. int flush_buffer();
  17. virtual int sync();
  18. };
  19. /**
  20. * @brief Adapts ostream to mg_write
  21. *
  22. */
  23. class MGStreamAdapter : public std::ostream {
  24. private:
  25. mg_buf buf;
  26. public:
  27. MGStreamAdapter(struct mg_connection* _conn);
  28. };
  29. // Custom streambuf
  30. class mg_read_buf : public std::streambuf {
  31. private:
  32. struct mg_connection* conn;
  33. char buffer[BUF_SIZE];
  34. public:
  35. mg_read_buf(struct mg_connection* _conn);
  36. protected:
  37. virtual int_type underflow();
  38. };
  39. /**
  40. * @brief Adapts istream to mg_read
  41. */
  42. class MGInputStreamAdapter : public std::istream {
  43. private:
  44. mg_read_buf buf;
  45. public:
  46. MGInputStreamAdapter(struct mg_connection* _conn);
  47. };