3 //=============================================================================
5 * @file HTBP_Stream.cpp
7 * @author Phil Mesnier, Priyanka Gontla
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.
21 ACE::HTBP::Stream::Stream (ACE::HTBP::Session
*s
)
25 // create a temporary session to be replaced on first recv.
26 ACE_NEW (session_
, ACE::HTBP::Session
);
27 session_
->stream (this);
31 ACE::HTBP::Stream::~Stream ()
35 /// Dump the state of an object.
37 ACE::HTBP::Stream::dump () const
42 //---------------------------------------------------------------------------
45 /// Recv an <n> byte buffer from the connected socket.
47 ACE::HTBP::Stream::recv (void *buf
,
50 const ACE_Time_Value
*timeout
) const
52 if (this->session_
->inbound() == 0)
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")),
61 return this->session_
->inbound()->recv(buf
,n
,flags
,timeout
);
64 /// Recv an <n> byte buffer from the connected socket.
66 ACE::HTBP::Stream::recv (void *buf
,
68 const ACE_Time_Value
*timeout
) const
70 if (this->session_
->inbound() == 0)
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")),
79 return this->session_
->inbound()->recv(buf
,n
,timeout
);
82 /// Recv an <iovec> of size <n> from the connected socket.
84 ACE::HTBP::Stream::recvv (iovec iov
[],
86 const ACE_Time_Value
*timeout
) const
88 if (this->session_
->inbound() == 0)
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")),
97 return this->session_
->inbound()->recvv(iov
,iovcnt
,timeout
);
101 ACE::HTBP::Stream::recvv (iovec
*io_vec
,
102 const ACE_Time_Value
*timeout
) const
104 if (this->session_
->inbound() == 0)
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")),
113 return this->session_
->inbound()->recvv(io_vec
,timeout
);
117 ACE::HTBP::Stream::recv (void *,
119 ACE_OVERLAPPED
*) const
122 ACE_ERROR_RETURN ((LM_ERROR
,
123 ACE_TEXT("ACE::HTBP::Stream: Asynch ")
124 ACE_TEXT("recv not supported\n")),-1);
128 ACE::HTBP::Stream::send (const void *buf
,
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
);
147 ACE::HTBP::Stream::send (const void *buf
,
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
);
162 ACE::HTBP::Stream::sendv (const iovec iov
[],
164 const ACE_Time_Value
*timeout
) const
166 if (this->session_
->outbound() == 0)
168 ACE_Message_Block
*msg
= 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
);
182 ACE::HTBP::Stream::send (const void *,
184 ACE_OVERLAPPED
*) const
187 ACE_ERROR_RETURN ((LM_ERROR
,
188 ACE_TEXT("ACE::HTBP::Stream: Asynch ")
189 ACE_TEXT("send not supported\n")),
194 ACE::HTBP::Stream::recv_n (void *,
197 const ACE_Time_Value
*,
201 ACE_ERROR_RETURN ((LM_ERROR
,
202 ACE_TEXT("ACE::HTBP::Stream: recv_n not supported\n")),
206 /// Try to recv exactly <len> bytes into <buf> from the connected socket.
208 ACE::HTBP::Stream::recv_n (void *,
210 const ACE_Time_Value
*,
214 ACE_ERROR_RETURN ((LM_ERROR
,
215 ACE_TEXT("ACE::HTBP::Stream: recv_n not supported\n")),
219 /// Receive an <iovec> of size <iovcnt> from the connected socket.
221 ACE::HTBP::Stream::recvv_n (iovec
[],
223 const ACE_Time_Value
*,
227 ACE_ERROR_RETURN ((LM_ERROR
,
228 ACE_TEXT("ACE::HTBP::Stream: recvv_n not supported\n")),
232 /// Try to send exactly <len> bytes from <buf> to the connection socket.
234 ACE::HTBP::Stream::send_n (const void *,
237 const ACE_Time_Value
*,
241 ACE_ERROR_RETURN ((LM_ERROR
,
242 ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")),
246 /// Try to send exactly <len> bytes from <buf> to the connected socket.
248 ACE::HTBP::Stream::send_n (const void *,
250 const ACE_Time_Value
*,
254 ACE_ERROR_RETURN ((LM_ERROR
,
255 ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")),
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.
263 ACE::HTBP::Stream::send_n (const ACE_Message_Block
*,
264 const ACE_Time_Value
*,
268 ACE_ERROR_RETURN ((LM_ERROR
,
269 ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")),
273 /// Send an <iovec> of size <iovcnt> to the connected socket.
275 ACE::HTBP::Stream::sendv_n (const iovec
[],
277 const ACE_Time_Value
*,
281 ACE_ERROR_RETURN ((LM_ERROR
,
282 ACE_TEXT("ACE::HTBP::Stream: sendv_n not supported\n")),
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 ();
324 ACE::HTBP::Stream::get_remote_addr (ACE::HTBP::Addr
&peer_addr
) const
326 peer_addr
= this->session_
->peer_addr();
331 ACE::HTBP::Stream::session () const
333 return this->session_
;
337 ACE::HTBP::Stream::session (ACE::HTBP::Session
*s
)
339 delete this->session_
;
346 ACE::HTBP::Stream::get_handle () const
348 return ACE_INVALID_HANDLE
;
352 ACE::HTBP::Stream::set_handle (ACE_HANDLE
)
356 ACE_END_VERSIONED_NAMESPACE_DECL