2 #include "ace/OS_NS_string.h"
3 #include "ace/Truncate.h"
5 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 ACE_Reactive_MEM_IO::ACE_Reactive_MEM_IO ()
12 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
14 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue ()
21 ACE_MT_MEM_IO::ACE_MT_MEM_IO ()
23 this->recv_channel_.sema_ = 0;
24 this->recv_channel_.lock_ = 0;
25 this->send_channel_.sema_ = 0;
26 this->send_channel_.lock_ = 0;
30 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (MQ_Struct *mq)
37 ACE_MT_MEM_IO::Simple_Queue::init (MQ_Struct *mq,
38 ACE_MEM_SAP::MALLOC_TYPE *malloc)
44 this->malloc_ = malloc;
47 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
50 ACE_Reactive_MEM_IO::get_buf_len (const ACE_OFF_T off, ACE_MEM_SAP_Node *&buf)
52 #if !defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
53 ACE_TRACE ("ACE_Reactive_MEM_IO::get_buf_len");
54 #endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */
56 if (this->shm_malloc_ == 0)
66 reinterpret_cast<ACE_MEM_SAP_Node *> (
67 static_cast<char *> (this->shm_malloc_->base_addr ()) + off);
68 retv = ACE_Utils::truncate_cast<ssize_t> (buf->size ());
70 ACE_SEH_EXCEPT (this->shm_malloc_->memory_pool ().seh_selector (GetExceptionInformation ()))
77 // Send an n byte message to the connected socket.
79 ACE_MEM_IO::ACE_MEM_IO ()
80 : deliver_strategy_ (0),
85 // ACE_TRACE ("ACE_MEM_IO::ACE_MEM_IO");
89 ACE_MEM_IO::fetch_recv_buf (int flag, const ACE_Time_Value *timeout)
91 ACE_TRACE ("ACE_MEM_IO::fetch_recv_buf");
93 if (this->deliver_strategy_ == 0)
96 // This method can only be called when <buf_size_> == <cur_offset_>.
97 ACE_ASSERT (this->buf_size_ == this->cur_offset_);
99 // We have done using the previous buffer, return it to malloc.
100 if (this->recv_buffer_ != 0)
101 this->deliver_strategy_->release_buffer (this->recv_buffer_);
103 this->cur_offset_ = 0;
106 if ((retv = this->deliver_strategy_->recv_buf (this->recv_buffer_,
109 this->buf_size_ = retv;
117 ACE_MEM_IO::~ACE_MEM_IO ()
119 delete this->deliver_strategy_;
123 ACE_MEM_IO::send (const void *buf,
126 const ACE_Time_Value *timeout)
128 ACE_TRACE ("ACE_MEM_IO::send");
130 if (this->deliver_strategy_ == 0)
135 ACE_MEM_SAP_Node *sbuf =
136 this->deliver_strategy_->acquire_buffer (
137 ACE_Utils::truncate_cast<ssize_t> (len));
141 return -1; // Memory buffer not initialized.
144 ACE_OS::memcpy (sbuf->data (), buf, len);
150 return this->deliver_strategy_->send_buf (sbuf,
156 ACE_MEM_IO::recv (void *buf,
159 const ACE_Time_Value *timeout)
161 ACE_TRACE ("ACE_MEM_IO::recv");
165 size_t buf_len = this->buf_size_ - this->cur_offset_;
169 ssize_t blen = // Buffer length
170 this->fetch_recv_buf (flags, timeout);
177 buf_len = this->buf_size_;
180 size_t length = (len > buf_len ? buf_len : len);
182 ACE_OS::memcpy ((char *) buf + count,
183 (char *) this->recv_buffer_->data () + this->cur_offset_,
185 this->cur_offset_ += ACE_Utils::truncate_cast<ssize_t> (length);
188 return ACE_Utils::truncate_cast<ssize_t> (count);
192 ACE_MEM_IO::send (const void *buf, size_t n, int flags)
194 ACE_TRACE ("ACE_MEM_IO::send");
195 return this->send (buf, n, flags, 0);
198 // Recv an n byte message from the connected socket.
201 ACE_MEM_IO::recv (void *buf, size_t n, int flags)
203 ACE_TRACE ("ACE_MEM_IO::recv");
204 return this->recv (buf, n, flags, 0);
207 // Send an n byte message to the connected socket.
210 ACE_MEM_IO::send (const void *buf, size_t n)
212 ACE_TRACE ("ACE_MEM_IO::send");
213 return this->send (buf, n, 0);
216 // Recv an n byte message from the connected socket.
219 ACE_MEM_IO::recv (void *buf, size_t n)
221 ACE_TRACE ("ACE_MEM_IO::recv");
223 return this->recv (buf, n, 0);
227 ACE_MEM_IO::recv (void *buf,
229 const ACE_Time_Value *timeout)
231 ACE_TRACE ("ACE_MEM_IO::recv");
232 return this->recv (buf, len, 0, timeout);
236 ACE_MEM_IO::send (const void *buf,
238 const ACE_Time_Value *timeout)
240 ACE_TRACE ("ACE_MEM_IO::send");
241 return this->send (buf, len, 0, timeout);
244 ACE_END_VERSIONED_NAMESPACE_DECL