crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs

wakeuphandler.c (1676B)


      1 /*************************************************************************
      2  * This file is part of Crosroads 1.23, a load balancer and fail over
      3  * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL.
      4  * Visit http://crossroads.e-tunity.com for information.
      5  *************************************************************************/
      6 #include "crossroads.h"
      7 
      8 void wakeup_handler () {
      9     int sock, i;
     10     
     11     /* Set the stage and any signals that we want. */
     12     program_stage = stage_retrying;
     13     for (i = 0; relevant_sigs[i]; i++)
     14 	signal (relevant_sigs[i], interrupt);
     15 
     16     /* Forever, until a signal kills us, or Sol explodes, causing
     17      * massive electromagnetic pulses that fry my CPU.
     18      */
     19     while (1) {
     20 	/* Wait for the alarm to go off. */
     21 	sleep (activeservice->rev_interval);
     22 
     23 	/* Now do our stuff. */
     24 	for (current_backend = 0;
     25 	     current_backend < activeservice->nbackend;
     26 	     current_backend++) {
     27 
     28 	    /* Only loop through unavailable back ends. */
     29 	    if (servicereport->backendstate[current_backend].avail !=
     30 		st_unavailable)
     31 		continue;
     32 
     33 	    /* Mark state as WAKING */		    
     34 	    lock_reporter();
     35 	    servicereport->backendstate[current_backend].avail = st_waking;
     36 	    unlock_reporter();
     37 
     38 	    /* Try to TCP connect */
     39 	    sock = backend_connect();
     40 	    
     41 	    /* Set state accordingly */
     42 	    if (sock >= 0) {
     43 		close (sock);
     44 		warning ("Backend %s of service %s has woken up",
     45 			 activeservice->backend[current_backend].name,
     46 			 activeservice->name);
     47 	    }
     48 	    lock_reporter();
     49 	    servicereport->backendstate[current_backend].avail =
     50 		sock >= 0 ? st_available : st_unavailable;
     51 	    unlock_reporter();	   
     52 	}
     53     }
     54 }