1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/*
* C h e c k s _ O r i g i n _ O f _ S i g n a l
*
*/
static int Checks_Origin_Of_Signal ( void )
{
int s=-2, ss, i, n = 0 , ncar_a_lire=0 ;
if ( PARTIAL_DEBUG )
fprintf (stderr, "Checks Origin");
/*
--- If it is the main server
*/
if ( Checks_Communication(-1) == SUCCESS )
{
/* Checks the state of the communication */
if ( PARTIAL_DEBUG )
fprintf (stderr, " checks if data on client-server");
ss = ioctl(MyServer.Canal_In,FIONREAD,&ncar_a_lire);
if ( PARTIAL_DEBUG )
fprintf(stderr,"\nSORTIE DE IOCTL ss = %d ncar_a_lire = %d\n",ss, ncar_a_lire);
if ( PARTIAL_DEBUG )
fprintf (stderr, " after checking s %d ncar %d ",ss,ncar_a_lire);
if ( (ss == -1) || (ncar_a_lire != 0) /*|| (ss > 0)*/ )
return (-1) ;
}
else
{
if ( PARTIAL_DEBUG )
fprintf(stderr,"ERREUR DANS CHECK_COMMUNICATION\n");
return (-9999);
}
/*
--- Otherwise, if it is a slave server (we use the return to give for which server it arrived)
*/
if ( MyServer.NServers > 0 )
{
for ( i = 0 ; i < MyServer.NServers ; i++ )
{
if ( (! MyServer.Servers[i].Connected) &&
(Optimize_Process) &&
(MyServer.Servers[i].DispatchDisconnected) )
continue ;
if ( MyServer.Servers[i].Canal_In == 0 )
{
n = n + 1 ;
continue ;
}
/* Checks the state of the communication */
if ( Checks_Communication(i) != SUCCESS )
{
s = -10 - i ;
break ;
}
else
{
if ( PARTIAL_DEBUG )
fprintf ( stderr, " checks if data on server %d",i);
ncar_a_lire = 0 ;
ss = ioctl(MyServer.Servers[i].Canal_In,FIONREAD,&ncar_a_lire);
if ( PARTIAL_DEBUG )
fprintf ( stderr, " After checking s %d ncar %d",ss,ncar_a_lire);
if ( (ss == -1) || (ncar_a_lire != 0) )
{
if ( ss == -1 )
s = -10 - i ;
else
s = i ;
break ;
}
}
}
if ( n == MyServer.NServers )
s = -1 ;
}
if ( PARTIAL_DEBUG )
fprintf (stderr, " Origin ends");
return (s);
} |
Partager