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

UPIPE_Acceptor.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // UPIPE_Acceptor.cpp
00003 // $Id: UPIPE_Acceptor.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:23 chad Exp $
00004 
00005 #include "ace/UPIPE_Acceptor.h"
00006 
00007 ACE_RCSID(ace, UPIPE_Acceptor, "$Id: UPIPE_Acceptor.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:23 chad Exp $")
00008 
00009 #if defined (ACE_HAS_THREADS)
00010 
00011 #if defined (ACE_LACKS_INLINE_FUNCTIONS)
00012 #include "ace/UPIPE_Acceptor.i"
00013 #endif
00014 
00015 ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Acceptor)
00016 
00017 void
00018 ACE_UPIPE_Acceptor::dump (void) const
00019 {
00020   ACE_TRACE ("ACE_UPIPE_Acceptor::dump");
00021 }
00022 
00023 /* Do nothing routine for constructor. */
00024 
00025 ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor (void)
00026   : mb_ (sizeof (ACE_UPIPE_Stream *))
00027 {
00028   ACE_TRACE ("ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor");
00029 }
00030 
00031 ACE_UPIPE_Acceptor::~ACE_UPIPE_Acceptor (void)
00032 {
00033   ACE_TRACE ("ACE_UPIPE_Acceptor::~ACE_UPIPE_Acceptor");
00034 }
00035 
00036 // General purpose routine for performing server ACE_UPIPE.
00037 
00038 int
00039 ACE_UPIPE_Acceptor::open (const ACE_UPIPE_Addr &local_addr,
00040                           int reuse_addr)
00041 {
00042   ACE_TRACE ("ACE_UPIPE_Acceptor::open");
00043   return this->ACE_SPIPE_Acceptor::open (local_addr, reuse_addr);
00044 }
00045 
00046 int
00047 ACE_UPIPE_Acceptor::close (void)
00048 {
00049   ACE_TRACE ("ACE_UPIPE_Acceptor::close");
00050   return this->ACE_SPIPE_Acceptor::close ();
00051 }
00052 
00053 // General purpose routine for accepting new connections.
00054 
00055 ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor (const ACE_UPIPE_Addr &local_addr,
00056                                         int reuse_addr)
00057   : mb_ (sizeof (ACE_UPIPE_Stream *))
00058 {
00059   ACE_TRACE ("ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor");
00060 
00061   if (this->open (local_addr, reuse_addr) == -1)
00062     ACE_ERROR ((LM_ERROR,
00063                 ACE_LIB_TEXT ("%p\n"),
00064                 ACE_LIB_TEXT ("ACE_UPIPE_Acceptor")));
00065 }
00066 
00067 int
00068 ACE_UPIPE_Acceptor::accept (ACE_UPIPE_Stream &new_stream,
00069                             ACE_UPIPE_Addr *remote_addr,
00070                             ACE_Time_Value *timeout,
00071                             int restart,
00072                             int reset_new_handle)
00073 {
00074   ACE_TRACE ("ACE_UPIPE_Acceptor::accept");
00075   ACE_UNUSED_ARG (reset_new_handle);
00076 
00077   ACE_SPIPE_Stream new_io;
00078 
00079   if (this->ACE_SPIPE_Acceptor::accept (new_io, remote_addr,
00080                                         timeout, restart) == -1)
00081     return -1;
00082   else
00083     {
00084       ACE_UPIPE_Stream *remote_stream = 0;
00085 
00086       ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, new_stream.lock_, -1));
00087 
00088       new_stream.set_handle (new_io.get_handle ());
00089       new_stream.reference_count_++;
00090 
00091       // Transfer address ownership.
00092       new_io.get_local_addr (new_stream.local_addr_);
00093       new_io.get_remote_addr (new_stream.remote_addr_);
00094 
00095       // Now that we got the handle, we'll read the address of the
00096       // connector-side ACE_UPIPE_Stream out of the pipe and link that
00097       // ACE_UPIPE_Stream to our ACE_UPIPE_Stream.
00098 
00099       if (ACE_OS::read (new_stream.get_handle (),
00100                         (char *) &remote_stream,
00101                         sizeof remote_stream) == -1)
00102         ACE_ERROR ((LM_ERROR,
00103                     ACE_LIB_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
00104                     ACE_LIB_TEXT ("read stream address failed")));
00105       else if (new_stream.stream_.link (remote_stream->stream_) == -1)
00106         ACE_ERROR ((LM_ERROR,
00107                     ACE_LIB_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
00108                     ACE_LIB_TEXT ("link streams failed")));
00109       // Send a message over the new streampipe to confirm acceptance.
00110       else if (new_stream.send (&mb_, 0) == -1)
00111         ACE_ERROR ((LM_ERROR,
00112                     ACE_LIB_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
00113                     ACE_LIB_TEXT ("linked stream.put failed")));
00114 
00115       // Close down the new_stream at this point in order to conserve
00116       // handles.  Note that we don't need the SPIPE connection
00117       // anymore since we're now linked via the <Message_Queue>.
00118       new_stream.ACE_SPIPE::close ();
00119       return 0;
00120     }
00121 }
00122 
00123 #endif /* ACE_HAS_THREADS */

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