3 //=============================================================================
7 * @author Phil Mesnier, Priyanka Gontla
9 //=============================================================================
11 #ifndef ACE_HTBP_STREAM_H
12 #define ACE_HTBP_STREAM_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.
39 * @brief A stream facade for the HTTP Tunneling Bidirectional Protocol
41 * This adds provides the common interface for applications to do
42 * I/O that ultimately is wrapped in HTTP for tunneling through
45 * This class is modelled after the ACE_SOCK_Stream class, and
46 * provides all of the I/O methods available in that class. Since
47 * this is a facade, it does not derive from ACE_SOCK_Stream. It
48 * also does not provide the same performance as ACE_SOCK_Stream,
49 * as some data may have to be stored by the HTBP classes prior to
52 * <buf> is the buffer to write from or receive into.
53 * <len> is the number of bytes to transfer.
54 * The <timeout> parameter in the following methods indicates how
55 * long to blocking trying to transfer data. If <timeout> == 0,
56 * then the call behaves as a normal send/recv call, i.e., for
57 * blocking sockets, the call will block until action is possible;
58 * for non-blocking sockets, EWOULDBLOCK will be returned if no
59 * action is immediately possible.
60 * If <timeout> != 0, the call will wait for data to arrive no longer
61 * than the relative time specified in *<timeout>.
62 * The "_n()" I/O methods keep looping until all the data has been
63 * transferred. These methods also work for sockets in non-blocking
64 * mode i.e., they keep looping on EWOULDBLOCK. <timeout> is used
65 * to make sure we keep making progress, i.e., the same timeout
66 * value is used for every I/O operation in the loop and the timeout
67 * is not counted down.
68 * The return values for the "*_n()" methods match the return values
69 * from the non "_n()" methods and are specified as follows:
70 * - On complete transfer, the number of bytes transferred is returned.
71 * - On timeout, -1 is returned, errno == ETIME.
72 * - On error, -1 is returned, errno is set to appropriate error.
73 * - On EOF, 0 is returned, errno is irrelevant.
75 * On partial transfers, i.e., if any data is transferred before
76 * timeout/error/EOF, <bytes_transferred> will contain the number of
78 * Methods with <iovec> parameter are I/O vector variants of the I/O
80 * Methods with the extra <flags> argument will always result in
81 * <send> getting called. Methods without the extra <flags> argument
82 * will result in <send> getting called on Win32 platforms, and
83 * <write> getting called on non-Win32 platforms.
85 class HTBP_Export Stream
88 // Initialization and termination methods.
90 Stream (Session
*s
= 0);
97 /// The Stream is a sibling of the ACE_SOCK_IO class, rather
98 /// than a decendant. This is due to the requirement to wrap all
99 /// messages with an HTTP request or reply wrapper, and to send
100 /// application data in only one direction on one stream.
102 /// Recv an <n> byte buffer from the connected socket.
103 ssize_t
recv (void *buf
,
106 const ACE_Time_Value
*timeout
= 0) const;
108 /// Recv an <n> byte buffer from the connected socket.
109 ssize_t
recv (void *buf
,
111 const ACE_Time_Value
*timeout
= 0) const;
113 /// Recv an <iovec> of size <n> from the connected socket.
114 ssize_t
recvv (iovec iov
[],
116 const ACE_Time_Value
*timeout
= 0) const;
118 /// Same as above. Deprecated.
119 ssize_t
recv (iovec iov
[],
121 const ACE_Time_Value
*timeout
= 0) const;
124 * Allows a client to read from a socket without having to
125 * provide a buffer to read. This method determines how much
126 * data is in the socket, allocates a buffer of this size, reads
127 * in the data, and returns the number of bytes read. The
128 * caller is responsible for deleting the member in the
129 * <iov_base> field of <io_vec> using delete []
132 ssize_t
recvv (iovec
*io_vec
,
133 const ACE_Time_Value
*timeout
= 0) const;
135 /// Recv <n> bytes via Win32 <ReadFile> using overlapped I/O.
136 ssize_t
recv (void *buf
,
138 ACE_OVERLAPPED
*overlapped
) const;
140 /// Send an <n> byte buffer to the connected socket.
141 ssize_t
send (const void *buf
,
144 const ACE_Time_Value
*timeout
= 0) const;
146 /// Send an <n> byte buffer to the connected socket.
147 ssize_t
send (const void *buf
,
149 const ACE_Time_Value
*timeout
= 0) const;
151 /// Send an <iovec> of size <n> to the connected socket.
152 ssize_t
sendv (const iovec iov
[],
154 const ACE_Time_Value
*timeout
= 0) const;
156 /// Send <n> bytes via Win32 <WriteFile> using overlapped I/O.
157 ssize_t
send (const void *buf
,
159 ACE_OVERLAPPED
*overlapped
) const;
162 /// Try to recv exactly <len> bytes into <buf> from the
163 /// connected socket.
164 ssize_t
recv_n (void *buf
,
167 const ACE_Time_Value
*timeout
= 0,
168 size_t *bytes_transferred
= 0) const;
170 /// Try to recv exactly <len> bytes into <buf> from the
171 /// connected socket.
172 ssize_t
recv_n (void *buf
,
174 const ACE_Time_Value
*timeout
= 0,
175 size_t *bytes_transferred
= 0) const;
177 /// Receive an <iovec> of size <iovcnt> from the connected
179 ssize_t
recvv_n (iovec iov
[],
181 const ACE_Time_Value
*timeout
= 0,
182 size_t *bytes_transferred
= 0) const;
184 /// Try to send exactly <len> bytes from <buf> to the connection
186 ssize_t
send_n (const void *buf
,
189 const ACE_Time_Value
*timeout
= 0,
190 size_t *bytes_transferred
= 0) const;
192 /// Try to send exactly <len> bytes from <buf> to the connected
194 ssize_t
send_n (const void *buf
,
196 const ACE_Time_Value
*timeout
= 0,
197 size_t *bytes_transferred
= 0) const;
199 /// Send all the <message_block>s chained through their <next>
200 /// and <cont> pointers. This call uses the underlying OS
201 /// gather-write operation to reduce the domain-crossing
203 ssize_t
send_n (const ACE_Message_Block
*message_block
,
204 const ACE_Time_Value
*timeout
= 0,
205 size_t *bytes_transferred
= 0) const;
207 /// Send an <iovec> of size <iovcnt> to the connected socket.
208 ssize_t
sendv_n (const iovec iov
[],
210 const ACE_Time_Value
*timeout
= 0,
211 size_t *bytes_transferred
= 0) const;
213 // = Selectively close endpoints. / Close down the reader.
216 /// Close down the writer.
220 * Close down the socket (we need this to make things work correctly
221 * on Win32, which requires use to do a <close_writer> before doing
222 * the close to avoid losing data).
227 typedef Addr PEER_ADDR
;
229 /// Dump the state of an object.
232 /// Declare the dynamic allocation hooks.
233 ACE_ALLOC_HOOK_DECLARE
;
236 ///@notes Added the following methods to continue with
237 /// current compilation of HTIOP. Might not be needed in
238 /// future. - Priyanka
240 void set_handle (ACE_HANDLE h
);
241 ACE_HANDLE
get_handle () const;
243 Session
*session () const;
244 void session (Session
*s
);
247 * Enable asynchronous I/O (ACE_SIGIO), urgent data (ACE_SIGURG),
248 * non-blocking I/O (ACE_NONBLOCK), or close-on-exec (ACE_CLOEXEC),
249 * which is passed as the <value>.
251 int enable (int value
) const;
254 * Disable asynchronous I/O (ACE_SIGIO), urgent data (ACE_SIGURG),
255 * non-blocking I/O (ACE_NONBLOCK), or close-on-exec (ACE_CLOEXEC),
256 * which is passed as the <value>.
258 int disable (int value
) const;
261 * Return the address of the remotely connected peer (if there is
262 * one), in the referenced <ACE_Addr>. Returns 0 if successful, else
265 int get_remote_addr (Addr
&) const;
268 * Return the address of the remotely connected peer (if there is
269 * one), in the referenced <ACE_Addr>. Returns 0 if successful, else
272 int get_local_addr (Addr
&) const;
277 /// The session_ is a reference to the persistent session this stream is
278 /// associated with. On the inside, sessions are created by the Connector,
279 /// which then create streams on demand.
285 ACE_END_VERSIONED_NAMESPACE_DECL
287 #include /**/ "ace/post.h"
288 #endif /* ACE_HTBP_STREAM_H */