1 #ifndef ACE_HTTP_STREAM_POLICY_CPP
2 #define ACE_HTTP_STREAM_POLICY_CPP
4 #include "ace/INet/HTTP_StreamPolicy.h"
7 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 template <class STREAM_BUFFER
>
14 FixedLengthStreamPolicyBase
<STREAM_BUFFER
>::FixedLengthStreamPolicyBase (std::streamsize length
)
15 : StreamPolicyBase
<STREAM_BUFFER
> (),
21 template <class STREAM_BUFFER
>
22 FixedLengthStreamPolicyBase
<STREAM_BUFFER
>::~FixedLengthStreamPolicyBase ()
26 template <class STREAM_BUFFER
>
27 int FixedLengthStreamPolicyBase
<STREAM_BUFFER
>::read_from_stream (
29 std::streamsize length
)
32 if (this->count_
< this->length_
)
34 if (this->count_
+ length
> this->length_
)
35 length
= this->length_
- this->count_
;
36 n
= this->read_from_stream_i (buf
, length
);
37 if (n
> 0) this->count_
+= n
;
42 template <class STREAM_BUFFER
>
43 int FixedLengthStreamPolicyBase
<STREAM_BUFFER
>::write_to_stream (
44 const char_type
* buf
,
45 std::streamsize length
)
48 if (this->count_
< this->length_
)
50 if ((this->count_
+ length
) > this->length_
)
51 length
= this->length_
- this->count_
;
52 n
= this->write_to_stream_i (buf
, length
);
53 if (n
> 0) this->count_
+= n
;
58 template <class STREAM_BUFFER
>
59 ChunkedTransferStreamPolicyBase
<STREAM_BUFFER
>::ChunkedTransferStreamPolicyBase ()
60 : StreamPolicyBase
<STREAM_BUFFER
> (),
65 template <class STREAM_BUFFER
>
66 ChunkedTransferStreamPolicyBase
<STREAM_BUFFER
>::~ChunkedTransferStreamPolicyBase ()
70 template <class STREAM_BUFFER
>
71 int ChunkedTransferStreamPolicyBase
<STREAM_BUFFER
>::getc ()
73 static const int eof_
=
74 std::char_traits
<char_type
>::eof ();
77 if (this->read_from_stream_i (chbuf
, 1) <= 0)
83 template <class STREAM_BUFFER
>
84 int ChunkedTransferStreamPolicyBase
<STREAM_BUFFER
>::read_from_stream (
86 std::streamsize length
)
88 static const int eof_
=
89 std::char_traits
<char_type
>::eof ();
91 char_type lf
= this->chunk_
.widen ('\n');
92 if (this->chunk_cnt_
== 0)
94 int ch
= this->getc ();
95 while (std::isspace (ch
))
97 typename
buffer_type::string_type chunk_len_str
;
98 while (std::isxdigit (ch
))
100 chunk_len_str
+= (char_type
) ch
;
103 while (ch
!= eof_
&& ch
!= lf
)
107 ACE::IOS::String_IStreamBase
<char_type
> chunk_len_is (chunk_len_str
);
109 if (!(chunk_len_is
>> chunk_len
))
111 this->chunk_cnt_
= (std::streamsize
) chunk_len
;
113 if (this->chunk_cnt_
> 0)
115 if (length
> this->chunk_cnt_
)
116 length
= this->chunk_cnt_
;
117 int n
= this->read_from_stream_i (buf
, length
);
119 this->chunk_cnt_
-= n
;
124 int ch
= this->getc ();
125 while (ch
!= eof_
&& ch
!= lf
)
131 template <class STREAM_BUFFER
>
132 int ChunkedTransferStreamPolicyBase
<STREAM_BUFFER
>::write_to_stream (
133 const char_type
* buf
,
134 std::streamsize length
)
136 this->chunk_
.clear ();
137 this->chunk_
<< std::hex
<< length
<< std::dec
;
138 this->chunk_
<< this->chunk_
.widen ('\r') << this->chunk_
.widen ('\n');
139 this->chunk_
.write (buf
, length
);
140 this->chunk_
<< this->chunk_
.widen ('\r') << this->chunk_
.widen ('\n');
141 const typename
buffer_type::string_type
& str
= this->chunk_
.str ();
142 return this->write_to_stream_i (str
.c_str (), str
.length ());
147 ACE_END_VERSIONED_NAMESPACE_DECL
149 #endif /* ACE_HTTP_STREAM_POLICY_CPP */