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