MEM_Acceptor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    MEM_Acceptor.h
00006  *
00007  *  MEM_Acceptor.h,v 4.24 2005/11/26 03:13:13 ossama Exp
00008  *
00009  *  @author Nanbor Wang <nanbor@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_MEM_ACCEPTOR_H
00014 #define ACE_MEM_ACCEPTOR_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "ace/ACE_export.h"
00018 
00019 #include "ace/SOCK_Acceptor.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00026 
00027 #include "ace/MEM_Stream.h"
00028 #include "ace/MEM_Addr.h"
00029 
00030 #if !defined (ACE_HAS_WINCE)
00031 #include "ace/OS_QoS.h"
00032 #endif  // ACE_HAS_WINCE
00033 
00034 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00035 
00036 // Forward decl.
00037 class ACE_Reactor;
00038 
00039 /**
00040  * @class ACE_MEM_Acceptor
00041  *
00042  * @brief Defines the format and interface for the acceptor side of the
00043  * local mmap stream.
00044  *
00045  * This class should be modified to prevent user passing a
00046  * non-localhost endpoint as the acceptor listen point because
00047  * it doesn't make any sense at all to make the listening
00048  * endpoint visible (or connectable) anywhere outside of this
00049  * machine.  However, the type of endpoint is left as <ACE_Addr>
00050  * so we can later changed to use UNIX-domain sockets with mmap stream
00051  * if so desired.  (Currently, using UNIX-domain sockets, i.e.,
00052  * ACE_LSOCK_*, with this class will not work.)
00053  */
00054 class ACE_Export ACE_MEM_Acceptor : public ACE_SOCK_Acceptor
00055 {
00056 public:
00057   // = Initialization methods.
00058   /// Default constructor.
00059   ACE_MEM_Acceptor (void);
00060 
00061   /// destructor.
00062   ~ACE_MEM_Acceptor (void);
00063 
00064   /// Initiate a passive mode socket.
00065   ACE_MEM_Acceptor (const ACE_MEM_Addr &remote_sap,
00066                     int reuse_addr = 0,
00067                     int backlog = ACE_DEFAULT_BACKLOG,
00068                     int protocol = 0);
00069 
00070   /**
00071    * Initialize a passive-mode BSD-style acceptor socket (no QoS).
00072    * @a local_sap is the address that we're going to listen for
00073    * connections on.  If @a reuse_addr is 1 then we'll use the
00074    * @c SO_REUSEADDR to reuse this address.  Returns 0 on success and
00075    * -1 on failure.
00076    */
00077   int open (const ACE_MEM_Addr &local_sap,
00078             int reuse_addr = 0,
00079             int backlog = ACE_DEFAULT_BACKLOG,
00080             int protocol = 0);
00081 
00082   /// Accept a new data transfer connection.
00083   int accept (ACE_MEM_Stream &new_ipc_sap,
00084               ACE_MEM_Addr *remote_addr = 0,
00085               ACE_Time_Value *timeout = 0,
00086               int restart = 1,
00087               int reset_new_handle = 0);
00088 
00089   /// Perform operations that must occur after <ACE_OS::accept> is
00090   /// called.
00091   int shared_accept_finish (ACE_MEM_Stream new_stream,
00092                             int in_blocking_mode,
00093                             int reset_new_handle) const;
00094 
00095   /**
00096    * Accessor/mutator of mmap filename prefix.  By default, the
00097    * <mmap_prefix_> is not set and the mmap filename is
00098    * ${(TMP|TEMP)}//ACE_MEM_Acceptor_(port-number)_(&stream),
00099    * otherwise, it is <mmap_prefix_>_(port-number)_(&stream),
00100    * <mmap_prefix_> should include _absolute_ path so the connector
00101    * within the same host can located the mmap file.  Example:
00102    * /tmp/mmapfile.
00103    */
00104   const ACE_TCHAR *mmap_prefix (void) const;
00105   void mmap_prefix (const ACE_TCHAR *prefix);
00106 
00107   /**
00108    * Change the initial MMAP buffer size (in bytes) of the MEM_Stream
00109    * this MEM_Acceptor creates.
00110    */
00111   void init_buffer_size (off_t bytes);
00112 
00113   /// Get the preferred signaling strategy.
00114   ACE_MEM_IO::Signal_Strategy preferred_strategy (void) const;
00115 
00116   /// Set the preferred signaling strategy.
00117   void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy);
00118 
00119   /// Return the local endpoint address in the referenced <ACE_Addr>.
00120   /// Returns 0 if successful, else -1.
00121   int get_local_addr (ACE_MEM_Addr &) const;
00122 
00123   /// Accessor to the mmap options.
00124   /// @deprecated This method has been deprecated.
00125   ACE_MEM_SAP::MALLOC_OPTIONS& malloc_options (void);
00126 
00127   // = Meta-type info
00128   typedef ACE_MEM_Addr PEER_ADDR;
00129   typedef ACE_MEM_Stream PEER_STREAM;
00130 
00131   /// Dump the state of an object.
00132   void dump (void) const;
00133 
00134   /// Declare the dynamic allocation hooks.
00135   ACE_ALLOC_HOOK_DECLARE;
00136 
00137 protected:
00138   // = The following methods should not be accessable externally
00139   //   because MEM_Acceptor do not support their semantics.
00140   int open (const ACE_Addr &local_sap,
00141             int reuse_addr = 0,
00142             int protocol_family = PF_INET,
00143             int backlog = ACE_DEFAULT_BACKLOG,
00144             int protocol = 0);
00145 
00146   int open (const ACE_Addr &local_sap,
00147             ACE_Protocol_Info *protocolinfo,
00148             ACE_SOCK_GROUP g,
00149             u_long flags,
00150             int reuse_addr,
00151             int protocol_family,
00152             int backlog = ACE_DEFAULT_BACKLOG,
00153             int protocol = 0);
00154 
00155   int accept (ACE_SOCK_Stream &new_stream,
00156               ACE_Addr *remote_addr = 0,
00157               ACE_Time_Value *timeout = 0,
00158               int restart = 1,
00159               int reset_new_handle = 0) const;
00160 
00161 #if !defined (ACE_HAS_WINCE)
00162   int accept (ACE_SOCK_Stream &new_stream,
00163               ACE_Accept_QoS_Params qos_params,
00164               ACE_Addr *remote_addr = 0,
00165               ACE_Time_Value *timeout = 0,
00166               int restart = 1,
00167               int reset_new_handle = 0) const;
00168 #endif  // ACE_HAS_WINCE
00169 
00170 private:
00171   /// The filename prefix of the created mmap files.  It should
00172   /// contains the absolute path name of the file.
00173   ACE_TCHAR *mmap_prefix_;
00174 
00175   /// A cached MALLOC_OPTIONS.  MEM_Accaptor use it to create the shared
00176   /// mamory malloc upon every incoming connection.
00177   ACE_MEM_SAP::MALLOC_OPTIONS malloc_options_;
00178 
00179   /// Preferred signaling strategy.
00180   ACE_MEM_IO::Signal_Strategy preferred_strategy_;
00181 };
00182 
00183 ACE_END_VERSIONED_NAMESPACE_DECL
00184 
00185 #if defined (__ACE_INLINE__)
00186 #include "ace/MEM_Acceptor.inl"
00187 #endif /* __ACE_INLINE__ */
00188 
00189 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00190 
00191 #include /**/ "ace/post.h"
00192 #endif /* ACE_MEM_ACCEPTOR_H */

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