List Info

Thread: Apache Modules - Modifying and Persisting Values in Memory Across Requests




Apache Modules - Modifying and Persisting Values in Memory Across Requests
user name
2007-09-25 17:56:07
Hello,

Can someone explain a way via a C module to update a counter value for every request served by the module and write that value (via ap_rputs or something similar) to the browser.  For example, the first time the module services a request, it writes 1 to the browser, the next time it writes 2, ....  I tried apr_pool_userdata_get/set with r->server->process->pool as my memory pool, but this doesn't seem to work. ; This value appears to be in memory sometimes but not others.  It will increment as expected for awhile and then drop back to 0.  I'm not trying to implement a counter for my page. ; I'm trying to think of the simplest example so that once I see how this is done, I can easily extrapolate to solve my real problem.  Any help is appreciated, especially code!

Here is some sample code that I was using without success:


    static int ContentHandler( request_rec* r )
    {
        //Don't processs any requests not intended for us
        if(!nStringUtils::SensitiveEqual(r->handler, "mo_test-handler"))
        {
  ;          return DECLINED;
  ;      }

        int* pData = 0;
        apr_status_t retStatus = apr_pool_userdata_get((void**)&pData, "mo_test::__my_test_value__", r->server->process->pool);
 ;       if(retStatus == APR_SUCCESS)
        {
            if(pData != 0)
            {
                (*pData) = (*pData) + 1;
            }
            else
            {
                pData = (int*)malloc(sizeof(int));
                *pData = 0;
                apr_status_t retStatus2 = apr_pool_userdata_set(pData, "mo_test::__my_test_value__", apr_pool_cleanup_null, r->server->process->pool);
            }

 ;           char buf[255];
  ;          itoa(*pData, buf, 10);
 ;           ap_rputs(buf, r);
   ;         ap_rflush(r);
        }
        return OK;
   ; }

Re: Apache Modules - Modifying and Persisting Values in Memory Across Requests
user name
2007-09-25 18:05:25
On 9/25/07, Mike O'Leary <moleary45gmail.com> wrote:
> Hello,
>
> Can someone explain a way via a C module to update a
counter value for every
> request served by the module and write that value (via
ap_rputs or something
> similar) to the browser.  For example, the first time
the module services a
> request, it writes 1 to the browser, the next time it
writes 2, ....  I
> tried apr_pool_userdata_get/set with
r->server->process->pool as my memory
> pool, but this doesn't seem to work.  This value
appears to be in memory
> sometimes but not others.  It will increment as
expected for awhile and then
> drop back to 0.  I'm not trying to implement a counter
for my page.  I'm
> trying to think of the simplest example so that once I
see how this is done,
> I can easily extrapolate to solve my real problem.  Any
help is appreciated,
> especially code!

You'll need to use shared memory for that. Apache pool
memory is process-local.

You'll probably get more detailed help on the module
developer's list.
http:/
/httpd.apache.org/lists.html#modules-dev

Joshua.

------------------------------------------------------------
---------
The official User-To-User support forum of the Apache HTTP
Server Project.
See <URL:http://htt
pd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribehttpd.apache.org
   "   from the digest: users-digest-unsubscribehttpd.apache.org
For additional commands, e-mail: users-helphttpd.apache.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )