From 06c319b726983ebc483b261cbb23ccc26f9eace9 Mon Sep 17 00:00:00 2001 From: koinec <> Date: Sat, 14 Nov 2009 14:00:29 +0000 Subject: [PATCH] *** empty log message *** --- deamon/drd64_server_recvstatus.c | 149 +++++++++++++++++++++++---------------- include/drd64_conf.h | 1 + 2 files changed, 90 insertions(+), 60 deletions(-) diff --git a/deamon/drd64_server_recvstatus.c b/deamon/drd64_server_recvstatus.c index 56e6b22..8163213 100644 --- a/deamon/drd64_server_recvstatus.c +++ b/deamon/drd64_server_recvstatus.c @@ -45,62 +45,110 @@ int gi_recvalloc_now; int gi_recvstat_max; -EXTERN_SERVER_RECVSTATUS int - Drd64_Server_RecvStatus_Init( - int i_alloc_units ) + Drd64_Server_RecvStatus_FreeRecvStatus_All( + void ) { int i_cnt; - void *pv_temp; - gpp_recvstat = (Drd64_Server_RecvStatus **)malloc( - sizeof( Drd64_Server_RecvStatus *) * FD_SETSIZE ); - if( NULL == gpp_recvstat ) { - return 0x01; + for( i_cnt = 0; i_cnt < gi_recvalloc_max; i_cnt++ ) { + free( (gp_recvalloc + i_cnt)->pv_buf ); + (gp_recvalloc + i_cnt)->pv_buf = NULL; } - gi_recvstat_max = 0; + free( gp_recvalloc ); + gi_recvalloc_max = 0; + gi_recvalloc_now = 0; + gp_recvalloc = NULL; + + free( gpp_recvstat ); + gpp_recvstat = NULL; + + return; +} - gp_recvalloc = (Drd64_Server_RecvStatus *)malloc( + +Drd64_Server_RecvStatus * + Drd64_Server_RecvStatus_AllocRecvStatus_Unit( + int i_alloc_units ) +{ + int i_cnt; + int i_init_start_id; + int i_init_end_id; + void *pv_temp; + Drd64_Server_RecvStatus *p_recvs; + + p_recvs = NULL; + + if( 0 == gi_recvalloc_max ) { + p_recvs = (Drd64_Server_RecvStatus *)malloc( sizeof( Drd64_Server_RecvStatus ) * i_alloc_units ); - if( NULL == gp_recvalloc ) { - free( gpp_recvstat ); - gpp_recvstat = NULL; - return 0x02; + + i_init_start_id = 0; + i_init_end_id = i_alloc_units; } + else { + p_recvs = realloc( gp_recvalloc, + gi_recvalloc_max + i_alloc_units ); - memset( gpp_recvstat, 0x00, - sizeof( Drd64_Server_RecvStatus *) * FD_SETSIZE ); + i_init_start_id = gi_recvalloc_max; + i_init_end_id = gi_recvalloc_max + i_alloc_units; + } - memset( gp_recvalloc, 0x00, - sizeof( Drd64_Server_RecvStatus ) - * i_alloc_units ); - for( i_cnt = 0; i_cnt < i_alloc_units; i_cnt++ ) { - (gp_recvalloc + i_cnt)->i_fds_id = -1; + if( NULL == p_recvs ) { + return NULL; + } + + + for( i_cnt = i_init_start_id; i_cnt < i_init_end_id; i_cnt++ ) { + memset( (p_recvs + i_cnt), 0x00, + sizeof( Drd64_Server_RecvStatus ) ); + (p_recvs + i_cnt)->i_fds_id = -1; + pv_temp = malloc( DRD64_MAX_PACKET_LENGTH ); if( NULL == pv_temp ) { break; } - - (gp_recvalloc + i_cnt)->pv_buf = pv_temp; + (p_recvs + i_cnt)->pv_buf = pv_temp; + gi_recvalloc_max++; } - if( NULL == pv_temp ) { - for( ; i_cnt >= 0; i_cnt-- ) { - free( (gp_recvalloc + i_cnt)->pv_buf ); - (gp_recvalloc + i_cnt)->pv_buf = NULL; - } - free( gp_recvalloc ); - gi_recvalloc_max = 0; - gi_recvalloc_now = 0; - gp_recvalloc = NULL; + if( gi_recvalloc_max == i_init_start_id ) { + return NULL; + } + + gp_recvalloc = p_recvs; + return p_recvs; +} + + +EXTERN_SERVER_RECVSTATUS +int + Drd64_Server_RecvStatus_Init( + int i_alloc_units ) +{ + Drd64_Server_RecvStatus *p_recvs; + + /* Alloc RecvStatus Struct Management Area --- */ + gpp_recvstat + = (Drd64_Server_RecvStatus **)malloc( + sizeof( Drd64_Server_RecvStatus *) + * FD_SETSIZE * DRD64_PACKET_MAX_MULTIPLE); + if( NULL == gpp_recvstat ) { return 0x01; } + + memset( gpp_recvstat, 0x00, + sizeof( Drd64_Server_RecvStatus *) + * FD_SETSIZE * DRD64_PACKET_MAX_MULTIPLE ); + + gi_recvstat_max = 0; - free( gpp_recvstat ); - gpp_recvstat = NULL; - - return 0x01; + /* Alloc RecvStatus Area ( with Packet Data buffer ) ---*/ + p_recvs = Drd64_Server_RecvStatus_AllocRecvStatus_Unit( i_alloc_units ); + if( NULL == p_recvs ) { + Drd64_Server_RecvStatus_FreeRecvStatus_All(); + return 0x02; } - gi_recvalloc_max = i_alloc_units; + gp_recvalloc = p_recvs; gi_recvalloc_now = 0; return 0x00; @@ -112,20 +160,7 @@ int Drd64_Server_RecvStatus_Term( void ) { - int i_cnt; - - for( i_cnt = 0; i_cnt < gi_recvalloc_max; i_cnt++ ) { - free( (gp_recvalloc + i_cnt)->pv_buf ); - (gp_recvalloc + i_cnt)->pv_buf = NULL; - } - - free( gp_recvalloc ); - gi_recvalloc_max = 0; - gi_recvalloc_now = 0; - gp_recvalloc = NULL; - - free( gpp_recvstat ); - gpp_recvstat = NULL; + Drd64_Server_RecvStatus_FreeRecvStatus_All(); return; } @@ -152,18 +187,12 @@ Drd64_Server_RecvStatus * } if( NULL == p_recv ) { - p_temp = realloc( gp_recvalloc, - gi_recvalloc_max + i_alloc_units ); + p_temp + = Drd64_Server_RecvStatus_AllocRecvStatus_Unit( + i_alloc_units ); if( NULL == p_temp ) { return NULL; } - - for( i_cnt = gi_recvalloc_max; - i_cnt < i_alloc_units + gi_recvalloc_max; - i_cnt++ ) { - (gp_recvalloc + i_cnt)->i_fds_id = -1; - } gp_recvalloc = p_temp; - gi_recvalloc_max += i_alloc_units; p_recv = gp_recvalloc + gi_recvalloc_now++; } } diff --git a/include/drd64_conf.h b/include/drd64_conf.h index 5b8ed9c..5a017ed 100644 --- a/include/drd64_conf.h +++ b/include/drd64_conf.h @@ -51,6 +51,7 @@ Comment: #define DRD64_LOG_FACILITY_DEBUGD LOG_LOCAL4 #define DRD64_LOG_LEVEL_DEBUGD DRD64_LOG_LEVEL_DEBUG +#define DRD64_PACKET_MAX_MULTIPLE 2 #endif /* DRD64_HEADER_CONF */ -- 2.11.0