~ubuntu-branches/ubuntu/edgy/libapache2-mod-perl2/edgy

« back to all changes in this revision

Viewing changes to docs/api/APR/Status.pod

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-08-12 01:40:38 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050812014038-gjigefs55pqx4qc8
Tags: 2.0.1-3
Grr.  Really include perl.conf file; it got lost due to diff not
wanting to add an empty file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=head1 NAME
 
2
 
 
3
APR::Status - Perl Interface to the APR_STATUS_IS_* macros
 
4
 
 
5
 
 
6
 
 
7
=head1 Synopsis
 
8
 
 
9
  use APR::Status ();
 
10
  eval { $obj->mp_method() };
 
11
  if ($@ && $ref $@ eq 'APR::Error' && APR::Status::is_EAGAIN($@)) {
 
12
      # APR_STATUS_IS_EAGAIN(s) of apr_errno.h is satisfied
 
13
  }
 
14
 
 
15
 
 
16
 
 
17
 
 
18
 
 
19
 
 
20
=head1 Description
 
21
 
 
22
An interface to F<apr_errno.h> composite error codes.
 
23
 
 
24
As discussed in the C<L<APR::Error|docs::2.0::api::APR::Error>>
 
25
manpage, it is possible to handle APR/Apache/mod_perl exceptions in
 
26
the following way:
 
27
 
 
28
  eval { $obj->mp_method() };
 
29
  if ($@ && $ref $@ eq 'APR::Error' && $@ == $some_code)
 
30
      warn "handled exception: $@";
 
31
  }
 
32
 
 
33
However, in cases where C<$some_code> is an L<APR::Const
 
34
constant|docs::2.0::api::APR::Const>, there may be more than one
 
35
condition satisfying the intent of this exception. For this purpose
 
36
the APR C library provides in F<apr_errno.h> a series of macros,
 
37
C<APR_STATUS_IS_*>, which are the recommended way to check for such
 
38
conditions. For example, the C<APR_STATUS_IS_EAGAIN> macro is defined
 
39
as
 
40
 
 
41
  #define APR_STATUS_IS_EAGAIN(s)         ((s) == APR_EAGAIN \
 
42
                  || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \
 
43
                  || (s) == APR_OS_START_SYSERR + SOCEWOULDBLOCK \
 
44
                  || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION)
 
45
 
 
46
The purpose of C<APR::Status> is to provide functions corresponding
 
47
to these macros.
 
48
 
 
49
 
 
50
 
 
51
 
 
52
 
 
53
 
 
54
=head1 Functions
 
55
 
 
56
 
 
57
 
 
58
 
 
59
=head2 C<is_EACCES>
 
60
 
 
61
Check if the error is matching C<EACCES> and its variants (corresponds
 
62
to the C<APR_STATUS_IS_EACCES> macro).
 
63
 
 
64
  $status = APR::Status::is_EACCES($error_code);
 
65
 
 
66
=over 4
 
67
 
 
68
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
69
object|docs::2.0::api::APR::Error>> )
 
70
 
 
71
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
72
object|docs::2.0::api::APR::Error>>.
 
73
 
 
74
=item ret: C<$status> ( boolean )
 
75
 
 
76
=item since: 2.0.00
 
77
 
 
78
=back
 
79
 
 
80
An example of using C<is_EACCES> is when reading the contents of a
 
81
file where access may be forbidden:
 
82
 
 
83
  eval { $obj->slurp_filename(0) };
 
84
  if ($@) {
 
85
      return Apache2::Const::FORBIDDEN
 
86
          if ref $@ eq 'APR::Error' && APR::Status::is_EACCES($@);
 
87
      die $@;
 
88
   }
 
89
 
 
90
Due to possible variants in conditions matching C<EACCES>,
 
91
the use of this function is recommended for checking error codes
 
92
against this value, rather than just using
 
93
C<L<APR::Const::EACCES|docs::2.0::api::APR::Const/C_APR__Const__EACCES_>>
 
94
directly.
 
95
 
 
96
 
 
97
 
 
98
 
 
99
 
 
100
 
 
101
 
 
102
=head2 C<is_EAGAIN>
 
103
 
 
104
Check if the error is matching C<EAGAIN> and its variants (corresponds
 
105
to the C<APR_STATUS_IS_EAGAIN> macro).
 
106
 
 
107
  $status = APR::Status::is_EAGAIN($error_code);
 
108
 
 
109
=over 4
 
110
 
 
111
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
112
object|docs::2.0::api::APR::Error>> )
 
113
 
 
114
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
115
object|docs::2.0::api::APR::Error>>.
 
116
 
 
117
=item ret: C<$status> ( boolean )
 
118
 
 
119
=item since: 2.0.00
 
120
 
 
121
=back
 
122
 
 
123
For example, here is how you may want to handle socket read exceptions
 
124
and do retries:
 
125
 
 
126
  use APR::Status ();
 
127
  # ....
 
128
  my $tries = 0;
 
129
  RETRY: eval { $socket->recv(my $buffer, SIZE) };
 
130
  if ($@ && ref($@) && APR::Status::is_EAGAIN($@)) {
 
131
      if ($tries++ < 3) {
 
132
          goto RETRY;
 
133
      }
 
134
      else {
 
135
          # do something else
 
136
      }
 
137
  }
 
138
  else {
 
139
      die "eval block has failed: $@";
 
140
  }
 
141
 
 
142
Notice that just checking against
 
143
C<L<APR::Const::EAGAIN|docs::2.0::api::APR::Const/C_APR__Const__EAGAIN_>>
 
144
may work on some Unices, but then it will certainly break on
 
145
win32. Thefore make sure to use this macro and not
 
146
C<APR::Const::EAGAIN> unless you know what you are doing.
 
147
 
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
 
 
155
 
 
156
 
 
157
=head2 C<is_ENOENT>
 
158
 
 
159
Check if the error is matching C<ENOENT> and its variants (corresponds
 
160
to the C<APR_STATUS_IS_ENOENT> macro).
 
161
 
 
162
  $status = APR::Status::is_ENOENT($error_code);
 
163
 
 
164
=over 4
 
165
 
 
166
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
167
object|docs::2.0::api::APR::Error>> )
 
168
 
 
169
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
170
object|docs::2.0::api::APR::Error>>.
 
171
 
 
172
=item ret: C<$status> ( boolean )
 
173
 
 
174
=item since: 2.0.00
 
175
 
 
176
=back
 
177
 
 
178
An example of using C<is_ENOENT> is when reading the contents of a
 
179
file which may not exist:
 
180
 
 
181
  eval { $obj->slurp_filename(0) };
 
182
  if ($@) {
 
183
      return Apache2::Const::NOT_FOUND
 
184
          if ref $@ eq 'APR::Error' && APR::Status::is_ENOENT($@);
 
185
      die $@;
 
186
  }
 
187
 
 
188
Due to possible variants in conditions matching C<ENOENT>,
 
189
the use of this function is recommended for checking error codes
 
190
against this value, rather than just using
 
191
C<L<APR::Const::ENOENT|docs::2.0::api::APR::Const/C_APR__Const__ENOENT_>>
 
192
directly.
 
193
 
 
194
 
 
195
 
 
196
 
 
197
 
 
198
 
 
199
 
 
200
 
 
201
 
 
202
=head2 C<is_EOF>
 
203
 
 
204
Check if the error is matching C<EOF> and its variants (corresponds
 
205
to the C<APR_STATUS_IS_EOF> macro).
 
206
 
 
207
  $status = APR::Status::is_EOF($error_code);
 
208
 
 
209
=over 4
 
210
 
 
211
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
212
object|docs::2.0::api::APR::Error>> )
 
213
 
 
214
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
215
object|docs::2.0::api::APR::Error>>.
 
216
 
 
217
=item ret: C<$status> ( boolean )
 
218
 
 
219
=item since: 2.0.00
 
220
 
 
221
=back
 
222
 
 
223
Due to possible variants in conditions matching C<EOF>,
 
224
the use of this function is recommended for checking error codes
 
225
against this value, rather than just using
 
226
C<L<APR::Const::EOF|docs::2.0::api::APR::Const/C_APR__Const__EOF_>>
 
227
directly.
 
228
 
 
229
 
 
230
 
 
231
 
 
232
 
 
233
 
 
234
 
 
235
 
 
236
 
 
237
 
 
238
 
 
239
 
 
240
 
 
241
 
 
242
=head2 C<is_ECONNABORTED>
 
243
 
 
244
Check if the error is matching C<ECONNABORTED> and its variants (corresponds
 
245
to the C<APR_STATUS_IS_ECONNABORTED> macro).
 
246
 
 
247
  $status = APR::Status::is_ECONNABORTED($error_code);
 
248
 
 
249
=over 4
 
250
 
 
251
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
252
object|docs::2.0::api::APR::Error>> )
 
253
 
 
254
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
255
object|docs::2.0::api::APR::Error>>.
 
256
 
 
257
=item ret: C<$status> ( boolean )
 
258
 
 
259
=item since: 2.0.00
 
260
 
 
261
=back
 
262
 
 
263
Due to possible variants in conditions matching C<ECONNABORTED>,
 
264
the use of this function is recommended for checking error codes
 
265
against this value, rather than just using
 
266
C<L<APR::Const::ECONNABORTED|docs::2.0::api::APR::Const/C_APR__Const__ECONNABORTED_>> directly.
 
267
 
 
268
 
 
269
 
 
270
 
 
271
 
 
272
 
 
273
 
 
274
=head2 C<is_ECONNRESET>
 
275
 
 
276
Check if the error is matching C<ECONNRESET> and its variants
 
277
(corresponds to the C<APR_STATUS_IS_ECONNRESET> macro).
 
278
 
 
279
  $status = APR::Status::is_ECONNRESET($error_code);
 
280
 
 
281
=over 4
 
282
 
 
283
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
284
object|docs::2.0::api::APR::Error>> )
 
285
 
 
286
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
287
object|docs::2.0::api::APR::Error>>.
 
288
 
 
289
=item ret: C<$status> ( boolean )
 
290
 
 
291
=item since: 2.0.00
 
292
 
 
293
=back
 
294
 
 
295
Due to possible variants in conditions matching C<ECONNRESET>, the use
 
296
of this function is recommended for checking error codes against this
 
297
value, rather than just using
 
298
C<L<APR::Const::ECONNRESET|docs::2.0::api::APR::Const/C_APR__Const__ECONNRESET_>>
 
299
directly.
 
300
 
 
301
 
 
302
 
 
303
 
 
304
 
 
305
 
 
306
 
 
307
 
 
308
 
 
309
 
 
310
=head2 C<is_TIMEUP>
 
311
 
 
312
Check if the error is matching C<TIMEUP> and its variants (corresponds
 
313
to the C<APR_STATUS_IS_TIMEUP> macro).
 
314
 
 
315
  $status = APR::Status::is_TIMEUP($error_code);
 
316
 
 
317
=over 4
 
318
 
 
319
=item arg1: C<$error_code> (integer or C<L<APR::Error
 
320
object|docs::2.0::api::APR::Error>> )
 
321
 
 
322
The error code or to check, normally C<$@> blessed into C<L<APR::Error
 
323
object|docs::2.0::api::APR::Error>>.
 
324
 
 
325
=item ret: C<$status> ( boolean )
 
326
 
 
327
=item since: 2.0.00
 
328
 
 
329
=back
 
330
 
 
331
Due to possible variants in conditions matching C<TIMEUP>,
 
332
the use of this function is recommended for checking error codes
 
333
against this value, rather than just using
 
334
C<L<APR::Const::TIMEUP|docs::2.0::api::APR::Const/C_APR__Const__TIMEUP_>>
 
335
directly.
 
336
 
 
337
 
 
338
=head1 See Also
 
339
 
 
340
L<mod_perl 2.0 documentation|docs::2.0::index>.
 
341
 
 
342
 
 
343
=head1 Copyright
 
344
 
 
345
mod_perl 2.0 and its core modules are copyrighted under
 
346
The Apache Software License, Version 2.0.
 
347
 
 
348
 
 
349
 
 
350
=head1 Authors
 
351
 
 
352
L<The mod_perl development team and numerous
 
353
contributors|about::contributors::people>.
 
354
 
 
355
=cut