ACE_MEM_Acceptor Class Reference

Defines the format and interface for the acceptor side of the local mmap stream. More...

#include <MEM_Acceptor.h>

Inheritance diagram for ACE_MEM_Acceptor:

Inheritance graph
[legend]
Collaboration diagram for ACE_MEM_Acceptor:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_MEM_Addr PEER_ADDR
typedef ACE_MEM_Stream PEER_STREAM

Public Member Functions

 ACE_MEM_Acceptor (void)
 Default constructor.
 ~ACE_MEM_Acceptor (void)
 destructor.
 ACE_MEM_Acceptor (const ACE_MEM_Addr &remote_sap, int reuse_addr=0, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0)
 Initiate a passive mode socket.
int open (const ACE_MEM_Addr &local_sap, int reuse_addr=0, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0)
int accept (ACE_MEM_Stream &new_ipc_sap, ACE_MEM_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0)
 Accept a new data transfer connection.
int shared_accept_finish (ACE_MEM_Stream new_stream, int in_blocking_mode, int reset_new_handle) const
const ACE_TCHARmmap_prefix (void) const
void mmap_prefix (const ACE_TCHAR *prefix)
void init_buffer_size (ACE_OFF_T bytes)
ACE_MEM_IO::Signal_Strategy preferred_strategy (void) const
 Get the preferred signaling strategy.
void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy)
 Set the preferred signaling strategy.
int get_local_addr (ACE_MEM_Addr &) const
ACE_MEM_SAP::MALLOC_OPTIONS & malloc_options (void)
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Member Functions

int open (const ACE_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_INET, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0)
int open (const ACE_Addr &local_sap, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr, int protocol_family, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0)
int accept (ACE_SOCK_Stream &new_stream, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0) const
int accept (ACE_SOCK_Stream &new_stream, ACE_Accept_QoS_Params qos_params, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0) const

Private Attributes

ACE_TCHARmmap_prefix_
ACE_MEM_SAP::MALLOC_OPTIONS malloc_options_
ACE_MEM_IO::Signal_Strategy preferred_strategy_
 Preferred signaling strategy.

Detailed Description

Defines the format and interface for the acceptor side of the local mmap stream.

This class should be modified to prevent user passing a non-localhost endpoint as the acceptor listen point because it doesn't make any sense at all to make the listening endpoint visible (or connectable) anywhere outside of this machine. However, the type of endpoint is left as <ACE_Addr> so we can later changed to use UNIX-domain sockets with mmap stream if so desired. (Currently, using UNIX-domain sockets, i.e., ACE_LSOCK_*, with this class will not work.)

Definition at line 54 of file MEM_Acceptor.h.


Member Typedef Documentation

typedef ACE_MEM_Addr ACE_MEM_Acceptor::PEER_ADDR

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 128 of file MEM_Acceptor.h.

typedef ACE_MEM_Stream ACE_MEM_Acceptor::PEER_STREAM

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 129 of file MEM_Acceptor.h.


Constructor & Destructor Documentation

ACE_MEM_Acceptor::ACE_MEM_Acceptor ( void   ) 

Default constructor.

Definition at line 32 of file MEM_Acceptor.cpp.

References ACE_TRACE.

00033   : mmap_prefix_ (0),
00034     malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00035     preferred_strategy_ (ACE_MEM_IO::Reactive)
00036 {
00037   ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor");
00038 }

ACE_MEM_Acceptor::~ACE_MEM_Acceptor ( void   ) 

destructor.

Definition at line 40 of file MEM_Acceptor.cpp.

References ACE_TRACE, and mmap_prefix_.

00041 {
00042   ACE_TRACE ("ACE_MEM_Acceptor::~ACE_MEM_Acceptor");
00043   delete[] this->mmap_prefix_;
00044 }

ACE_MEM_Acceptor::ACE_MEM_Acceptor ( const ACE_MEM_Addr &  remote_sap,
int  reuse_addr = 0,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 0 
)

Initiate a passive mode socket.

Definition at line 48 of file MEM_Acceptor.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, and LM_ERROR.

00052   : mmap_prefix_ (0),
00053     malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00054     preferred_strategy_ (ACE_MEM_IO::Reactive)
00055 {
00056   ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor");
00057   if (this->open (remote_sap,
00058                   reuse_addr,
00059                   backlog,
00060                   protocol) == -1)
00061     ACE_ERROR ((LM_ERROR,
00062                 ACE_TEXT ("ACE_MEM_Acceptor::ACE_MEM_Acceptor")));
00063 }


Member Function Documentation

ACE_INLINE int ACE_MEM_Acceptor::accept ( ACE_SOCK_Stream new_stream,
ACE_Accept_QoS_Params  qos_params,
ACE_Addr remote_addr = 0,
ACE_Time_Value timeout = 0,
int  restart = 1,
int  reset_new_handle = 0 
) const [protected]

Accept a new ACE_SOCK_Stream connection using the QoS information in qos_params. A timeout of 0 means block forever, a timeout of {0, 0} means poll. restart == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that new_stream inherits the "blocking mode" of this ACE_SOCK_Acceptor, i.e., if this acceptor factory is in non-blocking mode, the new_stream will be in non-blocking mode and vice versa.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 35 of file MEM_Acceptor.inl.

References ACE_SOCK_Acceptor::accept().

00041 {
00042   return this->ACE_SOCK_Acceptor::accept
00043     (new_stream, qos_params, remote_addr, timeout, restart, reset_new_handle);
00044 }

ACE_INLINE int ACE_MEM_Acceptor::accept ( ACE_SOCK_Stream new_stream,
ACE_Addr remote_addr = 0,
ACE_Time_Value timeout = 0,
int  restart = 1,
int  reset_new_handle = 0 
) const [protected]

Accept a new ACE_SOCK_Stream connection. A timeout of 0 means block forever, a timeout of {0, 0} means poll. <restart> == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that new_stream inherits the "blocking mode" of this ACE_SOCK_Acceptor, i.e., if this acceptor factory is in non-blocking mode, the new_stream will be in non-blocking mode and vice versa.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 23 of file MEM_Acceptor.inl.

References ACE_SOCK_Acceptor::accept().

00028 {
00029   return this->ACE_SOCK_Acceptor::accept
00030     (new_stream, remote_addr, timeout, restart, reset_new_handle);
00031 }

int ACE_MEM_Acceptor::accept ( ACE_MEM_Stream &  new_ipc_sap,
ACE_MEM_Addr *  remote_addr = 0,
ACE_Time_Value timeout = 0,
int  restart = 1,
int  reset_new_handle = 0 
)

Accept a new data transfer connection.

Definition at line 82 of file MEM_Acceptor.cpp.

References ACE_OS::accept(), ACE_ERROR, ACE_ERROR_RETURN, ACE_NONBLOCK, ACE_TEXT, ACE_TRACE, ACE_INET_Addr::get_port_number(), ACE::get_temp_dir(), LM_DEBUG, LM_ERROR, malloc_options_, MAXPATHLEN, preferred_strategy_, ACE::recv(), ACE::send(), ACE_OS::sprintf(), ACE_OS::strcat(), ACE_OS::strlen(), ACE_OS::unique_name(), and ACE_OS::unlink().

00087 {
00088   ACE_TRACE ("ACE_MEM_Acceptor::accept");
00089 
00090   int in_blocking_mode = 1;
00091   if (this->shared_accept_start (timeout,
00092                                  restart,
00093                                  in_blocking_mode) == -1)
00094     return -1;
00095   else
00096     {
00097       sockaddr *addr = 0;
00098       struct sockaddr_in inet_addr;
00099       int *len_ptr = 0;
00100       int len = 0;
00101 
00102       if (remote_sap != 0)
00103         {
00104           addr = reinterpret_cast<sockaddr *> (&inet_addr);
00105           len = sizeof (inet_addr);
00106           len_ptr = &len;
00107         }
00108 
00109       do
00110         // On Win32 the third parameter to <accept> must be a NULL
00111         // pointer if to ignore the client's address.
00112         new_stream.set_handle (ACE_OS::accept (this->get_handle (),
00113                                                addr,
00114                                                len_ptr));
00115       while (new_stream.get_handle () == ACE_INVALID_HANDLE
00116              && restart != 0
00117              && errno == EINTR
00118              && timeout == 0);
00119 
00120       if (remote_sap != 0)
00121         {
00122           ACE_INET_Addr temp (&inet_addr, len);
00123           remote_sap->set_port_number (temp.get_port_number ());
00124         }
00125     }
00126 
00127   if (this->shared_accept_finish (new_stream,
00128                                   in_blocking_mode,
00129                                   reset_new_handle) == -1)
00130     return -1;
00131 
00132   // Allocate 2 * MAXPATHLEN so we can accomodate the unique
00133   // name that gets appended later
00134   ACE_TCHAR buf [2 * MAXPATHLEN + 1];
00135 
00136   ACE_INET_Addr local_addr;
00137   if (new_stream.get_local_addr (local_addr) == -1)
00138     return -1;
00139 
00140   if (this->mmap_prefix_ != 0)
00141     {
00142       ACE_OS::sprintf (buf,
00143                        ACE_TEXT ("%s_%d_"),
00144                        this->mmap_prefix_,
00145                        local_addr.get_port_number ());
00146     }
00147   else
00148     {
00149       ACE_TCHAR name[25];
00150       // - 24 is so we can append name to the end.
00151       if (ACE::get_temp_dir (buf, MAXPATHLEN - 24) == -1)
00152         {
00153           ACE_ERROR ((LM_ERROR,
00154                       ACE_TEXT ("Temporary path too long, ")
00155                       ACE_TEXT ("defaulting to current directory\n")));
00156           buf[0] = 0;
00157         }
00158 
00159       ACE_OS::sprintf (name,
00160                        ACE_TEXT ("MEM_Acceptor_%d_"),
00161                        local_addr.get_port_number ());
00162       ACE_OS::strcat (buf, name);
00163     }
00164   ACE_TCHAR unique [MAXPATHLEN];
00165   ACE_OS::unique_name (&new_stream, unique, MAXPATHLEN);
00166 
00167   ACE_OS::strcat (buf, unique);
00168 
00169   // Make sure we have a fresh start.
00170   ACE_OS::unlink (buf);
00171 
00172   new_stream.disable (ACE_NONBLOCK);
00173   ACE_HANDLE new_handle = new_stream.get_handle ();
00174 
00175   // Protocol negociation:
00176   //   Tell the client side what level of signaling strategy
00177   //   we support.
00178   ACE_MEM_IO::Signal_Strategy client_signaling =
00179 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00180     this->preferred_strategy_;
00181 #else
00182     // We don't support MT.
00183     ACE_MEM_IO::Reactive;
00184 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
00185   if (ACE::send (new_handle, &client_signaling,
00186                  sizeof (ACE_INT16)) == -1)
00187     ACE_ERROR_RETURN ((LM_DEBUG,
00188                        ACE_TEXT ("ACE_MEM_Acceptor::accept error sending strategy\n")),
00189                       -1);
00190 
00191   //   Now we get the signaling strategy the client support.
00192   if (ACE::recv (new_handle, &client_signaling,
00193                  sizeof (ACE_INT16)) == -1)
00194     ACE_ERROR_RETURN ((LM_DEBUG,
00195                        ACE_TEXT ("ACE_MEM_Acceptor::%p error receiving strategy\n"), ACE_TEXT ("accept")),
00196                       -1);
00197 
00198   // Ensure minimum buffer size
00199   if (this->malloc_options_.minimum_bytes_ < ACE_MEM_STREAM_MIN_BUFFER)
00200     this->malloc_options_.minimum_bytes_ = ACE_MEM_STREAM_MIN_BUFFER;
00201 
00202   // Client will decide what signaling strategy to use.
00203 
00204   // Now set up the shared memory malloc pool.
00205   if (new_stream.init (buf,
00206                        static_cast<ACE_MEM_IO::Signal_Strategy> (client_signaling),
00207                        &this->malloc_options_) == -1)
00208     return -1;
00209 
00210   // @@ Need to handle timeout here.
00211   ACE_UINT16 buf_len = static_cast<ACE_UINT16> ((ACE_OS::strlen (buf) + 1) *
00212                                                 sizeof (ACE_TCHAR));
00213 
00214   // No need to worry about byte-order because both parties should always
00215   // be on the same machine.
00216   if (ACE::send (new_handle, &buf_len, sizeof (ACE_UINT16)) == -1)
00217     return -1;
00218 
00219   // Now send the pathname of the mmap file.
00220   if (ACE::send (new_handle, buf, buf_len) == -1)
00221     return -1;
00222   return 0;
00223 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_MEM_Acceptor::dump ( void   )  const

Dump the state of an object.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 23 of file MEM_Acceptor.cpp.

References ACE_TRACE.

00024 {
00025 #if defined (ACE_HAS_DUMP)
00026   ACE_TRACE ("ACE_MEM_Acceptor::dump");
00027 #endif /* ACE_HAS_DUMP */
00028 }

ACE_INLINE int ACE_MEM_Acceptor::get_local_addr ( ACE_MEM_Addr &   )  const

Return the local endpoint address in the referenced <ACE_Addr>. Returns 0 if successful, else -1.

Definition at line 48 of file MEM_Acceptor.inl.

References ACE_SOCK::get_local_addr(), and ACE_INET_Addr::get_port_number().

00049 {
00050   ACE_INET_Addr temp;
00051 
00052   this->ACE_SOCK_Acceptor::get_local_addr (temp);
00053   sap.set_port_number (temp.get_port_number ());
00054   return 0;
00055 }

ACE_INLINE void ACE_MEM_Acceptor::init_buffer_size ( ACE_OFF_T  bytes  ) 

Change the initial MMAP buffer size (in bytes) of the MEM_Stream this MEM_Acceptor creates.

Definition at line 89 of file MEM_Acceptor.inl.

References malloc_options_.

00090 {
00091   this->malloc_options_.minimum_bytes_ = bytes;
00092 }

ACE_INLINE ACE_MEM_SAP::MALLOC_OPTIONS & ACE_MEM_Acceptor::malloc_options ( void   ) 

Accessor to the mmap options.

Deprecated:
This method has been deprecated.

Definition at line 95 of file MEM_Acceptor.inl.

References malloc_options_.

00096 {
00097   // @@ This function has been deprecated and will be removed in the
00098   // future.
00099 
00100   return this->malloc_options_;
00101 }

ACE_INLINE void ACE_MEM_Acceptor::mmap_prefix ( const ACE_TCHAR prefix  ) 

Definition at line 64 of file MEM_Acceptor.inl.

References mmap_prefix_, and ACE::strnew().

00065 {
00066   if (prefix == 0)
00067     {
00068       this->mmap_prefix_ = 0;
00069     }
00070   else
00071     {
00072       this->mmap_prefix_ = ACE::strnew (prefix);
00073     }
00074 }

ACE_INLINE const ACE_TCHAR * ACE_MEM_Acceptor::mmap_prefix ( void   )  const

Accessor/mutator of mmap filename prefix. By default, the <mmap_prefix_> is not set and the mmap filename is ${(TMP|TEMP)}//ACE_MEM_Acceptor_(port-number)_(&stream), otherwise, it is <mmap_prefix_>_(port-number)_(&stream), <mmap_prefix_> should include _absolute_ path so the connector within the same host can located the mmap file. Example: /tmp/mmapfile.

Definition at line 58 of file MEM_Acceptor.inl.

References mmap_prefix_.

00059 {
00060   return this->mmap_prefix_;
00061 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_MEM_Acceptor::open ( const ACE_Addr local_sap,
ACE_Protocol_Info protocolinfo,
ACE_SOCK_GROUP  g,
u_long  flags,
int  reuse_addr,
int  protocol_family,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 0 
) [protected]

Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 8 of file MEM_Acceptor.inl.

References ACE_SOCK_Acceptor::open().

00016 {
00017   return this->ACE_SOCK_Acceptor::open
00018     (local_sap, protocolinfo, g, flags, reuse_addr, protocol_family,
00019      backlog, protocol);
00020 }

int ACE_MEM_Acceptor::open ( const ACE_Addr local_sap,
int  reuse_addr = 0,
int  protocol_family = PF_INET,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 0 
) [protected]

Initialize a passive-mode BSD-style acceptor socket (no QoS). local_sap is the address that we're going to listen for connections on. If reuse_addr is 1 then we'll use the SO_REUSEADDR to reuse this address. Returns 0 on success and -1 on failure.

Reimplemented from ACE_SOCK_Acceptor.

int ACE_MEM_Acceptor::open ( const ACE_MEM_Addr &  local_sap,
int  reuse_addr = 0,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 0 
)

Initialize a passive-mode BSD-style acceptor socket (no QoS). local_sap is the address that we're going to listen for connections on. If reuse_addr is 1 then we'll use the SO_REUSEADDR to reuse this address. Returns 0 on success and -1 on failure.

Definition at line 66 of file MEM_Acceptor.cpp.

References ACE_TRACE, ACE_SOCK_Acceptor::open(), and PF_INET.

00070 {
00071   ACE_TRACE ("ACE_MEM_Acceptor::open");
00072   return this->ACE_SOCK_Acceptor::open (remote_sap.get_local_addr (),
00073                                         reuse_addr,
00074                                         PF_INET,
00075                                         back_log,
00076                                         protocol);
00077 }

ACE_INLINE void ACE_MEM_Acceptor::preferred_strategy ( ACE_MEM_IO::Signal_Strategy  strategy  ) 

Set the preferred signaling strategy.

Definition at line 83 of file MEM_Acceptor.inl.

References preferred_strategy_.

00084 {
00085   this->preferred_strategy_ = strategy;
00086 }

ACE_INLINE ACE_MEM_IO::Signal_Strategy ACE_MEM_Acceptor::preferred_strategy ( void   )  const

Get the preferred signaling strategy.

Definition at line 77 of file MEM_Acceptor.inl.

References preferred_strategy_.

00078 {
00079   return this->preferred_strategy_;
00080 }

int ACE_MEM_Acceptor::shared_accept_finish ( ACE_MEM_Stream  new_stream,
int  in_blocking_mode,
int  reset_new_handle 
) const

Perform operations that must occur after <ACE_OS::accept> is called.

Definition at line 226 of file MEM_Acceptor.cpp.

References ACE_NONBLOCK, ACE_TRACE, and ACE::clr_flags().

00229 {
00230   ACE_TRACE ("ACE_MEM_Acceptor::shared_accept_finish ()");
00231 
00232   ACE_HANDLE new_handle = new_stream.get_handle ();
00233 
00234   // Check to see if we were originally in blocking mode, and if so,
00235   // set the <new_stream>'s handle and <this> handle to be in blocking
00236   // mode.
00237   if (in_blocking_mode)
00238     {
00239       // Save/restore errno.
00240       ACE_Errno_Guard error (errno);
00241 
00242       // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
00243       // originally.
00244       ACE::clr_flags (this->get_handle (),
00245                                  ACE_NONBLOCK);
00246       ACE::clr_flags (new_handle,
00247                                  ACE_NONBLOCK);
00248     }
00249 
00250 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00251   if (reset_new_handle)
00252     // Reset the event association inherited by the new handle.
00253     ::WSAEventSelect ((SOCKET) new_handle, 0, 0);
00254 #else
00255   ACE_UNUSED_ARG (reset_new_handle);
00256 #endif /* ACE_WIN32 */
00257   if (new_handle == ACE_INVALID_HANDLE)
00258     return -1;
00259 
00260   return 0;
00261 }


Member Data Documentation

ACE_MEM_Acceptor::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 135 of file MEM_Acceptor.h.

ACE_MEM_SAP::MALLOC_OPTIONS ACE_MEM_Acceptor::malloc_options_ [private]

A cached MALLOC_OPTIONS. MEM_Accaptor use it to create the shared mamory malloc upon every incoming connection.

Definition at line 177 of file MEM_Acceptor.h.

Referenced by accept(), init_buffer_size(), and malloc_options().

ACE_TCHAR* ACE_MEM_Acceptor::mmap_prefix_ [private]

The filename prefix of the created mmap files. It should contains the absolute path name of the file.

Definition at line 173 of file MEM_Acceptor.h.

Referenced by mmap_prefix(), and ~ACE_MEM_Acceptor().

ACE_MEM_IO::Signal_Strategy ACE_MEM_Acceptor::preferred_strategy_ [private]

Preferred signaling strategy.

Definition at line 180 of file MEM_Acceptor.h.

Referenced by accept(), and preferred_strategy().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:19 2010 for ACE by  doxygen 1.4.7