Parent Directory
|
Revision Log
Revision 6 - (view) (download) (as text)
| 1 : | gage | 6 | #!/usr/local/bin/perl |
| 2 : | sam | 2 | |
| 3 : | #################################################################### | ||
| 4 : | # Copyright @ 1995-1998 University of Rochester | ||
| 5 : | # All Rights Reserved | ||
| 6 : | #################################################################### | ||
| 7 : | |||
| 8 : | |||
| 9 : | |||
| 10 : | use GDBM_File; | ||
| 11 : | |||
| 12 : | my $TieMaxTries =30; # try to tie() 30 times, then fail | ||
| 13 : | my $TieSleepInterval =2; # sleep 2 sec after failed tie() | ||
| 14 : | |||
| 15 : | sub tie_hash { | ||
| 16 : | my($fileHandle, $db_obj_ref, $hash_ref, $file_name, $mode_flag, $permission) = @_; | ||
| 17 : | |||
| 18 : | ## try to achieve tie $Max_Tries times, with a wait of $Sleep_interval | ||
| 19 : | ## between attempts. | ||
| 20 : | |||
| 21 : | ## \$fileHandle and \$db_obj_ref are not used for gdbm databases | ||
| 22 : | |||
| 23 : | my ($tries, $mode); | ||
| 24 : | if (($mode_flag eq 'W') or ($mode_flag eq 'w')) {$mode = &GDBM_WRCREAT();} else {$mode = &GDBM_READER();} | ||
| 25 : | for ($tries = 0; $tries < $TieMaxTries; $tries++) { | ||
| 26 : | my $success_flag = tie(%$hash_ref, 'GDBM_File', $file_name, $mode, $permission); | ||
| 27 : | $Global::DBtie_tries += $tries + 1 if $success_flag; | ||
| 28 : | return 1 if $success_flag; | ||
| 29 : | sleep($TieSleepInterval); | ||
| 30 : | } | ||
| 31 : | &Global::error("Key database error", "Can't tie $file_name: $!"); | ||
| 32 : | } | ||
| 33 : | sub untie_hash { | ||
| 34 : | my($fileHandle,$DbObj_ref,$hash_ref,$file_name) = @_; | ||
| 35 : | |||
| 36 : | untie(%$hash_ref) || &Global::error("WeBWorK database error", "Can't untie database $file_name at"); | ||
| 37 : | 1; # Explicitly return 1 if successful | ||
| 38 : | } | ||
| 39 : | |||
| 40 : | 1; ## script must return a true value | ||
| 41 : | |||
| 42 : | |||
| 43 : |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |