Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / LSOCK_Acceptor.cpp
blob4b99a906454273c0a97d66c70586ceb56a3cd4c3
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.
17 int
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_;
26 return 0;
29 void
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");
48 int
49 ACE_LSOCK_Acceptor::open (const ACE_Addr &remote_sap,
50 int reuse_addr,
51 int protocol_family,
52 int backlog,
53 int protocol)
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,
64 int reuse_addr,
65 int protocol_family,
66 int backlog,
67 int protocol)
69 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
70 if (this->open (remote_sap,
71 reuse_addr,
72 protocol_family,
73 backlog,
74 protocol) == -1)
75 ACELIB_ERROR ((LM_ERROR,
76 "ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor"));
79 // General purpose routine for accepting new connections.
81 int
82 ACE_LSOCK_Acceptor::accept (ACE_LSOCK_Stream &new_stream,
83 ACE_Addr *remote_addr,
84 ACE_Time_Value *timeout,
85 bool restart,
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,
92 restart,
93 in_blocking_mode) == -1)
94 return -1;
95 else
97 sockaddr *addr = 0;
98 int len = 0;
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 (),
108 addr,
109 &len));
110 while (new_stream.get_handle () == ACE_INVALID_HANDLE
111 && restart != 0
112 && errno == EINTR
113 && timeout == 0);
115 // Reset the size of the addr, which is only necessary for UNIX
116 // domain sockets.
117 if (new_stream.get_handle () != ACE_INVALID_HANDLE
118 && remote_addr != 0)
119 remote_addr->set_size (len);
122 return this->shared_accept_finish (new_stream,
123 in_blocking_mode,
124 reset_new_handle);
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 */