3 // $Id: MEM_IO.inl 82559 2008-08-07 20:23:07Z parsons $
5 #include "ace/OS_NS_string.h"
6 #include "ace/Truncate.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_Reactive_MEM_IO::ACE_Reactive_MEM_IO ()
15 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
17 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (void)
24 ACE_MT_MEM_IO::ACE_MT_MEM_IO ()
26 this->recv_channel_.sema_ = 0;
27 this->recv_channel_.lock_ = 0;
28 this->send_channel_.sema_ = 0;
29 this->send_channel_.lock_ = 0;
33 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (MQ_Struct *mq)
40 ACE_MT_MEM_IO::Simple_Queue::init (MQ_Struct *mq,
41 ACE_MEM_SAP::MALLOC_TYPE *malloc)
47 this->malloc_ = malloc;
50 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
53 ACE_Reactive_MEM_IO::get_buf_len (const ACE_OFF_T off, ACE_MEM_SAP_Node *&buf)
55 #if !defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
56 ACE_TRACE ("ACE_Reactive_MEM_IO::get_buf_len");
57 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
59 if (this->shm_malloc_ == 0)
69 reinterpret_cast<ACE_MEM_SAP_Node *> (
70 static_cast<char *> (this->shm_malloc_->base_addr ()) + off);
71 retv = ACE_Utils::truncate_cast<ssize_t> (buf->size ());
73 ACE_SEH_EXCEPT (this->shm_malloc_->memory_pool ().seh_selector (GetExceptionInformation ()))
80 // Send an n byte message to the connected socket.
82 ACE_MEM_IO::ACE_MEM_IO (void)
83 : deliver_strategy_ (0),
88 // ACE_TRACE ("ACE_MEM_IO::ACE_MEM_IO");
92 ACE_MEM_IO::fetch_recv_buf (int flag, const ACE_Time_Value *timeout)
94 ACE_TRACE ("ACE_MEM_IO::fetch_recv_buf");
96 if (this->deliver_strategy_ == 0)
99 // This method can only be called when <buf_size_> == <cur_offset_>.
100 ACE_ASSERT (this->buf_size_ == this->cur_offset_);
102 // We have done using the previous buffer, return it to malloc.
103 if (this->recv_buffer_ != 0)
104 this->deliver_strategy_->release_buffer (this->recv_buffer_);
106 this->cur_offset_ = 0;
109 if ((retv = this->deliver_strategy_->recv_buf (this->recv_buffer_,
112 this->buf_size_ = retv;
120 ACE_MEM_IO::~ACE_MEM_IO (void)
122 delete this->deliver_strategy_;
126 ACE_MEM_IO::send (const void *buf,
129 const ACE_Time_Value *timeout)
131 ACE_TRACE ("ACE_MEM_IO::send");
133 if (this->deliver_strategy_ == 0)
138 ACE_MEM_SAP_Node *sbuf =
139 this->deliver_strategy_->acquire_buffer (
140 ACE_Utils::truncate_cast<ssize_t> (len));
144 return -1; // Memory buffer not initialized.
147 ACE_OS::memcpy (sbuf->data (), buf, len);
153 return this->deliver_strategy_->send_buf (sbuf,
159 ACE_MEM_IO::recv (void *buf,
162 const ACE_Time_Value *timeout)
164 ACE_TRACE ("ACE_MEM_IO::recv");
168 size_t buf_len = this->buf_size_ - this->cur_offset_;
172 ssize_t blen = // Buffer length
173 this->fetch_recv_buf (flags, timeout);
180 buf_len = this->buf_size_;
183 size_t length = (len > buf_len ? buf_len : len);
185 ACE_OS::memcpy ((char *) buf + count,
186 (char *) this->recv_buffer_->data () + this->cur_offset_,
188 this->cur_offset_ += ACE_Utils::truncate_cast<ssize_t> (length);
191 return ACE_Utils::truncate_cast<ssize_t> (count);
195 ACE_MEM_IO::send (const void *buf, size_t n, int flags)
197 ACE_TRACE ("ACE_MEM_IO::send");
198 return this->send (buf, n, flags, 0);
201 // Recv an n byte message from the connected socket.
204 ACE_MEM_IO::recv (void *buf, size_t n, int flags)
206 ACE_TRACE ("ACE_MEM_IO::recv");
207 return this->recv (buf, n, flags, 0);
210 // Send an n byte message to the connected socket.
213 ACE_MEM_IO::send (const void *buf, size_t n)
215 ACE_TRACE ("ACE_MEM_IO::send");
216 return this->send (buf, n, 0);
219 // Recv an n byte message from the connected socket.
222 ACE_MEM_IO::recv (void *buf, size_t n)
224 ACE_TRACE ("ACE_MEM_IO::recv");
226 return this->recv (buf, n, 0);
230 ACE_MEM_IO::recv (void *buf,
232 const ACE_Time_Value *timeout)
234 ACE_TRACE ("ACE_MEM_IO::recv");
235 return this->recv (buf, len, 0, timeout);
239 ACE_MEM_IO::send (const void *buf,
241 const ACE_Time_Value *timeout)
243 ACE_TRACE ("ACE_MEM_IO::send");
244 return this->send (buf, len, 0, timeout);
247 ACE_END_VERSIONED_NAMESPACE_DECL