3 //==========================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //==========================================================================
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Default_Constants.h"
24 #include "ace/OS_NS_sys_uio.h"
25 #include "ace/OS_NS_unistd.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 class ACE_Message_Block
;
36 * @brief Provides a portable bidirectional "pipe" abstraction.
38 * This class is designed to work with select()-based demuxers, such
39 * as the ACE_Select_Reactor, which is why it uses sockets on Windows
40 * rather than Win32 pipes (which aren't select()'able).
42 class ACE_Export ACE_Pipe
45 /// Default constructor (does nothing...).
48 /// Open the pipe and initialize the handles.
49 ACE_Pipe (ACE_HANDLE handles
[2]);
51 /// Initialize the ACE_Pipe from the @a read and @a write handles.
52 ACE_Pipe (ACE_HANDLE read
, ACE_HANDLE write
);
54 /// Default dtor. It doesn't close the handles for you.
57 /// Open the pipe and initialize the handles.
58 int open (ACE_HANDLE handles
[2]);
60 /// Open the pipe, setting the buffer size to the maximum.
61 int open (int buffer_size
= ACE_DEFAULT_MAX_SOCKET_BUFSIZ
);
63 /// Close down the pipe HANDLEs;
71 * This is the "read" side of the pipe. Note, however, that
72 * processes can also write to this handle as well since pipes are
75 ACE_HANDLE
read_handle () const;
78 * This is the "write" side of the pipe. Note, however, that
79 * processes can also read to this handle as well since pipes are
82 ACE_HANDLE
write_handle () const;
84 /// Dump the state of the object.
87 /// send upto @a n bytes in @a buf.
88 ssize_t
send (const void *buf
, size_t n
) const;
90 /// Recv upto @a n bytes in @a buf.
91 ssize_t
recv (void *buf
, size_t n
) const;
93 /// Send n bytes, keep trying until n are sent.
94 ssize_t
send_n (const void *buf
, size_t n
) const;
96 /// Send all the @a message_blocks chained through their <next> and
97 /// <cont> pointers. This call uses the underlying OS gather-write
98 /// operation to reduce the domain-crossing penalty.
99 ssize_t
send_n (const ACE_Message_Block
*message_block
,
100 const ACE_Time_Value
*timeout
= 0,
101 size_t *bytes_transferred
= 0);
103 /// Recv n bytes, keep trying until n are received.
104 ssize_t
recv_n (void *buf
, size_t n
) const;
106 /// Send iovecs via <::writev>.
107 ssize_t
send (const iovec iov
[], int n
) const;
109 /// Recv iovecs via <::readv>.
110 ssize_t
recv (iovec iov
[], int n
) const;
112 #if !defined (ACE_LACKS_VA_FUNCTIONS)
114 * Send N char *ptrs and int lengths. Note that the char *'s
115 * precede the ints (basically, an varargs version of writev). The
116 * count N is the *total* number of trailing arguments, *not* a
117 * couple of the number of tuple pairs!
119 ssize_t
send (size_t n
, ...) const;
122 * This is an interface to ::readv, that doesn't use the struct
123 * iovec explicitly. The ... can be passed as an arbitrary number
124 * of (char *ptr, int len) tuples. However, the count N is the
125 * *total* number of trailing arguments, *not* a count of the
126 * number of tuple pairs!
128 ssize_t
recv (size_t n
, ...) const;
129 #endif /* !ACE_LACKS_VA_FUNCTIONS */
131 /// Send @a n bytes via Win32 WriteFile using overlapped I/O.
132 ssize_t
send (const void *buf
,
134 ACE_OVERLAPPED
*overlapped
) const;
136 /// Recv @a n bytes via Win32 ReadFile using overlapped I/O.
137 ssize_t
recv (void *buf
,
139 ACE_OVERLAPPED
*overlapped
) const;
141 /// Send an <iovec> of size @a n to the file.
142 ssize_t
sendv (const iovec iov
[],
145 /// Send an @c iovec of size @a n to the file. Will block until all
146 /// bytes are sent or an error occurs.
147 ssize_t
sendv_n (const iovec iov
[],
150 /// Receive an @c iovec of size @a n to the file.
151 ssize_t
recvv_n (iovec iov
[],
155 ACE_HANDLE handles_
[2];
156 int close_handle (int which
);
159 ACE_END_VERSIONED_NAMESPACE_DECL
161 #if defined (__ACE_INLINE__)
162 #include "ace/Pipe.inl"
163 #endif /* __ACE_INLINE__ */
165 #include /**/ "ace/post.h"
167 #endif /* ACE_PIPE_H */