Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / LSOCK_Acceptor.cpp
blob28a45ea3faa961ecda92b52c88180275f63f49b0
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.
20 int
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_;
29 return 0;
32 void
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");
51 int
52 ACE_LSOCK_Acceptor::open (const ACE_Addr &remote_sap,
53 int reuse_addr,
54 int protocol_family,
55 int backlog,
56 int protocol)
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,
67 int reuse_addr,
68 int protocol_family,
69 int backlog,
70 int protocol)
72 ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
73 if (this->open (remote_sap,
74 reuse_addr,
75 protocol_family,
76 backlog,
77 protocol) == -1)
78 ACELIB_ERROR ((LM_ERROR,
79 "ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor"));
82 // General purpose routine for accepting new connections.
84 int
85 ACE_LSOCK_Acceptor::accept (ACE_LSOCK_Stream &new_stream,
86 ACE_Addr *remote_addr,
87 ACE_Time_Value *timeout,
88 bool restart,
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,
95 restart,
96 in_blocking_mode) == -1)
97 return -1;
98 else
100 sockaddr *addr = 0;
101 int len = 0;
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 (),
111 addr,
112 &len));
113 while (new_stream.get_handle () == ACE_INVALID_HANDLE
114 && restart != 0
115 && errno == EINTR
116 && timeout == 0);
118 // Reset the size of the addr, which is only necessary for UNIX
119 // domain sockets.
120 if (new_stream.get_handle () != ACE_INVALID_HANDLE
121 && remote_addr != 0)
122 remote_addr->set_size (len);
125 return this->shared_accept_finish (new_stream,
126 in_blocking_mode,
127 reset_new_handle);
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 */