Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

UPIPE_Stream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    UPIPE_Stream.h
00006  *
00007  *  $Id: UPIPE_Stream.h,v 1.1.1.4 2003/02/21 18:36:32 chad 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 #include "ace/Synch.h"
00026 #include "ace/SPIPE.h"
00027 #include "ace/Message_Queue.h"
00028 #include "ace/UPIPE_Addr.h"
00029 
00030 #if defined (ACE_HAS_THREADS)
00031 
00032 // Use a typedef to make life easier later on.
00033 typedef ACE_Stream<ACE_SYNCH> MT_Stream;
00034 
00035 /**
00036  * @class ACE_UPIPE_Stream
00037  *
00038  * @brief Defines the method that transfer data on a UPIPE.
00039  */
00040 class ACE_Export ACE_UPIPE_Stream : public ACE_SPIPE
00041 {
00042 public:
00043   friend class ACE_UPIPE_Acceptor;
00044   friend class ACE_UPIPE_Connector;
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 <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 <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 <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 <UPIPE_Acceptor> and
00118   /// <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 #if defined (__ACE_INLINE__)
00132 #include "ace/UPIPE_Stream.i"
00133 #endif /* __ACE_INLINE__ */
00134 
00135 #endif /* ACE_HAS_THREADS */
00136 #include "ace/post.h"
00137 #endif /*ACE_UPIPE_STREAM_H */

Generated on Mon Jun 16 11:22:04 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002