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 */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK_Acceptor
)
18 // Return the local endpoint address.
21 ACE_LSOCK_Acceptor::get_local_addr (ACE_Addr
&a
) const
23 ACE_TRACE ("ACE_LSOCK_Acceptor::get_local_addr");
25 ACE_UNIX_Addr
& target
= dynamic_cast<ACE_UNIX_Addr
&> (a
);
27 target
= this->local_addr_
;
33 ACE_LSOCK_Acceptor::dump (void) const
35 #if defined (ACE_HAS_DUMP)
36 ACE_TRACE ("ACE_LSOCK_Acceptor::dump");
38 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
39 this->local_addr_
.dump ();
40 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
41 #endif /* ACE_HAS_DUMP */
44 // Do nothing routine for constructor.
46 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (void)
48 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
52 ACE_LSOCK_Acceptor::open (const ACE_Addr
&remote_sap
,
58 ACE_TRACE ("ACE_LSOCK_Acceptor::open");
59 this->local_addr_
= *((ACE_UNIX_Addr
*) &remote_sap
); // This is a gross hack...
60 return ACE_SOCK_Acceptor::open (remote_sap
, reuse_addr
,
61 protocol_family
, backlog
, protocol
);
64 // General purpose routine for performing server ACE_SOCK creation.
66 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (const ACE_Addr
&remote_sap
,
72 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
73 if (this->open (remote_sap
,
78 ACELIB_ERROR ((LM_ERROR
,
79 "ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor"));
82 // General purpose routine for accepting new connections.
85 ACE_LSOCK_Acceptor::accept (ACE_LSOCK_Stream
&new_stream
,
86 ACE_Addr
*remote_addr
,
87 ACE_Time_Value
*timeout
,
89 bool reset_new_handle
) const
91 ACE_TRACE ("ACE_LSOCK_Acceptor::accept");
93 int in_blocking_mode
= 0;
94 if (this->shared_accept_start (timeout
,
96 in_blocking_mode
) == -1)
103 if (remote_addr
!= 0)
105 len
= remote_addr
->get_size ();
106 addr
= (sockaddr
*) remote_addr
->get_addr ();
110 new_stream
.set_handle (ACE_OS::accept (this->get_handle (),
113 while (new_stream
.get_handle () == ACE_INVALID_HANDLE
118 // Reset the size of the addr, which is only necessary for UNIX
120 if (new_stream
.get_handle () != ACE_INVALID_HANDLE
122 remote_addr
->set_size (len
);
125 return this->shared_accept_finish (new_stream
,
130 // Close down the UNIX domain stream and remove the rendezvous point
131 // from the file system.
134 ACE_LSOCK_Acceptor::remove (void)
136 ACE_TRACE ("ACE_LSOCK_Acceptor::remove");
137 int result
= this->close ();
138 return ACE_OS::unlink (this->local_addr_
.get_path_name ()) == -1
139 || result
== -1 ? -1 : 0;
142 ACE_END_VERSIONED_NAMESPACE_DECL
144 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */