Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / protocols / ace / HTBP / HTBP_Stream.cpp
blob75da921bbda5a8621993b32b9169731f8a61f3cc
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file HTBP_Stream.cpp
7 * @author Phil Mesnier, Priyanka Gontla
8 */
9 //=============================================================================
10 #include "HTBP_Stream.h"
12 #include "HTBP_Session.h"
13 #include "HTBP_Filter_Factory.h"
15 #include "ace/Message_Block.h"
17 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 // Initialization and termination methods.
20 /// Constructor.
21 ACE::HTBP::Stream::Stream (ACE::HTBP::Session *s)
22 : session_ (s)
24 if (s == 0)
25 // create a temporary session to be replaced on first recv.
26 ACE_NEW (session_, ACE::HTBP::Session);
27 session_->stream (this);
30 /// Destructor.
31 ACE::HTBP::Stream::~Stream ()
35 /// Dump the state of an object.
36 void
37 ACE::HTBP::Stream::dump () const
42 //---------------------------------------------------------------------------
43 // = I/O functions.
45 /// Recv an <n> byte buffer from the connected socket.
46 ssize_t
47 ACE::HTBP::Stream::recv (void *buf,
48 size_t n,
49 int flags,
50 const ACE_Time_Value *timeout) const
52 if (this->session_->inbound() == 0)
54 errno = EWOULDBLOCK;
55 ACE_ERROR_RETURN ((LM_ERROR,
56 ACE_TEXT("ACE::HTBP::Stream::")
57 ACE_TEXT("recv(buf,n,flags) called, but no ")
58 ACE_TEXT("inbound channel connected to stream\n")),
59 -1);
61 return this->session_->inbound()->recv(buf,n,flags,timeout);
64 /// Recv an <n> byte buffer from the connected socket.
65 ssize_t
66 ACE::HTBP::Stream::recv (void *buf,
67 size_t n,
68 const ACE_Time_Value *timeout) const
70 if (this->session_->inbound() == 0)
72 errno = EWOULDBLOCK;
73 ACE_ERROR_RETURN ((LM_ERROR,
74 ACE_TEXT("ACE::HTBP::Stream::")
75 ACE_TEXT("recv(buf,n) called, but no ")
76 ACE_TEXT("inbound channel connected to stream\n")),
77 -1);
79 return this->session_->inbound()->recv(buf,n,timeout);
82 /// Recv an <iovec> of size <n> from the connected socket.
83 ssize_t
84 ACE::HTBP::Stream::recvv (iovec iov[],
85 int iovcnt,
86 const ACE_Time_Value *timeout) const
88 if (this->session_->inbound() == 0)
90 errno = EWOULDBLOCK;
91 ACE_ERROR_RETURN ((LM_ERROR,
92 ACE_TEXT("ACE::HTBP::Stream::")
93 ACE_TEXT("recv(iov,iovcnt) called, but no ")
94 ACE_TEXT("inbound channel connected to stream\n")),
95 -1);
97 return this->session_->inbound()->recvv(iov,iovcnt,timeout);
100 ssize_t
101 ACE::HTBP::Stream::recvv (iovec *io_vec,
102 const ACE_Time_Value *timeout) const
104 if (this->session_->inbound() == 0)
106 errno = EWOULDBLOCK;
107 ACE_ERROR_RETURN ((LM_ERROR,
108 ACE_TEXT("ACE::HTBP::Stream::")
109 ACE_TEXT("recv(io_vec) called, but no ")
110 ACE_TEXT("inbound channel connected to stream\n")),
111 -1);
113 return this->session_->inbound()->recvv(io_vec,timeout);
116 ssize_t
117 ACE::HTBP::Stream::recv (void *,
118 size_t,
119 ACE_OVERLAPPED *) const
121 errno = ENOTSUP;
122 ACE_ERROR_RETURN ((LM_ERROR,
123 ACE_TEXT("ACE::HTBP::Stream: Asynch ")
124 ACE_TEXT("recv not supported\n")),-1);
127 ssize_t
128 ACE::HTBP::Stream::send (const void *buf,
129 size_t n,
130 int flags,
131 const ACE_Time_Value *timeout) const
133 if (this->session_->outbound() == 0)
135 ACE_Message_Block *msg = 0;
136 ACE_NEW_RETURN (msg,ACE_Message_Block(n),-1);
137 msg->copy ((const char *)buf,n);
138 // probably ought to separately enqueue the flags and put the data buf
139 // in a continuation message
140 // Also, the timeout poses another interesting problem.
141 return this->session_->enqueue(msg);
143 return this->session_->outbound()->send(buf,n,flags,timeout);
146 ssize_t
147 ACE::HTBP::Stream::send (const void *buf,
148 size_t n,
149 const ACE_Time_Value *timeout) const
151 if (this->session_->outbound() == 0)
153 ACE_Message_Block *msg = 0;
154 ACE_NEW_RETURN (msg,ACE_Message_Block(n),-1);
155 msg->copy ((const char *)buf,n);
156 return this->session_->enqueue(msg);
158 return this->session_->outbound()->send(buf,n,timeout);
161 ssize_t
162 ACE::HTBP::Stream::sendv (const iovec iov[],
163 int iovcnt,
164 const ACE_Time_Value *timeout) const
166 if (this->session_->outbound() == 0)
168 ACE_Message_Block *msg = 0;
169 size_t total = 0;
170 int i = 0;
171 for (; i < iovcnt; i++)
172 total += iov[i].iov_len;
173 ACE_NEW_RETURN (msg,ACE_Message_Block(total),-1);
174 for (i = 0; i < iovcnt; i++)
175 msg->copy ((const char *)iov[i].iov_base,iov[i].iov_len);
176 return this->session_->enqueue(msg);
178 return this->session_->outbound()->sendv(iov,iovcnt,timeout);
181 ssize_t
182 ACE::HTBP::Stream::send (const void *,
183 size_t ,
184 ACE_OVERLAPPED *) const
186 errno = ENOTSUP;
187 ACE_ERROR_RETURN ((LM_ERROR,
188 ACE_TEXT("ACE::HTBP::Stream: Asynch ")
189 ACE_TEXT("send not supported\n")),
190 -1);
193 ssize_t
194 ACE::HTBP::Stream::recv_n (void *,
195 size_t ,
196 int ,
197 const ACE_Time_Value *,
198 size_t *) const
200 errno = ENOTSUP;
201 ACE_ERROR_RETURN ((LM_ERROR,
202 ACE_TEXT("ACE::HTBP::Stream: recv_n not supported\n")),
203 -1);
206 /// Try to recv exactly <len> bytes into <buf> from the connected socket.
207 ssize_t
208 ACE::HTBP::Stream::recv_n (void *,
209 size_t ,
210 const ACE_Time_Value *,
211 size_t *) const
213 errno = ENOTSUP;
214 ACE_ERROR_RETURN ((LM_ERROR,
215 ACE_TEXT("ACE::HTBP::Stream: recv_n not supported\n")),
216 -1);
219 /// Receive an <iovec> of size <iovcnt> from the connected socket.
220 ssize_t
221 ACE::HTBP::Stream::recvv_n (iovec [],
222 int ,
223 const ACE_Time_Value *,
224 size_t *) const
226 errno = ENOTSUP;
227 ACE_ERROR_RETURN ((LM_ERROR,
228 ACE_TEXT("ACE::HTBP::Stream: recvv_n not supported\n")),
229 -1);
232 /// Try to send exactly <len> bytes from <buf> to the connection socket.
233 ssize_t
234 ACE::HTBP::Stream::send_n (const void *,
235 size_t ,
236 int ,
237 const ACE_Time_Value *,
238 size_t *) const
240 errno = ENOTSUP;
241 ACE_ERROR_RETURN ((LM_ERROR,
242 ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")),
243 -1);
246 /// Try to send exactly <len> bytes from <buf> to the connected socket.
247 ssize_t
248 ACE::HTBP::Stream::send_n (const void *,
249 size_t ,
250 const ACE_Time_Value *,
251 size_t *) const
253 errno = ENOTSUP;
254 ACE_ERROR_RETURN ((LM_ERROR,
255 ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")),
256 -1);
259 /// Send all the <message_block>s chained through their <next> and
260 /// <cont> pointers. This call uses the underlying OS gather-write
261 /// operation to reduce the domain-crossing penalty.
262 ssize_t
263 ACE::HTBP::Stream::send_n (const ACE_Message_Block *,
264 const ACE_Time_Value *,
265 size_t *) const
267 errno = ENOTSUP;
268 ACE_ERROR_RETURN ((LM_ERROR,
269 ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")),
270 -1);
273 /// Send an <iovec> of size <iovcnt> to the connected socket.
274 ssize_t
275 ACE::HTBP::Stream::sendv_n (const iovec [],
276 int,
277 const ACE_Time_Value *,
278 size_t *) const
280 errno = ENOTSUP;
281 ACE_ERROR_RETURN ((LM_ERROR,
282 ACE_TEXT("ACE::HTBP::Stream: sendv_n not supported\n")),
283 -1);
287 ACE::HTBP::Stream::close_reader ()
289 return this->session_->close_inbound();
293 ACE::HTBP::Stream::close_writer ()
295 return this->session_->close_outbound();
299 ACE::HTBP::Stream::close ()
301 return this->session_->close();
305 ACE::HTBP::Stream::enable (int value) const
307 return this->session_->enable(value);
311 ACE::HTBP::Stream::disable (int value) const
313 return this->session_->disable(value);
317 ACE::HTBP::Stream::get_local_addr (ACE::HTBP::Addr &local_addr) const
319 local_addr = this->session_->local_addr ();
320 return 0;
324 ACE::HTBP::Stream::get_remote_addr (ACE::HTBP::Addr &peer_addr) const
326 peer_addr = this->session_->peer_addr();
327 return 0;
330 ACE::HTBP::Session *
331 ACE::HTBP::Stream::session () const
333 return this->session_;
336 void
337 ACE::HTBP::Stream::session (ACE::HTBP::Session *s)
339 delete this->session_;
340 this->session_ = s;
341 s->stream (this);
345 ACE_HANDLE
346 ACE::HTBP::Stream::get_handle () const
348 return ACE_INVALID_HANDLE;
351 void
352 ACE::HTBP::Stream::set_handle (ACE_HANDLE )
356 ACE_END_VERSIONED_NAMESPACE_DECL