summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-02-03 16:09:52 +0000
committernanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-02-03 16:09:52 +0000
commitf55d95dbfa2e41fff4518c71f75707c4eeb8e384 (patch)
treecca7e9f77450f987d8088c07e3041199b2b17f81
parentaa5be78b82f88b31ec631665d56b4fce581cfc1a (diff)
downloadATCD-f55d95dbfa2e41fff4518c71f75707c4eeb8e384.tar.gz
*** empty log message ***
-rw-r--r--ace/MEM_Addr.cpp143
-rw-r--r--ace/MEM_Addr.h143
-rw-r--r--ace/MEM_Addr.i117
3 files changed, 403 insertions, 0 deletions
diff --git a/ace/MEM_Addr.cpp b/ace/MEM_Addr.cpp
new file mode 100644
index 00000000000..8d8a8b04e44
--- /dev/null
+++ b/ace/MEM_Addr.cpp
@@ -0,0 +1,143 @@
+// $Id$
+
+// Defines the Internet domain address family address format.
+
+#define ACE_BUILD_DLL
+#include "ace/MEM_Addr.h"
+
+#if !defined (__ACE_INLINE__)
+#include "ace/MEM_Addr.i"
+#endif /* __ACE_INLINE__ */
+
+ACE_RCSID(ace, MEM_Addr, "$Id$")
+
+ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Addr)
+
+// Transform the current address into string format.
+
+ACE_MEM_Addr::ACE_MEM_Addr (void)
+ : ACE_Addr (AF_INET, sizeof ACE_MEM_Addr)
+{
+ // ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
+ this->initialize_local (0);
+}
+
+ACE_MEM_Addr::ACE_MEM_Addr (const ACE_MEM_Addr &sa)
+ : ACE_Addr (AF_INET, sizeof ACE_MEM_Addr)
+{
+ ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
+ this->external_.set (sa.external_);
+ this->internal_.set (sa.internal_);
+}
+
+ACE_MEM_Addr::ACE_MEM_Addr (const ASYS_TCHAR port_number[])
+ : ACE_Addr (AF_INET, sizeof ACE_MEM_Addr)
+{
+ ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
+ u_short pn
+ = ACE_static_cast (u_short,
+ ACE_OS::strtoul (port_number,
+ NULL,
+ 10));
+ this->initialize_local (pn);
+}
+
+ACE_MEM_Addr::ACE_MEM_Addr (u_short port_number)
+ : ACE_Addr (AF_INET, sizeof ACE_MEM_Addr)
+{
+ ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
+ this->initialize_local (port_number);
+}
+
+int
+ACE_MEM_Addr::initialize_local (u_short port_number)
+{
+ ASYS_TCHAR name[MAXHOSTNAMELEN + 1];
+ if (ACE_OS::hostname (name, MAXHOSTNAMELEN+1) == -1)
+ return -1;
+
+ this->external_.set (port_number, name);
+ this->internal_.set (port_number, ASYS_TEXT ("localhost"));
+ return 0;
+}
+
+int
+ACE_MEM_Addr::same_host (const ACE_INET_Addr &sap)
+{
+ ACE_TRACE ("ACE_MEM_Addr::same_host");
+
+ return this->external_.get_ip_address () ==
+ sap.get_ip_address ();
+}
+
+int
+ACE_MEM_Addr::addr_to_string (ASYS_TCHAR s[],
+ size_t size,
+ int ipaddr_format) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::addr_to_string");
+
+ return this->external_.addr_to_string (s, size, ipaddr_format);
+}
+
+// Transform the string into the current addressing format.
+
+int
+ACE_MEM_Addr::string_to_addr (const ASYS_TCHAR s[])
+{
+ ACE_TRACE ("ACE_MEM_Addr::string_to_addr");
+
+ u_short pn
+ = ACE_static_cast (u_short,
+ ACE_OS::strtoul (s,
+ NULL,
+ 10));
+ return this->set (pn);
+}
+
+// Return the address.
+
+void *
+ACE_MEM_Addr::get_addr (void) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::get_addr");
+ return this->external_.get_addr ();
+}
+
+// Set a pointer to the address.
+void
+ACE_MEM_Addr::set_addr (void *addr, int len)
+{
+ ACE_TRACE ("ACE_MEM_Addr::set_addr");
+
+ this->external_.set_addr (addr, len);
+ this->internal_.set_port_number (this->external_.get_port_number ());
+}
+
+int
+ACE_MEM_Addr::get_host_name (ASYS_TCHAR hostname[],
+ size_t len) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::get_host_name");
+ return this->external_.get_host_name (hostname, len);
+}
+
+// Return the character representation of the hostname.
+
+const ASYS_TCHAR *
+ACE_MEM_Addr::get_host_name (void) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::get_host_name");
+ return this->external_.get_host_name ();
+}
+
+void
+ACE_MEM_Addr::dump (void) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::dump");
+
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ this->external_.dump ();
+ this->internal_.dump ();
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+}
diff --git a/ace/MEM_Addr.h b/ace/MEM_Addr.h
new file mode 100644
index 00000000000..8d683f7d4b6
--- /dev/null
+++ b/ace/MEM_Addr.h
@@ -0,0 +1,143 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// MEM_Addr.h
+//
+// = AUTHOR
+// Nanbor Wang <nanbor@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef ACE_MEM_ADDR_H
+#define ACE_MEM_ADDR_H
+
+#include "ace/ACE.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/INET_Addr.h"
+
+class ACE_Export ACE_MEM_Addr : public ACE_Addr
+{
+ // = TITLE
+ // Defines a C++ wrapper facade for the shared memory transport
+ // address family format.
+public:
+ // = Initialization methods.
+ ACE_MEM_Addr (void);
+ // Default constructor.
+
+ ACE_MEM_Addr (const ACE_MEM_Addr &);
+ // Copy constructor.
+
+ ACE_MEM_Addr (u_short port_number);
+ // Creates an <ACE_INET_Addr> from a <port_number> and the remote
+ // <host_name>.
+
+ ACE_MEM_Addr (const ASYS_TCHAR port_name[]);
+ // Creates an <ACE_INET_Addr> from a <port_name>.
+
+ ~ACE_MEM_Addr (void);
+ // Default dtor.
+
+ // = Direct initialization methods.
+
+ int initialize_local (u_short port);
+ // default initialization routine.
+
+ int same_host (const ACE_INET_Addr& sap);
+ // Check if <sap> designate an enpoint withing the same host.
+
+ // These methods are useful after the object has been constructed.
+
+ int set (u_short port_number,
+ int encode = 1);
+ // Initializes an <ACE_INET_Addr> from a <port_number> and the
+ // remote <host_name>. If <encode> is enabled then <port_number> is
+ // converted into network byte order, otherwise it is assumed to be
+ // in network byte order already and are passed straight through.
+
+ int set (const ASYS_TCHAR port_name[]);
+ // Uses <getservbyname> to initialize an <ACE_INET_Addr> from a
+ // <port_name>, the remote <host_name>, and the <protocol>.
+
+ virtual void *get_addr (void) const;
+ // Return a pointer to the underlying network address.
+
+ virtual void set_addr (void *, int len);
+ // Set a pointer to the address.
+
+ virtual int addr_to_string (ASYS_TCHAR buffer[],
+ size_t size,
+ int ipaddr_format = 1) const;
+ // Transform the external <ACE_INET_Addr> address into string
+ // format.
+
+ virtual int string_to_addr (const ASYS_TCHAR address[]);
+ // Initializes the external <ACE_INET_Addr> from the <address>.
+
+ void set_port_number (u_short,
+ int encode = 1);
+ // Sets the port number.
+
+ u_short get_port_number (void) const;
+ // Return the port number, converting it into host byte order.
+
+ int get_host_name (ASYS_TCHAR hostname[],
+ size_t hostnamelen) const;
+ // Return the character representation of the hostname.
+
+ const ASYS_TCHAR *get_host_name (void) const;
+ // Return the character representation of the hostname (this version
+ // is non-reentrant since it returns a pointer to a static data
+ // area).
+
+ const char *get_host_addr (void) const;
+ // Return the "dotted decimal" external address.
+
+ ACE_UINT32 get_ip_address (void) const;
+ // Return the 4-byte external IP address, converting it into host byte
+ // order.
+
+ const ACE_INET_Addr &get_remote_addr (void) const;
+ const ACE_INET_Addr &get_local_addr (void) const;
+
+ int operator == (const ACE_MEM_Addr &SAP) const;
+ int operator == (const ACE_INET_Addr &SAP) const;
+ // Compare two addresses for equality. The addresses are considered
+ // equal if they contain the same IP address and port number.
+
+ int operator != (const ACE_MEM_Addr &SAP) const;
+ int operator != (const ACE_INET_Addr &SAP) const;
+ // Compare two addresses for inequality.
+
+ virtual u_long hash (void) const;
+ // Computes and returns hash value.
+
+ void dump (void) const;
+ // Dump the state of an object.
+
+ ACE_ALLOC_HOOK_DECLARE;
+ // Declare the dynamic allocation hooks.
+
+private:
+ ACE_INET_Addr external_;
+ // External INET addr used for identifying host.
+
+ ACE_INET_Addr internal_;
+ // Internal INET addr for accepting/connecting.
+};
+
+#if defined (__ACE_INLINE__)
+#include "ace/MEM_Addr.i"
+#endif /* __ACE_INLINE__ */
+
+#endif /* ACE_MEM_ADDR_H */
diff --git a/ace/MEM_Addr.i b/ace/MEM_Addr.i
new file mode 100644
index 00000000000..23fc93b385d
--- /dev/null
+++ b/ace/MEM_Addr.i
@@ -0,0 +1,117 @@
+/* -*- C++ -*- */
+// $Id$
+
+// MEM_Addr.i
+
+// Default dtor.
+ACE_INLINE
+ACE_MEM_Addr::~ACE_MEM_Addr (void)
+{
+}
+
+ACE_INLINE int
+ACE_MEM_Addr::set (u_short port_number, int encode)
+{
+ ACE_TRACE ("ACE_INET_Addr::set");
+ this->set_port_number (port_number, encode);
+ return 0;
+}
+
+ACE_INLINE int
+ACE_MEM_Addr::set (const ASYS_TCHAR port_number[])
+{
+ ACE_TRACE ("ACE_MEM_Addr::set");
+ return this->string_to_addr (port_number);
+}
+
+// Set the port number.
+
+void
+ACE_MEM_Addr::set_port_number (u_short port_number,
+ int encode)
+{
+ ACE_TRACE ("ACE_MEM_Addr::set_port_number");
+
+ this->external_.set_port_number (port_number, encode);
+ this->internal_.set_port_number (port_number, encode);
+}
+
+// Return the port number.
+
+ACE_INLINE u_short
+ACE_MEM_Addr::get_port_number (void) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::get_port_number");
+ return this->internal_.get_port_number ();
+}
+
+// Return the dotted Internet address.
+
+ACE_INLINE const char *
+ACE_MEM_Addr::get_host_addr (void) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::get_host_addr");
+ return this->internal_.get_host_addr ();
+}
+
+// Return the 4-byte IP address, converting it into host byte order.
+
+ACE_INLINE ACE_UINT32
+ACE_MEM_Addr::get_ip_address (void) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::get_ip_address");
+ return this->external_.get_ip_address ();
+}
+
+ACE_INLINE const ACE_INET_Addr &
+ACE_MEM_Addr::get_local_addr (void) const
+{
+ return this->internal_;
+}
+
+ACE_INLINE const ACE_INET_Addr &
+ACE_MEM_Addr::get_remote_addr (void) const
+{
+ return this->external_;
+}
+
+// Compare two addresses for equality.
+
+ACE_INLINE int
+ACE_MEM_Addr::operator == (const ACE_MEM_Addr &sap) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::operator ==");
+
+ return this->external_ == sap.external_ &&
+ this->internal_ == sap.internal_;
+}
+
+int
+ACE_MEM_Addr::operator == (const ACE_INET_Addr &sap) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::operator ==");
+
+ return this->external_ == sap;
+}
+
+// Compare two addresses for inequality.
+
+int
+ACE_MEM_Addr::operator != (const ACE_MEM_Addr &sap) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::operator !=");
+ return !((*this) == sap);
+}
+
+int
+ACE_MEM_Addr::operator != (const ACE_INET_Addr &sap) const
+{
+ ACE_TRACE ("ACE_MEM_Addr::operator !=");
+ return !((*this) == sap);
+}
+
+ACE_INLINE u_long
+ACE_MEM_Addr::hash (void) const
+{
+ return this->external_.hash ();
+}