apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mladen Turk <mt...@apache.org>
Subject Re: Changing the order of cleanup for some core objects
Date Wed, 23 Jul 2008 07:23:07 GMT
Bojan Smojver wrote:
> 
>> Socket cleanup is private, so
>> cannot modify that.
> 
> When you create your socket with apr_socket_create(), there is a pool
> argument there. If you hang a cleanup off it, it will run before close()
> in socket_cleanup().

What do you mean by "hang a cleanup off it"?
Socket cleanup is private function and cannot be modified.


constructor(res, pool) {
    res->sock = socket_create(pool)
}

destructor(res) {

     socket_shutdown(res->sock);
     socket_close(res->sock);
}

Now this might core because socket_create always registers
a cleanup that will call socket_close before destructor, so
my calls in destructor will be touching closed socket.


What I can do is:

my_cleanup(res)
{
     socket_shutdown(res->sock);
     socket_close(res->sock);
     res->sock = NULL
}

constructor(res, pool) {
    res->sock = socket_create(pool)
    res->subpool = pool_create(pool)
    cleanup_register(res, res->subpool, my_cleanup);
}

destructor(res) {
    if (res->sock) {
       pool_cleanup_run(res->subpool, my_cleanup)
    }
}

So the whole bunch of code, two additional pools for each object
(16K of wasted memory; multiply that by 1000 sockets), for what?
A simple cleanup. I really don't understand the opposition
for doing a things in a clean and safe way :(.


Regards
-- 
^(TM)

Mime
View raw message