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

📄 apr::error.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "mod_perl-2.0.2::docs::api::APR::Error 3".TH mod_perl-2.0.2::docs::api::APR::Error 3 "2005-10-21" "perl v5.10.0" "User Contributed Perl Documentation".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"APR::Error \- Perl API for APR/Apache/mod_perl exceptions.SH "Synopsis".IX Header "Synopsis".Vb 7\&  eval { $obj\->mp_method() };\&  if ($@ && $ref $@ eq \*(AqAPR::Error\*(Aq && $@ == $some_code) {\&      # handle the exception\&  }\&  else {\&      die $@; # rethrow it\&  }.Ve.SH "Description".IX Header "Description"\&\f(CW\*(C`APR::Error\*(C'\fR handles APR/Apache/mod_perl exceptions for you, whileleaving you in control..PPApache and \s-1APR\s0 \s-1API\s0 return a status code for almost all methods, so ifyou didn't check the return code and handled any possible problems,you may have silent failures which may cause all kind of obscureproblems. On the other hand checking the status code after each callis just too much of a kludge and makes quick prototyping/developmentalmost impossible, not talking about the code readability. Havingmethods return status codes, also complicates the \s-1API\s0 if you need toreturn other values..PPTherefore to keep things nice and make the \s-1API\s0 readable we decided tonot return status codes, but instead throw exceptions with\&\f(CW\*(C`APR::Error\*(C'\fR objects for each method that fails. If you don't catchthose exceptions, everything works transparently \- perl will interceptthe exception object and \f(CW\*(C`die()\*(C'\fR with a proper error message. So youget all the errors logged without doing any work..PPNow, in certain cases you don't want to just die, but instead theerror needs to be trapped and handled. For example if some \s-1IO\s0operation times out, may be it is \s-1OK\s0 to trap that and try again. If wewere to die with an error message, you would have had to match theerror message, which is ugly, inefficient and may not work at all iflocale error strings are involved. Therefore you need to be able toget the original status code that Apache or \s-1APR\s0 has generated. And theexception objects give you that if you want to. Moreover the objectscontain additional information, such as the function name (in case youwere eval'ing several commands in one block), file and line numberwhere that function was invoked from. More attributes could be addedin the future..PP\&\f(CW\*(C`APR::Error\*(C'\fR uses Perl operator overloading, such that in boolean andnumerical contexts, the object returns the status code; in the stringcontext the full error message is returned..PPWhen intercepting exceptions you need to check whether \f(CW$@\fR is anobject (reference). If your application uses other exception objectsyou additionally need to check whether this is a an \f(CW\*(C`APR::Error\*(C'\fRobject. Therefore most of the time this is enough:.PP.Vb 4\&  eval { $obj\->mp_method() };\&  if ($@ && $ref $@ && $@ == $some_code)\&      warn "handled exception: $@";\&  }.Ve.PPBut with other, non\-mod_perl, exception objects you need to do:.PP.Vb 4\&  eval { $obj\->mp_method() };\&  if ($@ && $ref $@ eq \*(AqAPR::Error\*(Aq && $@ == $some_code)\&      warn "handled exception: $@";\&  }.Ve.PPIn theory you could even do:.PP.Vb 4\&  eval { $obj\->mp_method() };\&  if ($@ && $@ == $some_code)\&      warn "handled exception: $@";\&  }.Ve.PPbut it's possible that the method will die with a plain string and notan object, in which case \f(CW\*(C`$@ == $some_code\*(C'\fR won't quitework. Remember that mod_perl throws exception objects only when Apacheand \s-1APR\s0 fail, and in a few other special cases of its own (like\&\f(CW\*(C`exit\*(C'\fR)..PP.Vb 1\&  warn "handled exception: $@" if $@ && $ref $@;.Ve.PPThere are two ways to figure out whether an error fits your case. Inmost cases you just compare \f(CW$@\fR with an the error constant. Forexample if a socket has a timeout set and the data wasn't read withinthe timeout limit a\&\f(CW\*(C`APR::Const::TIMEUP\*(C'\fR).PP.Vb 5\&  use APR::Const \-compile => qw(TIMEUP);\&  $sock\->timeout_set(1_000_000); # 1 sec\&  my $buff;\&  eval { $sock\->recv($buff, BUFF_LEN) };\&  if ($@ && ref $@ && $@ == APR::Const::TIMEUP) {\&\&  }.Ve.PPHowever there are situations, where on different Operating Systems adifferent error code will be returned. In which case to simplify thecode you should use the special subroutines provided by the\&\f(CW\*(C`APR::Status\*(C'\fR class. One suchcondition is socket \f(CW\*(C`recv()\*(C'\fR timeout, which on Unix throws the\&\f(CW\*(C`EAGAIN\*(C'\fR error, but on other system it throws a different error. Inthis case\&\f(CW\*(C`APR::Status::is_EAGAIN\*(C'\fRshould be used..PPLet's look at a complete example. Here is a code that performs asocket read:.PP.Vb 2\&  my $rlen = $sock\->recv(my $buff, 1024);\&  warn "read $rlen bytes\en";.Ve.PPand in certain cases it times out. The code will die and log thereason for the failure, which is fine, but later on you may decidethat you want to have another attempt to read before dying and addsome fine grained sleep time between attempts, which can be achievedwith \f(CW\*(C`select\*(C'\fR. Which gives us:.PP.Vb 10\&  use APR::Status ();\&  # ....\&  my $tries = 0;\&  my $buffer;\&  RETRY: my $rlen = eval { $sock\->recv($buffer, SIZE) };\&  if ($@)\&      die $@ unless ref $@ && APR::Status::is_EAGAIN($@);\&      if ($tries++ < 3) {\&          # sleep 250msec\&          select undef, undef, undef, 0.25;\&          goto RETRY;\&      }\&      else {\&          # do something else\&      }\&  }\&  warn "read $rlen bytes\en".Ve.PPNotice that we handle non-object and non\-\f(CW\*(C`APR::Error\*(C'\fR exceptions aswell, by simply re-throwing them..PPFinally, the class is called \f(CW\*(C`APR::Error\*(C'\fR because it needs to be usedoutside mod_perl as well, when called from\&\f(CW\*(C`APR\*(C'\fR applications written in Perl..SH "API".IX Header "API".ie n .Sh """cluck""".el .Sh "\f(CWcluck\fP".IX Subsection "cluck"\&\f(CW\*(C`cluck\*(C'\fR is an equivalent of \f(CW\*(C`Carp::cluck\*(C'\fR that works with\&\f(CW\*(C`APR::Error\*(C'\fR exception objects..ie n .Sh """confess""".el .Sh "\f(CWconfess\fP".IX Subsection "confess"\&\f(CW\*(C`confess\*(C'\fR is an equivalent of \f(CW\*(C`Carp::confess\*(C'\fR that works with\&\f(CW\*(C`APR::Error\*(C'\fR exception objects..ie n .Sh """strerror""".el .Sh "\f(CWstrerror\fP".IX Subsection "strerror"Convert \s-1APR\s0 error code to its string representation..PP.Vb 1\&  $error_str = APR::Error::strerror($rc);.Ve.ie n .IP "ret: $rc\fR ( \f(CW""APR::Const status constant"" )" 4.el .IP "ret: \f(CW$rc\fR ( \f(CWAPR::Const status constant\fR )" 4.IX Item "ret: $rc ( APR::Const status constant )"The numerical value for the return (error) code.ie n .IP "ret: $error_str ( string )" 4.el .IP "ret: \f(CW$error_str\fR ( string )" 4.IX Item "ret: $error_str ( string )"The string error message corresponding to the numerical value inside\&\f(CW$rc\fR.  (Similar to the C function \f(CWstrerror(3)\fR).IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPExample:.PPTry to retrieve the bucket brigade, and if the return value doesn'tindicate success or end of file (usually in protocol handlers) die,but give the user the human-readable version of the error and not justthe code..PP.Vb 6\&  my $rc = $c\->input_filters\->get_brigade($bb_in,\&                                          Apache2::Const::MODE_GETLINE);\&  if ($rc != APR::Const::SUCCESS && $rc != APR::Const::EOF) {\&      my $error = APR::Error::strerror($rc);\&      die "get_brigade error: $rc: $error\en";\&  }.Ve.PPIt's probably a good idea not to omit the numerical value in the errormessage, in case the error string is generated with non-Englishlocale..SH "See Also".IX Header "See Also"mod_perl 2.0 documentation..SH "Copyright".IX Header "Copyright"mod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0..SH "Authors".IX Header "Authors"The mod_perl development team and numerouscontributors.

⌨️ 快捷键说明

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