00001
00002
00003
00004
00005 #include "ace/OS_NS_sys_uio.h"
00006 #include "ace/OS_NS_errno.h"
00007 #include "ace/OS_NS_unistd.h"
00008 #if defined (ACE_WIN32)
00009 #include "ace/OS_NS_sys_socket.h"
00010 #endif
00011
00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00013
00014
00015
00016 ACE_INLINE int
00017 ACE_SPIPE_Stream::get_remote_addr (ACE_SPIPE_Addr &remote_sap) const
00018 {
00019 ACE_TRACE ("ACE_SPIPE_Stream::get_remote_addr");
00020 remote_sap = this->remote_addr_;
00021 return 0;
00022 }
00023
00024
00025
00026
00027 ACE_INLINE ssize_t
00028 ACE_SPIPE_Stream::send_n (const void *buf, size_t n) const
00029 {
00030 ACE_TRACE ("ACE_SPIPE_Stream::send_n");
00031 return ACE::write_n (this->get_handle (), buf, n);
00032 }
00033
00034
00035
00036
00037 ACE_INLINE ssize_t
00038 ACE_SPIPE_Stream::recv_n (void *buf, size_t n) const
00039 {
00040 ACE_TRACE ("ACE_SPIPE_Stream::recv_n");
00041 return ACE::read_n (this->get_handle (), buf, n);
00042 }
00043
00044 ACE_INLINE ssize_t
00045 ACE_SPIPE_Stream::send (const void *buf, size_t n) const
00046 {
00047 ACE_TRACE ("ACE_SPIPE_Stream::send");
00048 return ACE_OS::write (this->get_handle (), (const char *) buf, n);
00049 }
00050
00051 ACE_INLINE ssize_t
00052 ACE_SPIPE_Stream::recv (void *buf, size_t n) const
00053 {
00054 ACE_TRACE ("ACE_SPIPE_Stream::recv");
00055 return ACE_OS::read (this->get_handle (), (char *) buf, n);
00056 }
00057
00058 ACE_INLINE ssize_t
00059 ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int flags) const
00060 {
00061 ACE_TRACE ("ACE_SPIPE_Stream::send");
00062 return ACE_OS::putmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
00063 }
00064
00065 ACE_INLINE ssize_t
00066 ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *flags) const
00067 {
00068 ACE_TRACE ("ACE_SPIPE_Stream::recv");
00069 return ACE_OS::getmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, flags);
00070 }
00071
00072 ACE_INLINE ssize_t
00073 ACE_SPIPE_Stream::send (const ACE_Str_Buf *cntl, const ACE_Str_Buf *data, int band, int flags) const
00074 {
00075 ACE_TRACE ("ACE_SPIPE_Stream::send");
00076 return ACE_OS::putpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
00077 }
00078
00079 ACE_INLINE ssize_t
00080 ACE_SPIPE_Stream::recv (ACE_Str_Buf *cntl, ACE_Str_Buf *data, int *band, int *flags) const
00081 {
00082 ACE_TRACE ("ACE_SPIPE_Stream::recv");
00083 return ACE_OS::getpmsg (this->get_handle (), (strbuf *) cntl, (strbuf *) data, band, flags);
00084 }
00085
00086 ACE_INLINE ssize_t
00087 ACE_SPIPE_Stream::send (const iovec iov[], int n) const
00088 {
00089 ACE_TRACE ("ACE_SPIPE_Stream::send");
00090 return ACE_OS::writev (this->get_handle (), iov, n);
00091 }
00092
00093 ACE_INLINE ssize_t
00094 ACE_SPIPE_Stream::recv (iovec iov[], int n) const
00095 {
00096 ACE_TRACE ("ACE_SPIPE_Stream::recv");
00097 return ACE_OS::readv (this->get_handle (), iov, n);
00098 }
00099
00100
00101
00102 ACE_INLINE int
00103 ACE_SPIPE_Stream::send_handle (ACE_HANDLE handle) const
00104 {
00105 ACE_TRACE ("ACE_SPIPE_Stream::send_handle");
00106 #if defined (ACE_HAS_STREAM_PIPES)
00107 return ACE_OS::ioctl (this->get_handle (), I_SENDFD, (void *) handle);
00108 #elif defined (ACE_WIN32) && \
00109 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) && \
00110 !defined (ACE_HAS_WINCE)
00111 DWORD procID;
00112 WSAPROTOCOL_INFO protInfo;
00113 ssize_t res;
00114 res = this->recv(&procID, sizeof(procID));
00115 if (res != sizeof(procID))
00116 {
00117 if(res != -1)
00118 errno = ENXIO;
00119 return -1;
00120 }
00121 if (::WSADuplicateSocket ((SOCKET)handle, procID, &protInfo) == -1)
00122 {
00123 ACE_OS::set_errno_to_wsa_last_error();
00124 return -1;
00125 }
00126 res = this->send(&protInfo, sizeof(protInfo));
00127 if (res != sizeof(protInfo))
00128 {
00129 if(res != -1)
00130 errno = ENXIO;
00131 return -1;
00132 }
00133
00134 res = this->recv(&procID, sizeof(procID));
00135 if (res != sizeof(procID))
00136 {
00137 if(res != -1)
00138 errno = ENXIO;
00139 return -1;
00140 }
00141 return 0;
00142 #else
00143 handle = handle;
00144 ACE_NOTSUP_RETURN (-1);
00145 #endif
00146 }
00147
00148
00149
00150 ACE_INLINE int
00151 ACE_SPIPE_Stream::recv_handle (ACE_HANDLE &handle) const
00152 {
00153 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
00154 #if defined (ACE_HAS_STREAM_PIPES)
00155 strrecvfd recvfd;
00156
00157 if (ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd) == -1)
00158 return -1;
00159 else
00160 {
00161 handle = recvfd.fd;
00162 return 0;
00163 }
00164 #elif defined (ACE_WIN32) && \
00165 (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
00166 pid_t procID = ACE_OS::getpid();
00167 WSAPROTOCOL_INFO protInfo;
00168 ssize_t res;
00169 res = this->send(&procID, sizeof(procID));
00170 if (res != sizeof(procID))
00171 {
00172 if(res != -1)
00173 errno = ENXIO;
00174 return -1;
00175 }
00176 res = this->recv(&protInfo, sizeof(protInfo));
00177 if (res != sizeof(protInfo))
00178 {
00179 if(res != -1)
00180 errno = ENXIO;
00181 return -1;
00182 }
00183 handle = ACE_OS::socket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
00184 &protInfo, 0, 0);
00185 if (handle == ACE_INVALID_HANDLE)
00186 {
00187 return -1;
00188 }
00189
00190
00191 res = this->send(&procID, sizeof(procID));
00192 if (res != sizeof(procID))
00193 {
00194 if(res != -1)
00195 errno = ENXIO;
00196 return -1;
00197 }
00198 return 0;
00199 #else
00200 handle = handle;
00201 ACE_NOTSUP_RETURN (-1);
00202 #endif
00203 }
00204
00205
00206
00207
00208 ACE_INLINE int
00209 ACE_SPIPE_Stream::recv_handle (strrecvfd &recvfd) const
00210 {
00211 ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
00212 #if defined (ACE_HAS_STREAM_PIPES)
00213 return ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd);
00214 #else
00215 ACE_UNUSED_ARG (recvfd);
00216 ACE_NOTSUP_RETURN (-1);
00217 #endif
00218 }
00219
00220 ACE_INLINE ssize_t
00221 ACE_SPIPE_Stream::send (const void *buf, size_t n,
00222 ACE_OVERLAPPED *overlapped) const
00223 {
00224 ACE_TRACE ("ACE_SPIPE_Stream::send");
00225 return ACE_OS::write (this->get_handle (),
00226 (const char *) buf, n,
00227 overlapped);
00228 }
00229
00230 ACE_INLINE ssize_t
00231 ACE_SPIPE_Stream::recv (void *buf, size_t n,
00232 ACE_OVERLAPPED *overlapped) const
00233 {
00234 ACE_TRACE ("ACE_SPIPE_Stream::recv");
00235 return ACE_OS::read (this->get_handle (),
00236 (char *) buf, n,
00237 overlapped);
00238 }
00239
00240 ACE_INLINE ssize_t
00241 ACE_SPIPE_Stream::sendv_n (const iovec iov[],
00242 int n) const
00243 {
00244 ACE_TRACE ("ACE_SPIPE_Stream::sendv_n");
00245 return ACE::writev_n (this->get_handle (),
00246 iov,
00247 n);
00248 }
00249
00250
00251
00252 ACE_INLINE ssize_t
00253 ACE_SPIPE_Stream::recvv_n (iovec iov[],
00254 int n) const
00255 {
00256 ACE_TRACE ("ACE_SPIPE_Stream::recvv_n");
00257
00258
00259 return ACE_OS::readv (this->get_handle (),
00260 iov,
00261 n);
00262 }
00263
00264
00265
00266 ACE_INLINE ssize_t
00267 ACE_SPIPE_Stream::sendv (const iovec iov[],
00268 int n) const
00269 {
00270 ACE_TRACE ("ACE_SPIPE_Stream::sendv");
00271 return ACE_OS::writev (this->get_handle (),
00272 iov,
00273 n);
00274 }
00275
00276 ACE_END_VERSIONED_NAMESPACE_DECL
00277