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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
/* -*- C++ -*- */
// $Id$
// SPIPE_Stream.i
// Create an ACE_SPIPE_Stream.
ASYS_INLINE int
ACE_SPIPE_Stream::get_remote_addr (ACE_SPIPE_Addr &remote_sap) const
{
ACE_TRACE ("ACE_SPIPE_Stream::get_remote_addr");
remote_sap = this->remote_addr_;
return 0;
}
// Send exactly N bytes from BUF to this socket. Keeping trying until
// this many bytes are sent.
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::send_n (const void *buf, size_t n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send_n");
return ACE::write_n (this->get_handle (), buf, n);
}
// Receive exactly N bytes from this socket into BUF. Keep trying
// until this many bytes are received.
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recv_n (void *buf, size_t n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv_n");
return ACE::read_n (this->get_handle (), buf, n);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::send (const void *buf, size_t n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send");
return ACE_OS::write (this->get_handle (), (const char *) buf, n);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recv (void *buf, size_t n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv");
return ACE_OS::read (this->get_handle (), (char *) buf, n);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int flags) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send");
return ACE_OS::putmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *flags) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv");
return ACE_OS::getmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int band, int flags) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send");
return ACE_OS::putpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *band, int *flags) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv");
return ACE_OS::getpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::send (const iovec iov[], int n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send");
return ACE_OS::writev (this->get_handle (), iov, n);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recv (iovec iov[], int n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv");
return ACE_OS::readv (this->get_handle (), iov, n);
}
// This routine sends an open file descriptor to this socket.
ASYS_INLINE int
ACE_SPIPE_Stream::send_handle (ACE_HANDLE handle) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send_handle");
#if defined (ACE_HAS_STREAM_PIPES)
return ACE_OS::ioctl (this->get_handle (), I_SENDFD, (void *) handle);
#elif defined (ACE_WIN32) && \
(defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) && \
!defined (ACE_HAS_WINCE) /* CE4 has WS2 but not WSADuplicateSocket */
DWORD procID;
WSAPROTOCOL_INFO protInfo;
ssize_t res;
res = this->recv(&procID, sizeof(procID));
if (res != sizeof(procID))
{
if(res != -1)
errno = ENXIO;
return -1;
}
if (::WSADuplicateSocket ((SOCKET)handle, procID, &protInfo) == -1)
{
ACE_OS::set_errno_to_wsa_last_error();
return -1;
}
res = this->send(&protInfo, sizeof(protInfo));
if (res != sizeof(protInfo))
{
if(res != -1)
errno = ENXIO;
return -1;
}
// This is just for synchronization, we will ignore the data
res = this->recv(&procID, sizeof(procID));
if (res != sizeof(procID))
{
if(res != -1)
errno = ENXIO;
return -1;
}
return 0;
#else
handle = handle;
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_STREAM_PIPES */
}
// This file receives an open file descriptor from this socket.
ASYS_INLINE int
ACE_SPIPE_Stream::recv_handle (ACE_HANDLE &handle) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
#if defined (ACE_HAS_STREAM_PIPES)
strrecvfd recvfd;
if (ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd) == -1)
return -1;
else
{
handle = recvfd.fd;
return 0;
}
#elif defined (ACE_WIN32) && \
(defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
pid_t procID = ACE_OS::getpid();
WSAPROTOCOL_INFO protInfo;
ssize_t res;
res = this->send(&procID, sizeof(procID));
if (res != sizeof(procID))
{
if(res != -1)
errno = ENXIO;
return -1;
}
res = this->recv(&protInfo, sizeof(protInfo));
if (res != sizeof(protInfo))
{
if(res != -1)
errno = ENXIO;
return -1;
}
handle = ACE_OS::socket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
&protInfo, 0, 0);
if (handle == ACE_INVALID_HANDLE)
{
return -1;
}
// Since it does not matter what the data is, just send something to
// synchronize the end of the exchange
res = this->send(&procID, sizeof(procID));
if (res != sizeof(procID))
{
if(res != -1)
errno = ENXIO;
return -1;
}
return 0;
#else
handle = handle;
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_STREAM_PIPES */
}
// This file receives an open file descriptor from this socket and
// also passes back the information about the address...
ASYS_INLINE int
ACE_SPIPE_Stream::recv_handle (strrecvfd &recvfd) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
#if defined (ACE_HAS_STREAM_PIPES)
return ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd);
#else
ACE_UNUSED_ARG (recvfd);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_STREAM_PIPES */
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::send (const void *buf, size_t n,
ACE_OVERLAPPED *overlapped) const
{
ACE_TRACE ("ACE_SPIPE_Stream::send");
return ACE_OS::write (this->get_handle (),
(const char *) buf, n,
overlapped);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recv (void *buf, size_t n,
ACE_OVERLAPPED *overlapped) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recv");
return ACE_OS::read (this->get_handle (),
(char *) buf, n,
overlapped);
}
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::sendv_n (const iovec iov[],
int n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::sendv_n");
return ACE::writev_n (this->get_handle (),
iov,
n);
}
// Recv an n byte message from the Stream.
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::recvv_n (iovec iov[],
int n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::recvv_n");
// @@ Carlos, can you please update this to call the
// new ACE::recvv_n() method that you write?
return ACE_OS::readv (this->get_handle (),
iov,
n);
}
// Send an <iovec> of size <n> to the Stream.
ASYS_INLINE ssize_t
ACE_SPIPE_Stream::sendv (const iovec iov[],
int n) const
{
ACE_TRACE ("ACE_SPIPE_Stream::sendv");
return ACE_OS::writev (this->get_handle (),
iov,
n);
}
|