Menu

Pass pool & server_rc to instantiators

2005-02-06
2013-05-15
  • Jeffrey L. Taylor

    In developing my handler, I find that having the pool and server_rec in the instanciator would be helpful.  Any reason to no pass them?

     
    • John K. Sterling

      Hi -

      We definitely have the process pool (thats the pool that calls the destructors on your modules.  What are you looking for when you say 'server_rec'?  Do you mean the  cmd_parms->server?  We do have that, and it could be included in the process to load the modules.  Let me know specifically what you are looking for and i'll ponder the change - Thanks for the great input!

       
    • Jeffrey L. Taylor

      Yes, cmd_parms->server.  I would like the hostname and port when I instantiate a handler derived from ApacheHandler.  This is nice, but not strictly necessary.

      The pool is necessary so I can use a placement new operator to allocate the derived object from the server pool.  I think this is proper way to do this.

      I have added the following code to my derived class:

      <pre>
      void* operator new(size_t size, apr_pool_t* pool)
      {
        return apr_palloc(pool, size);
      }
      </pre>

      and the instantiate_handler looks like this:

      <pre>
      ApacheHandler *instantiate_handler(apr_pool_t* pool,
                         cpp_server_rec* server_rec)
      {
        return new(pool) PiaHandler();
      }
      </pre>

       
      • John K. Sterling

        Hi -

        What I usually do is just make sure my Handler destructor cleans up all the objects - the server pool has a cleanup that should delete all Handlers before the pool goes away - which is a little cleaner than overloading 'new' - would that work for you?  Its not a bad idea to pass it in to the constructor either way, but usually I don't allocate out of the pool from within my handlers, I just manage my own memory.

        Would that work for you?

         
        • Jeffrey L. Taylor

          Okay, I dug thru code some more and understand better how it works.  I withdraw my request for pool to be passed to instantiator.

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.