pour le non-bloquant, je te conseil plutot d'utiliser select, avec un timeout.
voici un bout de code épuré:
void get_events()
{
fd_set rfds;
struct timeval ti;
int i,n;
char buff[2000];
unsigned char event=0;
rfds=rb.cfds; // select va ecraser le contenu de rfds
ti.tv_sec=1;
ti.tv_usec=0;
select(FD_SETSIZE,&rfds,0,0,&ti); // Attente d'activite sur l'une des sockets sockINLOG,connAPP,sockAPP, ou sockLIST (avec timeout)
if ((FD_ISSET(rb.connAPP,&rfds))) // applet connectee parle
{
n=read(rb.connAPP,buff,2000);
if (n>0) // un envoie non nul ?
printf("recu %d octets\n",n);
}
if (FD_ISSET(rb.sockAPP,&rfds)) post_event(EV_APPLET_CONNECT,buff,0); // une applet veut se connecter
if ((FD_ISSET(rb.sockINLOG,&rfds))) // reception de logs
{
n=recv(rb.sockINLOG,buff,3000,0);
...
}
if ((FD_ISSET(rb.sockLIST,&rfds)))
{
rb.connLIST=accept(rb.sockLIST,(sockaddr*)&rb.addrLISTPEER,&rb.len); // bah, on l'accepte
read(rb.connLIST,buff,1);
...
}
}
main()
{
...
FD_ZERO(&rb.cfds); // Monitoring des entrees/sorties:
FD_SET(rb.sockAPP,&rb.cfds); // au debut ya juste la socket qui listen les connections
FD_SET(rb.sockINLOG,&rb.cfds); // les log
FD_SET(rb.sockLIST,&rb.cfds); // et l'ecoute des requetes serverList
while(on)
{
get_events();
...
}
}
l'essentiel de l'attente se fait au nivo du select; dans l'exemple c pas du multithread