SPIPE_Stream.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: SPIPE_Stream.inl 80826 2008-03-04 14:51:23Z wotte $
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 // Create an ACE_SPIPE_Stream.
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 // Send exactly N bytes from BUF to this socket.  Keeping trying until
00025 // this many bytes are sent.
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 // Receive exactly N bytes from this socket into BUF.  Keep trying
00035 // until this many bytes are received.
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 // This routine sends an open file descriptor to this socket.
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)   /* CE4 has WS2 but not WSADuplicateSocket */
00111   DWORD procID;
00112   WSAPROTOCOL_INFO protInfo;
00113   ssize_t res = this->recv(&procID, sizeof(procID));
00114   if (res != sizeof(procID))
00115   {
00116     if(res != -1)
00117         errno = ENXIO;
00118     return -1;
00119   }
00120   if (::WSADuplicateSocket ((SOCKET)handle, procID, &protInfo) == -1)
00121   {
00122     ACE_OS::set_errno_to_wsa_last_error();
00123       return -1;
00124   }
00125   res = this->send(&protInfo, sizeof(protInfo));
00126   if (res != sizeof(protInfo))
00127   {
00128     if(res != -1)
00129         errno = ENXIO;
00130     return -1;
00131   }
00132   // This is just for synchronization, we will ignore the data
00133   res = this->recv(&procID, sizeof(procID));
00134   if (res != sizeof(procID))
00135   {
00136     if(res != -1)
00137         errno = ENXIO;
00138     return -1;
00139   }
00140   return 0;
00141 #else
00142   handle = handle;
00143   ACE_NOTSUP_RETURN (-1);
00144 #endif /* ACE_HAS_STREAM_PIPES */
00145 }
00146 
00147 // This file receives an open file descriptor from this socket.
00148 
00149 ACE_INLINE int
00150 ACE_SPIPE_Stream::recv_handle (ACE_HANDLE &handle) const
00151 {
00152   ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
00153 #if defined (ACE_HAS_STREAM_PIPES)
00154   strrecvfd recvfd;
00155 
00156   if (ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd) == -1)
00157     return -1;
00158   else
00159     {
00160       handle = recvfd.fd;
00161       return 0;
00162     }
00163 #elif defined (ACE_WIN32) && \
00164       (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
00165   pid_t procID = ACE_OS::getpid();
00166   WSAPROTOCOL_INFO protInfo;
00167   ssize_t res = this->send(&procID, sizeof(procID));
00168   if (res != sizeof(procID))
00169   {
00170     if(res != -1)
00171         errno = ENXIO;
00172     return -1;
00173   }
00174   res = this->recv(&protInfo, sizeof(protInfo));
00175   if (res != sizeof(protInfo))
00176   {
00177     if(res != -1)
00178         errno = ENXIO;
00179      return -1;
00180   }
00181   handle = ACE_OS::socket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
00182                            &protInfo, 0, 0);
00183   if (handle == ACE_INVALID_HANDLE)
00184   {
00185     return -1;
00186   }
00187   // Since it does not matter what the data is, just send something to
00188   // synchronize the end of the exchange
00189   res = this->send(&procID, sizeof(procID));
00190   if (res != sizeof(procID))
00191   {
00192     if(res != -1)
00193         errno = ENXIO;
00194     return -1;
00195   }
00196   return 0;
00197 #else
00198   handle = handle;
00199   ACE_NOTSUP_RETURN (-1);
00200 #endif /* ACE_HAS_STREAM_PIPES */
00201 }
00202 
00203 // This file receives an open file descriptor from this socket and
00204 // also passes back the information about the address...
00205 
00206 ACE_INLINE int
00207 ACE_SPIPE_Stream::recv_handle (strrecvfd &recvfd) const
00208 {
00209   ACE_TRACE ("ACE_SPIPE_Stream::recv_handle");
00210 #if defined (ACE_HAS_STREAM_PIPES)
00211   return ACE_OS::ioctl (this->get_handle (), I_RECVFD, (void *) &recvfd);
00212 #else
00213   ACE_UNUSED_ARG (recvfd);
00214   ACE_NOTSUP_RETURN (-1);
00215 #endif /* ACE_HAS_STREAM_PIPES */
00216 }
00217 
00218 ACE_INLINE ssize_t
00219 ACE_SPIPE_Stream::send (const void *buf, size_t n,
00220                         ACE_OVERLAPPED *overlapped) const
00221 {
00222   ACE_TRACE ("ACE_SPIPE_Stream::send");
00223   return ACE_OS::write (this->get_handle (),
00224                         (const char *) buf, n,
00225                         overlapped);
00226 }
00227 
00228 ACE_INLINE ssize_t
00229 ACE_SPIPE_Stream::recv (void *buf, size_t n,
00230                         ACE_OVERLAPPED *overlapped) const
00231 {
00232   ACE_TRACE ("ACE_SPIPE_Stream::recv");
00233   return ACE_OS::read (this->get_handle (),
00234                        (char *) buf, n,
00235                        overlapped);
00236 }
00237 
00238 ACE_INLINE ssize_t
00239 ACE_SPIPE_Stream::sendv_n (const iovec iov[],
00240                            int n) const
00241 {
00242   ACE_TRACE ("ACE_SPIPE_Stream::sendv_n");
00243   return ACE::writev_n (this->get_handle (),
00244                         iov,
00245                         n);
00246 }
00247 
00248 // Recv an n byte message from the Stream.
00249 
00250 ACE_INLINE ssize_t
00251 ACE_SPIPE_Stream::recvv_n (iovec iov[],
00252                            int n) const
00253 {
00254   ACE_TRACE ("ACE_SPIPE_Stream::recvv_n");
00255   // @@ Carlos, can you please update this to call the
00256   // new ACE::recvv_n() method that you write?
00257   return ACE_OS::readv (this->get_handle (),
00258                         iov,
00259                         n);
00260 }
00261 
00262 // Send an <iovec> of size <n> to the Stream.
00263 
00264 ACE_INLINE ssize_t
00265 ACE_SPIPE_Stream::sendv (const iovec iov[],
00266                          int n) const
00267 {
00268   ACE_TRACE ("ACE_SPIPE_Stream::sendv");
00269   return ACE_OS::writev (this->get_handle (),
00270                          iov,
00271                          n);
00272 }
00273 
00274 ACE_END_VERSIONED_NAMESPACE_DECL
00275 

Generated on Tue Feb 2 17:18:42 2010 for ACE by  doxygen 1.4.7