Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

LSOCK_Acceptor.cpp

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

Generated on Mon Jun 16 11:20:02 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002