00001
00002
00003
00004 #include "ace/FILE_Connector.h"
00005 #include "ace/Handle_Ops.h"
00006 #include "ace/OS_NS_stdlib.h"
00007
00008 #if !defined (__ACE_INLINE__)
00009 #include "ace/FILE_Connector.inl"
00010 #endif
00011
00012 ACE_RCSID(ace, FILE_Connector, "FILE_Connector.cpp,v 4.22 2005/10/28 16:14:52 ossama Exp")
00013
00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00015
00016 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Connector)
00017
00018 void
00019 ACE_FILE_Connector::dump (void) const
00020 {
00021 #if defined (ACE_HAS_DUMP)
00022 ACE_TRACE ("ACE_FILE_Connector::dump");
00023
00024 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00025 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00026 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00027 #endif
00028 }
00029
00030 ACE_FILE_Connector::ACE_FILE_Connector (void)
00031 {
00032 ACE_TRACE ("ACE_FILE_Connector::ACE_FILE_Connector");
00033 }
00034
00035 int
00036 ACE_FILE_Connector::connect (ACE_FILE_IO &new_io,
00037 const ACE_FILE_Addr &remote_sap,
00038 ACE_Time_Value *timeout,
00039 const ACE_Addr &,
00040 int,
00041 int flags,
00042 int perms)
00043 {
00044 ACE_TRACE ("ACE_FILE_Connector::connect");
00045 ACE_ASSERT (new_io.get_handle () == ACE_INVALID_HANDLE);
00046
00047 ACE_HANDLE handle = ACE_INVALID_HANDLE;
00048
00049
00050 if (reinterpret_cast<const ACE_Addr &> (
00051 const_cast<ACE_FILE_Addr &> (remote_sap)) == ACE_Addr::sap_any)
00052 {
00053
00054 #ifdef ACE_LACKS_MKSTEMP
00055 new_io.addr_ =
00056 ACE_FILE_Addr (ACE_sap_any_cast (ACE_FILE_Addr &));
00057 #else
00058
00059
00060
00061
00062
00063
00064
00065 char filename[] = "ace-file-XXXXXX";
00066
00067 handle = ACE_OS::mkstemp (filename);
00068
00069 if (handle == ACE_INVALID_HANDLE
00070 || new_io.addr_.set (ACE_TEXT_CHAR_TO_TCHAR (filename)) != 0)
00071 return -1;
00072
00073 new_io.set_handle (handle);
00074
00075 return 0;
00076 #endif
00077 }
00078 else
00079 new_io.addr_ = remote_sap;
00080
00081 handle = ACE::handle_timed_open (timeout,
00082 new_io.addr_.get_path_name (),
00083 flags,
00084 perms);
00085
00086 new_io.set_handle (handle);
00087 return handle == ACE_INVALID_HANDLE ? -1 : 0;
00088 }
00089
00090 ACE_END_VERSIONED_NAMESPACE_DECL