blob: 3d6406f584faf743e745039a5296b9bff32542fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// $Id$
#include "ace/INet/FTP_IOStream.h"
#include "ace/INet/IOS_util.h"
#if !defined (__ACE_INLINE__)
#include "ace/INet/FTP_IOStream.inl"
#endif
#include "ace/Truncate.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
namespace ACE
{
namespace FTP
{
StreamBuffer::StreamBuffer (std::iostream * stream)
: ACE::IOS::BufferedStreamBuffer (BUFFER_SIZE,
std::ios::in | std::ios::out),
stream_ (stream)
{
}
StreamBuffer::~StreamBuffer ()
{
}
std::iostream* StreamBuffer::set_stream (std::iostream * stream)
{
std::iostream * old_stream = this->stream_;
this->stream_ = stream;
this->reset_buffers ();
return old_stream;
}
int StreamBuffer::read_from_stream (char* buffer, std::streamsize length)
{
if (this->stream_ == 0) return -1;
this->stream_->read (buffer, length);
return ACE_Utils::truncate_cast<int> (this->stream_->gcount ());
}
int StreamBuffer::write_to_stream (const char* buffer, std::streamsize length)
{
if (this->stream_ == 0) return -1;
this->stream_->write (buffer, length);
return this->stream_->good () ? ACE_Utils::truncate_cast<int> (length) : -1;
}
int StreamBuffer::sync ()
{
if (this->stream_ == 0) return -1;
if (ACE::IOS::BufferedStreamBuffer::sync () == -1)
return -1;
return this->stream_->sync ();
}
IOS::IOS (std::iostream * stream)
: streambuf_ (stream)
{
ace_ios_init (&this->streambuf_);
}
IOS::~IOS ()
{
try
{
this->streambuf_.sync();
}
catch (...)
{
}
}
std::iostream* IOS::set_stream (std::iostream* stream)
{
std::iostream* old_stream = this->rdbuf ()->set_stream (stream);
this->clear ();
return old_stream;
}
OStream::OStream(std::iostream * stream)
: IOS (stream), std::ostream (&streambuf_)
{
}
OStream::~OStream()
{
}
IStream::IStream(std::iostream * stream)
: IOS (stream), std::istream (&streambuf_)
{
}
IStream::~IStream()
{
}
}
}
ACE_END_VERSIONED_NAMESPACE_DECL
|