summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ACE/ace/DLL_Manager.cpp157
-rw-r--r--ACE/ace/DLL_Manager.h25
2 files changed, 87 insertions, 95 deletions
diff --git a/ACE/ace/DLL_Manager.cpp b/ACE/ace/DLL_Manager.cpp
index a3ab8df7aa8..260ba863699 100644
--- a/ACE/ace/DLL_Manager.cpp
+++ b/ACE/ace/DLL_Manager.cpp
@@ -117,58 +117,14 @@ ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
this->get_dll_names (dll_name, dll_names);
#endif
- ACE_Array_Iterator<ACE_TString> name_iter (dll_names);
ACE_TString *name = 0;
- while (name_iter.next (name))
+ for (ACE_Array_Iterator<ACE_TString> name_iter (dll_names);
+ name_iter.next (name); name_iter.advance ())
{
- // The ACE_SHLIB_HANDLE object is obtained.
- this->handle_ = ACE_OS::dlopen (name->c_str (),
- open_mode);
-
- if (ACE::debug ())
- {
- ACE_TString err;
- ACELIB_DEBUG ((LM_DEBUG,
- ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
- ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
- name->c_str (),
- open_mode,
- ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
- ? ACE_TEXT ("succeeded")
- : ACE_TEXT ("failed")),
- this->error (err).c_str()));
- }
-
- if (this->handle_ != ACE_SHLIB_INVALID_HANDLE) // Good one?
+ if (this->open_i (name->c_str (), open_mode))
break;
- // If errno is ENOENT we just skip over this one,
- // anything else - like an undefined symbol, for
- // instance must be flagged here or the next error will
- // mask it.
- // @TODO: If we've found our DLL _and_ it's
- // broken, should we continue at all?
- if ((errno != ENOENT) && (errors || ACE::debug ()))
- {
- ACE_TString errtmp;
- if (errors)
- {
- errors->push (this->error (errtmp));
- }
-
- if (ACE::debug ())
- {
- if (!errors)
- this->error (errtmp);
- ACELIB_ERROR ((LM_ERROR,
- ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
- ACE_TEXT ("(\'%s\') failed, errno=")
- ACE_TEXT ("%d: <%s>\n"),
- name->c_str (),
- ACE_ERRNO_GET,
- errtmp.c_str ()));
- }
- }
+ this->log_error (name->c_str (), errors);
#if defined (AIX)
# define SHR_O ACE_TEXT("(shr.o)")
@@ -203,57 +159,12 @@ ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
}
open_mode |= RTLD_MEMBER;
- this->handle_ = ACE_OS::dlopen (aix_pathname, open_mode);
-
- if (ACE::debug ())
- {
- ACE_TString err;
- ACELIB_DEBUG ((LM_DEBUG,
- ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
- ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
- aix_pathname,
- open_mode,
- (this->handle_ != ACE_SHLIB_INVALID_HANDLE
- ? ACE_TEXT ("succeeded")
- : ACE_TEXT ("failed")),
- this->error(err).c_str()));
- }
-
- if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)
+ if (this->open_i (name->c_str (), open_mode))
break;
- // If errno is ENOENT we just skip over this one, anything
- // else - like an undefined symbol, for instance
- // must be flagged here or the next error will mask it.
- //
- // @TODO: If we've found our DLL _and_ it's broken,
- // should we continue at all?
- if ((errno != ENOENT) && (errors || ACE::debug ()))
- {
- ACE_TString errtmp;
- if (errors)
- {
- errors->push (this->error (errtmp));
- }
-
- if (ACE::debug ())
- {
- if (!errors)
- this->error (errtmp);
- ACELIB_ERROR ((LM_ERROR,
- ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
- ACE_TEXT ("(\'%s\') failed, errno=")
- ACE_TEXT ("%d: <%s>\n"),
- name->c_str (),
- ACE_ERRNO_GET,
- errtmp.c_str ()));
- }
- }
-
+ this->log_error (name->c_str (), errors);
}
#endif /* AIX */
-
- name_iter.advance ();
}
if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
@@ -560,6 +471,62 @@ ACE_DLL_Handle::get_dll_names (const ACE_TCHAR *dll_name,
return;
}
+bool
+ACE_DLL_Handle::open_i (const ACE_TCHAR *dll_name, int open_mode)
+{
+ // The ACE_SHLIB_HANDLE object is obtained.
+ this->handle_ = ACE_OS::dlopen (dll_name, open_mode);
+
+ if (ACE::debug ())
+ {
+ ACE_TString err;
+ ACELIB_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
+ ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
+ dll_name,
+ open_mode,
+ ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
+ ? ACE_TEXT ("succeeded")
+ : ACE_TEXT ("failed")),
+ this->error (err).c_str()));
+ }
+
+ return this->handle_ != ACE_SHLIB_INVALID_HANDLE;
+}
+
+void
+ACE_DLL_Handle::log_error (const ACE_TCHAR *dll_name, ERROR_STACK *errors)
+{
+ // If errno is ENOENT we just skip over this one, anything
+ // else - like an undefined symbol, for instance
+ // must be flagged here or the next error will mask it.
+ //
+ // @TODO: If we've found our DLL _and_ it's broken,
+ // should we continue at all?
+ if (errno != ENOENT && (errors || ACE::debug ()))
+ {
+ ACE_TString errtmp;
+ if (errors)
+ {
+ errors->push (this->error (errtmp));
+ }
+
+ if (ACE::debug ())
+ {
+ if (!errors)
+ this->error (errtmp);
+
+ ACELIB_ERROR ((LM_ERROR,
+ ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
+ ACE_TEXT ("(\'%s\') failed, errno=")
+ ACE_TEXT ("%d: <%s>\n"),
+ dll_name,
+ ACE_ERRNO_GET,
+ errtmp.c_str ()));
+ }
+ }
+}
+
/******************************************************************/
// Pointer to the Singleton instance.
diff --git a/ACE/ace/DLL_Manager.h b/ACE/ace/DLL_Manager.h
index b9876d7a1b6..9fea80a3085 100644
--- a/ACE/ace/DLL_Manager.h
+++ b/ACE/ace/DLL_Manager.h
@@ -154,6 +154,31 @@ private:
void get_dll_names (const ACE_TCHAR *dll_name,
ACE_Array<ACE_TString> &try_names);
+ /**
+ * This method opens and dynamically links a library/DLL.
+ * @param dll_name The filename or path of the DLL to load.
+ * @param open_mode Flags to alter the actions taken when loading the DLL.
+ * The possible values are:
+ * @li @c RTLD_LAZY (this the default): loads identifier symbols but
+ * not the symbols for functions, which are loaded dynamically
+ * on demand.
+ * @li @c RTLD_NOW: performs all necessary relocations when
+ * @a dll_name is first loaded
+ * @li @c RTLD_GLOBAL: makes symbols available for relocation
+ * processing of any other DLLs.
+ * @retval false On failure
+ * @retval true On success.
+ */
+ bool open_i (const ACE_TCHAR *dll_name, int open_mode);
+
+ /**
+ * This method logs error of opening the DLL.
+ * @param dll_name The filename or path of the DLL to load.
+ * @param errors Optional address of an error stack to collect any errors
+ * encountered.
+ */
+ void log_error (const ACE_TCHAR *dll_name, ERROR_STACK *errors);
+
/// Disallow copying and assignment since we don't handle them.
ACE_DLL_Handle (const ACE_DLL_Handle &);
void operator= (const ACE_DLL_Handle &);