3 //=============================================================================
7 * @author Phil Mesnier, Priyanka Gontla
9 //=============================================================================
11 #ifndef ACE_HTBP_CHANNEL_H
12 #define ACE_HTBP_CHANNEL_H
13 #include /**/ "ace/pre.h"
15 #include "ace/SOCK_Stream.h"
16 #include "ace/Message_Block.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "HTBP_Export.h"
23 #include "HTBP_Addr.h"
24 #include "HTBP_Filter.h"
25 #include "HTBP_Notifier.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
33 // Forward declarations.
37 * @class ACE::HTBP::Channel
39 * @brief Defines the methods in the <Ht_Channel> abstraction.
41 * This adds additional wrapper methods atop the <IO>
44 * <buf> is the buffer to write from or receive into.
45 * <len> is the number of bytes to transfer.
46 * The <timeout> parameter in the following methods indicates how
47 * long to blocking trying to transfer data. If <timeout> == 0,
48 * then the call behaves as a normal send/recv call, i.e., for
49 * blocking sockets, the call will block until action is possible;
50 * for non-blocking sockets, EWOULDBLOCK will be returned if no
51 * action is immediately possible.
52 * If <timeout> != 0, the call will wait for data to arrive no longer
53 * than the relative time specified in *<timeout>.
54 * The "_n()" I/O methods keep looping until all the data has been
55 * transferred. These methods also work for sockets in non-blocking
56 * mode i.e., they keep looping on EWOULDBLOCK. <timeout> is used
57 * to make sure we keep making progress, i.e., the same timeout
58 * value is used for every I/O operation in the loop and the timeout
59 * is not counted down.
60 * The return values for the "*_n()" methods match the return values
61 * from the non "_n()" methods and are specified as follows:
62 * - On complete transfer, the number of bytes transferred is returned.
63 * - On timeout, -1 is returned, errno == ETIME.
64 * - On error, -1 is returned, errno is set to appropriate error.
65 * - On EOF, 0 is returned, errno is irrelevant.
67 * On partial transfers, i.e., if any data is transferred before
68 * timeout/error/EOF, <bytes_transferred> will contain the number of
70 * Methods with <iovec> parameter are I/O vector variants of the I/O
72 * Methods with the extra <flags> argument will always result in
73 * <send> getting called. Methods without the extra <flags> argument
74 * will result in <send> getting called on Win32 platforms, and
75 * <write> getting called on non-Win32 platforms.
77 class HTBP_Export Channel
80 friend class Notifier
;
81 // Initialization and termination methods.
83 Channel (Session
*s
= 0);
85 Channel (ACE_SOCK_Stream
&s
);
86 Channel (ACE_HANDLE h
);
106 /// The Channel is a sibling of the ACE_SOCK_IO class, rather than a
107 /// decendant. This is due to the requirement to wrap all messages with
108 /// an HTTP request or reply wrapper, and to send application data in only
109 /// one direction on one stream.
111 /// Recv an <n> byte buffer from the connected socket.
112 ssize_t
recv (void *buf
,
115 const ACE_Time_Value
*timeout
= 0);
117 /// Recv an <n> byte buffer from the connected socket.
118 ssize_t
recv (void *buf
,
120 const ACE_Time_Value
*timeout
= 0);
122 /// Recv an <iovec> of size <n> from the connected socket.
123 ssize_t
recvv (iovec iov
[],
125 const ACE_Time_Value
*timeout
= 0);
127 /// Same as above. Deprecated.
128 ssize_t
recv (iovec iov
[],
130 const ACE_Time_Value
*timeout
= 0);
133 * Allows a client to read from a socket without having to provide a
134 * buffer to read. This method determines how much data is in the
135 * socket, allocates a buffer of this size, reads in the data, and
136 * returns the number of bytes read. The caller is responsible for
137 * deleting the member in the <iov_base> field of <io_vec> using
138 * delete [] io_vec->iov_base.
140 ssize_t
recvv (iovec
*io_vec
,
141 const ACE_Time_Value
*timeout
= 0);
143 /// Send an <n> byte buffer to the connected socket.
144 ssize_t
send (const void *buf
,
147 const ACE_Time_Value
*timeout
= 0);
149 /// Send an <n> byte buffer to the connected socket.
150 ssize_t
send (const void *buf
,
152 const ACE_Time_Value
*timeout
= 0);
154 /// Send an <iovec> of size <n> to the connected socket.
155 ssize_t
sendv (const iovec iov
[],
157 const ACE_Time_Value
*timeout
= 0);
159 // = Selectively close endpoints.
160 /// Close down the reader.
163 /// Close down the writer.
167 * Close down the socket (we need this to make things work correctly
168 * on Win32, which requires use to do a <close_writer> before doing
169 * the close to avoid losing data).
174 typedef ACE_INET_Addr PEER_ADDR
;
176 /// Dump the state of an object.
179 /// Declare the dynamic allocation hooks.
180 ACE_ALLOC_HOOK_DECLARE
;
183 Session
*session () const;
184 void session (Session
*);
186 Notifier
*notifier ();
188 void register_notifier (ACE_Reactor
*r
);
190 ACE_HANDLE
get_handle () const;
192 const ACE_SOCK_Stream
&ace_stream () const;
193 ACE_SOCK_Stream
&ace_stream ();
195 ///@notes Added the following methods to continue with
196 /// current compilation of HTIOP. Might not be needed in
197 /// future. - Priyanka
199 void set_handle (ACE_HANDLE h
);
202 * Enable asynchronous I/O (ACE_SIGIO), urgent data (ACE_SIGURG),
203 * non-blocking I/O (ACE_NONBLOCK), or close-on-exec (ACE_CLOEXEC),
204 * which is passed as the <value>.
206 int enable (int value
) const;
209 * Disable asynchronous I/O (ACE_SIGIO), urgent data (ACE_SIGURG),
210 * non-blocking I/O (ACE_NONBLOCK), or close-on-exec (ACE_CLOEXEC),
211 * which is passed as the <value>.
213 int disable (int value
) const;
216 // buffer related methods.
217 ACE_Message_Block
&leftovers ();
218 size_t data_len () const;
219 void data_len (size_t n
);
220 size_t data_consumed () const;
221 void data_consumed (size_t n
);
226 unsigned long request_count();
227 Filter
*filter () const;
228 void filter (Filter
*);
229 State
state () const;
230 void state (Channel::State s
);
232 int consume_error ();
235 /// The filter_ is a pluggable component used to manage the
236 /// wrapping of data in a way suitable for the proxy to
237 /// manage. The actual filter instance is owned by the
238 /// session. Different filters may be required depending on
239 /// which side of the proxy we are on, and the direction of data
243 /// The session_ is a reference to the persistent session this
244 /// stream is associated with. On the inside, sessions are
245 /// created by the Connector, which then create streams on
249 /// Since this stream implements its own send and recv methods,
250 /// the filter cannot simply call the send and recv methods of
251 /// this class. Therefore an ACE_SOCK_Stream wrapper around the
252 /// same socket instance is necessary to avoid recursion.
253 ACE_SOCK_Stream ace_stream_
;
257 ACE_Message_Block leftovers_
;
259 size_t data_consumed_
;
261 ACE_Message_Block
*error_buffer_
;
262 unsigned long request_count_
;
267 ACE_END_VERSIONED_NAMESPACE_DECL
269 #if defined (__ACE_INLINE__)
270 #include "HTBP_Channel.inl"
273 #include /**/ "ace/post.h"
274 #endif /* ACE_HTBP_CHANNEL_H */