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

MEM_Connector.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // MEM_Connector.cpp
00003 // $Id: MEM_Connector.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $
00004 
00005 #include "ace/MEM_Connector.h"
00006 
00007 ACE_RCSID(ace, MEM_Connector, "$Id: MEM_Connector.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $")
00008 
00009 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00010 
00011 #if defined (ACE_LACKS_INLINE_FUNCTIONS)
00012 #include "ace/MEM_Connector.i"
00013 #endif
00014 
00015 ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Connector)
00016 
00017 void
00018 ACE_MEM_Connector::dump (void) const
00019 {
00020   ACE_TRACE ("ACE_MEM_Connector::dump");
00021 
00022   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\n")));
00024   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00025 }
00026 
00027 ACE_MEM_Connector::ACE_MEM_Connector (void)
00028   : malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00029     preferred_strategy_ (ACE_MEM_IO::Reactive)
00030 {
00031   ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
00032 }
00033 
00034 // Establish a connection.
00035 ACE_MEM_Connector::ACE_MEM_Connector (ACE_MEM_Stream &new_stream,
00036                                       const ACE_INET_Addr &remote_sap,
00037                                       ACE_Time_Value *timeout,
00038                                       const ACE_Addr &local_sap,
00039                                       int reuse_addr,
00040                                       int flags,
00041                                       int perms)
00042   : malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
00043     preferred_strategy_ (ACE_MEM_IO::Reactive)
00044 {
00045   ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
00046   // This is necessary due to the weird inheritance relationships of
00047   // ACE_MEM_Stream.
00048   this->connect (new_stream,
00049                  remote_sap,
00050                  timeout,
00051                  local_sap,
00052                  reuse_addr,
00053                  flags,
00054                  perms);
00055 }
00056 
00057 int
00058 ACE_MEM_Connector::connect (ACE_MEM_Stream &new_stream,
00059                             const ACE_INET_Addr &remote_sap,
00060                             ACE_Time_Value *timeout,
00061                             const ACE_Addr &local_sap,
00062                             int reuse_addr,
00063                             int flags,
00064                             int perms)
00065 {
00066   ACE_TRACE ("ACE_MEM_Connector::connect");
00067 
00068   if (!this->address_.same_host (remote_sap))
00069     ACE_ERROR_RETURN ((LM_ERROR,
00070                        ACE_LIB_TEXT ("(%P|%t) MEM_Connector can't connect ")
00071                        ACE_LIB_TEXT ("to %s:%d which is not a local endpoint ")
00072                        ACE_LIB_TEXT ("(local address is %s:%d)\n"),
00073                        remote_sap.get_host_name (),
00074                        remote_sap.get_port_number (),
00075                        this->address_.get_host_name (),
00076                        this->address_.get_port_number ()),
00077                       -1);
00078   else
00079     this->address_.set_port_number (remote_sap.get_port_number ());
00080 
00081 
00082   ACE_SOCK_Stream temp_stream;
00083 
00084   if (ACE_SOCK_Connector::connect (temp_stream,
00085                                    this->address_.get_local_addr (),
00086                                    timeout, local_sap,
00087                                    reuse_addr, flags, perms) == -1)
00088     ACE_ERROR_RETURN ((LM_DEBUG,
00089                        ACE_LIB_TEXT ("%p\n"),
00090                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect")),
00091                       -1);
00092 
00093 
00094   ACE_HANDLE new_handle = temp_stream.get_handle ();
00095   new_stream.set_handle (new_handle);
00096   new_stream.disable (ACE_NONBLOCK);
00097   // Do not close the handle.
00098 
00099   // now we should setup the mmap malloc.
00100   ACE_TCHAR buf[MAXPATHLEN];
00101 
00102   // @@ Need to handle timeout here.
00103   ACE_INT16 server_strategy = ACE_MEM_IO::Reactive;
00104   // Receive the signaling strategy theserver support.
00105   if (ACE::recv (new_handle, &server_strategy,
00106                  sizeof (ACE_INT16)) == -1)
00107     ACE_ERROR_RETURN ((LM_DEBUG,
00108                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving strategy\n")),
00109                       -1);
00110 
00111     // If either side don't support MT, we will not use it.
00112 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
00113   if (! (this->preferred_strategy_ == ACE_MEM_IO::MT &&
00114          server_strategy == ACE_MEM_IO::MT))
00115 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
00116     server_strategy = ACE_MEM_IO::Reactive;
00117 
00118   if (ACE::send (new_handle, &server_strategy,
00119                  sizeof (ACE_INT16)) == -1)
00120     ACE_ERROR_RETURN ((LM_DEBUG,
00121                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error sending strategy\n")),
00122                       -1);
00123 
00124   ACE_INT16 buf_len;
00125   // Byte-order is not a problem for this read.
00126   if (ACE::recv (new_handle, &buf_len, sizeof (buf_len)) == -1)
00127     ACE_ERROR_RETURN ((LM_DEBUG,
00128                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving shm filename length\n")),
00129                       -1);
00130 
00131   if (ACE::recv (new_handle, buf, buf_len) == -1)
00132     ACE_ERROR_RETURN ((LM_DEBUG,
00133                        ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving shm filename.\n")),
00134                       -1);
00135 
00136   if (new_stream.init (buf, ACE_static_cast (ACE_MEM_IO::Signal_Strategy, server_strategy),
00137                        &this->malloc_options_) == -1)
00138     return -1;
00139 
00140   return 0;
00141 }
00142 
00143 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */

Generated on Mon Jun 16 11:20:17 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002