#include <Pipe.h>
Public Member Functions | |
ACE_Pipe (void) | |
Default constructor (does nothing...). | |
ACE_Pipe (ACE_HANDLE handles[2]) | |
Open the pipe and initialize the handles. | |
ACE_Pipe (ACE_HANDLE read, ACE_HANDLE write) | |
Initialize the ACE_Pipe from the read and write handles. | |
~ACE_Pipe (void) | |
Default dtor. It doesn't close the handles for you. | |
int | open (ACE_HANDLE handles[2]) |
Open the pipe and initialize the handles. | |
int | open (int buffer_size=ACE_DEFAULT_MAX_SOCKET_BUFSIZ) |
Open the pipe, setting the buffer size to the maximum. | |
int | close (void) |
Close down the pipe HANDLEs;. | |
ACE_HANDLE | read_handle (void) const |
ACE_HANDLE | write_handle (void) const |
void | dump (void) const |
Dump the state of the object. | |
ssize_t | send (const void *buf, size_t n) const |
send upto n bytes in buf. | |
ssize_t | recv (void *buf, size_t n) const |
Recv upto n bytes in buf. | |
ssize_t | send_n (const void *buf, size_t n) const |
Send n bytes, keep trying until n are sent. | |
ssize_t | send_n (const ACE_Message_Block *message_block, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ssize_t | recv_n (void *buf, size_t n) const |
Recv n bytes, keep trying until n are received. | |
ssize_t | send (const iovec iov[], int n) const |
Send iovecs via <::writev>. | |
ssize_t | recv (iovec iov[], int n) const |
Recv iovecs via <::readv>. | |
ssize_t | send (size_t n,...) const |
ssize_t | recv (size_t n,...) const |
ssize_t | send (const void *buf, size_t n, ACE_OVERLAPPED *overlapped) const |
Send n bytes via Win32 WriteFile using overlapped I/O. | |
ssize_t | recv (void *buf, size_t n, ACE_OVERLAPPED *overlapped) const |
Recv n bytes via Win32 ReadFile using overlapped I/O. | |
ssize_t | sendv (const iovec iov[], int n) const |
Send an of size n to the file. | |
ssize_t | sendv_n (const iovec iov[], int n) const |
ssize_t | recvv_n (iovec iov[], int n) const |
Receive an of size n to the file. | |
Private Attributes | |
ACE_HANDLE | handles_ [2] |
This class is designed to work with select()-based demuxers, such as the ACE_Select_Reactor, which is why it uses sockets on Windows rather than Win32 pipes (which aren't select()'able).
Definition at line 44 of file Pipe.h.
|
Default constructor (does nothing...).
Definition at line 207 of file Pipe.cpp. References ACE_TRACE.
|
|
Open the pipe and initialize the handles.
Definition at line 215 of file Pipe.cpp. References ACE_ERROR, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().
|
|
Initialize the ACE_Pipe from the read and write handles.
Definition at line 224 of file Pipe.cpp. References ACE_TRACE.
|
|
Default dtor. It doesn't close the handles for you.
Definition at line 11 of file Pipe.inl. References ACE_TRACE.
00012 { 00013 ACE_TRACE ("ACE_Pipe::~ACE_Pipe"); 00014 // Notice that the destructor doesn't close the handles for you. 00015 } |
|
Close down the pipe HANDLEs;.
Definition at line 233 of file Pipe.cpp. References ACE_TRACE, and ACE_OS::closesocket(). Referenced by ACE_Select_Reactor_Notify::close(), and open().
00234 { 00235 ACE_TRACE ("ACE_Pipe::close"); 00236 00237 int result = 0; 00238 00239 // Note that the following will work even if we aren't closing down 00240 // sockets because <ACE_OS::closesocket> will just call <::close> in 00241 // that case! 00242 00243 if (this->handles_[0] != ACE_INVALID_HANDLE) 00244 result = ACE_OS::closesocket (this->handles_[0]); 00245 this->handles_[0] = ACE_INVALID_HANDLE; 00246 00247 if (this->handles_[1] != ACE_INVALID_HANDLE) 00248 result |= ACE_OS::closesocket (this->handles_[1]); 00249 this->handles_[1] = ACE_INVALID_HANDLE; 00250 00251 return result; 00252 } |
|
Dump the state of the object.
Definition at line 26 of file Pipe.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, and LM_DEBUG. Referenced by ACE_Select_Reactor_Notify::dump().
00027 { 00028 #if defined (ACE_HAS_DUMP) 00029 ACE_TRACE ("ACE_Pipe::dump"); 00030 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00031 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("handles_[0] = %d"), this->handles_[0])); 00032 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhandles_[1] = %d"), this->handles_[1])); 00033 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); 00034 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00035 #endif /* ACE_HAS_DUMP */ 00036 } |
|
Open the pipe, setting the buffer size to the maximum.
Definition at line 39 of file Pipe.cpp. References ACE_SOCK_Acceptor::accept(), ACE_ERROR_RETURN, ACE_IPPROTO_TCP, ACE_LOCALHOST, ACE_TEXT, ACE_TRACE, AF_UNIX, close(), ACE_SOCK_Acceptor::close(), ACE_SOCK_Stream::close(), ACE_SOCK_Connector::connect(), ENOTSUP, ACE_IPC_SAP::get_handle(), ACE_SOCK::get_local_addr(), ACE_INET_Addr::get_port_number(), ACE_OS::ioctl(), LM_ERROR, ACE_SOCK_Acceptor::open(), ACE_OS::pipe(), ACE_SOCK::set_option(), ACE_OS::setsockopt(), SO_RCVBUF, SO_SNDBUF, SOCK_STREAM, ACE_OS::socketpair(), SOL_SOCKET, and TCP_NODELAY.
00040 { 00041 ACE_TRACE ("ACE_Pipe::open"); 00042 00043 #if defined (ACE_LACKS_SOCKETPAIR) || defined (__Lynx__) 00044 ACE_INET_Addr my_addr; 00045 ACE_SOCK_Acceptor acceptor; 00046 ACE_SOCK_Connector connector; 00047 ACE_SOCK_Stream reader; 00048 ACE_SOCK_Stream writer; 00049 int result = 0; 00050 # if defined (ACE_WIN32) 00051 ACE_INET_Addr local_any (static_cast<u_short> (0), ACE_LOCALHOST); 00052 # else 00053 ACE_Addr local_any = ACE_Addr::sap_any; 00054 # endif /* ACE_WIN32 */ 00055 00056 // Bind listener to any port and then find out what the port was. 00057 if (acceptor.open (local_any) == -1 00058 || acceptor.get_local_addr (my_addr) == -1) 00059 result = -1; 00060 else 00061 { 00062 ACE_INET_Addr sv_addr (my_addr.get_port_number (), 00063 ACE_LOCALHOST); 00064 00065 // Establish a connection within the same process. 00066 if (connector.connect (writer, sv_addr) == -1) 00067 result = -1; 00068 else if (acceptor.accept (reader) == -1) 00069 { 00070 writer.close (); 00071 result = -1; 00072 } 00073 } 00074 00075 // Close down the acceptor endpoint since we don't need it anymore. 00076 acceptor.close (); 00077 if (result == -1) 00078 return -1; 00079 00080 this->handles_[0] = reader.get_handle (); 00081 this->handles_[1] = writer.get_handle (); 00082 00083 # if !defined (ACE_LACKS_TCP_NODELAY) 00084 int one = 1; 00085 00086 // Make sure that the TCP stack doesn't try to buffer small writes. 00087 // Since this communication is purely local to the host it doesn't 00088 // affect network performance. 00089 00090 if (writer.set_option (ACE_IPPROTO_TCP, 00091 TCP_NODELAY, 00092 &one, 00093 sizeof one) == -1) 00094 { 00095 this->close (); 00096 return -1; 00097 } 00098 # endif /* ! ACE_LACKS_TCP_NODELAY */ 00099 00100 # if defined (ACE_LACKS_SOCKET_BUFSIZ) 00101 ACE_UNUSED_ARG (buffer_size); 00102 # else /* ! ACE_LACKS_SOCKET_BUFSIZ */ 00103 if (reader.set_option (SOL_SOCKET, 00104 SO_RCVBUF, 00105 reinterpret_cast <void *> (&buffer_size), 00106 sizeof (buffer_size)) == -1 00107 && errno != ENOTSUP) 00108 { 00109 this->close (); 00110 return -1; 00111 } 00112 else if (writer.set_option (SOL_SOCKET, 00113 SO_SNDBUF, 00114 reinterpret_cast <void *> (&buffer_size), 00115 sizeof (buffer_size)) == -1 00116 && errno != ENOTSUP) 00117 { 00118 this->close (); 00119 return -1; 00120 } 00121 # endif /* ! ACE_LACKS_SOCKET_BUFSIZ */ 00122 00123 #elif defined (ACE_HAS_STREAM_PIPES) || defined (__QNX__) 00124 ACE_UNUSED_ARG (buffer_size); 00125 if (ACE_OS::pipe (this->handles_) == -1) 00126 ACE_ERROR_RETURN ((LM_ERROR, 00127 ACE_TEXT ("%p\n"), 00128 ACE_TEXT ("pipe")), 00129 -1); 00130 00131 #if !defined(__QNX__) 00132 int arg = RMSGN; 00133 00134 // Enable "msg no discard" mode, which ensures that record 00135 // boundaries are maintained when messages are sent and received. 00136 if (ACE_OS::ioctl (this->handles_[0], 00137 I_SRDOPT, 00138 (void *) arg) == -1 00139 || ACE_OS::ioctl (this->handles_[1], 00140 I_SRDOPT, 00141 (void *) arg) == -1) 00142 { 00143 this->close (); 00144 ACE_ERROR_RETURN ((LM_ERROR, 00145 ACE_TEXT ("%p\n"), 00146 ACE_TEXT ("ioctl")), -1); 00147 } 00148 #endif /* __QNX__ */ 00149 00150 #else /* ! ACE_LACKS_SOCKETPAIR && ! ACE_HAS_STREAM_PIPES */ 00151 if (ACE_OS::socketpair (AF_UNIX, 00152 SOCK_STREAM, 00153 0, 00154 this->handles_) == -1) 00155 ACE_ERROR_RETURN ((LM_ERROR, 00156 ACE_TEXT ("%p\n"), 00157 ACE_TEXT ("socketpair")), 00158 -1); 00159 # if defined (ACE_LACKS_SOCKET_BUFSIZ) 00160 ACE_UNUSED_ARG (buffer_size); 00161 # else /* ! ACE_LACKS_SOCKET_BUFSIZ */ 00162 if (ACE_OS::setsockopt (this->handles_[0], 00163 SOL_SOCKET, 00164 SO_RCVBUF, 00165 reinterpret_cast <const char *> (&buffer_size), 00166 sizeof (buffer_size)) == -1 00167 && errno != ENOTSUP) 00168 { 00169 this->close (); 00170 return -1; 00171 } 00172 if (ACE_OS::setsockopt (this->handles_[1], 00173 SOL_SOCKET, 00174 SO_SNDBUF, 00175 reinterpret_cast <const char *> (&buffer_size), 00176 sizeof (buffer_size)) == -1 00177 && errno != ENOTSUP) 00178 { 00179 this->close (); 00180 return -1; 00181 } 00182 # endif /* ! ACE_LACKS_SOCKET_BUFSIZ */ 00183 #endif /* ! ACE_LACKS_SOCKETPAIR && ! ACE_HAS_STREAM_PIPES */ 00184 // Point both the read and write HANDLES to the appropriate socket 00185 // HANDLEs. 00186 00187 return 0; 00188 } |
|
Open the pipe and initialize the handles.
Definition at line 191 of file Pipe.cpp. References ACE_TRACE. Referenced by ACE_Pipe(), and ACE_Select_Reactor_Notify::open().
|
|
This is the "read" side of the pipe. Note, however, that processes can also write to this handle as well since pipes are bi-directional. Definition at line 18 of file Pipe.inl. References ACE_TRACE. Referenced by ACE_Select_Reactor_Notify::close(), ACE_Select_Reactor_Notify::dispatch_notifications(), ACE_Select_Reactor_Notify::notify_handle(), and ACE_Select_Reactor_Notify::open().
|
|
Recv n bytes via Win32 ReadFile using overlapped I/O.
Definition at line 180 of file Pipe.inl. References ACE_OVERLAPPED, ACE_TRACE, and ACE_OS::read().
00182 { 00183 ACE_TRACE ("ACE_Pipe::recv"); 00184 return ACE_OS::read (this->read_handle (), static_cast <char *> (buf), n, 00185 overlapped); 00186 } |
|
This is an interface to ::readv, that doesn't use the struct iovec explicitly. The ... can be passed as an arbitrary number of (char *ptr, int len) tuples. However, the count N is the *total* number of trailing arguments, *not* a couple of the number of tuple pairs! Definition at line 306 of file Pipe.cpp. References ACE_NEW_RETURN, ACE_TRACE, ACE_OS::readv(), ACE::recvv(), and ssize_t.
00307 { 00308 ACE_TRACE ("ACE_Pipe::recv"); 00309 va_list argp; 00310 int total_tuples = ACE_Utils::truncate_cast<int> (n / 2); 00311 iovec *iovp; 00312 #if defined (ACE_HAS_ALLOCA) 00313 iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); 00314 #else 00315 ACE_NEW_RETURN (iovp, 00316 iovec[total_tuples], 00317 -1); 00318 #endif /* !defined (ACE_HAS_ALLOCA) */ 00319 00320 va_start (argp, n); 00321 00322 for (int i = 0; i < total_tuples; ++i) 00323 { 00324 iovp[i].iov_base = va_arg (argp, char *); 00325 iovp[i].iov_len = va_arg (argp, int); 00326 } 00327 00328 #if defined (ACE_WIN32) 00329 ssize_t result = ACE::recvv (this->read_handle (), 00330 iovp, 00331 total_tuples); 00332 #else 00333 ssize_t result = ACE_OS::readv (this->read_handle (), 00334 iovp, 00335 total_tuples); 00336 #endif /* ACE_WIN32 */ 00337 00338 #if !defined (ACE_HAS_ALLOCA) 00339 delete [] iovp; 00340 #endif /* !defined (ACE_HAS_ALLOCA) */ 00341 va_end (argp); 00342 return result; 00343 } |
|
Recv iovecs via <::readv>.
Definition at line 159 of file Pipe.inl. References ACE_TRACE, ACE_OS::readv(), and ACE_OS::recvv().
00160 { 00161 ACE_TRACE ("ACE_Pipe::recv"); 00162 #if defined (ACE_WIN32) 00163 return ACE_OS::recvv (this->read_handle (), iov, n); 00164 #else 00165 return ACE_OS::readv (this->read_handle (), iov, n); 00166 #endif /* ACE_WIN32 */ 00167 } |
|
Recv upto n bytes in buf.
Definition at line 137 of file Pipe.inl. References ACE_TRACE, ACE_OS::read(), and ACE_OS::recv().
00138 { 00139 ACE_TRACE ("ACE_Pipe::recv"); 00140 #if defined (ACE_WIN32) 00141 return ACE_OS::recv (this->read_handle (), static_cast <char *> (buf), n); 00142 #else 00143 return ACE_OS::read (this->read_handle (), static_cast <char *> (buf), n); 00144 #endif /* ACE_WIN32 */ 00145 } |
|
Recv n bytes, keep trying until n are received.
Definition at line 115 of file Pipe.inl. References ACE_TRACE, ACE::read_n(), and ACE::recv_n().
00116 { 00117 ACE_TRACE ("ACE_Pipe::recv_n"); 00118 #if defined (ACE_WIN32) 00119 return ACE::recv_n (this->read_handle (), buf, n); 00120 #else 00121 return ACE::read_n (this->read_handle (), buf, n); 00122 #endif /* ACE_WIN32 */ 00123 } |
|
Receive an of size n to the file.
Definition at line 68 of file Pipe.inl. References ACE_TRACE, ACE_OS::readv(), and ACE_OS::sendv().
00069 { 00070 ACE_TRACE ("ACE_Pipe::recvv_n"); 00071 // @@ Carlos, can you please update this to call the 00072 // new ACE::recvv_n() method that you write? 00073 #if defined (ACE_WIN32) 00074 return ACE_OS::sendv (this->read_handle (), 00075 iov, 00076 n); 00077 #else 00078 return ACE_OS::readv (this->read_handle (), 00079 iov, 00080 n); 00081 #endif /* ACE_WIN32 */ 00082 } |
|
Send n bytes via Win32 WriteFile using overlapped I/O.
Definition at line 170 of file Pipe.inl. References ACE_OVERLAPPED, ACE_TRACE, and ACE_OS::write().
00172 { 00173 ACE_TRACE ("ACE_Pipe::send"); 00174 return ACE_OS::write (this->write_handle (), 00175 static_cast <const char *> (buf), n, 00176 overlapped); 00177 } |
|
Send N char *ptrs and int lengths. Note that the char *'s precede the ints (basically, an varargs version of writev). The count N is the *total* number of trailing arguments, *not* a couple of the number of tuple pairs! Definition at line 260 of file Pipe.cpp. References ACE_NEW_RETURN, ACE_TRACE, ACE::sendv(), ssize_t, and ACE_OS::writev().
00261 { 00262 ACE_TRACE ("ACE_Pipe::send"); 00263 va_list argp; 00264 int total_tuples = ACE_Utils::truncate_cast<int> (n / 2); 00265 iovec *iovp; 00266 #if defined (ACE_HAS_ALLOCA) 00267 iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); 00268 #else 00269 ACE_NEW_RETURN (iovp, 00270 iovec[total_tuples], 00271 -1); 00272 #endif /* !defined (ACE_HAS_ALLOCA) */ 00273 00274 va_start (argp, n); 00275 00276 for (int i = 0; i < total_tuples; ++i) 00277 { 00278 iovp[i].iov_base = va_arg (argp, char *); 00279 iovp[i].iov_len = va_arg (argp, int); 00280 } 00281 00282 #if defined (ACE_WIN32) 00283 ssize_t result = ACE::sendv (this->write_handle (), 00284 iovp, 00285 total_tuples); 00286 #else 00287 ssize_t result = ACE_OS::writev (this->write_handle (), 00288 iovp, 00289 total_tuples); 00290 #endif /* ACE_WIN32 */ 00291 00292 #if !defined (ACE_HAS_ALLOCA) 00293 delete [] iovp; 00294 #endif /* !defined (ACE_HAS_ALLOCA) */ 00295 va_end (argp); 00296 return result; 00297 } |
|
Send iovecs via <::writev>.
Definition at line 148 of file Pipe.inl. References ACE_TRACE, ACE_OS::sendv(), and ACE_OS::writev().
00149 { 00150 ACE_TRACE ("ACE_Pipe::send"); 00151 #if defined (ACE_WIN32) 00152 return ACE_OS::sendv (this->write_handle (), iov, n); 00153 #else 00154 return ACE_OS::writev (this->write_handle (), iov, n); 00155 #endif /* ACE_WIN32 */ 00156 } |
|
send upto n bytes in buf.
Definition at line 126 of file Pipe.inl. References ACE_TRACE, ACE_OS::send(), and ACE_OS::write().
00127 { 00128 ACE_TRACE ("ACE_Pipe::send"); 00129 #if defined (ACE_WIN32) 00130 return ACE_OS::send (this->write_handle (), static_cast <const char *> (buf), n); 00131 #else 00132 return ACE_OS::write (this->write_handle (), static_cast <const char *> (buf), n); 00133 #endif /* ACE_WIN32 */ 00134 } |
|
Send all the s chained through their and pointers. This call uses the underlying OS gather-write operation to reduce the domain-crossing penalty. Definition at line 47 of file Pipe.inl. References ACE_TRACE, ACE::send_n(), and ACE::write_n().
00050 { 00051 ACE_TRACE ("ACE_Pipe::send_n"); 00052 #if defined (ACE_WIN32) 00053 return ACE::send_n (this->write_handle (), 00054 message_block, 00055 timeout, 00056 bytes_transferred); 00057 #else 00058 ACE_UNUSED_ARG (timeout); 00059 return ACE::write_n (this->write_handle (), 00060 message_block, 00061 bytes_transferred); 00062 #endif /* ACE_WIN32 */ 00063 } |
|
Send n bytes, keep trying until n are sent.
Definition at line 101 of file Pipe.inl. References ACE_TRACE, ACE::send_n(), and ACE::write_n().
00102 { 00103 ACE_TRACE ("ACE_Pipe::send_n"); 00104 #if defined (ACE_WIN32) 00105 return ACE::send_n (this->write_handle (), buf, n); 00106 #else 00107 return ACE::write_n (this->write_handle (), buf, n); 00108 #endif /* ACE_WIN32 */ 00109 } |
|
Send an of size n to the file.
Definition at line 87 of file Pipe.inl. References ACE_TRACE, ACE_OS::sendv(), and ACE_OS::writev().
00088 { 00089 ACE_TRACE ("ACE_Pipe::sendv"); 00090 #if defined (ACE_WIN32) 00091 return ACE_OS::sendv (this->write_handle (), iov, n); 00092 #else 00093 return ACE_OS::writev (this->write_handle (), iov, n); 00094 #endif /* ACE_WIN32 */ 00095 } |
|
Send an of size n to the file. Will block until all bytes are sent or an error occurs. Definition at line 32 of file Pipe.inl. References ACE_TRACE, ACE::sendv_n(), and ACE::writev_n().
00033 { 00034 ACE_TRACE ("ACE_Pipe::sendv_n"); 00035 #if defined (ACE_WIN32) 00036 return ACE::sendv_n (this->write_handle (), 00037 iov, 00038 n); 00039 #else 00040 return ACE::writev_n (this->write_handle (), 00041 iov, 00042 n); 00043 #endif /* ACE_WIN32 */ 00044 } |
|
This is the "write" side of the pipe. Note, however, that processes can also read to this handle as well since pipes are bi-directional. Definition at line 25 of file Pipe.inl. References ACE_TRACE.
|
|
|