⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynaloader.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
Perl-to-C 'glue'.  There is, for example, no mechanism for calling a Clibrary function or supplying arguments.  A C::DynaLib moduleis available from CPAN sites which performs that function for somecommon system types.  And since the year 2000, there's also Inline::C,a module that allows you to write Perl subroutines in C.  Also availablefrom your local CPAN site.DynaLoader Interface Summary  @dl_library_path  @dl_resolve_using  @dl_require_symbols  $dl_debug  @dl_librefs  @dl_modules  @dl_shared_objects                                                  Implemented in:  bootstrap($modulename)                               Perl  @filepaths = dl_findfile(@names)                     Perl  $flags = $modulename->dl_load_flags                  Perl  $symref  = dl_find_symbol_anywhere($symbol)          Perl  $libref  = dl_load_file($filename, $flags)           C  $status  = dl_unload_file($libref)                   C  $symref  = dl_find_symbol($libref, $symbol)          C  @symbols = dl_undef_symbols()                        C  dl_install_xsub($name, $symref [, $filename])        C  $message = dl_error                                  C=over 4=item @dl_library_pathThe standard/default list of directories in which dl_findfile() willsearch for libraries etc.  Directories are searched in order:$dl_library_path[0], [1], ... etc@dl_library_path is initialised to hold the list of 'normal' directories(F</usr/lib>, etc) determined by B<Configure> (C<$Config{'libpth'}>).  This shouldensure portability across a wide range of platforms.@dl_library_path should also be initialised with any other directoriesthat can be determined from the environment at runtime (such asLD_LIBRARY_PATH for SunOS).After initialisation @dl_library_path can be manipulated by anapplication using push and unshift before calling dl_findfile().Unshift can be used to add directories to the front of the search ordereither to save search time or to override libraries with the same namein the 'normal' directories.The load function that dl_load_file() calls may require an absolutepathname.  The dl_findfile() function and @dl_library_path can beused to search for and return the absolute pathname for thelibrary/object that you wish to load.=item @dl_resolve_usingA list of additional libraries or other shared objects which can beused to resolve any undefined symbols that might be generated by alater call to load_file().This is only required on some platforms which do not handle dependentlibraries automatically.  For example the Socket Perl extensionlibrary (F<auto/Socket/Socket.so>) contains references to many socketfunctions which need to be resolved when it's loaded.  Most platformswill automatically know where to find the 'dependent' library (e.g.,F</usr/lib/libsocket.so>).  A few platforms need to be told thelocation of the dependent library explicitly.  Use @dl_resolve_usingfor this.Example usage:    @dl_resolve_using = dl_findfile('-lsocket');=item @dl_require_symbolsA list of one or more symbol names that are in the library/object fileto be dynamically loaded.  This is only required on some platforms.=item @dl_librefsAn array of the handles returned by successful calls to dl_load_file(),made by bootstrap, in the order in which they were loaded.Can be used with dl_find_symbol() to look for a symbol in any ofthe loaded files.=item @dl_modulesAn array of module (package) names that have been bootstrap'ed.=item @dl_shared_objectsAn array of file names for the shared objects that were loaded.=item dl_error()Syntax:    $message = dl_error();Error message text from the last failed DynaLoader function.  Notethat, similar to errno in unix, a successful function call does notreset this message.Implementations should detect the error as soon as it occurs in any ofthe other functions and save the corresponding message for laterretrieval.  This will avoid problems on some platforms (such as SunOS)where the error message is very temporary (e.g., dlerror()).=item $dl_debugInternal debugging messages are enabled when $dl_debug is set true.Currently setting $dl_debug only affects the Perl side of theDynaLoader.  These messages should help an application developer toresolve any DynaLoader usage problems.$dl_debug is set to C<$ENV{'PERL_DL_DEBUG'}> if defined.For the DynaLoader developer/porter there is a similar debuggingvariable added to the C code (see dlutils.c) and enabled if Perl wasbuilt with the B<-DDEBUGGING> flag.  This can also be set via thePERL_DL_DEBUG environment variable.  Set to 1 for minimal information orhigher for more.=item dl_findfile()Syntax:    @filepaths = dl_findfile(@names)Determine the full paths (including file suffix) of one or moreloadable files given their generic names and optionally one or moredirectories.  Searches directories in @dl_library_path by default andreturns an empty list if no files were found.Names can be specified in a variety of platform independent forms.  Anynames in the form B<-lname> are converted into F<libname.*>, where F<.*> isan appropriate suffix for the platform.If a name does not already have a suitable prefix and/or suffix thenthe corresponding file will be searched for by trying combinations ofprefix and suffix appropriate to the platform: "$name.o", "lib$name.*"and "$name".If any directories are included in @names they are searched before@dl_library_path.  Directories may be specified as B<-Ldir>.  Any othernames are treated as filenames to be searched for.Using arguments of the form C<-Ldir> and C<-lname> is recommended.Example:     @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));=item dl_expandspec()Syntax:    $filepath = dl_expandspec($spec)Some unusual systems, such as VMS, require special filename handling inorder to deal with symbolic names for files (i.e., VMS's Logical Names).To support these systems a dl_expandspec() function can be implementedeither in the F<dl_*.xs> file or code can be added to the autoloadabledl_expandspec() function in F<DynaLoader.pm>.  See F<DynaLoader.pm> formore information.=item dl_load_file()Syntax:    $libref = dl_load_file($filename, $flags)Dynamically load $filename, which must be the path to a shared objector library.  An opaque 'library reference' is returned as a handle forthe loaded object.  Returns undef on error.The $flags argument to alters dl_load_file behaviour.  Assigned bits: 0x01  make symbols available for linking later dl_load_file's.       (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))       (ignored under VMS; this is a normal part of image linking)(On systems that provide a handle for the loaded object such as SunOSand HPUX, $libref will be that handle.  On other systems $libref willtypically be $filename or a pointer to a buffer containing $filename.The application should not examine or alter $libref in any way.)This is the function that does the real work.  It should use thecurrent values of @dl_require_symbols and @dl_resolve_using if required.    SunOS: dlopen($filename)    HP-UX: shl_load($filename)    Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)    NeXT:  rld_load($filename, @dl_resolve_using)    VMS:   lib$find_image_symbol($filename,$dl_require_symbols[0])(The dlopen() function is also used by Solaris and some versions ofLinux, and is a common choice when providing a "wrapper" on othermechanisms as is done in the OS/2 port.)=item dl_unload_file()Syntax:    $status = dl_unload_file($libref)Dynamically unload $libref, which must be an opaque 'library reference' asreturned from dl_load_file.  Returns one on success and zero on failure.This function is optional and may not necessarily be provided on all platforms.If it is defined, it is called automatically when the interpreter exits forevery shared object or library loaded by DynaLoader::bootstrap.  All suchlibrary references are stored in @dl_librefs by DynaLoader::Bootstrap as itloads the libraries.  The files are unloaded in last-in, first-out order.This unloading is usually necessary when embedding a shared-object perl (e.g.one configured with -Duseshrplib) within a larger application, and the perlinterpreter is created and destroyed several times within the lifetime of theapplication.  In this case it is possible that the system dynamic linker willunload and then subsequently reload the shared libperl without relocating anyreferences to it from any files DynaLoaded by the previous incarnation of theinterpreter.  As a result, any shared objects opened by DynaLoader may point toa now invalid 'ghost' of the libperl shared object, causing apparently randommemory corruption and crashes.  This behaviour is most commonly seen when usingApache and mod_perl built with the APXS mechanism.    SunOS: dlclose($libref)    HP-UX: ???    Linux: ???    NeXT:  ???    VMS:   ???(The dlclose() function is also used by Solaris and some versions ofLinux, and is a common choice when providing a "wrapper" on othermechanisms as is done in the OS/2 port.)=item dl_load_flags()Syntax:    $flags = dl_load_flags $modulename;Designed to be a method call, and to be overridden by a derived class(i.e. a class which has DynaLoader in its @ISA).  The definition inDynaLoader itself returns 0, which produces standard behavior fromdl_load_file().=item dl_find_symbol()Syntax:    $symref = dl_find_symbol($libref, $symbol)Return the address of the symbol $symbol or C<undef> if not found.  If thetarget system has separate functions to search for symbols of differenttypes then dl_find_symbol() should search for function symbols first andthen other types.The exact manner in which the address is returned in $symref is notcurrently defined.  The only initial requirement is that $symref canbe passed to, and understood by, dl_install_xsub().    SunOS: dlsym($libref, $symbol)    HP-UX: shl_findsym($libref, $symbol)    Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)    NeXT:  rld_lookup("_$symbol")    VMS:   lib$find_image_symbol($libref,$symbol)=item dl_find_symbol_anywhere()Syntax:    $symref = dl_find_symbol_anywhere($symbol)Applies dl_find_symbol() to the members of @dl_librefs and returnsthe first match found.=item dl_undef_symbols()Example    @symbols = dl_undef_symbols()Return a list of symbol names which remain undefined after load_file().Returns C<()> if not known.  Don't worry if your platform does not providea mechanism for this.  Most do not need it and hence do not provide it,they just return an empty list.=item dl_install_xsub()Syntax:    dl_install_xsub($perl_name, $symref [, $filename])Create a new Perl external subroutine named $perl_name using $symref asa pointer to the function which implements the routine.  This is simplya direct call to newXSUB().  Returns a reference to the installedfunction.The $filename parameter is used by Perl to identify the source file forthe function if required by die(), caller() or the debugger.  If$filename is not defined then "DynaLoader" will be used.=item bootstrap()Syntax:bootstrap($module)This is the normal entry point for automatic dynamic loading in Perl.It performs the following actions:=over 8=item *locates an auto/$module directory by searching @INC=item *uses dl_findfile() to determine the filename to load=item *sets @dl_require_symbols to C<("boot_$module")>=item *executes an F<auto/$module/$module.bs> file if it exists(typically used to add to @dl_resolve_using any files whichare required to load the module on the current platform)=item *calls dl_load_flags() to determine how to load the file.=item *calls dl_load_file() to load the file=item *calls dl_undef_symbols() and warns if any symbols are undefined=item *calls dl_find_symbol() for "boot_$module"=item *calls dl_install_xsub() to install it as "${module}::bootstrap"=item *calls &{"${module}::bootstrap"} to bootstrap the module (actuallyit uses the function reference returned by dl_install_xsub for speed)=back=back=head1 AUTHORTim Bunce, 11 August 1994.This interface is based on the work and comments of (in no particularorder): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, AnnoSiegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.Larry Wall designed the elegant inherited bootstrap mechanism andimplemented the first Perl 5 dynamic loader using it.Solaris global loading added by Nick Ing-Simmons with design/codingassistance from Tim Bunce, January 1996.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -