Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / UPIPE_Stream.h
blob5e911ca1cd4a8b5016fc57cbb5072d2d16ef377f
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file UPIPE_Stream.h
7 * @author Gerhard Lenzer
8 * @author Douglas C. Schmidt
9 */
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)
20 # 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
31 /**
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
38 public:
39 friend class ACE_UPIPE_Acceptor;
40 friend class ACE_UPIPE_Connector;
42 typedef ACE_Stream<ACE_SYNCH> MT_Stream;
44 ACE_UPIPE_Stream ();
46 virtual ~ACE_UPIPE_Stream ();
48 /// Shut down the UPIPE and release resources.
49 int close ();
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,
56 /// else 0.
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
61 /// 0.
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,
69 size_t n,
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,
75 size_t n,
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,
81 size_t n,
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,
87 size_t n,
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.
97 void dump () const;
99 /// Declare the dynamic allocation hooks.
100 ACE_ALLOC_HOOK_DECLARE;
102 // = Meta-type info
103 typedef ACE_UPIPE_Addr PEER_ADDR;
105 private:
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.
115 MT_Stream stream_;
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 */