Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / ATM_Acceptor.cpp
blobd9bd51330708a81edc4e654ed936fb1daa93fe67
1 #include "ace/ATM_Acceptor.h"
3 #if defined (ACE_HAS_ATM)
5 #if defined (ACE_HAS_LINUX_ATM)
6 #include /**/ "linux/atmdev.h"
7 #endif /* ACE_HAS_LINUX_ATM */
9 #if !defined (__ACE_INLINE__)
10 #include "ace/ATM_Acceptor.inl"
11 #endif /* __ACE_INLINE__ */
13 // Open versioned namespace, if enabled by the user.
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 // Put the actual definitions of the ACE_ATM_Request and
17 // ACE_ATM_Request_Queue classes here to hide them from clients...
19 ACE_ALLOC_HOOK_DEFINE(ACE_ATM_Acceptor)
21 ACE_ATM_Acceptor::ACE_ATM_Acceptor ()
23 ACE_TRACE ("ACE_ATM_Acceptor::ACE_ATM_Acceptor");
26 ACE_ATM_Acceptor::~ACE_ATM_Acceptor ()
28 ACE_TRACE ("ACE_ATM_Acceptor::~ACE_ATM_Acceptor");
31 int
32 ACE_ATM_Acceptor::get_local_addr (ACE_ATM_Addr &local_addr)
34 ACE_TRACE ("ACE_ATM_Acceptor::get_local_addr");
36 #if defined (ACE_HAS_FORE_ATM_WS2)
37 unsigned long ret = 0;
38 DWORD deviceID = 0;
39 ATM_ADDRESS addr;
40 struct sockaddr_atm *laddr;
42 if (::WSAIoctl ((int) ((ACE_SOCK_Acceptor *)this) -> get_handle (),
43 SIO_GET_ATM_ADDRESS,
44 (LPVOID) &deviceID,
45 sizeof (DWORD),
46 (LPVOID)&addr,
47 sizeof (ATM_ADDRESS),
48 &ret,
50 0) == SOCKET_ERROR) {
51 ACE_OS::printf ("ATM_Acceptor (get_local_addr): WSIoctl: %d\n",
52 ::WSAGetLastError ());
53 return -1;
56 laddr = (struct sockaddr_atm *)local_addr.get_addr ();
57 ACE_OS::memcpy ((void *)& (laddr -> satm_number),
58 (void *)&addr,
59 ATM_ADDR_SIZE - 1);
61 return 0;
62 #elif defined (ACE_HAS_FORE_ATM_XTI)
63 ACE_UNUSED_ARG (local_addr);
65 return 0;
66 #elif defined (ACE_HAS_LINUX_ATM)
67 ATM_Addr *myaddr = (ATM_Addr *)local_addr.get_addr ();
68 int addrlen = sizeof (myaddr->sockaddratmsvc);
70 if (ACE_OS::getsockname (acceptor_.get_handle (),
71 (struct sockaddr *) & (myaddr->sockaddratmsvc),
72 &addrlen) < 0) {
73 ACELIB_DEBUG ((LM_DEBUG,
74 ACE_TEXT ("ATM_Acceptor (get_local_addr): ioctl: %d\n"),
75 errno));
76 return -1;
79 return 0;
80 #else
81 ACE_UNUSED_ARG (local_addr);
83 return 0;
84 #endif /* ACE_HAS_FORE_ATM_WS2 && ACE_HAS_FORE_ATM_XTI */
87 ACE_HANDLE
88 ACE_ATM_Acceptor::open (const ACE_Addr &remote_sap,
89 int backlog,
90 ACE_ATM_Params params)
92 ACE_TRACE ("ACE_ATM_Acceptor::open");
93 #if defined (ACE_HAS_FORE_ATM_XTI)
94 ACE_HANDLE handle = acceptor_.open (remote_sap,
95 params.get_reuse_addr (),
96 params.get_oflag (),
97 params.get_info (),
98 backlog,
99 params.get_device ());
100 return (handle == ACE_INVALID_HANDLE ? -1 : 0);
101 #elif defined (ACE_HAS_FORE_ATM_WS2)
102 struct sockaddr_atm local_atm_addr;
103 ACE_HANDLE ret;
104 DWORD flags = 0;
106 /* Create a local endpoint of communication */
108 // Only leaves can listen.
109 flags = ACE_FLAG_MULTIPOINT_C_LEAF | ACE_FLAG_MULTIPOINT_D_LEAF;
111 if ((ret = ACE_OS::socket (AF_ATM,
112 SOCK_RAW,
113 ATMPROTO_AAL5,
116 flags))
117 == ACE_INVALID_HANDLE) {
118 ACE_OS::printf ("Acceptor (open): socket %d\n",
119 ::WSAGetLastError ());
120 return (ret);
123 ((ACE_SOCK_Acceptor *)this) -> set_handle (ret);
125 /* Set up the address information to become a server */
126 ACE_OS::memset ((void *) &local_atm_addr, 0, sizeof local_atm_addr);
127 local_atm_addr.satm_family = AF_ATM;
128 local_atm_addr.satm_number.AddressType = SAP_FIELD_ANY_AESA_REST;
129 local_atm_addr.satm_number.Addr[ ATM_ADDR_SIZE - 1 ]
130 = ((ACE_ATM_Addr *)&remote_sap) -> get_selector ();
131 local_atm_addr.satm_blli.Layer2Protocol = SAP_FIELD_ANY;
132 local_atm_addr.satm_blli.Layer3Protocol = SAP_FIELD_ABSENT;
133 local_atm_addr.satm_bhli.HighLayerInfoType = SAP_FIELD_ABSENT;
135 /* Associate address with endpoint */
136 if (ACE_OS::bind (((ACE_SOCK_Acceptor *)this) -> get_handle (),
137 reinterpret_cast<struct sockaddr *> (&local_atm_addr),
138 sizeof local_atm_addr) == -1) {
139 ACE_OS::printf ("Acceptor (open): bind %d\n", ::WSAGetLastError ());
140 return (ACE_INVALID_HANDLE);
143 /* Make endpoint listen for service requests */
144 if (ACE_OS::listen (( (ACE_SOCK_Acceptor *)this) -> get_handle (),
145 backlog)
146 == -1) {
147 ACE_OS::printf ("Acceptor (open): listen %d\n", ::WSAGetLastError ());
148 return (ACE_INVALID_HANDLE);
151 return 0;
152 #elif defined (ACE_HAS_LINUX_ATM)
153 //we need to set the qos before binding to the socket
154 //use remote_sap as local_sap
156 ACE_ATM_Addr local_sap;
157 ATM_Addr *local_sap_addr = (ATM_Addr*)local_sap.get_addr ();
158 ACE_ATM_QoS def_qos;
159 ATM_QoS qos = def_qos.get_qos ();
161 ACE_HANDLE handle;
162 if ((handle = ACE_OS::socket (params.get_protocol_family (),
163 params.get_type (),
164 params.get_protocol (),
165 params.get_protocol_info (),
166 params.get_sock_group (),
167 params.get_flags ()
169 == ACE_INVALID_HANDLE) {
170 ACELIB_DEBUG (LM_DEBUG,
171 ACE_TEXT ("Acceptor (socket): socket %d\n"),
172 errno);
173 return (ACE_INVALID_HANDLE);
176 ((ACE_SOCK_Acceptor *)this) -> set_handle (handle);
177 if (ACE_OS::setsockopt (handle,
178 SOL_ATM,
179 SO_ATMQOS,
180 reinterpret_cast<char*> (&qos),
181 sizeof (qos)) < 0) {
182 ACE_OS::printf ("Acceptor (setsockopt): setsockopt:%d\n",
183 errno);
186 struct atmif_sioc req;
187 struct sockaddr_atmsvc aux_addr[1024];
189 req.number = 0;
190 req.arg = aux_addr;
191 req.length = sizeof (aux_addr);
192 if (ACE_OS::ioctl (handle,
193 ATM_GETADDR,
194 &req) < 0) {
195 ACE_OS::perror ("Acceptor (setsockopt): ioctl:");
197 else {
198 local_sap_addr->sockaddratmsvc = aux_addr[0];
200 local_sap.set_selector (( (ACE_ATM_Addr*)&remote_sap)->get_selector ());
202 if (ACE_OS::bind (handle,
203 reinterpret_cast<struct sockaddr *> (
204 &(local_sap_addr->sockaddratmsvc)),
205 sizeof (local_sap_addr->sockaddratmsvc)
206 ) == -1) {
207 ACELIB_DEBUG (LM_DEBUG,
208 ACE_TEXT ("Acceptor (open): bind %d\n"),
209 errno);
210 return -1;
212 // Make endpoint listen for service requests
213 if (ACE_OS::listen (handle,
214 backlog)
215 == -1) {
216 ACELIB_DEBUG (LM_DEBUG,
217 ACE_TEXT ("Acceptor (listen): listen %d\n"),
218 errno);
219 return -1;
222 return 0;
223 #else
224 ACE_UNUSED_ARG (remote_sap);
225 ACE_UNUSED_ARG (backlog);
226 ACE_UNUSED_ARG (params);
227 #endif /* ACE_HAS_FORE_ATM_XTI/ACE_HAS_FORE_ATM_WS2/ACE_HAS_LINUX_ATM */
231 ACE_ATM_Acceptor::accept (ACE_ATM_Stream &new_sap,
232 ACE_Addr *remote_addr,
233 ACE_Time_Value *timeout,
234 bool restart,
235 bool reset_new_handle,
236 ACE_ATM_Params params,
237 ACE_ATM_QoS qos)
239 ACE_TRACE ("ACE_ATM_Acceptor::accept");
240 #if defined (ACE_HAS_FORE_ATM_XTI)
241 ATM_QoS optbuf = qos.get_qos ();
243 return (acceptor_.accept (new_sap.get_stream (),
244 remote_addr,
245 timeout,
246 restart,
247 reset_new_handle,
248 params.get_rw_flag (),
249 params.get_user_data (),
250 &optbuf));
251 #elif defined (ACE_HAS_FORE_ATM_WS2)
252 ACE_HANDLE n_handle;
253 ACE_HANDLE s_handle = ((ACE_SOCK_Acceptor *) this) -> get_handle ();
254 struct sockaddr_atm *cli_addr
255 = (struct sockaddr_atm *)remote_addr -> get_addr ();
256 int caddr_len = sizeof (struct sockaddr_atm);
258 do {
259 n_handle = ACE_OS::accept (s_handle,
260 reinterpret_cast<struct sockaddr *> (cli_addr),
261 &caddr_len);
262 } while (n_handle == ACE_INVALID_HANDLE && errno == EINTR);
264 ((ACE_ATM_Addr *)remote_addr) -> set (cli_addr,
265 ((ACE_ATM_Addr *)remote_addr) -> get_selector ());
266 ((ACE_IPC_SAP *)&new_sap) -> set_handle (n_handle);
268 return 0;
269 #elif defined (ACE_HAS_LINUX_ATM)
270 ACE_UNUSED_ARG (params);
272 ACE_HANDLE s_handle = ((ACE_SOCK_Acceptor *) this) -> get_handle ();
273 struct atm_qos accept_qos = qos.get_qos ();
275 if (ACE_OS::setsockopt (s_handle,
276 SOL_ATM,
277 SO_ATMQOS,
278 reinterpret_cast<char*> (&accept_qos),
279 sizeof (accept_qos)) < 0) {
280 ACE_OS::printf ("Acceptor (accept): error setting Qos");
283 return (acceptor_.accept (new_sap.get_stream (),
284 remote_addr,
285 timeout,
286 restart,
287 reset_new_handle));
288 #else
289 ACE_UNUSED_ARG (new_sap);
290 ACE_UNUSED_ARG (remote_addr);
291 ACE_UNUSED_ARG (timeout);
292 ACE_UNUSED_ARG (restart);
293 ACE_UNUSED_ARG (reset_new_handle);
294 ACE_UNUSED_ARG (params);
295 ACE_UNUSED_ARG (qos);
296 return 0;
297 #endif /* ACE_HAS_FORE_ATM_XTI */
300 // Close versioned namespace, if enabled by the user.
301 ACE_END_VERSIONED_NAMESPACE_DECL
304 #endif /* ACE_HAS_ATM */