1 #include "ace/LSOCK_Acceptor.h"
3 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
5 #include "ace/Log_Category.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/OS_NS_sys_socket.h"
8 #if defined (ACE_HAS_ALLOC_HOOKS)
9 # include "ace/Malloc_Base.h"
10 #endif /* ACE_HAS_ALLOC_HOOKS */
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK_Acceptor
)
16 // Return the local endpoint address.
18 ACE_LSOCK_Acceptor::get_local_addr (ACE_Addr
&a
) const
20 ACE_TRACE ("ACE_LSOCK_Acceptor::get_local_addr");
22 ACE_UNIX_Addr
& target
= dynamic_cast<ACE_UNIX_Addr
&> (a
);
24 target
= this->local_addr_
;
30 ACE_LSOCK_Acceptor::dump () const
32 #if defined (ACE_HAS_DUMP)
33 ACE_TRACE ("ACE_LSOCK_Acceptor::dump");
35 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
36 this->local_addr_
.dump ();
37 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
38 #endif /* ACE_HAS_DUMP */
41 // Do nothing routine for constructor.
43 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor ()
45 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
49 ACE_LSOCK_Acceptor::open (const ACE_Addr
&remote_sap
,
55 ACE_TRACE ("ACE_LSOCK_Acceptor::open");
56 this->local_addr_
= *((ACE_UNIX_Addr
*) &remote_sap
); // This is a gross hack...
57 return ACE_SOCK_Acceptor::open (remote_sap
, reuse_addr
,
58 protocol_family
, backlog
, protocol
);
61 // General purpose routine for performing server ACE_SOCK creation.
63 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (const ACE_Addr
&remote_sap
,
69 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
70 if (this->open (remote_sap
,
75 ACELIB_ERROR ((LM_ERROR
,
76 "ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor"));
79 // General purpose routine for accepting new connections.
82 ACE_LSOCK_Acceptor::accept (ACE_LSOCK_Stream
&new_stream
,
83 ACE_Addr
*remote_addr
,
84 ACE_Time_Value
*timeout
,
86 bool reset_new_handle
) const
88 ACE_TRACE ("ACE_LSOCK_Acceptor::accept");
90 int in_blocking_mode
= 0;
91 if (this->shared_accept_start (timeout
,
93 in_blocking_mode
) == -1)
100 if (remote_addr
!= 0)
102 len
= remote_addr
->get_size ();
103 addr
= (sockaddr
*) remote_addr
->get_addr ();
107 new_stream
.set_handle (ACE_OS::accept (this->get_handle (),
110 while (new_stream
.get_handle () == ACE_INVALID_HANDLE
115 // Reset the size of the addr, which is only necessary for UNIX
117 if (new_stream
.get_handle () != ACE_INVALID_HANDLE
119 remote_addr
->set_size (len
);
122 return this->shared_accept_finish (new_stream
,
127 // Close down the UNIX domain stream and remove the rendezvous point
128 // from the file system.
131 ACE_LSOCK_Acceptor::remove ()
133 ACE_TRACE ("ACE_LSOCK_Acceptor::remove");
134 int result
= this->close ();
135 return ACE_OS::unlink (this->local_addr_
.get_path_name ()) == -1
136 || result
== -1 ? -1 : 0;
139 ACE_END_VERSIONED_NAMESPACE_DECL
141 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */