From: <no...@so...> - 2010-07-21 14:35:17
|
Update of /cvsroot/ijbswa/current In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv25157 Modified Files: jcc.c jcc.h loaders.c project.h Log Message: 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. Index: jcc.c =================================================================== RCS file: /cvsroot/ijbswa/current/jcc.c,v retrieving revision 1.323 retrieving revision 1.324 diff -u -d -r1.323 -r1.324 --- jcc.c 21 Jul 2010 14:32:00 -0000 1.323 +++ jcc.c 21 Jul 2010 14:35:09 -0000 1.324 @@ -120,7 +120,7 @@ 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 @@ *********************************************************************/ 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 @@ } #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 @@ } /* 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) { Index: jcc.h =================================================================== RCS file: /cvsroot/ijbswa/current/jcc.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- jcc.h 3 Jan 2010 12:37:14 -0000 1.28 +++ jcc.h 21 Jul 2010 14:35:09 -0000 1.29 @@ -50,7 +50,7 @@ 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 Index: loaders.c =================================================================== RCS file: /cvsroot/ijbswa/current/loaders.c,v retrieving revision 1.75 retrieving revision 1.76 diff -u -d -r1.75 -r1.76 --- loaders.c 26 May 2010 23:01:47 -0000 1.75 +++ loaders.c 21 Jul 2010 14:35:09 -0000 1.76 @@ -114,7 +114,8 @@ 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 @@ } 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 @@ 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 @@ } #endif /* def FEATURE_STATISTICS */ - freez(csp); + freez(client_list); - csp = last_active->next; + client_list = last_active->next; } } Index: project.h =================================================================== RCS file: /cvsroot/ijbswa/current/project.h,v retrieving revision 1.157 retrieving revision 1.158 diff -u -d -r1.157 -r1.158 --- project.h 24 May 2010 11:39:36 -0000 1.157 +++ project.h 21 Jul 2010 14:35:09 -0000 1.158 @@ -914,11 +914,17 @@ * 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 |