Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / SOCK.cpp
blob651014e1d9950c280928d01d264eb7fcf42c2d9c
1 #include "ace/SOCK.h"
2 #include "ace/Log_Category.h"
3 #if defined (ACE_HAS_ALLOC_HOOKS)
4 # include "ace/Malloc_Base.h"
5 #endif /* ACE_HAS_ALLOC_HOOKS */
7 #if !defined (__ACE_INLINE__)
8 #include "ace/SOCK.inl"
9 #endif /* __ACE_INLINE__ */
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 ACE_ALLOC_HOOK_DEFINE(ACE_SOCK)
15 void
16 ACE_SOCK::dump () const
18 #if defined (ACE_HAS_DUMP)
19 ACE_TRACE ("ACE_SOCK::dump");
20 #endif /* ACE_HAS_DUMP */
23 ACE_SOCK::ACE_SOCK ()
25 // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
28 // Returns information about the remote peer endpoint (if there is
29 // one).
31 int
32 ACE_SOCK::get_remote_addr (ACE_Addr &sa) const
34 ACE_TRACE ("ACE_SOCK::get_remote_addr");
36 int len = sa.get_size ();
37 sockaddr *addr = reinterpret_cast<sockaddr *> (sa.get_addr ());
39 if (ACE_OS::getpeername (this->get_handle (),
40 addr,
41 &len) == -1)
42 return -1;
44 sa.set_size (len);
45 sa.set_type (addr->sa_family);
46 return 0;
49 int
50 ACE_SOCK::get_local_addr (ACE_Addr &sa) const
52 ACE_TRACE ("ACE_SOCK::get_local_addr");
54 int len = sa.get_size ();
55 sockaddr *addr = reinterpret_cast<sockaddr *> (sa.get_addr ());
57 if (ACE_OS::getsockname (this->get_handle (),
58 addr,
59 &len) == -1)
60 return -1;
62 sa.set_type (addr->sa_family);
63 sa.set_size (len);
64 return 0;
67 // Close down a ACE_SOCK.
69 int
70 ACE_SOCK::close ()
72 ACE_TRACE ("ACE_SOCK::close");
73 int result = 0;
75 if (this->get_handle () != ACE_INVALID_HANDLE)
77 result = ACE_OS::closesocket (this->get_handle ());
78 this->set_handle (ACE_INVALID_HANDLE);
80 return result;
83 int
84 ACE_SOCK::open (int type,
85 int protocol_family,
86 int protocol,
87 int reuse_addr)
89 ACE_TRACE ("ACE_SOCK::open");
90 int one = 1;
92 this->set_handle (ACE_OS::socket (protocol_family,
93 type,
94 protocol));
96 if (this->get_handle () == ACE_INVALID_HANDLE)
97 return -1;
98 else if (protocol_family != PF_UNIX
99 && reuse_addr
100 && this->set_option (SOL_SOCKET,
101 SO_REUSEADDR,
102 &one,
103 sizeof one) == -1)
105 this->close ();
106 return -1;
108 return 0;
111 // General purpose constructor for performing server ACE_SOCK
112 // creation.
114 ACE_SOCK::ACE_SOCK (int type,
115 int protocol_family,
116 int protocol,
117 int reuse_addr)
119 // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
120 if (this->open (type,
121 protocol_family,
122 protocol,
123 reuse_addr) == -1)
124 ACELIB_ERROR ((LM_ERROR,
125 ACE_TEXT ("%p\n"),
126 ACE_TEXT ("ACE_SOCK::ACE_SOCK")));
130 ACE_SOCK::open (int type,
131 int protocol_family,
132 int protocol,
133 ACE_Protocol_Info *protocolinfo,
134 ACE_SOCK_GROUP g,
135 u_long flags,
136 int reuse_addr)
138 ACE_TRACE ("ACE_SOCK::open");
140 this->set_handle (ACE_OS::socket (protocol_family,
141 type,
142 protocol,
143 protocolinfo,
145 flags));
146 int one = 1;
148 if (this->get_handle () == ACE_INVALID_HANDLE)
149 return -1;
150 else if (reuse_addr
151 && this->set_option (SOL_SOCKET,
152 SO_REUSEADDR,
153 &one,
154 sizeof one) == -1)
156 this->close ();
157 return -1;
159 else
160 return 0;
163 ACE_SOCK::ACE_SOCK (int type,
164 int protocol_family,
165 int protocol,
166 ACE_Protocol_Info *protocolinfo,
167 ACE_SOCK_GROUP g,
168 u_long flags,
169 int reuse_addr)
171 // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
172 if (this->open (type,
173 protocol_family,
174 protocol,
175 protocolinfo,
177 flags,
178 reuse_addr) == -1)
179 ACELIB_ERROR ((LM_ERROR,
180 ACE_TEXT ("%p\n"),
181 ACE_TEXT ("ACE_SOCK::ACE_SOCK")));
184 ACE_END_VERSIONED_NAMESPACE_DECL