Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / OS_NS_stropts.inl
blob6f433a441ce82209d7c8dcbc2f742e566e6a5dac
1 // -*- C++ -*-
2 #include "ace/os_include/os_errno.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/OS_NS_string.h"
5 #include "ace/OS_NS_macros.h"
6 #include "ace/OS_Memory.h"
7 #include "ace/OS_QoS.h"
8 #include "ace/Global_Macros.h"
10 #if defined (ACE_HAS_ALLOC_HOOKS)
11 # include "ace/Malloc_Base.h"
12 #endif /* ACE_HAS_ALLOC_HOOKS */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 #if defined (ACE_LACKS_CONST_STRBUF_PTR)
17 typedef struct strbuf *ACE_STRBUF_TYPE;
18 #else
19 typedef const struct strbuf *ACE_STRBUF_TYPE;
20 #endif /* ACE_LACKS_CONST_STRBUF_PTR */
22 ACE_INLINE
23 ACE_Str_Buf::ACE_Str_Buf (void *b, int l, int max)
25   this->maxlen = max;
26   this->len = l;
27   this->buf = (char *) b;
30 ACE_INLINE
31 ACE_Str_Buf::ACE_Str_Buf (strbuf &sb)
33   this->maxlen = sb.maxlen;
34   this->len = sb.len;
35   this->buf = sb.buf;
38 /*****************************************************************************/
40 ACE_INLINE int
41 ACE_OS::getmsg (ACE_HANDLE handle,
42                 struct strbuf *ctl,
43                 struct strbuf *data,
44                 int *flags)
46   ACE_OS_TRACE ("ACE_OS::getmsg");
47 #if defined (ACE_HAS_STREAM_PIPES)
48   ACE_OSCALL_RETURN (::getmsg (handle, ctl, data, flags), int, -1);
49 #else
50   ACE_UNUSED_ARG (handle);
51   ACE_UNUSED_ARG (ctl);
52   ACE_UNUSED_ARG (data);
53   ACE_UNUSED_ARG (flags);
55   // I'm not sure how to implement this correctly.
56   ACE_NOTSUP_RETURN (-1);
57 #endif /* ACE_HAS_STREAM_PIPES */
60 ACE_INLINE int
61 ACE_OS::getpmsg (ACE_HANDLE handle,
62                  struct strbuf *ctl,
63                  struct strbuf *data,
64                  int *band,
65                  int *flags)
67   ACE_OS_TRACE ("ACE_OS::getpmsg");
68 #if defined (ACE_HAS_STREAM_PIPES)
69   ACE_OSCALL_RETURN (::getpmsg (handle, ctl, data, band, flags), int, -1);
70 #else
71   ACE_UNUSED_ARG (handle);
72   ACE_UNUSED_ARG (ctl);
73   ACE_UNUSED_ARG (data);
74   ACE_UNUSED_ARG (band);
75   ACE_UNUSED_ARG (flags);
77   // I'm not sure how to implement this correctly.
78   ACE_NOTSUP_RETURN (-1);
79 #endif /* ACE_HAS_STREAM_PIPES */
82 ACE_INLINE int
83 ACE_OS::fattach (int handle, const char *path)
85   ACE_OS_TRACE ("ACE_OS::fattach");
86 #if defined (ACE_HAS_STREAM_PIPES)
87   ACE_OSCALL_RETURN (::fattach (handle, path), int, -1);
88 #else
89   ACE_UNUSED_ARG (handle);
90   ACE_UNUSED_ARG (path);
92   ACE_NOTSUP_RETURN (-1);
93 #endif /* ACE_HAS_STREAM_PIPES */
96 ACE_INLINE int
97 ACE_OS::fdetach (const char *file)
99   ACE_OS_TRACE ("ACE_OS::fdetach");
100 #if defined (ACE_HAS_STREAM_PIPES)
101   ACE_OSCALL_RETURN (::fdetach (file), int, -1);
102 #else
103   ACE_UNUSED_ARG (file);
105   ACE_NOTSUP_RETURN (-1);
106 #endif /* ACE_HAS_STREAM_PIPES */
109 ACE_INLINE int
110 ACE_OS::ioctl (ACE_HANDLE handle,
111                ACE_IOCTL_TYPE_ARG2 cmd,
112                void *val)
114   ACE_OS_TRACE ("ACE_OS::ioctl");
115 #if defined (ACE_LACKS_IOCTL)
116   ACE_UNUSED_ARG (handle);
117   ACE_UNUSED_ARG (cmd);
118   ACE_UNUSED_ARG (val);
119   ACE_NOTSUP_RETURN (-1);
120 #elif defined (ACE_WIN32)
121   ACE_SOCKET sock = (ACE_SOCKET) handle;
122   ACE_SOCKCALL_RETURN (::ioctlsocket (sock, cmd, reinterpret_cast<unsigned long *> (val)), int, -1);
123 #elif defined (ACE_HAS_IOCTL_INT_3_PARAM)
124   ACE_OSCALL_RETURN (::ioctl (handle, cmd, reinterpret_cast<int> (val)),
125                      int, -1);
126 #elif defined (ACE_MQX)
127   // TBD: See if there is a way to provide this functionality
128   ACE_NOTSUP_RETURN (0);
129 #else
130   ACE_OSCALL_RETURN (::ioctl (handle, cmd, val), int, -1);
131 #endif /* ACE_WIN32 */
134 ACE_INLINE int
135 ACE_OS::isastream (ACE_HANDLE handle)
137   ACE_OS_TRACE ("ACE_OS::isastream");
138 #if defined (ACE_HAS_STREAM_PIPES)
139   ACE_OSCALL_RETURN (::isastream (handle), int, -1);
140 #else
141   ACE_UNUSED_ARG (handle);
143   ACE_NOTSUP_RETURN (-1);
144 #endif /* ACE_HAS_STREAM_PIPES */
147 ACE_INLINE int
148 ACE_OS::putmsg (ACE_HANDLE handle, const struct strbuf *ctl,
149                 const struct strbuf *data, int flags)
151   ACE_OS_TRACE ("ACE_OS::putmsg");
152 #if defined (ACE_HAS_STREAM_PIPES)
153   ACE_OSCALL_RETURN (::putmsg (handle,
154                                (ACE_STRBUF_TYPE) ctl,
155                                (ACE_STRBUF_TYPE) data,
156                                flags), int, -1);
157 #else
158   ACE_UNUSED_ARG (flags);
159   ssize_t result;
160   if (ctl == 0 && data == 0)
161     {
162       errno = EINVAL;
163       return 0;
164     }
165   // Handle the two easy cases.
166   else if (ctl != 0)
167     {
168       result =  ACE_OS::write (handle, ctl->buf, ctl->len);
169       return static_cast<int> (result);
170     }
171   else if (data != 0)
172     {
173       result = ACE_OS::write (handle, data->buf, data->len);
174       return static_cast<int> (result);
175     }
176   else
177     {
178       // This is the hard case.
179       char *buf;
180 #if defined (ACE_HAS_ALLOC_HOOKS)
181       ACE_ALLOCATOR_RETURN (buf, static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * (ctl->len + data->len))), -1);
182 #else
183       ACE_NEW_RETURN (buf, char [ctl->len + data->len], -1);
184 #endif /* ACE_HAS_ALLOC_HOOKS */
185       ACE_OS::memcpy (buf, ctl->buf, ctl->len);
186       ACE_OS::memcpy (buf + ctl->len, data->buf, data->len);
187       result = ACE_OS::write (handle, buf, ctl->len + data->len);
188 #if defined (ACE_HAS_ALLOC_HOOKS)
189       ACE_Allocator::instance()->free(buf);
190 #else
191       delete [] buf;
192 #endif /* ACE_HAS_ALLOC_HOOKS */
194       return static_cast<int> (result);
195     }
196 #endif /* ACE_HAS_STREAM_PIPES */
199 ACE_INLINE int
200 ACE_OS::putpmsg (ACE_HANDLE handle,
201                  const struct strbuf *ctl,
202                  const struct strbuf *data,
203                  int band,
204                  int flags)
206   ACE_OS_TRACE ("ACE_OS::putpmsg");
207 #if defined (ACE_HAS_STREAM_PIPES)
208   ACE_OSCALL_RETURN (::putpmsg (handle,
209                                 (ACE_STRBUF_TYPE) ctl,
210                                 (ACE_STRBUF_TYPE) data,
211                                 band, flags), int, -1);
212 #else
213   ACE_UNUSED_ARG (flags);
214   ACE_UNUSED_ARG (band);
215   return ACE_OS::putmsg (handle, ctl, data, flags);
216 #endif /* ACE_HAS_STREAM_PIPES */
219 ACE_END_VERSIONED_NAMESPACE_DECL