00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Ilya A. Volynets-Evenbakh * 00003 * ilya@total-knowledge.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the ied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #ifndef CSERVSERVLETOUTPUTSTREAM_H 00021 #define CSERVSERVLETOUTPUTSTREAM_H 00022 00023 #include <connection.h> 00024 00025 namespace container { 00026 00027 class HttpServletResponseImpl; 00028 class ServletOutputStreamBuf: public std::streambuf 00029 { 00030 Connection& m_con; 00031 HttpServletResponseImpl& m_resp; 00032 size_t m_bufSz; 00033 public: 00034 ServletOutputStreamBuf(Connection& con,HttpServletResponseImpl& resp) 00035 : m_con(con) 00036 , m_resp(resp) 00037 { 00038 m_bufSz=m_con.epptr()-m_con.pbase(); 00039 } 00040 00044 size_t getBufSize(){return m_bufSz;} 00045 protected: 00046 virtual int sync(); 00047 virtual int showmanyc() const {return 0;} 00048 virtual std::streamsize xsgetn(char* s, std::streamsize n) 00049 {return 0;} 00050 virtual int underflow(){return traits_type::eof();} 00051 virtual int pbackfail(); 00052 virtual std::streamsize xsputn(const char* s,std::streamsize n); 00053 virtual int overflow(int c); 00054 virtual std::streambuf* setbuf(char* s,std::streamsize n); 00055 }; 00056 00063 class ServletOutputStream : public std::ostream 00064 { 00065 private: 00066 ServletOutputStreamBuf m_buf; 00067 public: 00068 ServletOutputStream(Connection&,HttpServletResponseImpl&); 00069 virtual ~ServletOutputStream(); 00070 friend class HttpServletResponseImpl; 00071 protected: 00072 virtual void setBufferSize(size_t sz); 00073 virtual size_t getBufferSize(); 00074 }; 00075 00076 } 00077 00078 #endif