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

MEM_IO.i

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // $Id: MEM_IO.i,v 1.1.1.2 2001/12/04 14:33:02 chad Exp $
00003 
00004 // MEM_IO.i
00005 
00006 ASYS_INLINE
00007 ACE_Reactive_MEM_IO::ACE_Reactive_MEM_IO ()
00008 {
00009 }
00010 
00011 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00012 ASYS_INLINE
00013 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (void)
00014   : mq_ (0),
00015     malloc_ (0)
00016 {
00017 }
00018 
00019 ASYS_INLINE
00020 ACE_MT_MEM_IO::ACE_MT_MEM_IO ()
00021 {
00022   this->recv_channel_.sema_ = 0;
00023   this->recv_channel_.lock_ = 0;
00024   this->send_channel_.sema_ = 0;
00025   this->send_channel_.lock_ = 0;
00026 }
00027 
00028 ASYS_INLINE
00029 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (MQ_Struct *mq)
00030   : mq_ (mq),
00031     malloc_ (0)
00032 {
00033 }
00034 
00035 ASYS_INLINE int
00036 ACE_MT_MEM_IO::Simple_Queue::init (MQ_Struct *mq,
00037                                    ACE_MEM_SAP::MALLOC_TYPE *malloc)
00038 {
00039   if (this->mq_ != 0)
00040     return -1;
00041 
00042   this->mq_ = mq;
00043   this->malloc_ = malloc;
00044   return 0;
00045 }
00046 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
00047 
00048 ASYS_INLINE ssize_t
00049 ACE_Reactive_MEM_IO::get_buf_len (const off_t off, ACE_MEM_SAP_Node *&buf)
00050 {
00051 #if !defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00052   ACE_TRACE ("ACE_Reactive_MEM_IO::get_buf_len");
00053 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00054 
00055   if (this->shm_malloc_ == 0)
00056     return -1;
00057 
00058   ssize_t retv = 0;
00059 
00060   ACE_SEH_TRY
00061     {
00062       buf = ACE_reinterpret_cast (ACE_MEM_SAP_Node *,
00063                                   (ACE_static_cast(char *,
00064                                                    this->shm_malloc_->base_addr ())
00065                                    + off));
00066       retv = buf->size ();
00067     }
00068   ACE_SEH_EXCEPT (this->shm_malloc_->memory_pool ().seh_selector (GetExceptionInformation ()))
00069     {
00070     }
00071 
00072   return retv;
00073 }
00074 
00075 // Send an n byte message to the connected socket.
00076 ASYS_INLINE
00077 ACE_MEM_IO::ACE_MEM_IO (void)
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 }
00085 
00086 ASYS_INLINE ssize_t
00087 ACE_MEM_IO::fetch_recv_buf (int flag, const ACE_Time_Value *timeout)
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 }
00113 
00114 ASYS_INLINE
00115 ACE_MEM_IO::~ACE_MEM_IO (void)
00116 {
00117   delete this->deliver_strategy_;
00118 }
00119 
00120 ASYS_INLINE ssize_t
00121 ACE_MEM_IO::send (const void *buf,
00122                   size_t len,
00123                   int flags,
00124                   const ACE_Time_Value *timeout)
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 }
00143 
00144 ASYS_INLINE ssize_t
00145 ACE_MEM_IO::recv (void *buf,
00146                   size_t len,
00147                   int flags,
00148                   const ACE_Time_Value *timeout)
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 }
00178 
00179 ASYS_INLINE ssize_t
00180 ACE_MEM_IO::send (const void *buf, size_t n, int flags)
00181 {
00182   ACE_TRACE ("ACE_MEM_IO::send");
00183   return this->send (buf, n, flags, 0);
00184 }
00185 
00186 // Recv an n byte message from the connected socket.
00187 
00188 ASYS_INLINE ssize_t
00189 ACE_MEM_IO::recv (void *buf, size_t n, int flags)
00190 {
00191   ACE_TRACE ("ACE_MEM_IO::recv");
00192   return this->recv (buf, n, flags, 0);
00193 }
00194 
00195 // Send an n byte message to the connected socket.
00196 
00197 ASYS_INLINE ssize_t
00198 ACE_MEM_IO::send (const void *buf, size_t n)
00199 {
00200   ACE_TRACE ("ACE_MEM_IO::send");
00201   return this->send (buf, n, 0);
00202 }
00203 
00204 // Recv an n byte message from the connected socket.
00205 
00206 ASYS_INLINE ssize_t
00207 ACE_MEM_IO::recv (void *buf, size_t n)
00208 {
00209   ACE_TRACE ("ACE_MEM_IO::recv");
00210 
00211   return this->recv (buf, n, 0);
00212 }
00213 
00214 ASYS_INLINE ssize_t
00215 ACE_MEM_IO::recv (void *buf,
00216                   size_t len,
00217                   const ACE_Time_Value *timeout)
00218 {
00219   ACE_TRACE ("ACE_MEM_IO::recv");
00220   return this->recv (buf, len, 0, timeout);
00221 }
00222 
00223 ASYS_INLINE ssize_t
00224 ACE_MEM_IO::send (const void *buf,
00225                   size_t len,
00226                   const ACE_Time_Value *timeout)
00227 {
00228   ACE_TRACE ("ACE_MEM_IO::send");
00229   return this->send (buf, len, 0, timeout);
00230 }

Generated on Mon Jun 16 11:20:17 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002