MGStreamAdapter.h 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include <cstring>
  3. #include <iostream>
  4. #include <ostream>
  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. };