Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_MEM_IO Class Reference

Defines the methods for the ACE shared memeory wrapper I/O routines (e.g., send/recv). The shared memory transport uses ACE_SOCK_* class to implement the signaling mechanism so we can easily use the new mechanism with the Reactor pattern (which uses select under the hood.) ACE_MEM_Acceptor and ACE_MEM_Connector are used to establish connections. When a connection is established, ACE_MEM_Acceptor creates the MMAP file for data exchange and sends the location of the file (complete path name) to ACE_MEM_Connector thru the socket. ACE_MEM_Connector then reads the location of the file off the socket and opens up the same MMAP file. ACE_MEM_Stream at each side then contains a reference to the ACE_Mallo object using the same MMAP file. When sending information using methods provided in this class, ACE_MEM_IO requests a chunk of memory from the MALLOC_TYPE object, copy the data into the shared memory and send the memory offset (from the start of the ACE_Malloc) across the socket. This action also servers as a signal to the other end. The receiving side then reverses the procedures and copies the information into user buffer. More...

#include <MEM_IO.h>

Inheritance diagram for ACE_MEM_IO:

Inheritance graph
[legend]
Collaboration diagram for ACE_MEM_IO:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Signal_Strategy { Reactive, MT }

Public Methods

 ACE_MEM_IO (void)
 Constructor. More...

 ~ACE_MEM_IO (void)
 Destructor. More...

int init (const ACE_TCHAR *name, ACE_MEM_IO::Signal_Strategy type=ACE_MEM_IO::Reactive, ACE_MEM_SAP::MALLOC_OPTIONS *options=0)
int fini (void)
ssize_t send (const void *buf, size_t n, int flags)
 Send an <n> byte buffer to the other process using shm_malloc_ connected thru the socket. More...

ssize_t recv (void *buf, size_t n, int flags)
 Recv an <n> byte buffer from the shm_malloc_ thru connected socket. More...

ssize_t send (const void *buf, size_t n)
 Send an <n> byte buffer to the other process using shm_malloc_ connected thru the socket. More...

ssize_t recv (void *buf, size_t n)
 Recv an <n> byte buffer from the shm_malloc_ thru connected socket. More...

ssize_t send (const void *buf, size_t n, const ACE_Time_Value *timeout)
ssize_t send (const void *buf, size_t n, int flags, const ACE_Time_Value *timeout)
ssize_t send (const ACE_Message_Block *message_block, const ACE_Time_Value *timeout)
ssize_t recv (void *buf, size_t n, const ACE_Time_Value *timeout)
ssize_t recv (void *buf, size_t n, int flags, const ACE_Time_Value *timeout)
void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Methods

ssize_t fetch_recv_buf (int flag, const ACE_Time_Value *timeout)
 Return the local endpoint port number. Returns 0 if successful, else -1. More...


Private Attributes

ACE_MEM_SAPdeliver_strategy_
 Actual deliverying mechanism. More...

ACE_MEM_SAP_Noderecv_buffer_
 Internal pointer for support recv/send. More...

ssize_t buf_size_
 Record the current total buffer size of <recv_buffer_>. More...

ssize_t cur_offset_
 Record the current read pointer location in <recv_buffer_>. More...


Detailed Description

Defines the methods for the ACE shared memeory wrapper I/O routines (e.g., send/recv). The shared memory transport uses ACE_SOCK_* class to implement the signaling mechanism so we can easily use the new mechanism with the Reactor pattern (which uses select under the hood.) ACE_MEM_Acceptor and ACE_MEM_Connector are used to establish connections. When a connection is established, ACE_MEM_Acceptor creates the MMAP file for data exchange and sends the location of the file (complete path name) to ACE_MEM_Connector thru the socket. ACE_MEM_Connector then reads the location of the file off the socket and opens up the same MMAP file. ACE_MEM_Stream at each side then contains a reference to the ACE_Mallo object using the same MMAP file. When sending information using methods provided in this class, ACE_MEM_IO requests a chunk of memory from the MALLOC_TYPE object, copy the data into the shared memory and send the memory offset (from the start of the ACE_Malloc) across the socket. This action also servers as a signal to the other end. The receiving side then reverses the procedures and copies the information into user buffer.

Definition at line 163 of file MEM_IO.h.


Member Enumeration Documentation

enum ACE_MEM_IO::Signal_Strategy
 

Enumeration values:
Reactive 
MT 

Definition at line 173 of file MEM_IO.h.

Referenced by ACE_MEM_Acceptor::accept, ACE_MEM_Connector::connect, init, ACE_MEM_Connector::preferred_strategy, and ACE_MEM_Acceptor::preferred_strategy.

00174   {
00175     Reactive,
00176     MT
00177   }  Signal_Strategy;


Constructor & Destructor Documentation

ASYS_INLINE ACE_MEM_IO::ACE_MEM_IO void   
 

Constructor.

Definition at line 77 of file MEM_IO.i.

00078   : deliver_strategy_ (0),
00079     recv_buffer_ (0),
00080     buf_size_ (0),
00081     cur_offset_ (0)
00082 {
00083   // ACE_TRACE ("ACE_MEM_IO::ACE_MEM_IO");
00084 }

ASYS_INLINE ACE_MEM_IO::~ACE_MEM_IO void   
 

Destructor.

Definition at line 115 of file MEM_IO.i.

References deliver_strategy_.

00116 {
00117   delete this->deliver_strategy_;
00118 }


Member Function Documentation

void ACE_MEM_IO::dump void    const
 

Dump the state of an object.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_MEM_Stream.

Definition at line 313 of file MEM_IO.cpp.

References ACE_TRACE.

00314 {
00315   ACE_TRACE ("ACE_MEM_IO::dump");
00316 }

ASYS_INLINE ssize_t ACE_MEM_IO::fetch_recv_buf int    flag,
const ACE_Time_Value   timeout
[private]
 

Return the local endpoint port number. Returns 0 if successful, else -1.

Definition at line 87 of file MEM_IO.i.

References ACE_ASSERT, ACE_TRACE, buf_size_, cur_offset_, deliver_strategy_, ACE_MEM_SAP::recv_buf, recv_buffer_, and ACE_MEM_SAP::release_buffer.

Referenced by recv.

00088 {
00089   ACE_TRACE ("ACE_MEM_IO::fetch_recv_buf");
00090 
00091   if (this->deliver_strategy_ == 0)
00092     return -1;
00093 
00094   // This method can only be called when <buf_size_> == <cur_offset_>.
00095   ACE_ASSERT (this->buf_size_ == this->cur_offset_);
00096 
00097   // We have done using the previous buffer, return it to malloc.
00098   if (this->recv_buffer_ != 0)
00099     this->deliver_strategy_->release_buffer (this->recv_buffer_);
00100 
00101   this->cur_offset_ = 0;
00102   int retv = 0;
00103 
00104   if ((retv = this->deliver_strategy_->recv_buf (this->recv_buffer_,
00105                                                  flag,
00106                                                  timeout)) > 0)
00107     this->buf_size_ = retv;
00108   else
00109     this->buf_size_ = 0;
00110 
00111   return retv;
00112 }

int ACE_MEM_IO::fini void   
 

Finalizing the MEM_IO object. This method doesn't invoke the <remove> method.

Definition at line 351 of file MEM_IO.cpp.

References deliver_strategy_, and ACE_MEM_SAP::fini.

Referenced by ACE_MEM_Stream::close.

00352 {
00353   if (this->deliver_strategy_ != 0)
00354     return this->deliver_strategy_->fini ();
00355   else
00356     return -1;
00357 }

int ACE_MEM_IO::init const ACE_TCHAR   name,
ACE_MEM_IO::Signal_Strategy    type = ACE_MEM_IO::Reactive,
ACE_MEM_SAP::MALLOC_OPTIONS   options = 0
 

Initialize the MEM_SAP object.

Definition at line 319 of file MEM_IO.cpp.

References ACE_NEW_RETURN, ACE_TCHAR, deliver_strategy_, ACE_MEM_SAP::init, ACE_MEM_SAP::MALLOC_OPTIONS, MT, Reactive, and Signal_Strategy.

Referenced by ACE_MEM_Acceptor::accept, and ACE_MEM_Connector::connect.

00322 {
00323   ACE_UNUSED_ARG (type);
00324 
00325   delete this->deliver_strategy_;
00326   this->deliver_strategy_ = 0;
00327   switch (type)
00328     {
00329     case ACE_MEM_IO::Reactive:
00330       ACE_NEW_RETURN (this->deliver_strategy_,
00331                       ACE_Reactive_MEM_IO (),
00332                       -1);
00333       break;
00334 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00335     case ACE_MEM_IO::MT:
00336       ACE_NEW_RETURN (this->deliver_strategy_,
00337                       ACE_MT_MEM_IO (),
00338                       -1);
00339       break;
00340 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
00341     default:
00342       return -1;
00343     }
00344 
00345   return this->deliver_strategy_->init (this->get_handle (),
00346                                         name,
00347                                         options);
00348 }

ASYS_INLINE ssize_t ACE_MEM_IO::recv void *    buf,
size_t    n,
int    flags,
const ACE_Time_Value   timeout
 

Wait up to <timeout> amount of time to receive up to <n> bytes into <buf> from <handle> (uses the <recv> call). If <recv> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes received is returned.

Definition at line 145 of file MEM_IO.i.

References ACE_TRACE, buf_size_, cur_offset_, fetch_recv_buf, ACE_OS_String::memcpy, and ssize_t.

00149 {
00150   ACE_TRACE ("ACE_MEM_IO::recv");
00151 
00152   size_t count = 0;
00153 
00154 //    while (len > 0)
00155 //      {
00156       size_t buf_len = this->buf_size_ - this->cur_offset_;
00157       if (buf_len == 0)
00158         {
00159           ssize_t blen =         // Buffer length
00160             this->fetch_recv_buf (flags, timeout);
00161           if (blen <= 0)
00162             return blen;
00163           buf_len = this->buf_size_;
00164         }
00165 
00166       size_t length = (len > buf_len ? buf_len : len);
00167 
00168       ACE_OS::memcpy ((char *) buf + count,
00169                       (char *) this->recv_buffer_->data () + this->cur_offset_,
00170                       length);
00171       this->cur_offset_ += length;
00172 //        len -= length;
00173       count += length;
00174 //      }
00175 
00176   return count;
00177 }

ASYS_INLINE ssize_t ACE_MEM_IO::recv void *    buf,
size_t    n,
const ACE_Time_Value   timeout
 

Wait up to <timeout> amount of time to receive up to <n> bytes into <buf> from <handle> (uses the <recv> call). If <recv> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes received is returned.

Definition at line 215 of file MEM_IO.i.

References ACE_TRACE, and recv.

00218 {
00219   ACE_TRACE ("ACE_MEM_IO::recv");
00220   return this->recv (buf, len, 0, timeout);
00221 }

ASYS_INLINE ssize_t ACE_MEM_IO::recv void *    buf,
size_t    n
 

Recv an <n> byte buffer from the shm_malloc_ thru connected socket.

Definition at line 207 of file MEM_IO.i.

References ACE_TRACE, and recv.

00208 {
00209   ACE_TRACE ("ACE_MEM_IO::recv");
00210 
00211   return this->recv (buf, n, 0);
00212 }

ASYS_INLINE ssize_t ACE_MEM_IO::recv void *    buf,
size_t    n,
int    flags
 

Recv an <n> byte buffer from the shm_malloc_ thru connected socket.

Definition at line 189 of file MEM_IO.i.

References ACE_TRACE.

Referenced by recv, and ACE_MEM_Stream::recv_n.

00190 {
00191   ACE_TRACE ("ACE_MEM_IO::recv");
00192   return this->recv (buf, n, flags, 0);
00193 }

ssize_t ACE_MEM_IO::send const ACE_Message_Block   message_block,
const ACE_Time_Value   timeout
 

Wait to to <timeout> amount of time to send the <message_block>. If <send> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes sent is returned.

Definition at line 365 of file MEM_IO.cpp.

References ACE_TRACE, ACE_Message_Block::cont, ACE_MEM_SAP_Node::data, deliver_strategy_, ACE_Message_Block::length, ACE_OS_String::memcpy, ACE_Message_Block::next, ACE_Message_Block::rd_ptr, ACE_MEM_SAP::send_buf, ACE_MEM_SAP_Node::size_, ssize_t, and ACE_Message_Block::total_length.

00367 {
00368   ACE_TRACE ("ACE_MEM_IO::send");
00369 
00370   if (this->deliver_strategy_ == 0)
00371     return -1;                  // Something went seriously wrong.
00372 
00373   ssize_t len = message_block->total_length ();
00374 
00375   if (len != 0)
00376     {
00377       ACE_MEM_SAP_Node *buf =
00378         ACE_reinterpret_cast (ACE_MEM_SAP_Node *,
00379                               this->deliver_strategy_->acquire_buffer (len));
00380       ssize_t n = 0;
00381       while (message_block != 0)
00382         {
00383           ACE_OS::memcpy (ACE_static_cast (char *, buf->data ()) + n,
00384                           message_block->rd_ptr (),
00385                           message_block->length ());
00386           n += message_block->length ();
00387 
00388           if (message_block->cont ())
00389             message_block = message_block->cont ();
00390           else
00391             message_block = message_block->next ();
00392         }
00393 
00394       buf->size_ = len;
00395 
00396       return this->deliver_strategy_->send_buf (buf,
00397                                                 0,
00398                                                 timeout);
00399     }
00400   return 0;
00401 }

ASYS_INLINE ssize_t ACE_MEM_IO::send const void *    buf,
size_t    n,
int    flags,
const ACE_Time_Value   timeout
 

Wait to to <timeout> amount of time to send up to <n> bytes into <buf> from <handle> (uses the <send> call). If <send> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes sent is returned.

Definition at line 121 of file MEM_IO.i.

References ACE_TRACE, ACE_MEM_SAP::acquire_buffer, ACE_MEM_SAP_Node::data, deliver_strategy_, ACE_OS_String::memcpy, ACE_MEM_SAP::send_buf, and ACE_MEM_SAP_Node::size_.

00125 {
00126   ACE_TRACE ("ACE_MEM_IO::send");
00127   if (this->deliver_strategy_ == 0)
00128     return 0;
00129 
00130   ACE_MEM_SAP_Node *sbuf = this->deliver_strategy_->acquire_buffer (len);
00131   if (sbuf == 0)
00132     return -1;                  // Memory buffer not initialized.
00133   ACE_OS::memcpy (sbuf->data (), buf, len);
00134 
00135   ///
00136 
00137   sbuf->size_ = len;
00138 
00139   return this->deliver_strategy_->send_buf (sbuf,
00140                                             flags,
00141                                             timeout);
00142 }

ASYS_INLINE ssize_t ACE_MEM_IO::send const void *    buf,
size_t    n,
const ACE_Time_Value   timeout
 

Wait to to <timeout> amount of time to send up to <n> bytes into <buf> from <handle> (uses the <send> call). If <send> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes sent is returned.

Definition at line 224 of file MEM_IO.i.

References ACE_TRACE, and send.

00227 {
00228   ACE_TRACE ("ACE_MEM_IO::send");
00229   return this->send (buf, len, 0, timeout);
00230 }

ASYS_INLINE ssize_t ACE_MEM_IO::send const void *    buf,
size_t    n
 

Send an <n> byte buffer to the other process using shm_malloc_ connected thru the socket.

Definition at line 198 of file MEM_IO.i.

References ACE_TRACE, and send.

00199 {
00200   ACE_TRACE ("ACE_MEM_IO::send");
00201   return this->send (buf, n, 0);
00202 }

ASYS_INLINE ssize_t ACE_MEM_IO::send const void *    buf,
size_t    n,
int    flags
 

Send an <n> byte buffer to the other process using shm_malloc_ connected thru the socket.

Definition at line 180 of file MEM_IO.i.

References ACE_TRACE.

Referenced by ACE_MEM_Stream::close, send, and ACE_MEM_Stream::send_n.

00181 {
00182   ACE_TRACE ("ACE_MEM_IO::send");
00183   return this->send (buf, n, flags, 0);
00184 }


Member Data Documentation

ACE_MEM_IO::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_MEM_Stream.

Definition at line 267 of file MEM_IO.h.

ssize_t ACE_MEM_IO::buf_size_ [private]
 

Record the current total buffer size of <recv_buffer_>.

Definition at line 288 of file MEM_IO.h.

Referenced by fetch_recv_buf, and recv.

ssize_t ACE_MEM_IO::cur_offset_ [private]
 

Record the current read pointer location in <recv_buffer_>.

Definition at line 291 of file MEM_IO.h.

Referenced by fetch_recv_buf, and recv.

ACE_MEM_SAP* ACE_MEM_IO::deliver_strategy_ [private]
 

Actual deliverying mechanism.

Definition at line 282 of file MEM_IO.h.

Referenced by fetch_recv_buf, fini, init, send, and ~ACE_MEM_IO.

ACE_MEM_SAP_Node* ACE_MEM_IO::recv_buffer_ [private]
 

Internal pointer for support recv/send.

Definition at line 285 of file MEM_IO.h.

Referenced by fetch_recv_buf.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:50:19 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002