Go to the documentation of this file.00001
00002
00003 #include "ace/INet/HTTP_IOStream.h"
00004 #include "ace/INet/IOS_util.h"
00005
00006 #if !defined (__ACE_INLINE__)
00007 #include "ace/INet/HTTP_IOStream.inl"
00008 #endif
00009
00010 #include "ace/Truncate.h"
00011
00012 ACE_RCSID(NET_CLIENT,ACE_HTTP_IOStream,"$Id: HTTP_IOStream.cpp 90737 2010-06-21 09:46:14Z mcorino $")
00013
00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00015
00016 namespace ACE
00017 {
00018 namespace HTTP
00019 {
00020
00021 StreamBuffer::StreamBuffer (std::iostream& stream, StreamBuffer::policy_type* policy)
00022 : ACE::IOS::BufferedStreamBuffer (BUFFER_SIZE,
00023 std::ios::in | std::ios::out),
00024 stream_ (stream),
00025 policy_ (policy)
00026 {
00027 if (this->policy_)
00028 this->policy_->set_stream_buffer (this);
00029 }
00030
00031 StreamBuffer::~StreamBuffer ()
00032 {
00033 if (this->policy_)
00034 delete this->policy_;
00035 }
00036
00037 int StreamBuffer::read_from_stream (char* buffer, std::streamsize length)
00038 {
00039 if (this->policy_)
00040 return this->policy_->read_from_stream (buffer, length);
00041 else
00042 return this->read_from_stream_i (buffer, length);
00043 }
00044
00045 int StreamBuffer::read_from_stream_i (char* buffer, std::streamsize length)
00046 {
00047 this->stream_.read (buffer, length);
00048 return ACE_Utils::truncate_cast<int> (this->stream_.gcount ());
00049 }
00050
00051 int StreamBuffer::write_to_stream (const char* buffer, std::streamsize length)
00052 {
00053 if (this->policy_)
00054 return this->policy_->write_to_stream (buffer, length);
00055 else
00056 return this->write_to_stream_i (buffer, length);
00057 }
00058
00059 int StreamBuffer::write_to_stream_i (const char* buffer, std::streamsize length)
00060 {
00061 this->stream_.write (buffer, length);
00062 return this->stream_.good () ? ACE_Utils::truncate_cast<int> (length) : -1;
00063 }
00064
00065 int StreamBuffer::sync ()
00066 {
00067 if (ACE::IOS::BufferedStreamBuffer::sync () == -1)
00068 return -1;
00069 return this->stream_.sync ();
00070 }
00071
00072 IOS::IOS (std::iostream& stream, StreamBuffer::policy_type* policy)
00073 : streambuf_ (stream, policy)
00074 {
00075 ace_ios_init (&this->streambuf_);
00076 }
00077
00078 IOS::~IOS ()
00079 {
00080 try
00081 {
00082 this->streambuf_.sync();
00083 }
00084 catch (...)
00085 {
00086 }
00087 }
00088
00089 OStream::OStream(std::iostream& stream, StreamBuffer::policy_type* policy)
00090 : IOS (stream, policy), std::ostream (&streambuf_)
00091 {
00092 }
00093
00094 OStream::~OStream()
00095 {
00096 }
00097
00098 IStream::IStream(std::iostream& stream, StreamBuffer::policy_type* policy)
00099 : IOS (stream, policy), std::istream (&streambuf_)
00100 {
00101 }
00102
00103 IStream::~IStream()
00104 {
00105 }
00106
00107 }
00108 }
00109
00110 ACE_END_VERSIONED_NAMESPACE_DECL