# ACEXML_Mem_Map_Stream Class Reference

Provides a memory-mapped stream abstraction to simplify parsing of tokens. More...

`#include <ACEXML/common/Mem_Map_Stream.h>`

Collaboration diagram for ACEXML_Mem_Map_Stream:

[legend]
List of all members.

## Public Member Functions

| ACEXML_Mem_Map_Stream (void)
| Default constructor.
virtual int | open (Connector *connector, const ACE_INET_Addr &)
| Initialize this object.
virtual | ~ACEXML_Mem_Map_Stream (void)
| Destructor.
ACE_SOCK_Stream & | stream (void)
| Returns the underlying <ace_sock_stream>.
virtual ssize_t | send_n (const void *buf, size_t size, ACE_Time_Value *tv=0)
virtual int | get_char (void)
virtual const char * | recv (size_t &len)
virtual const char * | recv (void) const
virtual size_t | recv_len (void) const
virtual size_t | available (void) const
virtual void | rewind (void)
virtual int | peek_char (size_t offset)
virtual const char * | peek_str (size_t offset, size_t size)
virtual off_t | seek (off_t offset, int whence=SEEK_CUR)
virtual int | eof (void) const
| Returns 1 if we're at the end of the HTTP stream, else 0.
Svc_Handler * | svc_handler (void)
| Returns the underlying service handler.

## Private Member Functions

int | grow_file_and_remap (void)

## Private Attributes

Svc_Handler * | svc_handler_
ACE_Mem_Map | mem_map_
| Memory-mapped file that we're iterating over.
char * | recv_pos_
| Pointer to the address where the next <recv> method will start.
char * | get_pos_
char * | end_of_mapping_plus1_
| Address at the end of the file mapping.

## Detailed Description

Provides a memory-mapped stream abstraction to simplify parsing of tokens.

This class makes it possible to treat an connection as a stream of bytes, similar to the C library stdio streams. The contents of the connection are buffered incrementally in a memory-mapped file. This class maintains pointers to two positions in the stream:

1. The <recv> position, which keeps track of the beginning of a token that is in the stream.

2. The <get> position, which moves along character-by-character until the end of the token is reached.

Once a token has been located, it can be extracted from the stream by calling the <recv>. The length of the token, i.e., the <recv_len>, is the length in bytes between the <get> position and the <recv> position. Once the token has been extracted, the <recv> and <get> positions can be updated by the <seek> method.

## Constructor & Destructor Documentation

ACEXML_Mem_Map_Stream::ACEXML_Mem_Map_Stream | ( | void |  | ) |

| Default constructor.

ACEXML_Mem_Map_Stream::~ACEXML_Mem_Map_Stream | ( | void |  | ) | `[virtual]`

| Destructor.

## Member Function Documentation

size_t ACEXML_Mem_Map_Stream::available | ( | void |  | ) | const`[virtual]`

| Returns the no. of bytes available in the stream.

int ACEXML_Mem_Map_Stream::eof | ( | void |  | ) | const`[virtual]`

| Returns 1 if we're at the end of the HTTP stream, else 0.

int ACEXML_Mem_Map_Stream::get_char | ( | void |  | ) | `[virtual]`

| Return the next character in the stream and advance the <get> position. Returns EOF when the <get> position reaches the end of the HTTP stream.

int ACEXML_Mem_Map_Stream::grow_file_and_remap | ( | void |  | ) | `[private]`

| Grow the file by reading another chunk from the HTTP socket and extend the mapping to cover this chunk. Returns -1 on failure or EOF, else 0.

int ACEXML_Mem_Map_Stream::open | ( | Connector * | connector,
|  | const ACE_INET_Addr & |
| ) | `[virtual]`

| Initialize this object.

int ACEXML_Mem_Map_Stream::peek_char | ( | size_t | offset | ) | `[virtual]`

| Returns the nth character <offset> from the <get> position in the stream without advancing the <get> position. Automatically extends the backing store if necessary. Returns EOF if <offset> is past the end of the stream.

const char * ACEXML_Mem_Map_Stream::peek_str | ( | size_t | offset,
|  | size_t | size
| ) | `[virtual]`

| Return a pointer to an array of <size> characters starting at <offset> characters from the <get> position in the stream without advancing the <get> position. Automatically extends the backing store if necessary. Returns 0 if <offset> or <offset + size> is past the end of the stream.

const char * ACEXML_Mem_Map_Stream::recv | ( | void |  | ) | const`[virtual]`

| Returns a pointer to array of characters starting at the <recv> position.

const char * ACEXML_Mem_Map_Stream::recv | ( | size_t & | len | ) | `[virtual]`

| Returns a pointer to array of at most <len> characters starting at the <recv> position. If the <recv> position + <len> extends past the EOF then <len> is set to the number of characters between the <recv> position and the EOF and both the <get> and <recv> positions are advanced by <len>. Returns 0 if the <recv> position is at the EOF.

size_t ACEXML_Mem_Map_Stream::recv_len | ( | void |  | ) | const`[virtual]`

| Returns the length in bytes between the <get> position and the <recv> position.

void ACEXML_Mem_Map_Stream::rewind | ( | void |  | ) | `[virtual]`

| Resets the <get> and <recv> positions to the beginning of the stream. This works since all the data has been cached in the memory-mapped backing store.

off_t ACEXML_Mem_Map_Stream::seek | ( | off_t | offset,
|  | int | whence = `SEEK_CUR`
| ) | `[virtual]`

Sets the <get> and <recv> positions as follows: o If <whence> is <seek_set>, the positions are set to <offset> bytes from the start of the stream. o If <whence> is <seek_cur>, the positions are set to the current <get> position plus <offset>. o If <whence> is <seek_end>, the positions are set to the size of the stream plus <offset>.

If offset is greater than EOF, both <get> and <recv> are set to EOF. Note special return value is returned to indicate this condition.

ssize_t ACEXML_Mem_Map_Stream::send_n | ( | const void * | buf,
|  | size_t | size,
|  | ACE_Time_Value * | tv = `0`
| ) | `[virtual]`

| Send <size> bytes in <buf> to the connected peer. This is a completely unbuffered call.

ACE_SOCK_Stream & ACEXML_Mem_Map_Stream::stream | ( | void |  | ) |

| Returns the underlying <ace_sock_stream>.

Svc_Handler * ACEXML_Mem_Map_Stream::svc_handler | ( | void |  | ) |

| Returns the underlying service handler.

## Member Data Documentation

char* ACEXML_Mem_Map_Stream::end_of_mapping_plus1_`[private]`

| Address at the end of the file mapping.

char* ACEXML_Mem_Map_Stream::get_pos_`[private]`

| Pointer to the address where the next <get_char> method will start.

ACE_Mem_Map ACEXML_Mem_Map_Stream::mem_map_`[private]`

| Memory-mapped file that we're iterating over.

char* ACEXML_Mem_Map_Stream::recv_pos_`[private]`

| Pointer to the address where the next <recv> method will start.

Svc_Handler* ACEXML_Mem_Map_Stream::svc_handler_`[private]`

| Connection to peer. The granularity is at the Svc_Handler level. The Svc_Handler has an SOCK_Stream.

The documentation for this class was generated from the following files:

- Mem_Map_Stream.h
- Mem_Map_Stream.cpp