2 #include "ace/OS_NS_sys_uio.h"
3 #include "ace/OS_NS_errno.h"
4 #include "ace/OS_NS_unistd.h"
5 #if defined (ACE_WIN32)
6 #include "ace/OS_NS_sys_socket.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 // Create an ACE_SPIPE_Stream.
14 ACE_SPIPE_Stream::get_remote_addr (ACE_SPIPE_Addr &remote_sap) const
16 ACE_TRACE ("ACE_SPIPE_Stream::get_remote_addr");
17 remote_sap = this->remote_addr_;
21 // Send exactly N bytes from BUF to this socket. Keeping trying until
22 // this many bytes are sent.
25 ACE_SPIPE_Stream::send_n (const void *buf, size_t n) const
27 ACE_TRACE ("ACE_SPIPE_Stream::send_n");
28 return ACE::write_n (this->get_handle (), buf, n);
31 // Receive exactly N bytes from this socket into BUF. Keep trying
32 // until this many bytes are received.
35 ACE_SPIPE_Stream::recv_n (void *buf, size_t n) const
37 ACE_TRACE ("ACE_SPIPE_Stream::recv_n");
38 return ACE::read_n (this->get_handle (), buf, n);
42 ACE_SPIPE_Stream::send (const void *buf, size_t n) const
44 ACE_TRACE ("ACE_SPIPE_Stream::send");
45 return ACE_OS::write (this->get_handle (), (const char *) buf, n);
49 ACE_SPIPE_Stream::recv (void *buf, size_t n) const
51 ACE_TRACE ("ACE_SPIPE_Stream::recv");
52 return ACE_OS::read (this->get_handle (), (char *) buf, n);
56 ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int flags) const
58 ACE_TRACE ("ACE_SPIPE_Stream::send");
59 return ACE_OS::putmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
63 ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *flags) const
65 ACE_TRACE ("ACE_SPIPE_Stream::recv");
66 return ACE_OS::getmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
70 ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int band, int flags) const
72 ACE_TRACE ("ACE_SPIPE_Stream::send");
73 return ACE_OS::putpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
77 ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *band, int *flags) const
79 ACE_TRACE ("ACE_SPIPE_Stream::recv");
80 return ACE_OS::getpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
84 ACE_SPIPE_Stream::send (const iovec iov[], int n) const
86 ACE_TRACE ("ACE_SPIPE_Stream::send");
87 return ACE_OS::writev (this->get_handle (), iov, n);
91 ACE_SPIPE_Stream::recv (iovec iov[], int n) const
93 ACE_TRACE ("ACE_SPIPE_Stream::recv");
94 return ACE_OS::readv (this->get_handle (), iov, n);
97 // This routine sends an open file descriptor to this socket.
100 ACE_SPIPE_Stream::send_handle (ACE_HANDLE handle) const
102 ACE_TRACE ("ACE_SPIPE_Stream::send_handle");
103 #if defined (ACE_HAS_STREAM_PIPES)
104 return ACE_OS::ioctl (this->get_handle (), I_SENDFD, (void *) handle);
105 #elif defined (ACE_WIN32) && (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
107 WSAPROTOCOL_INFO protInfo;
108 ssize_t res = this->recv(&procID, sizeof(procID));
109 if (res != static_cast <ssize_t> (sizeof(procID)))
115 if (::WSADuplicateSocket ((SOCKET)handle, procID, &protInfo) == -1)
117 ACE_OS::set_errno_to_wsa_last_error();
120 res = this->send(&protInfo, sizeof(protInfo));
121 if (res != static_cast <ssize_t> (sizeof(protInfo)))
127 // This is just for synchronization, we will ignore the data
128 res = this->recv(&procID, sizeof(procID));
129 if (res != static_cast <ssize_t> (sizeof(procID)))
137 ACE_UNUSED_ARG (handle);
138 ACE_NOTSUP_RETURN (-1);
139 #endif /* ACE_HAS_STREAM_PIPES */
142 // This file receives an open file descriptor from this socket.
145 ACE_SPIPE_Stream::recv_handle (ACE_HANDLE &handle) const
147 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
148 #if defined (ACE_HAS_STREAM_PIPES)
151 if (ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd) == -1)
158 #elif defined (ACE_WIN32) && \
159 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
160 pid_t procID = ACE_OS::getpid();
161 WSAPROTOCOL_INFO protInfo;
162 ssize_t res = this->send(&procID, sizeof(procID));
163 if (res != static_cast <ssize_t> (sizeof(procID)))
169 res = this->recv(&protInfo, sizeof(protInfo));
170 if (res != static_cast <ssize_t> (sizeof(protInfo)))
176 handle = ACE_OS::socket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
178 if (handle == ACE_INVALID_HANDLE)
182 // Since it does not matter what the data is, just send something to
183 // synchronize the end of the exchange
184 res = this->send(&procID, sizeof(procID));
185 if (res != static_cast <ssize_t> (sizeof(procID)))
193 ACE_UNUSED_ARG (handle);
194 ACE_NOTSUP_RETURN (-1);
195 #endif /* ACE_HAS_STREAM_PIPES */
198 // This file receives an open file descriptor from this socket and
199 // also passes back the information about the address...
202 ACE_SPIPE_Stream::recv_handle (strrecvfd &recvfd) const
204 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
205 #if defined (ACE_HAS_STREAM_PIPES)
206 return ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd);
208 ACE_UNUSED_ARG (recvfd);
209 ACE_NOTSUP_RETURN (-1);
210 #endif /* ACE_HAS_STREAM_PIPES */
214 ACE_SPIPE_Stream::send (const void *buf, size_t n,
215 ACE_OVERLAPPED *overlapped) const
217 ACE_TRACE ("ACE_SPIPE_Stream::send");
218 return ACE_OS::write (this->get_handle (),
219 (const char *) buf, n,
224 ACE_SPIPE_Stream::recv (void *buf, size_t n,
225 ACE_OVERLAPPED *overlapped) const
227 ACE_TRACE ("ACE_SPIPE_Stream::recv");
228 return ACE_OS::read (this->get_handle (),
234 ACE_SPIPE_Stream::sendv_n (const iovec iov[],
237 ACE_TRACE ("ACE_SPIPE_Stream::sendv_n");
238 return ACE::writev_n (this->get_handle (),
243 // Recv an n byte message from the Stream.
246 ACE_SPIPE_Stream::recvv_n (iovec iov[],
249 ACE_TRACE ("ACE_SPIPE_Stream::recvv_n");
250 // @@ Carlos, can you please update this to call the
251 // new ACE::recvv_n() method that you write?
252 return ACE_OS::readv (this->get_handle (),
257 // Send an <iovec> of size <n> to the Stream.
260 ACE_SPIPE_Stream::sendv (const iovec iov[],
263 ACE_TRACE ("ACE_SPIPE_Stream::sendv");
264 return ACE_OS::writev (this->get_handle (),
269 ACE_END_VERSIONED_NAMESPACE_DECL