ACE_MEM_Connector Class Reference

Defines the format and interface for connecting to a peer on a ACE_MEM_Stream object. More...

#include <MEM_Connector.h>

Inheritance diagram for ACE_MEM_Connector:

Inheritance graph
[legend]
Collaboration diagram for ACE_MEM_Connector:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_INET_Addr PEER_ADDR
typedef ACE_MEM_Stream PEER_STREAM

Public Member Functions

 ACE_MEM_Connector (void)
 Default constructor.

 ACE_MEM_Connector (ACE_MEM_Stream &new_stream, const ACE_INET_Addr &remote_sap, ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, int reuse_addr=0, int flags=0, int perms=0)
int connect (ACE_MEM_Stream &new_stream, const ACE_INET_Addr &remote_sap, ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, int reuse_addr=0, int flags=0, int perms=0)
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.

ACE_MEM_SAP::MALLOC_OPTIONSmalloc_options (void)
void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Attributes

ACE_MEM_Addr address_
 The acceptor address this connector is connecting to.

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 connecting to a peer on a ACE_MEM_Stream object.

Definition at line 37 of file MEM_Connector.h.


Member Typedef Documentation

typedef ACE_INET_Addr ACE_MEM_Connector::PEER_ADDR
 

Reimplemented from ACE_SOCK_Connector.

Definition at line 149 of file MEM_Connector.h.

typedef ACE_MEM_Stream ACE_MEM_Connector::PEER_STREAM
 

Reimplemented from ACE_SOCK_Connector.

Definition at line 150 of file MEM_Connector.h.


Constructor & Destructor Documentation

ACE_MEM_Connector::ACE_MEM_Connector void   ) 
 

Default constructor.

Definition at line 30 of file MEM_Connector.cpp.

References ACE_DEFAULT_BASE_ADDR, and ACE_TRACE.

00031   : malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00032     preferred_strategy_ (ACE_MEM_IO::Reactive)
00033 {
00034   ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
00035 }

ACE_MEM_Connector::ACE_MEM_Connector ACE_MEM_Stream new_stream,
const ACE_INET_Addr remote_sap,
ACE_Time_Value timeout = 0,
const ACE_Addr local_sap = ACE_Addr::sap_any,
int  reuse_addr = 0,
int  flags = 0,
int  perms = 0
 

Actively connect to a peer, producing a connected ACE_MEM_Stream object if the connection succeeds.

Parameters:
new_stream The ACE_MEM_Stream object that will be connected to the peer.
remote_sap The address that we are trying to connect to. The protocol family of remote_sap is used for the connected socket. That is, if remote_sap contains an IPv6 address, a socket with family PF_INET6 will be used, else it will be PF_INET.
Note:
remote_sap must be an address on the local host.
Parameters:
timeout Pointer to an ACE_Time_Value object with amount of time to wait to connect. If the pointer is 0 then the call blocks until the connection attempt is complete, whether it succeeds or fails. If *timeout == {0, 0} then the connection is done using nonblocking mode. In this case, if the connection can't be made immediately, this method returns -1 and errno == EWOULDBLOCK. If *timeout > {0, 0} then this is the maximum amount of time to wait before timing out; if the specified amount of time passes before the connection is made, this method returns -1 and errno == ETIME. Note the difference between this case and when a blocking connect is attmpted that TCP times out - in the latter case, errno will be ETIMEDOUT.
local_sap (optional) The local address to bind to. If it's the default value of ACE_Addr::sap_any then the OS will choose an unused port.
reuse_addr (optional) If the value is 1, the local address (local_sap) is reused, even if it hasn't been cleaned up yet.
flags Ignored.
perms Ignored.

Definition at line 38 of file MEM_Connector.cpp.

References ACE_DEFAULT_BASE_ADDR, ACE_TRACE, and connect().

00045   : malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00046     preferred_strategy_ (ACE_MEM_IO::Reactive)
00047 {
00048   ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
00049   // This is necessary due to the weird inheritance relationships of
00050   // ACE_MEM_Stream.
00051   this->connect (new_stream,
00052                  remote_sap,
00053                  timeout,
00054                  local_sap,
00055                  reuse_addr,
00056                  flags,
00057                  perms);
00058 }


Member Function Documentation

int ACE_MEM_Connector::connect ACE_MEM_Stream new_stream,
const ACE_INET_Addr remote_sap,
ACE_Time_Value timeout = 0,
const ACE_Addr local_sap = ACE_Addr::sap_any,
int  reuse_addr = 0,
int  flags = 0,
int  perms = 0
 

Actively connect to a peer, producing a connected ACE_MEM_Stream object if the connection succeeds.

Parameters:
new_stream The ACE_MEM_Stream object that will be connected to the peer.
remote_sap The address that we are trying to connect to. The protocol family of remote_sap is used for the connected socket. That is, if remote_sap contains an IPv6 address, a socket with family PF_INET6 will be used, else it will be PF_INET.
Note:
remote_sap must be an address on the local host.
Parameters:
timeout Pointer to an ACE_Time_Value object with amount of time to wait to connect. If the pointer is 0 then the call blocks until the connection attempt is complete, whether it succeeds or fails. If *timeout == {0, 0} then the connection is done using nonblocking mode. In this case, if the connection can't be made immediately, this method returns -1 and errno == EWOULDBLOCK. If *timeout > {0, 0} then this is the maximum amount of time to wait before timing out; if the specified amount of time passes before the connection is made, this method returns -1 and errno == ETIME. Note the difference between this case and when a blocking connect is attmpted that TCP times out - in the latter case, errno will be ETIMEDOUT.
local_sap (optional) The local address to bind to. If it's the default value of ACE_Addr::sap_any then the OS will choose an unused port.
reuse_addr (optional) If the value is 1, the local address (local_sap) is reused, even if it hasn't been cleaned up yet.
flags Ignored.
perms Ignored.
Returns:
Returns 0 if the connection succeeds. If it fails, -1 is returned and errno contains a specific error code.

Definition at line 61 of file MEM_Connector.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NONBLOCK, ACE_TCHAR, ACE_TEXT_CHAR_TO_TCHAR, ACE_TRACE, address_, ACE_SOCK_Connector::connect(), ACE_IPC_SAP::disable(), ACE_IPC_SAP::get_handle(), ACE_INET_Addr::get_host_name(), ACE_SOCK::get_local_addr(), ACE_MEM_Addr::get_port_number(), ACE_INET_Addr::get_port_number(), ACE_MEM_IO::init(), LM_DEBUG, LM_ERROR, MAXPATHLEN, ACE::recv(), ACE_MEM_Addr::same_host(), ACE::send(), ACE_IPC_SAP::set_handle(), and ACE_MEM_Addr::set_port_number().

Referenced by ACE_MEM_Connector().

00068 {
00069   ACE_TRACE ("ACE_MEM_Connector::connect");
00070 
00071   if (!this->address_.same_host (remote_sap))
00072     ACE_ERROR_RETURN ((LM_ERROR,
00073                        ACE_LIB_TEXT ("(%P|%t) MEM_Connector can't connect ")
00074                        ACE_LIB_TEXT ("to %s:%d which is not a local endpoint ")
00075                        ACE_LIB_TEXT ("(local address is %s:%d)\n"),
00076                        ACE_TEXT_CHAR_TO_TCHAR (remote_sap.get_host_name ()),
00077                        remote_sap.get_port_number (),
00078                        ACE_TEXT_CHAR_TO_TCHAR (this->address_.get_host_name ()),
00079                        this->address_.get_port_number ()),
00080                       -1);
00081   else
00082     this->address_.set_port_number (remote_sap.get_port_number ());
00083 
00084 
00085   ACE_SOCK_Stream temp_stream;
00086 
00087   if (ACE_SOCK_Connector::connect (temp_stream,
00088                                    this->address_.get_local_addr (),
00089                                    timeout, local_sap,
00090                                    reuse_addr, flags, perms) == -1)
00091     ACE_ERROR_RETURN ((LM_DEBUG,
00092                        ACE_LIB_TEXT ("%p\n"),
00093                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect")),
00094                       -1);
00095 
00096 
00097   ACE_HANDLE new_handle = temp_stream.get_handle ();
00098   new_stream.set_handle (new_handle);
00099   new_stream.disable (ACE_NONBLOCK);
00100   // Do not close the handle.
00101 
00102   // now we should setup the mmap malloc.
00103   ACE_TCHAR buf[MAXPATHLEN];
00104 
00105   // @@ Need to handle timeout here.
00106   ACE_INT16 server_strategy = ACE_MEM_IO::Reactive;
00107   // Receive the signaling strategy theserver support.
00108   if (ACE::recv (new_handle, &server_strategy,
00109                  sizeof (ACE_INT16)) == -1)
00110     ACE_ERROR_RETURN ((LM_DEBUG,
00111                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving strategy\n")),
00112                       -1);
00113 
00114     // If either side don't support MT, we will not use it.
00115 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00116   if (! (this->preferred_strategy_ == ACE_MEM_IO::MT &&
00117          server_strategy == ACE_MEM_IO::MT))
00118 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
00119     server_strategy = ACE_MEM_IO::Reactive;
00120 
00121   if (ACE::send (new_handle, &server_strategy,
00122                  sizeof (ACE_INT16)) == -1)
00123     ACE_ERROR_RETURN ((LM_DEBUG,
00124                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error sending strategy\n")),
00125                       -1);
00126 
00127   ACE_INT16 buf_len;
00128   // Byte-order is not a problem for this read.
00129   if (ACE::recv (new_handle, &buf_len, sizeof (buf_len)) == -1)
00130     ACE_ERROR_RETURN ((LM_DEBUG,
00131                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving shm filename length\n")),
00132                       -1);
00133 
00134   if (ACE::recv (new_handle, buf, buf_len) == -1)
00135     ACE_ERROR_RETURN ((LM_DEBUG,
00136                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving shm filename.\n")),
00137                       -1);
00138 
00139   if (new_stream.init (buf,
00140                        static_cast<ACE_MEM_IO::Signal_Strategy> (server_strategy),
00141                        &this->malloc_options_) == -1)
00142     return -1;
00143 
00144   return 0;
00145 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_MEM_Connector::dump void   )  const
 

Dump the state of an object.

Reimplemented from ACE_SOCK_Connector.

Definition at line 19 of file MEM_Connector.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00020 {
00021 #if defined (ACE_HAS_DUMP)
00022   ACE_TRACE ("ACE_MEM_Connector::dump");
00023 
00024   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00025   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\n")));
00026   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00027 #endif /* ACE_HAS_DUMP */
00028 }

ACE_INLINE ACE_MEM_SAP::MALLOC_OPTIONS & ACE_MEM_Connector::malloc_options void   ) 
 

Accessor to underlying malloc options.

Deprecated:
This method has been deprecated.

Definition at line 22 of file MEM_Connector.inl.

00023 {
00024   // @@ This function has been deprecated and will be removed in the
00025   // future.
00026 
00027   return this->malloc_options_;
00028 }

ACE_INLINE void ACE_MEM_Connector::preferred_strategy ACE_MEM_IO::Signal_Strategy  strategy  ) 
 

Set the preferred signaling strategy.

Definition at line 16 of file MEM_Connector.inl.

00017 {
00018   this->preferred_strategy_ = strategy;
00019 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_MEM_IO::Signal_Strategy ACE_MEM_Connector::preferred_strategy void   )  const
 

Get the preferred signaling strategy.

Definition at line 10 of file MEM_Connector.inl.

00011 {
00012   return this->preferred_strategy_;
00013 }


Member Data Documentation

ACE_MEM_Connector::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK_Connector.

Definition at line 156 of file MEM_Connector.h.

ACE_MEM_Addr ACE_MEM_Connector::address_ [private]
 

The acceptor address this connector is connecting to.

Definition at line 160 of file MEM_Connector.h.

Referenced by connect().

ACE_MEM_SAP::MALLOC_OPTIONS ACE_MEM_Connector::malloc_options_ [private]
 

A cached MALLOC_OPTIONS that the MEM_Connector used to initialize the shared memory malloc update connection establishment.

Definition at line 164 of file MEM_Connector.h.

ACE_MEM_IO::Signal_Strategy ACE_MEM_Connector::preferred_strategy_ [private]
 

Preferred signaling strategy.

Definition at line 167 of file MEM_Connector.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:24:37 2006 for ACE by doxygen 1.3.6