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

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 Methods

 ACE_MEM_Acceptor (void)
 Default constructor. More...

 ~ACE_MEM_Acceptor (void)
 destructor. More...

 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. More...

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. More...

int 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. More...

const ACE_TCHARmmap_prefix (void) const
void mmap_prefix (const ACE_TCHAR *prefix)
ACE_MEM_IO::Signal_Strategy preferred_strategy (void) const
 Get the preferred signaling strategy. More...

void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy)
 Set the preferred signaling strategy. More...

int get_local_addr (ACE_MEM_Addr &) const
 Return the local endpoint address in the referenced <ACE_Addr>. Returns 0 if successful, else -1. More...

ACE_MEM_SAP::MALLOC_OPTIONSmalloc_options (void)
 Accessor to the mmap options. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Methods

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)
 Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure. More...

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_
 The filename prefix of the created mmap files. It should contains the absolute path name of the file. More...

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

ACE_MEM_IO::Signal_Strategy preferred_strategy_
 Preferred signaling strategy. More...


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 sockets with mmap stream if so desired. (Currently, using UNIX socket with this class will not work.)

Definition at line 51 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 118 of file MEM_Acceptor.h.

typedef ACE_MEM_Stream ACE_MEM_Acceptor::PEER_STREAM
 

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 119 of file MEM_Acceptor.h.


Constructor & Destructor Documentation

ACE_MEM_Acceptor::ACE_MEM_Acceptor void   
 

Default constructor.

Definition at line 25 of file MEM_Acceptor.cpp.

References ACE_DEFAULT_BASE_ADDR, and ACE_TRACE.

00026   : mmap_prefix_ (0),
00027     malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00028     preferred_strategy_ (ACE_MEM_IO::Reactive)
00029 {
00030   ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor");
00031 }

ACE_MEM_Acceptor::~ACE_MEM_Acceptor void   
 

destructor.

Definition at line 33 of file MEM_Acceptor.cpp.

References ACE_TRACE, and mmap_prefix_.

00034 {
00035   ACE_TRACE ("ACE_MEM_Acceptor::~ACE_MEM_Acceptor");
00036   delete[] this->mmap_prefix_;
00037 }

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 41 of file MEM_Acceptor.cpp.

References ACE_DEFAULT_BASE_ADDR, ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.

00045   : mmap_prefix_ (0),
00046     malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00047     preferred_strategy_ (ACE_MEM_IO::Reactive)
00048 {
00049   ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor");
00050   if (this->open (remote_sap,
00051                   reuse_addr,
00052                   backlog,
00053                   protocol) == -1)
00054     ACE_ERROR ((LM_ERROR,
00055                 ACE_LIB_TEXT ("ACE_MEM_Acceptor::ACE_MEM_Acceptor")));
00056 }


Member Function Documentation

ASYS_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 <net_stream> will be in non-blocking mode and vice versa.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 34 of file MEM_Acceptor.i.

References ACE_SOCK_Acceptor::accept.

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

ASYS_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 <net_stream> will be in non-blocking mode and vice versa.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 22 of file MEM_Acceptor.i.

References ACE_SOCK_Acceptor::accept.

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

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 75 of file MEM_Acceptor.cpp.

References ACE_OS::accept, ACE_ERROR, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NONBLOCK, ACE_TCHAR, ACE_TRACE, ACE_IPC_SAP::disable, ACE_IPC_SAP::get_handle, ACE_SOCK::get_local_addr, ACE_INET_Addr::get_port_number, ACE_Lib_Find::get_temp_dir, ACE_MEM_IO::init, LM_DEBUG, LM_ERROR, MAXPATHLEN, mmap_prefix_, preferred_strategy_, ACE_MEM_IO::Reactive, ACE::recv, ACE::send, ACE_IPC_SAP::set_handle, ACE_MEM_Addr::set_port_number, shared_accept_finish, ACE_SOCK_Acceptor::shared_accept_start, ACE_MEM_IO::Signal_Strategy, ACE_OS::sprintf, ACE_OS_String::strcat, ACE_OS_String::strlen, ACE_OS::unique_name, and ACE_OS::unlink.

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

void ACE_MEM_Acceptor::dump void    const
 

Dump the state of an object.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 18 of file MEM_Acceptor.cpp.

References ACE_TRACE.

00019 {
00020   ACE_TRACE ("ACE_MEM_Acceptor::dump");
00021 }

ASYS_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 47 of file MEM_Acceptor.i.

References ACE_SOCK::get_local_addr, ACE_INET_Addr::get_port_number, and ACE_MEM_Addr::set_port_number.

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

ASYS_INLINE ACE_MEM_SAP::MALLOC_OPTIONS & ACE_MEM_Acceptor::malloc_options void   
 

Accessor to the mmap options.

Definition at line 88 of file MEM_Acceptor.i.

References malloc_options_.

00089 {
00090   return this->malloc_options_;
00091 }

ASYS_INLINE void ACE_MEM_Acceptor::mmap_prefix const ACE_TCHAR   prefix
 

Definition at line 63 of file MEM_Acceptor.i.

References ACE_TCHAR, mmap_prefix_, and ACE::strnew.

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

ASYS_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 57 of file MEM_Acceptor.i.

References mmap_prefix_.

00058 {
00059   return this->mmap_prefix_;
00060 }

ASYS_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 7 of file MEM_Acceptor.i.

References ACE_SOCK_GROUP, and ACE_SOCK_Acceptor::open.

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

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 59 of file MEM_Acceptor.cpp.

References ACE_TRACE, ACE_MEM_Addr::get_local_addr, and ACE_SOCK_Acceptor::open.

Referenced by ACE_MEM_Acceptor.

00063 {
00064   ACE_TRACE ("ACE_MEM_Acceptor::open");
00065   return this->ACE_SOCK_Acceptor::open (remote_sap.get_local_addr (),
00066                                         reuse_addr,
00067                                         PF_INET,
00068                                         back_log,
00069                                         protocol);
00070 }

ASYS_INLINE void ACE_MEM_Acceptor::preferred_strategy ACE_MEM_IO::Signal_Strategy    strategy
 

Set the preferred signaling strategy.

Definition at line 82 of file MEM_Acceptor.i.

References preferred_strategy_, and ACE_MEM_IO::Signal_Strategy.

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

ASYS_INLINE ACE_MEM_IO::Signal_Strategy ACE_MEM_Acceptor::preferred_strategy void    const
 

Get the preferred signaling strategy.

Definition at line 76 of file MEM_Acceptor.i.

References preferred_strategy_.

00077 {
00078   return this->preferred_strategy_;
00079 }

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 210 of file MEM_Acceptor.cpp.

References ACE_NONBLOCK, ACE_TRACE, ACE_Flag_Manip::clr_flags, and ACE_IPC_SAP::get_handle.

Referenced by accept.

00213 {
00214   ACE_TRACE ("ACE_MEM_Acceptor::shared_accept_finish ()");
00215 
00216   ACE_HANDLE new_handle = new_stream.get_handle ();
00217 
00218   // Check to see if we were originally in blocking mode, and if so,
00219   // set the <new_stream>'s handle and <this> handle to be in blocking
00220   // mode.
00221   if (in_blocking_mode)
00222     {
00223       // Save/restore errno.
00224       ACE_Errno_Guard error (errno);
00225 
00226       // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
00227       // originally.
00228       ACE_Flag_Manip::clr_flags (this->get_handle (),
00229                                  ACE_NONBLOCK);
00230       ACE_Flag_Manip::clr_flags (new_handle,
00231                                  ACE_NONBLOCK);
00232     }
00233 
00234 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00235   if (reset_new_handle)
00236     // Reset the event association inherited by the new handle.
00237     ::WSAEventSelect ((SOCKET) new_handle, 0, 0);
00238 #else
00239   ACE_UNUSED_ARG (reset_new_handle);
00240 #endif /* ACE_WIN32 */
00241   if (new_handle == ACE_INVALID_HANDLE)
00242     return -1;
00243 
00244   return 0;
00245 }


Member Data Documentation

ACE_MEM_Acceptor::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK_Acceptor.

Definition at line 125 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 167 of file MEM_Acceptor.h.

Referenced by 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 163 of file MEM_Acceptor.h.

Referenced by accept, mmap_prefix, and ~ACE_MEM_Acceptor.

ACE_MEM_IO::Signal_Strategy ACE_MEM_Acceptor::preferred_strategy_ [private]
 

Preferred signaling strategy.

Definition at line 170 of file MEM_Acceptor.h.

Referenced by accept, and preferred_strategy.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:50:15 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002