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) && \
106 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) && \
107 !defined (ACE_HAS_WINCE) /* CE4 has WS2 but not WSADuplicateSocket */
109 WSAPROTOCOL_INFO protInfo;
110 ssize_t res = this->recv(&procID, sizeof(procID));
111 if (res != static_cast <ssize_t> (sizeof(procID)))
117 if (::WSADuplicateSocket ((SOCKET)handle, procID, &protInfo) == -1)
119 ACE_OS::set_errno_to_wsa_last_error();
122 res = this->send(&protInfo, sizeof(protInfo));
123 if (res != static_cast <ssize_t> (sizeof(protInfo)))
129 // This is just for synchronization, we will ignore the data
130 res = this->recv(&procID, sizeof(procID));
131 if (res != static_cast <ssize_t> (sizeof(procID)))
139 ACE_UNUSED_ARG (handle);
140 ACE_NOTSUP_RETURN (-1);
141 #endif /* ACE_HAS_STREAM_PIPES */
144 // This file receives an open file descriptor from this socket.
147 ACE_SPIPE_Stream::recv_handle (ACE_HANDLE &handle) const
149 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
150 #if defined (ACE_HAS_STREAM_PIPES)
153 if (ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd) == -1)
160 #elif defined (ACE_WIN32) && \
161 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
162 pid_t procID = ACE_OS::getpid();
163 WSAPROTOCOL_INFO protInfo;
164 ssize_t res = this->send(&procID, sizeof(procID));
165 if (res != static_cast <ssize_t> (sizeof(procID)))
171 res = this->recv(&protInfo, sizeof(protInfo));
172 if (res != static_cast <ssize_t> (sizeof(protInfo)))
178 handle = ACE_OS::socket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
180 if (handle == ACE_INVALID_HANDLE)
184 // Since it does not matter what the data is, just send something to
185 // synchronize the end of the exchange
186 res = this->send(&procID, sizeof(procID));
187 if (res != static_cast <ssize_t> (sizeof(procID)))
195 ACE_UNUSED_ARG (handle);
196 ACE_NOTSUP_RETURN (-1);
197 #endif /* ACE_HAS_STREAM_PIPES */
200 // This file receives an open file descriptor from this socket and
201 // also passes back the information about the address...
204 ACE_SPIPE_Stream::recv_handle (strrecvfd &recvfd) const
206 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
207 #if defined (ACE_HAS_STREAM_PIPES)
208 return ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd);
210 ACE_UNUSED_ARG (recvfd);
211 ACE_NOTSUP_RETURN (-1);
212 #endif /* ACE_HAS_STREAM_PIPES */
216 ACE_SPIPE_Stream::send (const void *buf, size_t n,
217 ACE_OVERLAPPED *overlapped) const
219 ACE_TRACE ("ACE_SPIPE_Stream::send");
220 return ACE_OS::write (this->get_handle (),
221 (const char *) buf, n,
226 ACE_SPIPE_Stream::recv (void *buf, size_t n,
227 ACE_OVERLAPPED *overlapped) const
229 ACE_TRACE ("ACE_SPIPE_Stream::recv");
230 return ACE_OS::read (this->get_handle (),
236 ACE_SPIPE_Stream::sendv_n (const iovec iov[],
239 ACE_TRACE ("ACE_SPIPE_Stream::sendv_n");
240 return ACE::writev_n (this->get_handle (),
245 // Recv an n byte message from the Stream.
248 ACE_SPIPE_Stream::recvv_n (iovec iov[],
251 ACE_TRACE ("ACE_SPIPE_Stream::recvv_n");
252 // @@ Carlos, can you please update this to call the
253 // new ACE::recvv_n() method that you write?
254 return ACE_OS::readv (this->get_handle (),
259 // Send an <iovec> of size <n> to the Stream.
262 ACE_SPIPE_Stream::sendv (const iovec iov[],
265 ACE_TRACE ("ACE_SPIPE_Stream::sendv");
266 return ACE_OS::writev (this->get_handle (),
271 ACE_END_VERSIONED_NAMESPACE_DECL