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__ */
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Connector
)
17 ACE_FILE_Connector::dump () const
19 #if defined (ACE_HAS_DUMP)
20 ACE_TRACE ("ACE_FILE_Connector::dump");
22 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
23 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
24 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
25 #endif /* ACE_HAS_DUMP */
28 ACE_FILE_Connector::ACE_FILE_Connector ()
30 ACE_TRACE ("ACE_FILE_Connector::ACE_FILE_Connector");
34 ACE_FILE_Connector::connect (ACE_FILE_IO
&new_io
,
35 const ACE_FILE_Addr
&remote_sap
,
36 ACE_Time_Value
*timeout
,
42 ACE_TRACE ("ACE_FILE_Connector::connect");
43 ACE_ASSERT (new_io
.get_handle () == ACE_INVALID_HANDLE
);
45 ACE_HANDLE handle
= ACE_INVALID_HANDLE
;
47 // Check to see if caller has requested that we create the filename.
48 if (reinterpret_cast<const ACE_Addr
&> (
49 const_cast<ACE_FILE_Addr
&> (remote_sap
)) == ACE_Addr::sap_any
)
51 // Create a new temporary file.
52 // Use ACE_OS::mkstemp() if it is available since it avoids a
53 // race condition, and subsequently a security hole due to that
54 // race condition (specifically, a denial-of-service attack).
56 // However, using mkstemp() prevents us from doing a timed open
57 // since it opens the file for us. Better to avoid the race
59 char filename
[] = "ace-file-XXXXXX";
61 handle
= ACE_OS::mkstemp (filename
); // mkstemp() replaces "XXXXXX"
63 if (handle
== ACE_INVALID_HANDLE
64 || new_io
.addr_
.set (ACE_TEXT_CHAR_TO_TCHAR (filename
)) != 0)
67 new_io
.set_handle (handle
);
72 new_io
.addr_
= remote_sap
; // class copy.
74 handle
= ACE::handle_timed_open (timeout
,
75 new_io
.addr_
.get_path_name (),
79 new_io
.set_handle (handle
);
80 return handle
== ACE_INVALID_HANDLE
? -1 : 0;
83 ACE_END_VERSIONED_NAMESPACE_DECL