3 // $Id: SPIPE_Stream.inl 80826 2008-03-04 14:51:23Z wotte $
5 #include "ace/OS_NS_sys_uio.h"
6 #include "ace/OS_NS_errno.h"
7 #include "ace/OS_NS_unistd.h"
8 #if defined (ACE_WIN32)
9 #include "ace/OS_NS_sys_socket.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 // Create an ACE_SPIPE_Stream.
17 ACE_SPIPE_Stream::get_remote_addr (ACE_SPIPE_Addr &remote_sap) const
19 ACE_TRACE ("ACE_SPIPE_Stream::get_remote_addr");
20 remote_sap = this->remote_addr_;
24 // Send exactly N bytes from BUF to this socket. Keeping trying until
25 // this many bytes are sent.
28 ACE_SPIPE_Stream::send_n (const void *buf, size_t n) const
30 ACE_TRACE ("ACE_SPIPE_Stream::send_n");
31 return ACE::write_n (this->get_handle (), buf, n);
34 // Receive exactly N bytes from this socket into BUF. Keep trying
35 // until this many bytes are received.
38 ACE_SPIPE_Stream::recv_n (void *buf, size_t n) const
40 ACE_TRACE ("ACE_SPIPE_Stream::recv_n");
41 return ACE::read_n (this->get_handle (), buf, n);
45 ACE_SPIPE_Stream::send (const void *buf, size_t n) const
47 ACE_TRACE ("ACE_SPIPE_Stream::send");
48 return ACE_OS::write (this->get_handle (), (const char *) buf, n);
52 ACE_SPIPE_Stream::recv (void *buf, size_t n) const
54 ACE_TRACE ("ACE_SPIPE_Stream::recv");
55 return ACE_OS::read (this->get_handle (), (char *) buf, n);
59 ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int flags) const
61 ACE_TRACE ("ACE_SPIPE_Stream::send");
62 return ACE_OS::putmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
66 ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *flags) const
68 ACE_TRACE ("ACE_SPIPE_Stream::recv");
69 return ACE_OS::getmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
73 ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int band, int flags) const
75 ACE_TRACE ("ACE_SPIPE_Stream::send");
76 return ACE_OS::putpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
80 ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *band, int *flags) const
82 ACE_TRACE ("ACE_SPIPE_Stream::recv");
83 return ACE_OS::getpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
87 ACE_SPIPE_Stream::send (const iovec iov[], int n) const
89 ACE_TRACE ("ACE_SPIPE_Stream::send");
90 return ACE_OS::writev (this->get_handle (), iov, n);
94 ACE_SPIPE_Stream::recv (iovec iov[], int n) const
96 ACE_TRACE ("ACE_SPIPE_Stream::recv");
97 return ACE_OS::readv (this->get_handle (), iov, n);
100 // This routine sends an open file descriptor to this socket.
103 ACE_SPIPE_Stream::send_handle (ACE_HANDLE handle) const
105 ACE_TRACE ("ACE_SPIPE_Stream::send_handle");
106 #if defined (ACE_HAS_STREAM_PIPES)
107 return ACE_OS::ioctl (this->get_handle (), I_SENDFD, (void *) handle);
108 #elif defined (ACE_WIN32) && \
109 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) && \
110 !defined (ACE_HAS_WINCE) /* CE4 has WS2 but not WSADuplicateSocket */
112 WSAPROTOCOL_INFO protInfo;
113 ssize_t res = this->recv(&procID, sizeof(procID));
114 if (res != sizeof(procID))
120 if (::WSADuplicateSocket ((SOCKET)handle, procID, &protInfo) == -1)
122 ACE_OS::set_errno_to_wsa_last_error();
125 res = this->send(&protInfo, sizeof(protInfo));
126 if (res != sizeof(protInfo))
132 // This is just for synchronization, we will ignore the data
133 res = this->recv(&procID, sizeof(procID));
134 if (res != sizeof(procID))
143 ACE_NOTSUP_RETURN (-1);
144 #endif /* ACE_HAS_STREAM_PIPES */
147 // This file receives an open file descriptor from this socket.
150 ACE_SPIPE_Stream::recv_handle (ACE_HANDLE &handle) const
152 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
153 #if defined (ACE_HAS_STREAM_PIPES)
156 if (ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd) == -1)
163 #elif defined (ACE_WIN32) && \
164 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
165 pid_t procID = ACE_OS::getpid();
166 WSAPROTOCOL_INFO protInfo;
167 ssize_t res = this->send(&procID, sizeof(procID));
168 if (res != sizeof(procID))
174 res = this->recv(&protInfo, sizeof(protInfo));
175 if (res != sizeof(protInfo))
181 handle = ACE_OS::socket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
183 if (handle == ACE_INVALID_HANDLE)
187 // Since it does not matter what the data is, just send something to
188 // synchronize the end of the exchange
189 res = this->send(&procID, sizeof(procID));
190 if (res != sizeof(procID))
199 ACE_NOTSUP_RETURN (-1);
200 #endif /* ACE_HAS_STREAM_PIPES */
203 // This file receives an open file descriptor from this socket and
204 // also passes back the information about the address...
207 ACE_SPIPE_Stream::recv_handle (strrecvfd &recvfd) const
209 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
210 #if defined (ACE_HAS_STREAM_PIPES)
211 return ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd);
213 ACE_UNUSED_ARG (recvfd);
214 ACE_NOTSUP_RETURN (-1);
215 #endif /* ACE_HAS_STREAM_PIPES */
219 ACE_SPIPE_Stream::send (const void *buf, size_t n,
220 ACE_OVERLAPPED *overlapped) const
222 ACE_TRACE ("ACE_SPIPE_Stream::send");
223 return ACE_OS::write (this->get_handle (),
224 (const char *) buf, n,
229 ACE_SPIPE_Stream::recv (void *buf, size_t n,
230 ACE_OVERLAPPED *overlapped) const
232 ACE_TRACE ("ACE_SPIPE_Stream::recv");
233 return ACE_OS::read (this->get_handle (),
239 ACE_SPIPE_Stream::sendv_n (const iovec iov[],
242 ACE_TRACE ("ACE_SPIPE_Stream::sendv_n");
243 return ACE::writev_n (this->get_handle (),
248 // Recv an n byte message from the Stream.
251 ACE_SPIPE_Stream::recvv_n (iovec iov[],
254 ACE_TRACE ("ACE_SPIPE_Stream::recvv_n");
255 // @@ Carlos, can you please update this to call the
256 // new ACE::recvv_n() method that you write?
257 return ACE_OS::readv (this->get_handle (),
262 // Send an <iovec> of size <n> to the Stream.
265 ACE_SPIPE_Stream::sendv (const iovec iov[],
268 ACE_TRACE ("ACE_SPIPE_Stream::sendv");
269 return ACE_OS::writev (this->get_handle (),
274 ACE_END_VERSIONED_NAMESPACE_DECL