MEM_Stream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    MEM_Stream.h
00006  *
00007  *  MEM_Stream.h,v 4.19 2006/02/10 10:02:24 jwillemsen Exp
00008  *
00009  *  @author Nanbor Wang <nanbor@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef ACE_MEM_STREAM_H
00015 #define ACE_MEM_STREAM_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/MEM_IO.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00025 
00026 #include "ace/INET_Addr.h"
00027 
00028 #if !defined (ACE_MEM_STREAM_MIN_BUFFER)
00029 # define ACE_MEM_STREAM_MIN_BUFFER 4096
00030 #endif /* ACE_MEM_STREAM_MIN_BUFFER */
00031 
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 class ACE_MEM_Acceptor;
00035 class ACE_MEM_Connector;
00036 
00037 /**
00038  * @class ACE_MEM_Stream
00039  *
00040  * @brief Defines the methods in the ACE_MEM_Stream abstraction.
00041  *
00042  * This adds additional wrapper methods atop the ACE_MEM_IO
00043  * class.  Notice that ACE_MEM_Stream can only send messages no bigger
00044  * than the underlying MMAP file size minus sizeof (ACE_MEM_SAP_Node).
00045  * The size of the MMAP file is default to ACE_MEM_STREAM_MIN_BUFFER.
00046  * (Define above in this file, to 4096 bytes.)
00047  * If you need to increase the size of allowable message
00048  * ACE_MEM_Stream can handle, you can set it to either
00049  * @c ACE_MEM_Acceptor::malloc_options(). minimal_bytes_
00050  * @c ACE_MEM_Acceptor::init_buffer_size (size_t size);
00051  * before establishing a connection.
00052  */
00053 class ACE_Export ACE_MEM_Stream : public ACE_MEM_IO
00054 {
00055 public:
00056 
00057   friend class ACE_MEM_Acceptor;
00058   friend class ACE_MEM_Connector;
00059 
00060   // Initialization and termination methods.
00061   /// Constructor.
00062   ACE_MEM_Stream (void);
00063 
00064   /// Constructor (sets the underlying ACE_HANDLE with <h>).
00065   ACE_MEM_Stream (ACE_HANDLE h);
00066 
00067   /// Destructor.
00068   ~ACE_MEM_Stream (void);
00069 
00070   //= The following two methods use write and read system calls.
00071   /// Send n bytes, keep trying until n are sent.
00072   /// Recv n bytes, keep trying until n are received.
00073   ssize_t send_n (const void *buf, size_t n);
00074   ssize_t recv_n (void *buf, size_t n);
00075 
00076   // = The following two methods use the send and recv system calls.
00077   /// Send n bytes, keep trying until n are sent.
00078   /// Recv n bytes, keep trying until n are received.
00079   ssize_t send_n (const void *buf, size_t n, int flags);
00080   ssize_t recv_n (void *buf, size_t n, int flags);
00081 
00082 #if 0
00083   /**
00084    * Try to send exactly <len> bytes into <buf> from <handle> (uses
00085    * the <send> call).  If <send> blocks for longer than <timeout> the
00086    * number of bytes actually sent is returned with <errno == ETIME>.
00087    * If a timeout does not occur, <send_n> return <len> (i.e., the
00088    * number of bytes requested to be sent).
00089    */
00090   ssize_t send_n (const void *buf,
00091                   size_t len,
00092                   int flags,
00093                   const ACE_Time_Value *timeout);
00094 
00095   /**
00096    * Try to recv exactly <len> bytes into <buf> from <handle> (uses
00097    * the <ACE::recv_n> call).  The <ACE_Time_Value> indicates how long
00098    * to blocking trying to receive.  If <timeout> == 0, the caller
00099    * will block until action is possible, else will wait until the
00100    * relative time specified in *<timeout> elapses).  If <recv> blocks
00101    * for longer than <timeout> the number of bytes actually read is
00102    * returned with <errno == ETIME>.  If a timeout does not occur,
00103    * <recv_n> return <len> (i.e., the number of bytes requested to be
00104    * read).
00105    */
00106   ssize_t recv_n (void *buf,
00107                   size_t len,
00108                   int flags,
00109                   const ACE_Time_Value *timeout);
00110 
00111   /**
00112    * Send an <iovec> of size <n> to the connected socket (uses
00113    * <ACE::sendv_n>).  Will block until all bytes are sent or an error
00114    * occurs.
00115    */
00116   ssize_t sendv_n (const iovec iov[],
00117                    size_t n) const;
00118 
00119   /// Receive an <iovec> of size <n> to the connected socket.
00120   ssize_t recvv_n (iovec iov[],
00121                    size_t n) const;
00122 #endif /* 0 */
00123 
00124   // = Selectively close endpoints.
00125 
00126   /// Close down the reader.
00127   int close_reader (void);
00128 
00129   /// Close down the writer.
00130   int close_writer (void);
00131 
00132   /**
00133    * Close down the socket (we need this to make things work correctly
00134    * on Win32, which requires use to do a <close_writer> before doing
00135    * the close to avoid losing data).
00136    */
00137   int close (void);
00138 
00139   // = Meta-type info
00140   typedef ACE_Addr PEER_ADDR;
00141 
00142   /// Dump the state of an object.
00143   void dump (void) const;
00144 
00145   /// Declare the dynamic allocation hooks.
00146   ACE_ALLOC_HOOK_DECLARE;
00147 };
00148 
00149 ACE_END_VERSIONED_NAMESPACE_DECL
00150 
00151 #if defined (__ACE_INLINE__)
00152 #include "ace/MEM_Stream.inl"
00153 #endif /* __ACE_INLINE__ */
00154 
00155 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00156 
00157 #include /**/ "ace/post.h"
00158 #endif /* ACE_MEM_STREAM_H */

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