00001
00002
00003
00004 #include "ace/OS_NS_string.h"
00005
00006 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00007
00008 ACE_INLINE
00009 ACE_Reactive_MEM_IO::ACE_Reactive_MEM_IO ()
00010 {
00011 }
00012
00013 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00014 ACE_INLINE
00015 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (void)
00016 : mq_ (0),
00017 malloc_ (0)
00018 {
00019 }
00020
00021 ACE_INLINE
00022 ACE_MT_MEM_IO::ACE_MT_MEM_IO ()
00023 {
00024 this->recv_channel_.sema_ = 0;
00025 this->recv_channel_.lock_ = 0;
00026 this->send_channel_.sema_ = 0;
00027 this->send_channel_.lock_ = 0;
00028 }
00029
00030 ACE_INLINE
00031 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (MQ_Struct *mq)
00032 : mq_ (mq),
00033 malloc_ (0)
00034 {
00035 }
00036
00037 ACE_INLINE int
00038 ACE_MT_MEM_IO::Simple_Queue::init (MQ_Struct *mq,
00039 ACE_MEM_SAP::MALLOC_TYPE *malloc)
00040 {
00041 if (this->mq_ != 0)
00042 return -1;
00043
00044 this->mq_ = mq;
00045 this->malloc_ = malloc;
00046 return 0;
00047 }
00048 #endif
00049
00050 ACE_INLINE ssize_t
00051 ACE_Reactive_MEM_IO::get_buf_len (const off_t off, ACE_MEM_SAP_Node *&buf)
00052 {
00053 #if !defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00054 ACE_TRACE ("ACE_Reactive_MEM_IO::get_buf_len");
00055 #endif
00056
00057 if (this->shm_malloc_ == 0)
00058 return -1;
00059
00060 ssize_t retv = 0;
00061
00062 ACE_SEH_TRY
00063 {
00064 buf =
00065 reinterpret_cast<ACE_MEM_SAP_Node *> (
00066 static_cast<char *> (this->shm_malloc_->base_addr ()) + off);
00067 retv = buf->size ();
00068 }
00069 ACE_SEH_EXCEPT (this->shm_malloc_->memory_pool ().seh_selector (GetExceptionInformation ()))
00070 {
00071 }
00072
00073 return retv;
00074 }
00075
00076
00077 ACE_INLINE
00078 ACE_MEM_IO::ACE_MEM_IO (void)
00079 : deliver_strategy_ (0),
00080 recv_buffer_ (0),
00081 buf_size_ (0),
00082 cur_offset_ (0)
00083 {
00084
00085 }
00086
00087 ACE_INLINE ssize_t
00088 ACE_MEM_IO::fetch_recv_buf (int flag, const ACE_Time_Value *timeout)
00089 {
00090 ACE_TRACE ("ACE_MEM_IO::fetch_recv_buf");
00091
00092 if (this->deliver_strategy_ == 0)
00093 return -1;
00094
00095
00096 ACE_ASSERT (this->buf_size_ == this->cur_offset_);
00097
00098
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 }
00114
00115 ACE_INLINE
00116 ACE_MEM_IO::~ACE_MEM_IO (void)
00117 {
00118 delete this->deliver_strategy_;
00119 }
00120
00121 ACE_INLINE ssize_t
00122 ACE_MEM_IO::send (const void *buf,
00123 size_t len,
00124 int flags,
00125 const ACE_Time_Value *timeout)
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;
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 }
00144
00145 ACE_INLINE ssize_t
00146 ACE_MEM_IO::recv (void *buf,
00147 size_t len,
00148 int flags,
00149 const ACE_Time_Value *timeout)
00150 {
00151 ACE_TRACE ("ACE_MEM_IO::recv");
00152
00153 size_t count = 0;
00154
00155
00156
00157 size_t buf_len = this->buf_size_ - this->cur_offset_;
00158 if (buf_len == 0)
00159 {
00160 ssize_t blen =
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
00174 count += length;
00175
00176
00177 return count;
00178 }
00179
00180 ACE_INLINE ssize_t
00181 ACE_MEM_IO::send (const void *buf, size_t n, int flags)
00182 {
00183 ACE_TRACE ("ACE_MEM_IO::send");
00184 return this->send (buf, n, flags, 0);
00185 }
00186
00187
00188
00189 ACE_INLINE ssize_t
00190 ACE_MEM_IO::recv (void *buf, size_t n, int flags)
00191 {
00192 ACE_TRACE ("ACE_MEM_IO::recv");
00193 return this->recv (buf, n, flags, 0);
00194 }
00195
00196
00197
00198 ACE_INLINE ssize_t
00199 ACE_MEM_IO::send (const void *buf, size_t n)
00200 {
00201 ACE_TRACE ("ACE_MEM_IO::send");
00202 return this->send (buf, n, 0);
00203 }
00204
00205
00206
00207 ACE_INLINE ssize_t
00208 ACE_MEM_IO::recv (void *buf, size_t n)
00209 {
00210 ACE_TRACE ("ACE_MEM_IO::recv");
00211
00212 return this->recv (buf, n, 0);
00213 }
00214
00215 ACE_INLINE ssize_t
00216 ACE_MEM_IO::recv (void *buf,
00217 size_t len,
00218 const ACE_Time_Value *timeout)
00219 {
00220 ACE_TRACE ("ACE_MEM_IO::recv");
00221 return this->recv (buf, len, 0, timeout);
00222 }
00223
00224 ACE_INLINE ssize_t
00225 ACE_MEM_IO::send (const void *buf,
00226 size_t len,
00227 const ACE_Time_Value *timeout)
00228 {
00229 ACE_TRACE ("ACE_MEM_IO::send");
00230 return this->send (buf, len, 0, timeout);
00231 }
00232
00233 ACE_END_VERSIONED_NAMESPACE_DECL