(trunk libT) #2261: Save memory by not initializing the RPC server's zlib stream until it's needed

This commit is contained in:
Charles Kerr 2009-07-02 20:20:00 +00:00
parent 5258ac0a83
commit 48b460c0c3
1 changed files with 12 additions and 8 deletions

View File

@ -73,6 +73,7 @@ struct tr_rpc_server
time_t sessionIdExpiresAt;
#ifdef HAVE_ZLIB
tr_bool isStreamInitialized;
z_stream stream;
#endif
};
@ -327,6 +328,15 @@ add_response( struct evhttp_request * req,
/* FIXME(libevent2): this won't compile under libevent2.
but we can use evbuffer_reserve_space() + evbuffer_commit_space() instead */
if( !server->isStreamInitialized )
{
server->isStreamInitialized = TRUE;
server->stream.zalloc = (alloc_func) Z_NULL;
server->stream.zfree = (free_func) Z_NULL;
server->stream.opaque = (voidpf) Z_NULL;
deflateInit( &server->stream, Z_BEST_COMPRESSION );
}
server->stream.next_in = (Bytef*) content;
server->stream.avail_in = content_len;
@ -859,7 +869,8 @@ closeServer( void * vserver )
while(( tmp = tr_list_pop_front( &s->whitelist )))
tr_free( tmp );
#ifdef HAVE_ZLIB
deflateEnd( &s->stream );
if( s->isStreamInitialized )
deflateEnd( &s->stream );
#endif
tr_free( s->sessionId );
tr_free( s->whitelistStr );
@ -932,13 +943,6 @@ tr_rpcInit( tr_session * session,
}
s->bindAddress = address.addr.addr4;
#ifdef HAVE_ZLIB
s->stream.zalloc = (alloc_func) Z_NULL;
s->stream.zfree = (free_func) Z_NULL;
s->stream.opaque = (voidpf) Z_NULL;
deflateInit( &s->stream, Z_BEST_COMPRESSION );
#endif
if( s->isEnabled )
{
tr_ninf( MY_NAME, _( "Serving RPC and Web requests on port %d" ), (int) s->port );