00001
00002
00003
00004
00005 #include "ace/OS_NS_string.h"
00006 #include "ace/Truncate.h"
00007
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009
00010 ACE_INLINE
00011 ACE_Reactive_MEM_IO::ACE_Reactive_MEM_IO ()
00012 {
00013 }
00014
00015 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00016 ACE_INLINE
00017 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (void)
00018 : mq_ (0),
00019 malloc_ (0)
00020 {
00021 }
00022
00023 ACE_INLINE
00024 ACE_MT_MEM_IO::ACE_MT_MEM_IO ()
00025 {
00026 this->recv_channel_.sema_ = 0;
00027 this->recv_channel_.lock_ = 0;
00028 this->send_channel_.sema_ = 0;
00029 this->send_channel_.lock_ = 0;
00030 }
00031
00032 ACE_INLINE
00033 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (MQ_Struct *mq)
00034 : mq_ (mq),
00035 malloc_ (0)
00036 {
00037 }
00038
00039 ACE_INLINE int
00040 ACE_MT_MEM_IO::Simple_Queue::init (MQ_Struct *mq,
00041 ACE_MEM_SAP::MALLOC_TYPE *malloc)
00042 {
00043 if (this->mq_ != 0)
00044 return -1;
00045
00046 this->mq_ = mq;
00047 this->malloc_ = malloc;
00048 return 0;
00049 }
00050 #endif
00051
00052 ACE_INLINE ssize_t
00053 ACE_Reactive_MEM_IO::get_buf_len (const ACE_OFF_T off, ACE_MEM_SAP_Node *&buf)
00054 {
00055 #if !defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00056 ACE_TRACE ("ACE_Reactive_MEM_IO::get_buf_len");
00057 #endif
00058
00059 if (this->shm_malloc_ == 0)
00060 {
00061 return -1;
00062 }
00063
00064 ssize_t retv = 0;
00065
00066 ACE_SEH_TRY
00067 {
00068 buf =
00069 reinterpret_cast<ACE_MEM_SAP_Node *> (
00070 static_cast<char *> (this->shm_malloc_->base_addr ()) + off);
00071 retv = ACE_Utils::truncate_cast<ssize_t> (buf->size ());
00072 }
00073 ACE_SEH_EXCEPT (this->shm_malloc_->memory_pool ().seh_selector (GetExceptionInformation ()))
00074 {
00075 }
00076
00077 return retv;
00078 }
00079
00080
00081 ACE_INLINE
00082 ACE_MEM_IO::ACE_MEM_IO (void)
00083 : deliver_strategy_ (0),
00084 recv_buffer_ (0),
00085 buf_size_ (0),
00086 cur_offset_ (0)
00087 {
00088
00089 }
00090
00091 ACE_INLINE ssize_t
00092 ACE_MEM_IO::fetch_recv_buf (int flag, const ACE_Time_Value *timeout)
00093 {
00094 ACE_TRACE ("ACE_MEM_IO::fetch_recv_buf");
00095
00096 if (this->deliver_strategy_ == 0)
00097 return -1;
00098
00099
00100 ACE_ASSERT (this->buf_size_ == this->cur_offset_);
00101
00102
00103 if (this->recv_buffer_ != 0)
00104 this->deliver_strategy_->release_buffer (this->recv_buffer_);
00105
00106 this->cur_offset_ = 0;
00107 ssize_t retv = 0;
00108
00109 if ((retv = this->deliver_strategy_->recv_buf (this->recv_buffer_,
00110 flag,
00111 timeout)) > 0)
00112 this->buf_size_ = retv;
00113 else
00114 this->buf_size_ = 0;
00115
00116 return retv;
00117 }
00118
00119 ACE_INLINE
00120 ACE_MEM_IO::~ACE_MEM_IO (void)
00121 {
00122 delete this->deliver_strategy_;
00123 }
00124
00125 ACE_INLINE ssize_t
00126 ACE_MEM_IO::send (const void *buf,
00127 size_t len,
00128 int flags,
00129 const ACE_Time_Value *timeout)
00130 {
00131 ACE_TRACE ("ACE_MEM_IO::send");
00132
00133 if (this->deliver_strategy_ == 0)
00134 {
00135 return 0;
00136 }
00137
00138 ACE_MEM_SAP_Node *sbuf =
00139 this->deliver_strategy_->acquire_buffer (
00140 ACE_Utils::truncate_cast<ssize_t> (len));
00141
00142 if (sbuf == 0)
00143 {
00144 return -1;
00145 }
00146
00147 ACE_OS::memcpy (sbuf->data (), buf, len);
00148
00149
00150
00151 sbuf->size_ = len;
00152
00153 return this->deliver_strategy_->send_buf (sbuf,
00154 flags,
00155 timeout);
00156 }
00157
00158 ACE_INLINE ssize_t
00159 ACE_MEM_IO::recv (void *buf,
00160 size_t len,
00161 int flags,
00162 const ACE_Time_Value *timeout)
00163 {
00164 ACE_TRACE ("ACE_MEM_IO::recv");
00165
00166 size_t count = 0;
00167
00168 size_t buf_len = this->buf_size_ - this->cur_offset_;
00169
00170 if (buf_len == 0)
00171 {
00172 ssize_t blen =
00173 this->fetch_recv_buf (flags, timeout);
00174
00175 if (blen <= 0)
00176 {
00177 return blen;
00178 }
00179
00180 buf_len = this->buf_size_;
00181 }
00182
00183 size_t length = (len > buf_len ? buf_len : len);
00184
00185 ACE_OS::memcpy ((char *) buf + count,
00186 (char *) this->recv_buffer_->data () + this->cur_offset_,
00187 length);
00188 this->cur_offset_ += ACE_Utils::truncate_cast<ssize_t> (length);
00189 count += length;
00190
00191 return ACE_Utils::truncate_cast<ssize_t> (count);
00192 }
00193
00194 ACE_INLINE ssize_t
00195 ACE_MEM_IO::send (const void *buf, size_t n, int flags)
00196 {
00197 ACE_TRACE ("ACE_MEM_IO::send");
00198 return this->send (buf, n, flags, 0);
00199 }
00200
00201
00202
00203 ACE_INLINE ssize_t
00204 ACE_MEM_IO::recv (void *buf, size_t n, int flags)
00205 {
00206 ACE_TRACE ("ACE_MEM_IO::recv");
00207 return this->recv (buf, n, flags, 0);
00208 }
00209
00210
00211
00212 ACE_INLINE ssize_t
00213 ACE_MEM_IO::send (const void *buf, size_t n)
00214 {
00215 ACE_TRACE ("ACE_MEM_IO::send");
00216 return this->send (buf, n, 0);
00217 }
00218
00219
00220
00221 ACE_INLINE ssize_t
00222 ACE_MEM_IO::recv (void *buf, size_t n)
00223 {
00224 ACE_TRACE ("ACE_MEM_IO::recv");
00225
00226 return this->recv (buf, n, 0);
00227 }
00228
00229 ACE_INLINE ssize_t
00230 ACE_MEM_IO::recv (void *buf,
00231 size_t len,
00232 const ACE_Time_Value *timeout)
00233 {
00234 ACE_TRACE ("ACE_MEM_IO::recv");
00235 return this->recv (buf, len, 0, timeout);
00236 }
00237
00238 ACE_INLINE ssize_t
00239 ACE_MEM_IO::send (const void *buf,
00240 size_t len,
00241 const ACE_Time_Value *timeout)
00242 {
00243 ACE_TRACE ("ACE_MEM_IO::send");
00244 return this->send (buf, len, 0, timeout);
00245 }
00246
00247 ACE_END_VERSIONED_NAMESPACE_DECL