UPIPE_Stream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    UPIPE_Stream.h
00006  *
00007  *  UPIPE_Stream.h,v 4.21 2005/12/12 02:11:51 ossama Exp
00008  *
00009  *  @author Gerhard Lenzer
00010  *  @author Douglas C. Schmidt
00011  */
00012 //=============================================================================
00013 
00014 
00015 #ifndef ACE_UPIPE_STREAM_H
00016 #define ACE_UPIPE_STREAM_H
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "ace/Stream.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #if defined (ACE_HAS_THREADS)
00026 
00027 #include "ace/SPIPE.h"
00028 #include "ace/Message_Queue.h"
00029 #include "ace/UPIPE_Addr.h"
00030 
00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 /**
00034  * @class ACE_UPIPE_Stream
00035  *
00036  * @brief Defines the method that transfer data on a UPIPE.
00037  */
00038 class ACE_Export ACE_UPIPE_Stream : public ACE_SPIPE
00039 {
00040 public:
00041   friend class ACE_UPIPE_Acceptor;
00042   friend class ACE_UPIPE_Connector;
00043 
00044   typedef ACE_Stream<ACE_SYNCH> MT_Stream;
00045 
00046   // = Initialization and Termination.
00047 
00048   ACE_UPIPE_Stream (void);
00049 
00050   virtual ~ACE_UPIPE_Stream (void);
00051 
00052   /// Shut down the UPIPE and release resources.
00053   int close (void);
00054 
00055   /// Return the underlying I/O handle.
00056   ACE_HANDLE get_handle (void) const;
00057 
00058   // = Send/recv ACE Message_Blocks.
00059   /// Send a message through the message queue.  Returns -1 on error,
00060   /// else 0.
00061   int send (ACE_Message_Block *mb_p,
00062             ACE_Time_Value *timeout  = 0);
00063 
00064   /// Recv a message from the message queue.  Returns -1 on error, else
00065   /// 0.
00066   int recv (ACE_Message_Block *&mb_p,
00067             ACE_Time_Value *timeout  = 0);
00068 
00069   // = Send/recv char buffers.
00070   /// Send a buffer of @a n bytes through the message queue.  Returns -1
00071   /// on error, else number of bytes sent.
00072   ssize_t send (const char *buffer,
00073                 size_t n,
00074                 ACE_Time_Value *timeout = 0);
00075 
00076   /// Recv a buffer of upto @a n bytes from the message queue.  Returns
00077   /// -1 on error, else number of bytes read.
00078   ssize_t recv (char *buffer,
00079                 size_t n,
00080                 ACE_Time_Value *timeout = 0);
00081 
00082   /// Send a buffer of exactly @a n bytes to the message queue.  Returns
00083   /// -1 on error, else number of bytes written (which should == n).
00084   ssize_t send_n (const char *buffer,
00085                   size_t n,
00086                   ACE_Time_Value *timeout = 0);
00087 
00088   /// Recv a buffer of exactly <n> bytes from the message queue.
00089   /// Returns -1 on error, else the number of bytes read.
00090   ssize_t recv_n (char *buffer,
00091                   size_t n,
00092                   ACE_Time_Value *timeout = 0);
00093 
00094   /// Perform control operations on the UPIPE_Stream.
00095   int control (int cmd, void *val) const;
00096 
00097   /// Return the remote address we are connected to.
00098   int get_remote_addr (ACE_UPIPE_Addr &remote_sap) const;
00099 
00100   /// Dump the state of an object.
00101   void dump (void) const;
00102 
00103   /// Declare the dynamic allocation hooks.
00104   ACE_ALLOC_HOOK_DECLARE;
00105 
00106   // = Meta-type info
00107   typedef ACE_UPIPE_Addr PEER_ADDR;
00108 
00109 private:
00110   /// To hold the last ACE_Message_Block read out of the stream. Thus
00111   /// allowing subsequent reads from one ACE_Message_Block
00112   ACE_Message_Block *mb_last_;
00113 
00114   /// Address of who we are connected to.
00115   ACE_UPIPE_Addr remote_addr_;
00116 
00117   /// Stream component used by the @c UPIPE_Acceptor and
00118   /// @c UPIPE_Connector to link together two UPIPE_Streams.
00119   MT_Stream stream_;
00120 
00121   /// Keep track of whether the sender and receiver have both shut
00122   /// down.
00123   int reference_count_;
00124 
00125 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00126   /// Ensure that we are thread-safe.
00127   ACE_Thread_Mutex lock_;
00128 #endif /* ACE_MT_SAFE */
00129 };
00130 
00131 ACE_END_VERSIONED_NAMESPACE_DECL
00132 
00133 #if defined (__ACE_INLINE__)
00134 #include "ace/UPIPE_Stream.inl"
00135 #endif /* __ACE_INLINE__ */
00136 
00137 #endif /* ACE_HAS_THREADS */
00138 
00139 #include /**/ "ace/post.h"
00140 
00141 #endif /*ACE_UPIPE_STREAM_H */

Generated on Thu Nov 9 09:42:09 2006 for ACE by doxygen 1.3.6