3 //=============================================================================
7 * @author Gerhard Lenzer
8 * @author Douglas C. Schmidt
10 //=============================================================================
13 #ifndef ACE_UPIPE_STREAM_H
14 #define ACE_UPIPE_STREAM_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Stream.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #if defined (ACE_HAS_THREADS)
25 #include "ace/SPIPE.h"
26 #include "ace/Message_Queue.h"
27 #include "ace/UPIPE_Addr.h"
29 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 * @class ACE_UPIPE_Stream
34 * @brief Defines the method that transfer data on a UPIPE.
36 class ACE_Export ACE_UPIPE_Stream
: public ACE_SPIPE
39 friend class ACE_UPIPE_Acceptor
;
40 friend class ACE_UPIPE_Connector
;
42 typedef ACE_Stream
<ACE_SYNCH
> MT_Stream
;
46 virtual ~ACE_UPIPE_Stream ();
48 /// Shut down the UPIPE and release resources.
51 /// Return the underlying I/O handle.
52 ACE_HANDLE
get_handle () const;
54 // = Send/recv ACE Message_Blocks.
55 /// Send a message through the message queue. Returns -1 on error,
57 int send (ACE_Message_Block
*mb_p
,
58 ACE_Time_Value
*timeout
= 0);
60 /// Recv a message from the message queue. Returns -1 on error, else
62 int recv (ACE_Message_Block
*&mb_p
,
63 ACE_Time_Value
*timeout
= 0);
65 // = Send/recv char buffers.
66 /// Send a buffer of @a n bytes through the message queue. Returns -1
67 /// on error, else number of bytes sent.
68 ssize_t
send (const char *buffer
,
70 ACE_Time_Value
*timeout
= 0);
72 /// Recv a buffer of upto @a n bytes from the message queue. Returns
73 /// -1 on error, else number of bytes read.
74 ssize_t
recv (char *buffer
,
76 ACE_Time_Value
*timeout
= 0);
78 /// Send a buffer of exactly @a n bytes to the message queue. Returns
79 /// -1 on error, else number of bytes written (which should == n).
80 ssize_t
send_n (const char *buffer
,
82 ACE_Time_Value
*timeout
= 0);
84 /// Recv a buffer of exactly @a n bytes from the message queue.
85 /// Returns -1 on error, else the number of bytes read.
86 ssize_t
recv_n (char *buffer
,
88 ACE_Time_Value
*timeout
= 0);
90 /// Perform control operations on the UPIPE_Stream.
91 int control (int cmd
, void *val
) const;
93 /// Return the remote address we are connected to.
94 int get_remote_addr (ACE_UPIPE_Addr
&remote_sap
) const;
96 /// Dump the state of an object.
99 /// Declare the dynamic allocation hooks.
100 ACE_ALLOC_HOOK_DECLARE
;
103 typedef ACE_UPIPE_Addr PEER_ADDR
;
106 /// To hold the last ACE_Message_Block read out of the stream. Thus
107 /// allowing subsequent reads from one ACE_Message_Block
108 ACE_Message_Block
*mb_last_
;
110 /// Address of who we are connected to.
111 ACE_UPIPE_Addr remote_addr_
;
113 /// Stream component used by the @c UPIPE_Acceptor and
114 /// @c UPIPE_Connector to link together two UPIPE_Streams.
117 /// Keep track of whether the sender and receiver have both shutdown.
118 int reference_count_
;
120 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
121 /// Ensure that we are thread-safe.
122 ACE_Thread_Mutex lock_
;
123 #endif /* ACE_MT_SAFE */
126 ACE_END_VERSIONED_NAMESPACE_DECL
128 #if defined (__ACE_INLINE__)
129 #include "ace/UPIPE_Stream.inl"
130 #endif /* __ACE_INLINE__ */
132 #endif /* ACE_HAS_THREADS */
134 #include /**/ "ace/post.h"
136 #endif /*ACE_UPIPE_STREAM_H */