diff options
author | nanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-02-10 19:58:09 +0000 |
---|---|---|
committer | nanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-02-10 19:58:09 +0000 |
commit | 7ad4f697cf767302feafe6a648498e57e3e960d0 (patch) | |
tree | b71587497c9c68d639be74d8dce2021af96d25f8 /ace/MEM_Connector.cpp | |
parent | 53ae527d407ebcf4cc9efb3bff2527a817da1c70 (diff) | |
download | ATCD-7ad4f697cf767302feafe6a648498e57e3e960d0.tar.gz |
ChangeLogTag:Thu Feb 10 13:49:34 2000 Nanbor Wang <nanbor@cs.wustl.edu>
Diffstat (limited to 'ace/MEM_Connector.cpp')
-rw-r--r-- | ace/MEM_Connector.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/ace/MEM_Connector.cpp b/ace/MEM_Connector.cpp new file mode 100644 index 00000000000..090e2cf2e9d --- /dev/null +++ b/ace/MEM_Connector.cpp @@ -0,0 +1,105 @@ +// MEM_Connector.cpp +// $Id$ + +#define ACE_BUILD_DLL +#include "ace/MEM_Connector.h" + +ACE_RCSID(ace, MEM_Connector, "$Id$") + +#if defined (ACE_LACKS_INLINE_FUNCTIONS) +#include "ace/MEM_Connector.i" +#endif + +ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Connector) + +void +ACE_MEM_Connector::dump (void) const +{ + ACE_TRACE ("ACE_MEM_Connector::dump"); + + ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); + ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("\n"))); + ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); +} + +ACE_MEM_Connector::ACE_MEM_Connector (void) +{ + ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector"); +} + +// Establish a connection. +ACE_MEM_Connector::ACE_MEM_Connector (ACE_MEM_Stream &new_stream, + const ACE_INET_Addr &remote_sap, + ACE_Time_Value *timeout, + const ACE_Addr &local_sap, + int reuse_addr, + int flags, + int perms, + int protocol) +{ + ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector"); + // This is necessary due to the weird inheritance relationships of + // ACE_MEM_Stream. + this->connect (new_stream, + remote_sap, + timeout, + local_sap, + reuse_addr, + flags, + perms, + protocol); +} + +int +ACE_MEM_Connector::connect (ACE_MEM_Stream &new_stream, + const ACE_INET_Addr &remote_sap, + ACE_Time_Value *timeout, + const ACE_Addr &local_sap, + int reuse_addr, + int flags, + int perms, + int protocol) +{ + ACE_TRACE ("ACE_MEM_Connector::connect"); + + if (!this->address_.same_host (remote_sap)) + ACE_ERROR_RETURN ((LM_ERROR, + ASYS_TEXT ("(%P|%t) MEM_Connector can't connect ") + ASYS_TEXT ("to %s:%d which is not a local endpoint"), + remote_sap.get_host_name (), + remote_sap.get_port_number ()), + -1); + else + this->address_.set_port_number (remote_sap.get_port_number ()); + + + ACE_SOCK_Stream temp_stream; + + if (ACE_SOCK_Connector::connect (temp_stream, + this->address_.get_local_addr (), + timeout, local_sap, + reuse_addr, flags, perms, + PF_INET, protocol) == -1) + return -1; + + ACE_HANDLE new_handle = temp_stream.get_handle (); + new_stream.set_handle (new_handle); + // Do not close the handle. + + // now we should setup the mmap malloc. + char buf[MAXPATHLEN]; + + // @@ Need to handle timeout here. + ACE_INT16 buf_len; + // Byte-order is not a problem for this read. + if (ACE::recv (new_handle, &buf_len, sizeof (buf_len)) == -1) + return -1; + + if (ACE::recv (new_handle, buf, buf_len) == -1) + return -1; + + if (new_stream.create_shm_malloc (buf, &this->malloc_options_) == -1) + return -1; + + return 0; +} |