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

FILE_Connector.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // FILE_Connector.cpp
00003 // $Id: FILE_Connector.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:21 chad Exp $
00004 
00005 #include "ace/FILE_Connector.h"
00006 #include "ace/Handle_Ops.h"
00007 
00008 #if defined (ACE_LACKS_INLINE_FUNCTIONS)
00009 #include "ace/FILE_Connector.i"
00010 #endif
00011 
00012 ACE_RCSID(ace, FILE_Connector, "$Id: FILE_Connector.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:21 chad Exp $")
00013 
00014 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Connector)
00015 
00016 void
00017 ACE_FILE_Connector::dump (void) const
00018 {
00019   ACE_TRACE ("ACE_FILE_Connector::dump");
00020 
00021   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00022   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\n")));
00023   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00024 }
00025 
00026 ACE_FILE_Connector::ACE_FILE_Connector (void)
00027 {
00028   ACE_TRACE ("ACE_FILE_Connector::ACE_FILE_Connector");
00029 }
00030 
00031 int
00032 ACE_FILE_Connector::connect (ACE_FILE_IO &new_io,
00033                              const ACE_FILE_Addr &remote_sap,
00034                              ACE_Time_Value *timeout,
00035                              const ACE_Addr &,
00036                              int,
00037                              int flags,
00038                              int perms)
00039 {
00040   ACE_TRACE ("ACE_FILE_Connector::connect");
00041   ACE_ASSERT (new_io.get_handle () == ACE_INVALID_HANDLE);
00042 
00043   ACE_HANDLE handle = ACE_INVALID_HANDLE;
00044 
00045   // Check to see if caller has requested that we create the filename.
00046   if (ACE_reinterpret_cast (const ACE_Addr &,
00047                             ACE_const_cast (ACE_FILE_Addr &,
00048                                             remote_sap)) == ACE_Addr::sap_any)
00049     {
00050       // Create a new temporary file.
00051 #ifdef ACE_LACKS_MKSTEMP
00052       new_io.addr_ =
00053         ACE_FILE_Addr (ACE_sap_any_cast (ACE_FILE_Addr &)); // class copy.
00054 #else
00055       // Use ACE_OS::mkstemp() if it is available since it avoids a
00056       // race condition, and subsequently a security hole due to that
00057       // race condition (specifically, a denial-of-service attack).
00058       //
00059       // However, using mkstemp() prevents us from doing a timed open
00060       // since it opens the file for us.  Better to avoid the race
00061       // condition.
00062       char filename[] = "ace-file-XXXXXX";
00063 
00064       handle = ACE_OS::mkstemp (filename); // mkstemp() replaces "XXXXXX"
00065 
00066       if (handle == ACE_INVALID_HANDLE
00067           || new_io.addr_.set (filename) != 0)
00068         return -1;
00069 
00070       new_io.set_handle (handle);
00071 
00072       return 0;
00073 #endif  /* ACE_LACKS_MKSTEMP */
00074     }
00075   else
00076     new_io.addr_ = remote_sap; // class copy.
00077 
00078   handle = ACE_Handle_Ops::handle_timed_open (timeout,
00079                                               new_io.addr_.get_path_name (),
00080                                               flags,
00081                                               perms);
00082 
00083   new_io.set_handle (handle);
00084   return handle == ACE_INVALID_HANDLE ? -1 : 0;
00085 }

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