GitHub Actions: Try MSVC builds with /std:c++17 and 20
[ACE_TAO.git] / ACE / ace / SPIPE_Addr.cpp
blob519f43f17802b4e1a69013e6590e55b83c8c049b
1 #include "ace/SPIPE_Addr.h"
2 #include "ace/OS_NS_string.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/os_include/sys/os_socket.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/SPIPE_Addr.inl"
8 #endif /* __ACE_INLINE__ */
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Addr)
14 void
15 ACE_SPIPE_Addr::dump (void) const
17 #if defined (ACE_HAS_DUMP)
18 #endif /* ACE_HAS_DUMP */
21 // Set a pointer to the address.
22 void
23 ACE_SPIPE_Addr::set_addr (const void *addr, int len)
25 ACE_TRACE ("ACE_SPIPE_Addr::set_addr");
27 this->ACE_Addr::base_set (AF_SPIPE, len);
28 ACE_OS::memcpy (&this->SPIPE_addr_, addr, len);
31 // Return the address.
33 void *
34 ACE_SPIPE_Addr::get_addr (void) const
36 return (void *) &this->SPIPE_addr_;
40 // Do nothing constructor.
42 ACE_SPIPE_Addr::ACE_SPIPE_Addr (void)
43 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
45 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
47 sizeof this->SPIPE_addr_);
50 int
51 ACE_SPIPE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
53 ACE_OS::strsncpy (s,
54 this->SPIPE_addr_.rendezvous_,
55 len);
56 return 0;
59 // Transform the string into the current addressing format.
61 int
62 ACE_SPIPE_Addr::string_to_addr (const ACE_TCHAR *addr)
64 return this->set (addr);
67 int
68 ACE_SPIPE_Addr::set (const ACE_SPIPE_Addr &sa)
70 this->base_set (sa.get_type (), sa.get_size ());
72 if (sa.get_type () == AF_ANY)
73 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
75 sizeof this->SPIPE_addr_);
76 else
77 (void) ACE_OS::memcpy ((void *) &this->SPIPE_addr_, (void *)
78 &sa.SPIPE_addr_,
79 sa.get_size ());
80 return 0;
83 // Copy constructor.
85 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_SPIPE_Addr &sa)
86 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
88 this->set (sa);
91 int
92 ACE_SPIPE_Addr::set (const ACE_TCHAR *addr,
93 gid_t gid,
94 uid_t uid)
96 int len = sizeof (this->SPIPE_addr_.uid_);
97 len += sizeof (this->SPIPE_addr_.gid_);
99 #if defined (ACE_WIN32)
100 const ACE_TCHAR *colonp = ACE_OS::strchr (addr, ':');
101 ACE_TCHAR temp[BUFSIZ];
103 if (colonp == 0) // Assume it's a local name.
105 ACE_OS::strcpy (temp, ACE_TEXT ( "\\\\.\\pipe\\"));
106 ACE_OS::strcat (temp, addr);
108 else
111 if (ACE_OS::strncmp (addr,
112 ACE_TEXT ("localhost"),
113 ACE_OS::strlen ("localhost")) == 0)
114 // change "localhost" to "."
115 ACE_OS::strcpy (temp, ACE_TEXT ("\\\\."));
116 else
118 ACE_OS::strcpy (temp, ACE_TEXT ("\\\\"));
120 ACE_TCHAR *t;
122 // We need to allocate a duplicate so that we can write a
123 // NUL character into it.
124 ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (addr), -1);
126 t[colonp - addr] = ACE_TEXT ('\0');
127 ACE_OS::strcat (temp, t);
129 ACE_OS::free (t);
132 ACE_OS::strcat (temp, ACE_TEXT ("\\pipe\\"));
133 ACE_OS::strcat (temp, colonp + 1);
135 len += static_cast<int> (ACE_OS::strlen (temp));
136 this->ACE_Addr::base_set (AF_SPIPE, len);
138 ACE_OS::strcpy (this->SPIPE_addr_.rendezvous_, temp);
139 #else
140 this->ACE_Addr::base_set (AF_SPIPE,
141 ACE_OS::strlen (addr) + 1 + len);
142 ACE_OS::strsncpy (this->SPIPE_addr_.rendezvous_,
143 addr,
144 sizeof this->SPIPE_addr_.rendezvous_);
145 #endif /* ACE_WIN32 */
146 this->SPIPE_addr_.gid_ = gid == 0 ? ACE_OS::getgid () : gid;
147 this->SPIPE_addr_.uid_ = uid == 0 ? ACE_OS::getuid () : uid;
148 return 0;
151 // Create a ACE_Addr from a ACE_SPIPE pathname.
153 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_TCHAR *addr,
154 gid_t gid,
155 uid_t uid)
156 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
158 this->set (addr, gid, uid);
161 ACE_END_VERSIONED_NAMESPACE_DECL