Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Web_Crawler / Mem_Map_Stream.h
blobf2e9195ce61d62a9b32948c96398b3065c2a0381
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Mem_Map_Stream.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
12 #ifndef _MEM_MAP_STREAM_H
13 #define _MEM_MAP_STREAM_H
14 #include /**/ "ace/pre.h"
16 #include "ace/SOCK_Stream.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Mem_Map.h"
24 #include "ace/SOCK_Connector.h"
25 #include "ace/Connector.h"
26 #include "ace/Svc_Handler.h"
27 #include "ace/Strategies_T.h"
29 /**
30 * @class Mem_Map_Stream
32 * @brief Provides a memory-mapped stream abstraction to simplify parsing
33 * of tokens.
35 * This class makes it possible to treat an connection as a stream
36 * of bytes, similar to the C library stdio streams. The contents
37 * of the connection are buffered incrementally in a memory-mapped
38 * file. This class maintains pointers to two positions in the
39 * stream:
40 * 1. The <recv> position, which keeps track of the beginning of a
41 * token that is in the stream.
42 * 2. The <get> position, which moves along character-by-character
43 * until the end of the token is reached.
44 * Once a token has been located, it can be extracted from the
45 * stream by calling the <recv>. The length of the token, i.e.,
46 * the <recv_len>, is the length in bytes between the <get>
47 * position and the <recv> position. Once the token has been
48 * extracted, the <recv> and <get> positions can be updated by the
49 * <seek> method.
51 class Mem_Map_Stream
53 public:
54 typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Svc_Handler;
56 typedef ACE_Strategy_Connector<Svc_Handler,
57 ACE_SOCK_CONNECTOR>
58 STRAT_CONNECTOR;
60 // Mem_Map_Stream ();
61 // constructor added:KIRTHIKA
62 /// Initialize this object.
63 virtual int open (STRAT_CONNECTOR *connector,
64 const ACE_INET_Addr &);
66 /// Destructor.
67 virtual ~Mem_Map_Stream ();
69 // = Accessor.
70 /// Returns the underlying <ACE_SOCK_Stream>.
71 ACE_SOCK_Stream &stream ();
73 // = I/O methods.
75 /// Send <size> bytes in <buf> to the connected peer. This is a
76 /// completely unbuffered call.
77 virtual ssize_t send_n (const void *buf,
78 size_t size,
79 ACE_Time_Value *tv = 0);
81 /**
82 * Return the next character in the stream and advance the <get>
83 * position. Returns EOF when the <get> position reaches the end of
84 * the HTTP stream.
86 virtual int get_char ();
88 /**
89 * Returns a pointer to array of at most <len> characters starting
90 * at the <recv> position. If the <recv> position + <len> extends
91 * past the EOF then <len> is set to the number of characters
92 * between the <recv> position and the EOF and both the <get> and
93 * <recv> positions are advanced by <len>. Returns 0 if the <recv>
94 * position is at the EOF.
96 virtual const char *recv (size_t &len);
98 /// Returns a pointer to array of characters starting at the <recv>
99 /// position.
100 virtual const char *recv () const;
102 /// Returns the length in bytes between the <get> position and the
103 /// <recv> position.
104 virtual size_t recv_len () const;
107 * Resets the <get> and <recv> positions to the beginning of the
108 * stream. This works since all the data has been cached in the
109 * memory-mapped backing store.
111 virtual int rewind ();
114 * Returns the nth character <offset> from the <get> position in the
115 * stream without advancing the <get> position. Automatically
116 * extends the backing store if necessary. Returns EOF if <offset>
117 * is past the end of the stream.
119 virtual int peek_char (size_t offset);
122 * Return a pointer to an array of <size> characters starting at
123 * <offset> characters from the <get> position in the stream without
124 * advancing the <get> position. Automatically extends the backing
125 * store if necessary. Returns 0 if <offset> or <offset + size> is
126 * past the end of the stream.
128 virtual const char *peek_str (size_t offset, size_t size);
131 * Sets the <get> and <recv> positions as follows:
132 * o If <whence> is <SEEK_SET>, the positions are set to <offset>
133 * bytes from the start of the stream.
135 * o If <whence> is <SEEK_CUR>, the positions are set to the
136 * current <get> position plus <offset>.
138 * o If <whence> is <SEEK_END>, the positions are set to the size
139 * of the stream plus <offset>.
141 virtual ACE_OFF_T seek (ACE_OFF_T offset, int whence = SEEK_CUR);
143 /// Returns 1 if we're at the end of the HTTP stream, else 0.
144 virtual int eof () const;
148 typedef ACE_NOOP_Creation_Strategy<Svc_Handler>
149 NULL_CREATION_STRATEGY;
150 typedef ACE_NOOP_Concurrency_Strategy<Svc_Handler>
151 NULL_ACTIVATION_STRATEGY;
152 typedef ACE_Cached_Connect_Strategy<Svc_Handler,
153 ACE_SOCK_CONNECTOR,
154 ACE_SYNCH_NULL_MUTEX>
155 CACHED_CONNECT_STRATEGY;*/
157 Svc_Handler *svc_handler ();
159 private:
161 * Grow the file by reading another chunk from the HTTP socket and
162 * extend the mapping to cover this chunk. Returns -1 on failure or
163 * EOF, else 0.
165 int grow_file_and_remap ();
167 //ACE_SOCK_Stream stream_;
170 * Connection to peer. The granularity is at the Svc_Handler level.
171 * The Svc_Handler has an SOCK_Stream.
172 * Configure the Strategy Connector with a strategy that caches
173 * connection.
175 Svc_Handler *svc_handler_;
177 NULL_CREATION_STRATEGY creation_strategy_;
178 NULL_ACTIVATION_STRATEGY activation_strategy_;
179 CACHED_CONNECT_STRATEGY caching_connect_strategy_;
181 STRAT_CONNECTOR *strat_connector_; */
183 /// Memory-mapped file that we're iterating over.
184 ACE_Mem_Map mem_map_;
186 /// Pointer to the address where the next <recv> method will start.
187 char *recv_pos_;
189 /// Pointer to the address where the next <get_char> method will
190 /// start.
191 char *get_pos_;
193 /// Address at the end of the file mapping.
194 char *end_of_mapping_plus1_;
197 #include /**/ "ace/post.h"
198 #endif /* _MEM_MAP_STREAM_H */