So before we start polishing the API, let's agree on a few things. One of them is the error messages variables. Since $! is unusable, we decided to use $APR::err and $Apache::err (and errstr) (similar to what DBI does. The problem is that it's confusing to switch between APR:: and Apache::, so it'd be nice to have one name. So we could use /$Apache::err(str)?/, but then if APR is used w/o mod_perl it'll be confusing. So Geoff suggested to alias these symbols one to each other to make things interchangable. A few more ideas:

How about using /$ModPerl::err(str)?/ instead of these two. Even though it's may be confusing when used outside mod_perl (pure APR), but better than /$Apache::err(str)?/, IMHO.

Furthermore ModPerl is too much to type, so how about /$MP::err(str)?/? in which case we probably want to reserve the MP namespace on CPAN?

So far we have the following 4 proposals:

1. use the right error message:

$Apache::errstr
$Apache::err
$APR::errstr
$APR::err

2. make the two interchangable via aliasing, so setting /$Apache::err(str)?/ will also set /$APR::err(str)?/

3. use just one set /$ModPerl::err(str)?/

4. use one set and shortcut it to /$MP::err(str)?/

So speak up before we started to change everything, tell which one do you like and if you have other ideas.

Here is the patch to my recent changes to opt_(get|set) using (4):


Index: src/modules/perl/modperl_util.h =================================================================== RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.h,v retrieving revision 1.54 diff -u -r1.54 modperl_util.h --- src/modules/perl/modperl_util.h 8 Apr 2004 20:47:41 -0000 1.54 +++ src/modules/perl/modperl_util.h 15 Apr 2004 02:15:20 -0000 @@ -73,16 +73,22 @@ } while (0)


-/* runs a given code and if failed sets $APR::err to the error message - * and returns &PL_sv_undef */ +/* runs a given code and if failed sets $MP::err to the rc code, + * $MP::errstr to the error message and returns &PL_sv_undef + */ #define MP_APR_RETURN_ON_FAILURE(rc_run) do { \ apr_status_t rc = (rc_run); \ if (rc != APR_SUCCESS) { \ - GV *gv = gv_fetchpv("APR::err", GV_ADDMULTI, SVt_PV); \ - sv_setpv(GvSV(gv), modperl_apr_strerror(rc)); \ + GV *gv = gv_fetchpv("MP::err", GV_ADDMULTI, SVt_IV); \ + GV *gvstr = gv_fetchpv("MP::errstr", GV_ADDMULTI, SVt_PV); \ + sv_setiv(GvSV(gv), rc); \ + sv_setpv(GvSV(gvstr), modperl_apr_strerror(rc)); \ return &PL_sv_undef; \ } \ } while (0) + +/* return a true value, but zero */ +#define MP_RETURN_TRUE return newSVpvn("0E0", 3)

 /* check whether the response phase has been initialized already */
 #define MP_CHECK_WBUCKET_INIT(func) \
Index: t/protocol/TestProtocol/echo.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/protocol/TestProtocol/echo.pm,v
retrieving revision 1.5
diff -u -r1.5 echo.pm
--- t/protocol/TestProtocol/echo.pm     8 Apr 2004 20:47:41 -0000       1.5
+++ t/protocol/TestProtocol/echo.pm     15 Apr 2004 02:15:20 -0000
@@ -19,16 +19,16 @@
     # on some platforms (e.g. OSX/Solaris) httpd hands us a
     # non-blocking socket
     my $nonblocking = $socket->opt_get(APR::SO_NONBLOCK);
-    die "failed to \$socket->opt_get: $ARP::err"
+    die "failed to \$socket->opt_get: $MP::errstr"
         unless defined $nonblocking;
     if ($nonblocking) {
-        my $prev_value = $socket->opt_set(APR::SO_NONBLOCK => 0);
-        die "failed to \$socket->opt_set: $ARP::err"
-            unless defined $prev_value;
+        my $success = $socket->opt_set(APR::SO_NONBLOCK => 0);
+        die "failed to \$socket->opt_set: $MP::errstr"
+            unless defined $success;

         # test that we really are in the non-blocking mode
         $nonblocking = $socket->opt_get(APR::SO_NONBLOCK);
-        die "failed to \$socket->opt_get: $ARP::err"
+        die "failed to \$socket->opt_get: $MP::errstr"
             unless defined $nonblocking;
         die "failed to set non-blocking mode" if $nonblocking;
     }
Index: xs/APR/Socket/APR__Socket.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/Socket/APR__Socket.h,v
retrieving revision 1.5
diff -u -r1.5 APR__Socket.h
--- xs/APR/Socket/APR__Socket.h 8 Apr 2004 20:47:41 -0000       1.5
+++ xs/APR/Socket/APR__Socket.h 15 Apr 2004 02:15:20 -0000
@@ -64,20 +64,18 @@
     return t;
 }

-static MP_INLINE SV *
-mpxs_APR__Socket_opt_get(pTHX_ apr_socket_t *socket, apr_int32_t opt)
+static MP_INLINE
+SV *mpxs_APR__Socket_opt_get(pTHX_ apr_socket_t *socket, apr_int32_t opt)
 {
     apr_int32_t val;
     MP_APR_RETURN_ON_FAILURE(apr_socket_opt_get(socket, opt, &val));
     return newSViv(val);
 }

-static MP_INLINE SV *
-mpxs_APR__Socket_opt_set(pTHX_ apr_socket_t *socket, apr_int32_t opt,
+static MP_INLINE
+SV *mpxs_APR__Socket_opt_set(pTHX_ apr_socket_t *socket, apr_int32_t opt,
                          apr_int32_t val)
 {
-    apr_int32_t oldval;
-    MP_APR_RETURN_ON_FAILURE(apr_socket_opt_get(socket, opt, &oldval));
     MP_APR_RETURN_ON_FAILURE(apr_socket_opt_set(socket, opt, val));
-    return newSViv(oldval);
+    MP_RETURN_TRUE;
 }




__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to