summaryrefslogtreecommitdiff
path: root/TAO/tao/SHMIOP_Endpoint.cpp
blob: 25c406019488b06a2f212e5104fd417246acc8ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// This may look like C, but it's really -*- C++ -*-
// $Id$


#include "tao/SHMIOP_Endpoint.h"

#if defined (TAO_HAS_SHMIOP) && (TAO_HAS_SHMIOP != 0)

#include "tao/SHMIOP_Connect.h"
#include "tao/debug.h"

ACE_RCSID(tao, SHMIOP_Endpoint, "$Id$")

#if !defined (__ACE_INLINE__)
# include "tao/SHMIOP_Endpoint.i"
#endif /* __ACE_INLINE__ */

TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const ACE_MEM_Addr &addr,
                                          int use_dotted_decimal_addresses)
  : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE),
    host_ (),
    port_ (0),
    object_addr_ (addr.get_remote_addr ()),
    hint_ (0),
    next_ (0)
{
  this->set (addr.get_remote_addr (), use_dotted_decimal_addresses);
}

TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const char *host,
                                          CORBA::UShort port,
                                          const ACE_INET_Addr &addr)
  : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE),
    host_ (),
    port_ (port),
    object_addr_ (addr),
    hint_ (0),
    next_ (0)
{
  if (host != 0)
    this->host_ = host;
}

TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (void)
  : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE),
    host_ (),
    port_ (0),
    object_addr_ (),
    hint_ (0),
    next_ (0)
{
}

TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const char *host,
                                          CORBA::UShort port,
                                          CORBA::Short priority)
  : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE),
    host_ (),
    port_ (port),
    object_addr_ (),
    hint_ (0),
    next_ (0)
{
  if (host != 0)
    this->host_ = host;

  this->object_addr_.set_type (-1);
  this->priority (priority);
}

TAO_SHMIOP_Endpoint::~TAO_SHMIOP_Endpoint (void)
{
}

int
TAO_SHMIOP_Endpoint::set (const ACE_INET_Addr &addr,
                        int use_dotted_decimal_addresses)
{
  char tmp_host[MAXHOSTNAMELEN + 1];

  if (use_dotted_decimal_addresses
      || addr.get_host_name (tmp_host, sizeof (tmp_host)) != 0)
    {
      const char *tmp = addr.get_host_addr ();
      if (tmp == 0)
        {
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n\nTAO (%P|%t) ")
                        ACE_TEXT ("SHMIOP_Endpoint::set ")
                        ACE_TEXT ("- %p\n\n"),
                        ACE_TEXT ("cannot determine hostname")));
          return -1;
        }
      else
        this->host_ = tmp;
    }
  else
    this->host_ = CORBA::string_dup (tmp_host);

  this->port_ = addr.get_port_number();

  return 0;
}

int
TAO_SHMIOP_Endpoint::addr_to_string (char *buffer, size_t length)
{
  size_t actual_len =
    ACE_OS::strlen (this->host_.in ()) // chars in host name
    + sizeof (':')                     // delimiter
    + ACE_OS::strlen ("65536")         // max port
    + sizeof ('\0');

  if (length < actual_len)
    return -1;

  ACE_OS::sprintf (buffer, "%s:%d",
                   this->host_.in (), this->port_);

  return 0;
}

const char *
TAO_SHMIOP_Endpoint::host (const char *h)
{
  this->host_ = h;

  return this->host_.in ();
}

void
TAO_SHMIOP_Endpoint::reset_hint (void)
{
  if (this->hint_)
    this->hint_->cleanup_hint ((void **) &this->hint_);
}

TAO_Endpoint *
TAO_SHMIOP_Endpoint::next (void)
{
  return this->next_;
}

#endif /* TAO_HAS_SHMIOP && TAO_HAS_SHMIOP != 0 */