#include "server.h" void traiterClient(int socket){ requete req; int nb_octet; int fini=0; char i = 0; while(!fini){ nb_octet = read(socket,&req,sizeof(requete)); IF_NB_OCTET_BREAK if(nb_octet == 0){ break; } DEBUG&& printf("Request received (operation/size) : (%d/%d)\n",req.type,req.taille); switch(req.type){ case FIN: { fini = 1; break; } case FACTO: { int nb; long res; DEBUG&& debug("loop","FACTO asked"); nb_octet = read(socket,&nb,sizeof(int)); IF_NB_OCTET_BREAK DEBUG&& printf("%d\n",nb); res = factoriel(nb); DEBUG&& debug("loop","Sending result"); nb_octet = write(socket, &res, sizeof(res)); IF_NB_OCTET_BREAK DEBUG&& printf("done\n"); break; } case POW: { int a,b; long res; nb_octet = read(socket, &a, sizeof(int)); IF_NB_OCTET_BREAK nb_octet = read(socket, &b, sizeof(int)); IF_NB_OCTET_BREAK res = puissance(a,b); nb_octet = write(socket, &res, sizeof(res)); IF_NB_OCTET_BREAK break; } case ANALYSE: { int nb_elem, attendu; int* donnees; char message[MAX_BUFFER_LENGTH]; res_analyse_donnees res; nb_elem = req.taille/sizeof(int); donnees = (int*) malloc(nb_elem*sizeof(int)); attendu = req.taille; while(attendu > 0){ nb_octet = read(socket, message, MAX_BUFFER_LENGTH); IF_NB_OCTET_BREAK memcpy(donnees+(req.taille - attendu), message,nb_octet); attendu -= nb_octet; } analyser_donnees(donnees,nb_elem,&res); write(socket, &res, sizeof(res)); free (donnees); break; } } } }