summaryrefslogtreecommitdiff
path: root/ACE/ace/Pipe.inl
blob: 35af84ff28771dec41a77e75102a4b8fcfec83d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// -*- C++ -*-
#include "ace/Global_Macros.h"
#include "ace/ACE.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_INLINE
ACE_Pipe::~ACE_Pipe (void)
{
  ACE_TRACE ("ACE_Pipe::~ACE_Pipe");
  // Notice that the destructor doesn't close the handles for you.
}

ACE_INLINE ACE_HANDLE
ACE_Pipe::read_handle () const
{
  ACE_TRACE ("ACE_Pipe::read_handle");
  return this->handles_[0];
}

ACE_INLINE ACE_HANDLE
ACE_Pipe::write_handle () const
{
  ACE_TRACE ("ACE_Pipe::write_handle");
  return this->handles_[1];
}

ACE_INLINE ssize_t
ACE_Pipe::sendv_n (const iovec iov[], int n) const
{
  ACE_TRACE ("ACE_Pipe::sendv_n");
#if defined (ACE_WIN32)
  return ACE::sendv_n (this->write_handle (),
                      iov,
                      n);
#else
  return ACE::writev_n (this->write_handle (),
                        iov,
                        n);
#endif /* ACE_WIN32 */
}

ACE_INLINE ssize_t
ACE_Pipe::send_n (const ACE_Message_Block *message_block,
                  const ACE_Time_Value *timeout,
                  size_t *bytes_transferred)
{
  ACE_TRACE ("ACE_Pipe::send_n");
#if defined (ACE_WIN32)
  return ACE::send_n (this->write_handle (),
                      message_block,
                      timeout,
                      bytes_transferred);
#else
  ACE_UNUSED_ARG (timeout);
  return ACE::write_n (this->write_handle (),
                      message_block,
                      bytes_transferred);
#endif /* ACE_WIN32 */
}

// Recv an n byte message from the file.

ACE_INLINE ssize_t
ACE_Pipe::recvv_n (iovec iov[], int n) const
{
  ACE_TRACE ("ACE_Pipe::recvv_n");
  // @@ Carlos, can you please update this to call the
  // new ACE::recvv_n() method that you write?
#if defined (ACE_WIN32)
  return ACE_OS::sendv (this->read_handle (),
                        iov,
                        n);
#else
  return ACE_OS::readv (this->read_handle (),
                        iov,
                        n);
#endif /* ACE_WIN32 */
}

// Send an <iovec> of size <n> to the file.

ACE_INLINE ssize_t
ACE_Pipe::sendv (const iovec iov[], int n) const
{
  ACE_TRACE ("ACE_Pipe::sendv");
#if defined (ACE_WIN32)
  return ACE_OS::sendv (this->write_handle (), iov, n);
#else
  return ACE_OS::writev (this->write_handle (), iov, n);
#endif /* ACE_WIN32 */
}

// Send exactly N bytes from BUF to this file.  Keeping trying until
// this many bytes are sent.

ACE_INLINE ssize_t
ACE_Pipe::send_n (const void *buf, size_t n) const
{
  ACE_TRACE ("ACE_Pipe::send_n");
#if defined (ACE_WIN32)
  return ACE::send_n (this->write_handle (), buf, n);
#else
  return ACE::write_n (this->write_handle (), buf, n);
#endif /* ACE_WIN32 */
}

// Receive exactly N bytes from this file into BUF.  Keep trying until
// this many bytes are received.

ACE_INLINE ssize_t
ACE_Pipe::recv_n (void *buf, size_t n) const
{
  ACE_TRACE ("ACE_Pipe::recv_n");
#if defined (ACE_WIN32)
  return ACE::recv_n (this->read_handle (), buf, n);
#else
  return ACE::read_n (this->read_handle (), buf, n);
#endif /* ACE_WIN32 */
}

ACE_INLINE ssize_t
ACE_Pipe::send (const void *buf, size_t n) const
{
  ACE_TRACE ("ACE_Pipe::send");
#if defined (ACE_WIN32)
  return ACE_OS::send (this->write_handle (), static_cast <const char *> (buf), n);
#else
  return ACE_OS::write (this->write_handle (), static_cast <const char *> (buf), n);
#endif /* ACE_WIN32 */
}

ACE_INLINE ssize_t
ACE_Pipe::recv (void *buf, size_t n) const
{
  ACE_TRACE ("ACE_Pipe::recv");
#if defined (ACE_WIN32)
  return ACE_OS::recv (this->read_handle (), static_cast <char *> (buf), n);
#else
  return ACE_OS::read (this->read_handle (), static_cast <char *> (buf), n);
#endif /* ACE_WIN32 */
}

ACE_INLINE ssize_t
ACE_Pipe::send (const iovec iov[], int n) const
{
  ACE_TRACE ("ACE_Pipe::send");
#if defined (ACE_WIN32)
  return ACE_OS::sendv (this->write_handle (), iov, n);
#else
  return ACE_OS::writev (this->write_handle (), iov, n);
#endif /* ACE_WIN32 */
}

ACE_INLINE ssize_t
ACE_Pipe::recv (iovec iov[], int n) const
{
  ACE_TRACE ("ACE_Pipe::recv");
#if defined (ACE_WIN32)
  return ACE_OS::recvv (this->read_handle (), iov, n);
#else
  return ACE_OS::readv (this->read_handle (), iov, n);
#endif /* ACE_WIN32 */
}

ACE_INLINE ssize_t
ACE_Pipe::send (const void *buf, size_t n,
                ACE_OVERLAPPED *overlapped) const
{
  ACE_TRACE ("ACE_Pipe::send");
  return ACE_OS::write (this->write_handle (),
                        static_cast <const char *> (buf), n,
                        overlapped);
}

ACE_INLINE ssize_t
ACE_Pipe::recv (void *buf, size_t n,
                ACE_OVERLAPPED *overlapped) const
{
  ACE_TRACE ("ACE_Pipe::recv");
  return ACE_OS::read (this->read_handle (), static_cast <char *> (buf), n,
                       overlapped);
}

ACE_INLINE int
ACE_Pipe::close_handle (int which)
{
  int result = 0;

  // Note that the following will work even if we aren't closing down
  // sockets because <ACE_OS::closesocket> will just call <::close> in
  // that case!

  if (this->handles_[which] != ACE_INVALID_HANDLE)
    result = ACE_OS::closesocket (this->handles_[which]);
  this->handles_[which] = ACE_INVALID_HANDLE;
  return result;
}

ACE_END_VERSIONED_NAMESPACE_DECL