LSOCK_Acceptor.cpp

Go to the documentation of this file.
00001 // LSOCK_Acceptor.cpp,v 4.14 2005/10/28 16:14:52 ossama Exp
00002 
00003 #include "ace/LSOCK_Acceptor.h"
00004 
00005 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
00006 
00007 #include "ace/Log_Msg.h"
00008 #include "ace/OS_NS_unistd.h"
00009 #include "ace/OS_NS_sys_socket.h"
00010 
00011 ACE_RCSID(ace, LSOCK_Acceptor, "LSOCK_Acceptor.cpp,v 4.14 2005/10/28 16:14:52 ossama Exp")
00012 
00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00014 
00015 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK_Acceptor)
00016 
00017 // Return the local endpoint address.
00018 
00019 int
00020 ACE_LSOCK_Acceptor::get_local_addr (ACE_Addr &a) const
00021 {
00022   ACE_TRACE ("ACE_LSOCK_Acceptor::get_local_addr");
00023 
00024   ACE_UNIX_Addr& target = dynamic_cast<ACE_UNIX_Addr &> (a);
00025 
00026   target = this->local_addr_;
00027 
00028   return 0;
00029 }
00030 
00031 void
00032 ACE_LSOCK_Acceptor::dump (void) const
00033 {
00034 #if defined (ACE_HAS_DUMP)
00035   ACE_TRACE ("ACE_LSOCK_Acceptor::dump");
00036 
00037   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00038   this->local_addr_.dump ();
00039   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00040 #endif /* ACE_HAS_DUMP */
00041 }
00042 
00043 // Do nothing routine for constructor.
00044 
00045 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (void)
00046 {
00047   ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
00048 }
00049 
00050 int
00051 ACE_LSOCK_Acceptor::open (const ACE_Addr &remote_sap,
00052                           int reuse_addr,
00053                           int protocol_family,
00054                           int backlog,
00055                           int protocol)
00056 {
00057   ACE_TRACE ("ACE_LSOCK_Acceptor::open");
00058   this->local_addr_ = *((ACE_UNIX_Addr *) &remote_sap); // This is a gross hack...
00059   return ACE_SOCK_Acceptor::open (remote_sap, reuse_addr,
00060                                   protocol_family, backlog, protocol);
00061 }
00062 
00063 // General purpose routine for performing server ACE_SOCK creation.
00064 
00065 ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor (const ACE_Addr &remote_sap,
00066                                         int reuse_addr,
00067                                         int protocol_family,
00068                                         int backlog,
00069                                         int protocol)
00070 {
00071   ACE_TRACE ("ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor");
00072   if (this->open (remote_sap,
00073                   reuse_addr,
00074                   protocol_family,
00075                   backlog,
00076                   protocol) == -1)
00077     ACE_ERROR ((LM_ERROR,
00078                 "ACE_LSOCK_Acceptor::ACE_LSOCK_Acceptor"));
00079 }
00080 
00081 // General purpose routine for accepting new connections.
00082 
00083 int
00084 ACE_LSOCK_Acceptor::accept (ACE_LSOCK_Stream &new_stream,
00085                             ACE_Addr *remote_addr,
00086                             ACE_Time_Value *timeout,
00087                             int restart,
00088                             int reset_new_handle) const
00089 {
00090   ACE_TRACE ("ACE_LSOCK_Acceptor::accept");
00091 
00092   int in_blocking_mode = 0;
00093   if (this->shared_accept_start (timeout,
00094                                  restart,
00095                                  in_blocking_mode) == -1)
00096     return -1;
00097   else
00098     {
00099       sockaddr *addr = 0;
00100       int len = 0;
00101 
00102       if (remote_addr != 0)
00103         {
00104           len = remote_addr->get_size ();
00105           addr = (sockaddr *) remote_addr->get_addr ();
00106         }
00107 
00108       do
00109         new_stream.set_handle (ACE_OS::accept (this->get_handle (),
00110                                                addr,
00111                                                &len));
00112       while (new_stream.get_handle () == ACE_INVALID_HANDLE
00113              && restart != 0
00114              && errno == EINTR
00115              && timeout == 0);
00116 
00117       // Reset the size of the addr, which is only necessary for UNIX
00118       // domain sockets.
00119       if (new_stream.get_handle () != ACE_INVALID_HANDLE
00120           && remote_addr != 0)
00121         remote_addr->set_size (len);
00122     }
00123 
00124   return this->shared_accept_finish (new_stream,
00125                                      in_blocking_mode,
00126                                      reset_new_handle);
00127 }
00128 
00129 // Close down the UNIX domain stream and remove the rendezvous point
00130 // from the file system.
00131 
00132 int
00133 ACE_LSOCK_Acceptor::remove (void)
00134 {
00135   ACE_TRACE ("ACE_LSOCK_Acceptor::remove");
00136   int result = this->close ();
00137   return ACE_OS::unlink (this->local_addr_.get_path_name ()) == -1
00138     || result == -1 ? -1 : 0;
00139 }
00140 
00141 ACE_END_VERSIONED_NAMESPACE_DECL
00142 
00143 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */

Generated on Thu Nov 9 09:41:53 2006 for ACE by doxygen 1.3.6