[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / MEM_IO.inl
blobe3ec07fc5cefa0f079a3c1190f13168928b3df18
1 // -*- C++ -*-
2 //
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
10 ACE_INLINE
11 ACE_Reactive_MEM_IO::ACE_Reactive_MEM_IO ()
15 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
16 ACE_INLINE
17 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (void)
18   : mq_ (0),
19     malloc_ (0)
23 ACE_INLINE
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;
32 ACE_INLINE
33 ACE_MT_MEM_IO::Simple_Queue::Simple_Queue (MQ_Struct *mq)
34   : mq_ (mq),
35     malloc_ (0)
39 ACE_INLINE int
40 ACE_MT_MEM_IO::Simple_Queue::init (MQ_Struct *mq,
41                                    ACE_MEM_SAP::MALLOC_TYPE *malloc)
43   if (this->mq_ != 0)
44     return -1;
46   this->mq_ = mq;
47   this->malloc_ = malloc;
48   return 0;
50 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
52 ACE_INLINE ssize_t
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)
60     {
61       return -1;
62     }
64   ssize_t retv = 0;
66   ACE_SEH_TRY
67     {
68       buf =
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 ());
72     }
73   ACE_SEH_EXCEPT (this->shm_malloc_->memory_pool ().seh_selector (GetExceptionInformation ()))
74     {
75     }
77   return retv;
80 // Send an n byte message to the connected socket.
81 ACE_INLINE
82 ACE_MEM_IO::ACE_MEM_IO (void)
83   : deliver_strategy_ (0),
84     recv_buffer_ (0),
85     buf_size_ (0),
86     cur_offset_ (0)
88   // ACE_TRACE ("ACE_MEM_IO::ACE_MEM_IO");
91 ACE_INLINE ssize_t
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)
97     return -1;
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;
107   ssize_t retv = 0;
109   if ((retv = this->deliver_strategy_->recv_buf (this->recv_buffer_,
110                                                  flag,
111                                                  timeout)) > 0)
112     this->buf_size_ = retv;
113   else
114     this->buf_size_ = 0;
116   return retv;
119 ACE_INLINE
120 ACE_MEM_IO::~ACE_MEM_IO (void)
122   delete this->deliver_strategy_;
125 ACE_INLINE ssize_t
126 ACE_MEM_IO::send (const void *buf,
127                   size_t len,
128                   int flags,
129                   const ACE_Time_Value *timeout)
131   ACE_TRACE ("ACE_MEM_IO::send");
132   
133   if (this->deliver_strategy_ == 0)
134     {
135       return 0;
136     }
138   ACE_MEM_SAP_Node *sbuf =
139     this->deliver_strategy_->acquire_buffer (
140       ACE_Utils::truncate_cast<ssize_t> (len));
141   
142   if (sbuf == 0)
143     {
144       return -1;                  // Memory buffer not initialized.
145     }
146     
147   ACE_OS::memcpy (sbuf->data (), buf, len);
149   ///
151   sbuf->size_ = len;
153   return this->deliver_strategy_->send_buf (sbuf,
154                                             flags,
155                                             timeout);
158 ACE_INLINE ssize_t
159 ACE_MEM_IO::recv (void *buf,
160                   size_t len,
161                   int flags,
162                   const ACE_Time_Value *timeout)
164   ACE_TRACE ("ACE_MEM_IO::recv");
166   size_t count = 0;
168   size_t buf_len = this->buf_size_ - this->cur_offset_;
169   
170   if (buf_len == 0)
171     {
172       ssize_t blen =         // Buffer length
173         this->fetch_recv_buf (flags, timeout);
174         
175       if (blen <= 0)
176         {
177           return blen;
178         }
179         
180       buf_len = this->buf_size_;
181     }
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_,
187                   length);
188   this->cur_offset_ += ACE_Utils::truncate_cast<ssize_t> (length);
189   count += length;
191   return ACE_Utils::truncate_cast<ssize_t> (count);
194 ACE_INLINE ssize_t
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.
203 ACE_INLINE ssize_t
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.
212 ACE_INLINE ssize_t
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.
221 ACE_INLINE ssize_t
222 ACE_MEM_IO::recv (void *buf, size_t n)
224   ACE_TRACE ("ACE_MEM_IO::recv");
226   return this->recv (buf, n, 0);
229 ACE_INLINE ssize_t
230 ACE_MEM_IO::recv (void *buf,
231                   size_t len,
232                   const ACE_Time_Value *timeout)
234   ACE_TRACE ("ACE_MEM_IO::recv");
235   return this->recv (buf, len, 0, timeout);
238 ACE_INLINE ssize_t
239 ACE_MEM_IO::send (const void *buf,
240                   size_t len,
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