From d19ac9846ff30aaf523f4d55202a35db70d447a6 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 21 Jul 2010 14:35:09 +0000 Subject: [PATCH] Remove the next member from the client_state struct. Only the main thread needs access to all client states so give it its own struct. --- jcc.c | 16 ++++++++++------ jcc.h | 4 ++-- loaders.c | 20 +++++++++++--------- project.h | 14 ++++++++++---- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/jcc.c b/jcc.c index dfe30af2..35d4a321 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.322 2010/07/21 14:30:40 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.323 2010/07/21 14:32:00 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -120,7 +120,7 @@ const char jcc_h_rcs[] = JCC_H_VERSION; const char project_h_rcs[] = PROJECT_H_VERSION; int daemon_mode = 1; -struct client_state clients[1]; +struct client_states clients[1]; struct file_list files[1]; #ifdef FEATURE_STATISTICS @@ -3341,6 +3341,7 @@ void w32_service_listen_loop(void *p) *********************************************************************/ static void listen_loop(void) { + struct client_states *csp_list = NULL; struct client_state *csp = NULL; jb_socket bfd; struct configuration_spec *config; @@ -3390,11 +3391,14 @@ static void listen_loop(void) } #endif - if ( NULL == (csp = (struct client_state *) zalloc(sizeof(*csp))) ) + csp_list = (struct client_states *)zalloc(sizeof(*csp_list)); + if (NULL == csp_list) { - log_error(LOG_LEVEL_FATAL, "malloc(%d) for csp failed: %E", sizeof(*csp)); + log_error(LOG_LEVEL_FATAL, + "malloc(%d) for csp_list failed: %E", sizeof(*csp_list)); continue; } + csp = &csp_list->csp; csp->flags |= CSP_FLAG_ACTIVE; csp->server_connection.sfd = JB_INVALID_SOCKET; @@ -3480,8 +3484,8 @@ static void listen_loop(void) } /* add it to the list of clients */ - csp->next = clients->next; - clients->next = csp; + csp_list->next = clients->next; + clients->next = csp_list; if (config->multi_threaded) { diff --git a/jcc.h b/jcc.h index dc97b0a8..cf608932 100644 --- a/jcc.h +++ b/jcc.h @@ -1,6 +1,6 @@ #ifndef JCC_H_INCLUDED #define JCC_H_INCLUDED -#define JCC_H_VERSION "$Id: jcc.h,v 1.27 2009/09/10 14:42:01 fabiankeil Exp $" +#define JCC_H_VERSION "$Id: jcc.h,v 1.28 2010/01/03 12:37:14 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.h,v $ @@ -50,7 +50,7 @@ extern int urls_read; extern int urls_rejected; #endif /*def FEATURE_STATISTICS*/ -extern struct client_state clients[1]; +extern struct client_states clients[1]; extern struct file_list files[1]; #ifdef unix diff --git a/loaders.c b/loaders.c index d68b40db..1bc06872 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.74 2009/09/26 13:29:57 fabiankeil Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.75 2010/05/26 23:01:47 ler762 Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -114,7 +114,8 @@ static struct file_list *current_re_filterfile[MAX_AF_FILES] = { unsigned int sweep(void) { struct file_list *fl, *nfl; - struct client_state *csp, *last_active; + struct client_state *csp; + struct client_states *last_active, *client_list; int i; unsigned int active_threads = 0; @@ -125,10 +126,11 @@ unsigned int sweep(void) } last_active = clients; - csp = clients->next; + client_list = clients->next; - while (NULL != csp) + while (NULL != client_list) { + csp = &client_list->csp; if (csp->flags & CSP_FLAG_ACTIVE) { /* Mark this client's files as active */ @@ -174,15 +176,15 @@ unsigned int sweep(void) active_threads++; - last_active = csp; - csp = csp->next; + last_active = client_list; + client_list = client_list->next; } else /* * This client is not active. Free its resources. */ { - last_active->next = csp->next; + last_active->next = client_list->next; freez(csp->ip_addr_str); freez(csp->iob->buf); @@ -208,9 +210,9 @@ unsigned int sweep(void) } #endif /* def FEATURE_STATISTICS */ - freez(csp); + freez(client_list); - csp = last_active->next; + client_list = last_active->next; } } diff --git a/project.h b/project.h index fdf153cb..ca96f328 100644 --- a/project.h +++ b/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 1.156 2010/05/24 11:38:22 fabiankeil Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.157 2010/05/24 11:39:36 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -914,11 +914,17 @@ struct client_state * or NULL. Currently only used for socks errors. */ char *error_message; - - /** Next thread in linked list. Only read or modify from the main thread! */ - struct client_state *next; }; +/** + * List of client states so the main thread can keep + * track of them and garbage collect their resources. + */ +struct client_states +{ + struct client_states *next; + struct client_state csp; +}; /** * A function to add a header -- 2.39.2