Correct feature names
[ACE_TAO.git] / ACE / ace / FILE_Connector.cpp
blob5ff46dec59242c7128ebc58a003b731ccb898b27
1 #include "ace/FILE_Connector.h"
2 #include "ace/Handle_Ops.h"
3 #include "ace/OS_NS_stdlib.h"
4 #if defined (ACE_HAS_ALLOC_HOOKS)
5 # include "ace/Malloc_Base.h"
6 #endif /* ACE_HAS_ALLOC_HOOKS */
8 #if !defined (__ACE_INLINE__)
9 #include "ace/FILE_Connector.inl"
10 #endif /* __ACE_INLINE__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Connector)
18 void
19 ACE_FILE_Connector::dump (void) const
21 #if defined (ACE_HAS_DUMP)
22 ACE_TRACE ("ACE_FILE_Connector::dump");
24 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
25 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
26 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
27 #endif /* ACE_HAS_DUMP */
30 ACE_FILE_Connector::ACE_FILE_Connector (void)
32 ACE_TRACE ("ACE_FILE_Connector::ACE_FILE_Connector");
35 int
36 ACE_FILE_Connector::connect (ACE_FILE_IO &new_io,
37 const ACE_FILE_Addr &remote_sap,
38 ACE_Time_Value *timeout,
39 const ACE_Addr &,
40 int,
41 int flags,
42 int perms)
44 ACE_TRACE ("ACE_FILE_Connector::connect");
45 ACE_ASSERT (new_io.get_handle () == ACE_INVALID_HANDLE);
47 ACE_HANDLE handle = ACE_INVALID_HANDLE;
49 // Check to see if caller has requested that we create the filename.
50 if (reinterpret_cast<const ACE_Addr &> (
51 const_cast<ACE_FILE_Addr &> (remote_sap)) == ACE_Addr::sap_any)
53 // Create a new temporary file.
54 // Use ACE_OS::mkstemp() if it is available since it avoids a
55 // race condition, and subsequently a security hole due to that
56 // race condition (specifically, a denial-of-service attack).
58 // However, using mkstemp() prevents us from doing a timed open
59 // since it opens the file for us. Better to avoid the race
60 // condition.
61 char filename[] = "ace-file-XXXXXX";
63 handle = ACE_OS::mkstemp (filename); // mkstemp() replaces "XXXXXX"
65 if (handle == ACE_INVALID_HANDLE
66 || new_io.addr_.set (ACE_TEXT_CHAR_TO_TCHAR (filename)) != 0)
67 return -1;
69 new_io.set_handle (handle);
71 return 0;
73 else
74 new_io.addr_ = remote_sap; // class copy.
76 handle = ACE::handle_timed_open (timeout,
77 new_io.addr_.get_path_name (),
78 flags,
79 perms);
81 new_io.set_handle (handle);
82 return handle == ACE_INVALID_HANDLE ? -1 : 0;
85 ACE_END_VERSIONED_NAMESPACE_DECL