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 Member Functions

 ACE_MEM_IO (void)
 Constructor.

 ~ACE_MEM_IO (void)
 Destructor.

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)
ssize_t recv (void *buf, size_t n, int flags)
 Recv an byte buffer from the shm_malloc_ thru connected socket.

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

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.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Member Functions

ssize_t fetch_recv_buf (int flag, const ACE_Time_Value *timeout)

Private Attributes

ACE_MEM_SAPdeliver_strategy_
 Actual deliverying mechanism.

ACE_MEM_SAP_Noderecv_buffer_
 Internal pointer for support recv/send.

ssize_t buf_size_
 Record the current total buffer size of .

ssize_t cur_offset_
 Record the current read pointer location in .


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 170 of file MEM_IO.h.


Member Enumeration Documentation

enum ACE_MEM_IO::Signal_Strategy
 

Enumeration values:
Reactive 
MT 

Definition at line 180 of file MEM_IO.h.

00181   {
00182     Reactive,
00183     MT
00184   }  Signal_Strategy;


Constructor & Destructor Documentation

ACE_INLINE ACE_MEM_IO::ACE_MEM_IO void   ) 
 

Constructor.

Definition at line 78 of file MEM_IO.inl.

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

ACE_INLINE ACE_MEM_IO::~ACE_MEM_IO void   ) 
 

Destructor.

Definition at line 116 of file MEM_IO.inl.

References deliver_strategy_.

00117 {
00118   delete this->deliver_strategy_;
00119 }


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 311 of file MEM_IO.cpp.

References ACE_TRACE.

00312 {
00313 #if defined (ACE_HAS_DUMP)
00314   ACE_TRACE ("ACE_MEM_IO::dump");
00315 #endif /* ACE_HAS_DUMP */
00316 }

ACE_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 88 of file MEM_IO.inl.

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

Referenced by recv().

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

int ACE_MEM_IO::fini void   ) 
 

Finalizing the MEM_IO object. This method doesn't invoke the 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, and Reactive.

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 }

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

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

Definition at line 146 of file MEM_IO.inl.

References ACE_TRACE, buf_size_, cur_offset_, fetch_recv_buf(), ACE_OS::memcpy(), and ssize_t.

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

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

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

Definition at line 216 of file MEM_IO.inl.

References ACE_TRACE, and recv().

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

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

Recv an byte buffer from the shm_malloc_ thru connected socket.

Definition at line 208 of file MEM_IO.inl.

References ACE_TRACE, and recv().

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

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

Recv an byte buffer from the shm_malloc_ thru connected socket.

Definition at line 190 of file MEM_IO.inl.

References ACE_TRACE.

Referenced by recv(), and ACE_MEM_Stream::recv_n().

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

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

Wait to to amount of time to send the . If 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_MEM_SAP::acquire_buffer(), ACE_Message_Block::cont(), ACE_MEM_SAP_Node::data(), deliver_strategy_, ACE_Message_Block::length(), ACE_OS::memcpy(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), ACE_MEM_SAP::send_buf(), ACE_MEM_SAP_Node::size_, 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   size_t len = message_block->total_length ();
00374 
00375   if (len != 0)
00376     {
00377       ACE_MEM_SAP_Node *buf =
00378         reinterpret_cast<ACE_MEM_SAP_Node *> (
00379           this->deliver_strategy_->acquire_buffer (len));
00380       size_t n = 0;
00381       while (message_block != 0)
00382         {
00383           ACE_OS::memcpy (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 }

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

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

Definition at line 122 of file MEM_IO.inl.

References ACE_TRACE, ACE_MEM_SAP::acquire_buffer(), ACE_MEM_SAP_Node::data(), deliver_strategy_, ACE_OS::memcpy(), ACE_MEM_SAP::send_buf(), and ACE_MEM_SAP_Node::size_.

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

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

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

Definition at line 225 of file MEM_IO.inl.

References ACE_TRACE, and send().

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

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

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

Definition at line 199 of file MEM_IO.inl.

References ACE_TRACE, and send().

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

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

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

Definition at line 181 of file MEM_IO.inl.

References ACE_TRACE.

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

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


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 274 of file MEM_IO.h.

ssize_t ACE_MEM_IO::buf_size_ [private]
 

Record the current total buffer size of .

Definition at line 295 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 .

Definition at line 298 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 289 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 292 of file MEM_IO.h.

Referenced by fetch_recv_buf().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:24:39 2006 for ACE by doxygen 1.3.6