00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Pipe.h 00006 * 00007 * $Id: Pipe.h 77153 2007-02-15 13:51:31Z johnnyw $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //========================================================================== 00012 00013 #ifndef ACE_PIPE_H 00014 #define ACE_PIPE_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include /**/ "ace/ACE_export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "ace/Default_Constants.h" 00025 00026 #include "ace/OS_NS_sys_uio.h" 00027 #include "ace/OS_NS_unistd.h" 00028 00029 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00030 00031 // Forward decl. 00032 class ACE_Message_Block; 00033 class ACE_Time_Value; 00034 00035 /** 00036 * @class ACE_Pipe 00037 * 00038 * @brief Provides a portable bidirectional "pipe" abstraction. 00039 * 00040 * This class is designed to work with select()-based demuxers, such 00041 * as the ACE_Select_Reactor, which is why it uses sockets on Windows 00042 * rather than Win32 pipes (which aren't select()'able). 00043 */ 00044 class ACE_Export ACE_Pipe 00045 { 00046 public: 00047 // = Initialization and termination. 00048 /// Default constructor (does nothing...). 00049 ACE_Pipe (void); 00050 00051 /// Open the pipe and initialize the handles. 00052 ACE_Pipe (ACE_HANDLE handles[2]); 00053 00054 /// Initialize the ACE_Pipe from the @a read and @a write handles. 00055 ACE_Pipe (ACE_HANDLE read, ACE_HANDLE write); 00056 00057 /// Default dtor. It doesn't close the handles for you. 00058 ~ACE_Pipe (void); 00059 00060 /// Open the pipe and initialize the handles. 00061 int open (ACE_HANDLE handles[2]); 00062 00063 /// Open the pipe, setting the buffer size to the maximum. 00064 int open (int buffer_size = ACE_DEFAULT_MAX_SOCKET_BUFSIZ); 00065 00066 /// Close down the pipe HANDLEs; 00067 int close (void); 00068 00069 // = Accessors. 00070 00071 /** 00072 * This is the "read" side of the pipe. Note, however, that 00073 * processes can also write to this handle as well since pipes are 00074 * bi-directional. 00075 */ 00076 ACE_HANDLE read_handle (void) const; 00077 00078 /** 00079 * This is the "write" side of the pipe. Note, however, that 00080 * processes can also read to this handle as well since pipes are 00081 * bi-directional. 00082 */ 00083 ACE_HANDLE write_handle (void) const; 00084 00085 /// Dump the state of the object. 00086 void dump (void) const; 00087 00088 /// send upto @a n bytes in @a buf. 00089 ssize_t send (const void *buf, size_t n) const; 00090 00091 /// Recv upto @a n bytes in @a buf. 00092 ssize_t recv (void *buf, size_t n) const; 00093 00094 /// Send n bytes, keep trying until n are sent. 00095 ssize_t send_n (const void *buf, size_t n) const; 00096 00097 /// Send all the <message_block>s chained through their <next> and 00098 /// <cont> pointers. This call uses the underlying OS gather-write 00099 /// operation to reduce the domain-crossing penalty. 00100 ssize_t send_n (const ACE_Message_Block *message_block, 00101 const ACE_Time_Value *timeout = 0, 00102 size_t *bytes_transferred = 0); 00103 00104 /// Recv n bytes, keep trying until n are received. 00105 ssize_t recv_n (void *buf, size_t n) const; 00106 00107 /// Send iovecs via <::writev>. 00108 ssize_t send (const iovec iov[], int n) const; 00109 00110 /// Recv iovecs via <::readv>. 00111 ssize_t recv (iovec iov[], int n) const; 00112 00113 /** 00114 * Send N char *ptrs and int lengths. Note that the char *'s 00115 * precede the ints (basically, an varargs version of writev). The 00116 * count N is the *total* number of trailing arguments, *not* a 00117 * couple of the number of tuple pairs! 00118 */ 00119 ssize_t send (size_t n, ...) const; 00120 00121 /** 00122 * This is an interface to ::readv, that doesn't use the struct 00123 * iovec explicitly. The ... can be passed as an arbitrary number 00124 * of (char *ptr, int len) tuples. However, the count N is the 00125 * *total* number of trailing arguments, *not* a couple of the 00126 * number of tuple pairs! 00127 */ 00128 ssize_t recv (size_t n, ...) const; 00129 00130 /// Send @a n bytes via Win32 WriteFile using overlapped I/O. 00131 ssize_t send (const void *buf, 00132 size_t n, 00133 ACE_OVERLAPPED *overlapped) const; 00134 00135 /// Recv @a n bytes via Win32 ReadFile using overlapped I/O. 00136 ssize_t recv (void *buf, 00137 size_t n, 00138 ACE_OVERLAPPED *overlapped) const; 00139 00140 /// Send an <iovec> of size @a n to the file. 00141 ssize_t sendv (const iovec iov[], 00142 int n) const; 00143 00144 /// Send an <iovec> of size @a n to the file. Will block until all 00145 /// bytes are sent or an error occurs. 00146 ssize_t sendv_n (const iovec iov[], 00147 int n) const; 00148 00149 /// Receive an <iovec> of size @a n to the file. 00150 ssize_t recvv_n (iovec iov[], 00151 int n) const; 00152 00153 private: 00154 ACE_HANDLE handles_[2]; 00155 }; 00156 00157 ACE_END_VERSIONED_NAMESPACE_DECL 00158 00159 #if defined (__ACE_INLINE__) 00160 #include "ace/Pipe.inl" 00161 #endif /* __ACE_INLINE__ */ 00162 00163 #include /**/ "ace/post.h" 00164 00165 #endif /* ACE_PIPE_H */