@@ -78,7 +78,8 @@ state_action http_respond_writecount_starting(scache_connection* connection) {
7878static state_action http_respond_start_to_count (scache_connection* connection) {
7979 DEBUG (" [#%d] Ready to start to count \n " , connection->client_sock );
8080 monitoring_add (connection);
81- return http_respond_cleanupafterwrite (connection);
81+ CONNECTION_HANDLER (connection, http_respond_cleanupafterwrite);
82+ return continue_processing;
8283}
8384
8485state_action http_mon_read_eol_inital (scache_connection* connection, char * buffer, int n, uint32_t & temporary) {
@@ -275,6 +276,7 @@ void monitoring_add(scache_connection* conn){
275276 if (mon_tail == NULL ){
276277 mon_tail = mon_head = conn;
277278 }else {
279+ // insert at tail
278280 assert (mon_tail->monitoring .next == NULL );
279281 mon_tail->monitoring .next = conn;
280282 conn->monitoring .prev = mon_tail;
@@ -286,26 +288,41 @@ void monitoring_destroy(scache_connection* connection){
286288 assert (connection->ltype == mon_listener);
287289 scache_connection* t;
288290
291+ /*
292+ head ... | connection | t | ... tail
293+ */
289294 t = connection->monitoring .next ;
290295 if (t != NULL ){
291296 assert (t->monitoring .prev == connection);
292297 t->monitoring .prev = connection->monitoring .prev ;
293298 if (t->monitoring .prev == NULL ) {
294- assert (mon_tail == connection);
295- mon_tail = t;
299+ assert (mon_head == connection);
300+ mon_head = t;
296301 }
302+ }else {
303+ // Only if we are destroying the tail t will be NULL
304+ assert (connection == mon_tail);
305+ mon_tail = t;
297306 }
298307
308+ /*
309+ head ... | t | connection | ... tail
310+ */
299311 t = connection->monitoring .prev ;
300312 if (t != NULL ){
301313 assert (t->monitoring .next == connection);
302314 t->monitoring .next = connection->monitoring .next ;
303315 if (t->monitoring .next == NULL ) {
304- assert (mon_head == connection);
305- mon_head = t;
316+ assert (mon_tail == connection);
317+ mon_tail = t;
306318 }
319+ }else {
320+ // Only if we are destroying the head will t be null
321+ assert (mon_head == connection);
322+ mon_head = t;
307323 }
308324}
325+
309326static void reverse (char s[])
310327{
311328 int i, j;
@@ -357,6 +374,7 @@ void monitoring_check(){
357374 mon_tail = mon_head = conn;
358375 conn->monitoring .next = conn->monitoring .prev = NULL ;
359376 }
377+ conn->monitoring .next = NULL ;
360378
361379 // If buffer wasnt cleared already, then we will need to disconnect
362380 if (conn->output_buffer != NULL ){
0 commit comments