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 (void)
23 ACE_TRACE ("ACE_ATM_Acceptor::ACE_ATM_Acceptor");
26 ACE_ATM_Acceptor::~ACE_ATM_Acceptor (void)
28 ACE_TRACE ("ACE_ATM_Acceptor::~ACE_ATM_Acceptor");
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;
40 struct sockaddr_atm
*laddr
;
42 if (::WSAIoctl ((int) ((ACE_SOCK_Acceptor
*)this) -> get_handle (),
51 ACE_OS::printf ("ATM_Acceptor (get_local_addr): WSIoctl: %d\n",
52 ::WSAGetLastError ());
56 laddr
= (struct sockaddr_atm
*)local_addr
.get_addr ();
57 ACE_OS::memcpy ((void *)& (laddr
-> satm_number
),
62 #elif defined (ACE_HAS_FORE_ATM_XTI)
63 ACE_UNUSED_ARG (local_addr
);
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
),
73 ACELIB_DEBUG ((LM_DEBUG
,
74 ACE_TEXT ("ATM_Acceptor (get_local_addr): ioctl: %d\n"),
81 ACE_UNUSED_ARG (local_addr
);
84 #endif /* ACE_HAS_FORE_ATM_WS2 && ACE_HAS_FORE_ATM_XTI */
88 ACE_ATM_Acceptor::open (const ACE_Addr
&remote_sap
,
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 (),
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
;
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
,
117 == ACE_INVALID_HANDLE
) {
118 ACE_OS::printf ("Acceptor (open): socket %d\n",
119 ::WSAGetLastError ());
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 (),
147 ACE_OS::printf ("Acceptor (open): listen %d\n", ::WSAGetLastError ());
148 return (ACE_INVALID_HANDLE
);
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 ();
159 ATM_QoS qos
= def_qos
.get_qos ();
162 if ((handle
= ACE_OS::socket (params
.get_protocol_family (),
164 params
.get_protocol (),
165 params
.get_protocol_info (),
166 params
.get_sock_group (),
169 == ACE_INVALID_HANDLE
) {
170 ACELIB_DEBUG (LM_DEBUG
,
171 ACE_TEXT ("Acceptor (socket): socket %d\n"),
173 return (ACE_INVALID_HANDLE
);
176 ((ACE_SOCK_Acceptor
*)this) -> set_handle (handle
);
177 if (ACE_OS::setsockopt (handle
,
180 reinterpret_cast<char*> (&qos
),
182 ACE_OS::printf ("Acceptor (setsockopt): setsockopt:%d\n",
186 struct atmif_sioc req
;
187 struct sockaddr_atmsvc aux_addr
[1024];
191 req
.length
= sizeof (aux_addr
);
192 if (ACE_OS::ioctl (handle
,
195 ACE_OS::perror ("Acceptor (setsockopt): ioctl:");
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
)
207 ACELIB_DEBUG (LM_DEBUG
,
208 ACE_TEXT ("Acceptor (open): bind %d\n"),
212 // Make endpoint listen for service requests
213 if (ACE_OS::listen (handle
,
216 ACELIB_DEBUG (LM_DEBUG
,
217 ACE_TEXT ("Acceptor (listen): listen %d\n"),
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
,
235 bool reset_new_handle
,
236 ACE_ATM_Params params
,
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 (),
248 params
.get_rw_flag (),
249 params
.get_user_data (),
251 #elif defined (ACE_HAS_FORE_ATM_WS2)
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
);
259 n_handle
= ACE_OS::accept (s_handle
,
260 reinterpret_cast<struct sockaddr
*> (cli_addr
),
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
);
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
,
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 (),
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
);
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 */