UPIPE_Acceptor.cpp

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

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