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

UPIPE_Connector.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // UPIPE_Connector.cpp
00003 // $Id: UPIPE_Connector.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:23 chad Exp $
00004 
00005 #include "ace/UPIPE_Connector.h"
00006 
00007 ACE_RCSID(ace, UPIPE_Connector, "$Id: UPIPE_Connector.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_Connector.i"
00013 #endif
00014 
00015 ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Connector)
00016 
00017 void
00018 ACE_UPIPE_Connector::dump (void) const
00019 {
00020   ACE_TRACE ("ACE_UPIPE_Connector::dump");
00021 }
00022 
00023 ACE_UPIPE_Connector::ACE_UPIPE_Connector (void)
00024 {
00025   ACE_TRACE ("ACE_UPIPE_Connector::ACE_UPIPE_Connector");
00026 }
00027 
00028 int
00029 ACE_UPIPE_Connector::connect (ACE_UPIPE_Stream &new_stream,
00030                               const ACE_UPIPE_Addr &addr,
00031                               ACE_Time_Value *timeout,
00032                               const ACE_Addr & /* local_sap */,
00033                               int /* reuse_addr */,
00034                               int flags,
00035                               int perms)
00036 {
00037   ACE_TRACE ("ACE_UPIPE_Connector::connect");
00038   ACE_ASSERT (new_stream.get_handle () == ACE_INVALID_HANDLE);
00039 
00040   ACE_HANDLE handle = ACE_Handle_Ops::handle_timed_open (timeout,
00041                                                          addr.get_path_name (),
00042                                                          flags, perms);
00043 
00044   if (handle == ACE_INVALID_HANDLE)
00045     return -1;
00046 #if !defined (ACE_WIN32)
00047   else if (ACE_OS::isastream (handle) != 1)
00048     return -1;
00049 #endif
00050   else // We're connected!
00051     {
00052       ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, new_stream.lock_, -1));
00053 
00054       ACE_UPIPE_Stream *ustream = &new_stream;
00055 
00056       new_stream.set_handle (handle);
00057       new_stream.remote_addr_ = addr; // class copy.
00058       new_stream.reference_count_++;
00059 
00060       // Now send the address of our ACE_UPIPE_Stream over this pipe
00061       // to our corresponding ACE_UPIPE_Acceptor, so he may link the
00062       // two streams.
00063       ssize_t result = ACE_OS::write (handle,
00064                                       (const char *) &ustream,
00065                                       sizeof ustream);
00066       if (result == -1)
00067         ACE_ERROR ((LM_ERROR,
00068                     ACE_LIB_TEXT ("ACE_UPIPE_Connector %p\n"),
00069                     ACE_LIB_TEXT ("write to pipe failed")));
00070 
00071       // Wait for confirmation of stream linking.
00072       ACE_Message_Block *mb_p = 0;
00073 
00074       // Our part is done, wait for server to confirm connection.
00075       result = new_stream.recv (mb_p, 0);
00076 
00077       // Do *not* coalesce the following two checks for result == -1.
00078       // They perform different checks and cannot be merged.
00079       if (result == -1)
00080           ACE_ERROR ((LM_ERROR,
00081                       ACE_LIB_TEXT ("ACE_UPIPE_Connector %p\n"),
00082                       ACE_LIB_TEXT ("no confirmation from server")));
00083       else
00084         // Close down the new_stream at this point in order to
00085         // conserve handles.  Note that we don't need the SPIPE
00086         // connection anymore since we're linked via the Message_Queue
00087         // now.
00088         new_stream.ACE_SPIPE::close ();
00089       return result;
00090     }
00091 }
00092 #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