Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / FTP_IOStream.cpp
blobb58eb0135e586bc2e0906fdfb5e715bf625496a9
1 #include "ace/INet/FTP_IOStream.h"
2 #include "ace/INet/IOS_util.h"
4 #if !defined (__ACE_INLINE__)
5 #include "ace/INet/FTP_IOStream.inl"
6 #endif
8 #include "ace/Truncate.h"
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 namespace ACE
15 namespace FTP
17 StreamBuffer::StreamBuffer (std::iostream * stream)
18 : ACE::IOS::BufferedStreamBuffer (BUFFER_SIZE,
19 std::ios::in | std::ios::out),
20 stream_ (stream)
24 StreamBuffer::~StreamBuffer ()
28 std::iostream* StreamBuffer::set_stream (std::iostream * stream)
30 std::iostream * old_stream = this->stream_;
31 this->stream_ = stream;
32 this->reset_buffers ();
33 return old_stream;
36 int StreamBuffer::read_from_stream (char* buffer, std::streamsize length)
38 if (this->stream_ == 0) return -1;
39 this->stream_->read (buffer, length);
40 return ACE_Utils::truncate_cast<int> (this->stream_->gcount ());
43 int StreamBuffer::write_to_stream (const char* buffer, std::streamsize length)
45 if (this->stream_ == 0) return -1;
46 this->stream_->write (buffer, length);
47 return this->stream_->good () ? ACE_Utils::truncate_cast<int> (length) : -1;
50 int StreamBuffer::sync ()
52 if (this->stream_ == 0) return -1;
53 if (ACE::IOS::BufferedStreamBuffer::sync () == -1)
54 return -1;
55 return this->stream_->sync ();
58 IOS::IOS (std::iostream * stream)
59 : streambuf_ (stream)
61 ace_ios_init (&this->streambuf_);
64 IOS::~IOS ()
66 try
68 this->streambuf_.sync();
70 catch (...)
75 std::iostream* IOS::set_stream (std::iostream* stream)
77 std::iostream* old_stream = this->rdbuf ()->set_stream (stream);
78 this->clear ();
79 return old_stream;
82 OStream::OStream(std::iostream * stream)
83 : IOS (stream), std::ostream (&streambuf_)
87 OStream::~OStream()
91 IStream::IStream(std::iostream * stream)
92 : IOS (stream), std::istream (&streambuf_)
96 IStream::~IStream()
103 ACE_END_VERSIONED_NAMESPACE_DECL