1 // $Id: LSOCK_Acceptor.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/LSOCK_Acceptor.h"
5 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
7 #include "ace/Log_Msg.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/OS_NS_sys_socket.h"
11 ACE_RCSID(ace
, LSOCK_Acceptor
, "$Id: LSOCK_Acceptor.cpp 80826 2008-03-04 14:51:23Z wotte $")
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK_Acceptor
)
17 // Return the local endpoint address.
20 ACE_LSOCK_Acceptor::get_local_addr (ACE_Addr
&a
) const
22 ACE_TRACE ("ACE_LSOCK_Acceptor::get_local_addr");
24 ACE_UNIX_Addr
& target
= dynamic_cast<ACE_UNIX_Addr
&> (a
);
26 target
= this->local_addr_
;
32 ACE_LSOCK_Acceptor::dump (void) const
34 #if defined (ACE_HAS_DUMP)
35 ACE_TRACE ("ACE_LSOCK_Acceptor::dump");
37 ACE_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
38 this->local_addr_
.dump ();
39 ACE_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
40 #endif /* ACE_HAS_DUMP */
43 // Do nothing routine for constructor.
45 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (void)
47 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
51 ACE_LSOCK_Acceptor::open (const ACE_Addr
&remote_sap
,
57 ACE_TRACE ("ACE_LSOCK_Acceptor::open");
58 this->local_addr_
= *((ACE_UNIX_Addr
*) &remote_sap
); // This is a gross hack...
59 return ACE_SOCK_Acceptor::open (remote_sap
, reuse_addr
,
60 protocol_family
, backlog
, protocol
);
63 // General purpose routine for performing server ACE_SOCK creation.
65 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (const ACE_Addr
&remote_sap
,
71 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
72 if (this->open (remote_sap
,
78 "ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor"));
81 // General purpose routine for accepting new connections.
84 ACE_LSOCK_Acceptor::accept (ACE_LSOCK_Stream
&new_stream
,
85 ACE_Addr
*remote_addr
,
86 ACE_Time_Value
*timeout
,
88 int reset_new_handle
) const
90 ACE_TRACE ("ACE_LSOCK_Acceptor::accept");
92 int in_blocking_mode
= 0;
93 if (this->shared_accept_start (timeout
,
95 in_blocking_mode
) == -1)
102 if (remote_addr
!= 0)
104 len
= remote_addr
->get_size ();
105 addr
= (sockaddr
*) remote_addr
->get_addr ();
109 new_stream
.set_handle (ACE_OS::accept (this->get_handle (),
112 while (new_stream
.get_handle () == ACE_INVALID_HANDLE
117 // Reset the size of the addr, which is only necessary for UNIX
119 if (new_stream
.get_handle () != ACE_INVALID_HANDLE
121 remote_addr
->set_size (len
);
124 return this->shared_accept_finish (new_stream
,
129 // Close down the UNIX domain stream and remove the rendezvous point
130 // from the file system.
133 ACE_LSOCK_Acceptor::remove (void)
135 ACE_TRACE ("ACE_LSOCK_Acceptor::remove");
136 int result
= this->close ();
137 return ACE_OS::unlink (this->local_addr_
.get_path_name ()) == -1
138 || result
== -1 ? -1 : 0;
141 ACE_END_VERSIONED_NAMESPACE_DECL
143 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */