[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / FIFO_Recv_Msg.inl
blob0a0b0673d3870c738b444d4ccafa42abc5608074
1 // -*- C++ -*-
2 //
3 // $Id: FIFO_Recv_Msg.inl 82559 2008-08-07 20:23:07Z parsons $
5 #include "ace/Min_Max.h"
6 #include "ace/OS_NS_stropts.h"
7 #include "ace/Truncate.h"
9 #if !defined (ACE_HAS_STREAM_PIPES)
10 #include "ace/OS_NS_unistd.h"
11 #endif
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_INLINE ssize_t
16 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg)
18   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
19 #if defined (ACE_HAS_STREAM_PIPES)
20   int i = 0;
21   if (ACE_OS::getmsg (this->get_handle (),
22                       (strbuf *) 0,
23                       (strbuf *) &recv_msg,
24                       &i) == -1)
25     {
26       return -1;
27     }
28   else
29     {
30       return recv_msg.len;
31     }
32 #else /* Do the ol' 2-read trick... */
33   if (ACE_OS::read (this->get_handle (),
34                     (char *) &recv_msg.len,
35                     sizeof recv_msg.len) != sizeof recv_msg.len)
36     {
37       return -1;
38     }
39   else
40     {
41       size_t remaining = static_cast<size_t> (recv_msg.len);
42       size_t requested = static_cast<size_t> (recv_msg.maxlen);
43       ssize_t recv_len = ACE_OS::read (this->get_handle (),
44                                        (char *) recv_msg.buf,
45                                        ACE_MIN (remaining, requested));
46                                        
47       if (recv_len == -1)
48         {
49           return -1;
50         }
51         
52       // Tell caller what's really in the buffer.
53       recv_msg.len = static_cast<int> (recv_len);
55       // If there are more bytes remaining in the message, read them and
56       // throw them away. Leaving them in the FIFO would make it difficult
57       // to find the start of the next message in the fifo.
58       // Since the ACE_HAS_STREAM_PIPES version of this method doesn't
59       // return getmsg()'s indication of "data remaining", don't worry about
60       // saving the indication here either to read the remainder later.
61       size_t total_msg_size = remaining;
62       remaining -= recv_len;
63       
64       while (remaining > 0)
65         {
66           const size_t throw_away = 1024;
67           char dev_null[throw_away];
68           recv_len = ACE_OS::read (this->get_handle (),
69                                    dev_null,
70                                    ACE_MIN (remaining, throw_away));
71                                    
72           if (recv_len == -1)
73             {
74               break;
75             }
76             
77           remaining -= recv_len;
78         }
79         
80       return ACE_Utils::truncate_cast<ssize_t> (total_msg_size);
81     }
82 #endif /* ACE_HAS_STREAM_PIPES */
85 ACE_INLINE ssize_t
86 ACE_FIFO_Recv_Msg::recv (void *buf, size_t max_len)
88   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
89   ACE_Str_Buf recv_msg ((char *) buf, 0, static_cast<int> (max_len));
91   return this->recv (recv_msg);
94 #if defined (ACE_HAS_STREAM_PIPES)
95 ACE_INLINE ssize_t
96 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf *data,
97                          ACE_Str_Buf *cntl,
98                          int *flags)
100   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
101   if (ACE_OS::getmsg (this->get_handle (),
102                       (strbuf *) cntl,
103                       (strbuf *) data,
104                       flags) == -1)
105     {
106       return -1;
107     }
108   else
109     {
110       return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
111     }
114 ACE_INLINE ssize_t
115 ACE_FIFO_Recv_Msg::recv (int *band,
116                          ACE_Str_Buf *data,
117                          ACE_Str_Buf *cntl,
118                          int *flags)
120   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
121   
122   if (ACE_OS::getpmsg (this->get_handle (),
123                        (strbuf *) cntl,
124                        (strbuf *) data,
125                        band,
126                        flags) == -1)
127     {
128       return -1;
129     }
130   else
131     {
132       return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
133     }
135 #endif /* ACE_HAS_STREAM_PIPES */
137 ACE_END_VERSIONED_NAMESPACE_DECL