/library/server/fcgi/spec/include/libfcgi/fcgio.h

http://github.com/jocelyn/EiffelWebReloaded · C++ Header · 151 lines · 56 code · 37 blank · 58 comment · 0 complexity · 0b9ce197d716977a2bb0e5a8447a3391 MD5 · raw file

  1. //
  2. // Provides support for FastCGI via C++ iostreams.
  3. //
  4. // $Id: fcgio.h,v 1.15 2002/02/25 13:16:11 robs Exp $
  5. //
  6. // This work is based on routines written by George Feinberg. They
  7. // have been mostly re-written and extensively changed by
  8. // Michael Richards.
  9. //
  10. // Rewritten again with bug fixes and numerous enhancements by
  11. // Michael Shell.
  12. //
  13. // And rewritten again by Rob Saccoccio.
  14. //
  15. // Special Thanks to Dietmar Kuehl for his help and the numerous custom
  16. // streambuf examples on his web site.
  17. //
  18. // Copyright (c) 2000 Tux the Linux Penguin
  19. // Copyright (c) 2001 Rob Saccoccio and Chelsea Networks
  20. //
  21. // You are free to use this software without charge or royalty
  22. // as long as this notice is not removed or altered, and recognition
  23. // is given to the author(s)
  24. //
  25. // This code is offered as-is without any warranty either expressed or
  26. // implied; without even the implied warranty of MERCHANTABILITY or
  27. // FITNESS FOR A PARTICULAR PURPOSE. If it breaks, you get to keep
  28. // both halves.
  29. #ifndef FCGIO_H
  30. #define FCGIO_H
  31. #include <iostream>
  32. #include "fcgiapp.h"
  33. #ifndef DLLAPI
  34. #ifdef _WIN32
  35. #define DLLAPI __declspec(dllimport)
  36. #else
  37. #define DLLAPI
  38. #endif
  39. #endif
  40. #if ! HAVE_STREAMBUF_CHAR_TYPE
  41. typedef char char_type;
  42. #endif
  43. /*
  44. * fcgi_streambuf
  45. */
  46. class DLLAPI fcgi_streambuf : public std::streambuf
  47. {
  48. public:
  49. // Note that if no buf is assigned (the default), iostream methods
  50. // such as peek(), unget() and putback() will fail. If a buf is
  51. // assigned, I/O is a bit less effecient and output streams will
  52. // have to be flushed (or the streambuf destroyed) before the next
  53. // call to "accept".
  54. fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int len);
  55. fcgi_streambuf(char_type * buf, std::streamsize len);
  56. fcgi_streambuf(FCGX_Stream * fcgx = 0);
  57. ~fcgi_streambuf(void);
  58. int attach(FCGX_Stream * fcgx);
  59. protected:
  60. // Consume the put area (if buffered) and c (if c is not EOF).
  61. virtual int overflow(int);
  62. // Flush the put area (if buffered) and the FCGX buffer to the client.
  63. virtual int sync();
  64. // Remove and return the current character.
  65. virtual int uflow();
  66. // Fill the get area (if buffered) and return the current character.
  67. virtual int underflow();
  68. // Use a buffer. The only reasons that a buffer would be useful is
  69. // to support the use of the unget()/putback() or seek() methods. Using
  70. // a buffer will result in less efficient I/O. Note: the underlying
  71. // FastCGI library (FCGX) maintains its own input and output buffers.
  72. virtual std::streambuf * setbuf(char_type * buf, std::streamsize len);
  73. virtual std::streamsize xsgetn(char_type * s, std::streamsize n);
  74. virtual std::streamsize xsputn(const char_type * s, std::streamsize n);
  75. private:
  76. FCGX_Stream * fcgx;
  77. // buf is just handy to have around
  78. char_type * buf;
  79. // this isn't kept by the base class
  80. std::streamsize bufsize;
  81. void init(FCGX_Stream * fcgx, char_type * buf, std::streamsize bufsize);
  82. void reset(void);
  83. };
  84. /*
  85. * fcgi_istream - deprecated
  86. */
  87. class DLLAPI fcgi_istream : public std::istream
  88. {
  89. public:
  90. // deprecated
  91. fcgi_istream(FCGX_Stream * fcgx = 0);
  92. // deprecated
  93. ~fcgi_istream(void) {}
  94. // deprecated
  95. virtual void attach(FCGX_Stream * fcgx);
  96. private:
  97. fcgi_streambuf fcgi_strmbuf;
  98. };
  99. /*
  100. * fcgi_ostream - deprecated
  101. */
  102. class DLLAPI fcgi_ostream : public std::ostream
  103. {
  104. public:
  105. // deprecated
  106. fcgi_ostream(FCGX_Stream * fcgx = 0);
  107. // deprecated
  108. ~fcgi_ostream(void) {}
  109. // deprecated
  110. virtual void attach(FCGX_Stream *fcgx);
  111. private:
  112. fcgi_streambuf fcgi_strmbuf;
  113. };
  114. #endif /* FCGIO_H */