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
|
/*
... définition de constantes...
*/
int main( int argc, char **argv )
{
struct soap soap;
soap_init(&soap);
//specify the timeout values for non-blocking socket I/O operations.
soap.send_timeout = 20; //seconds
soap.recv_timeout = 20;
soap.accept_timeout = 0;// 3600 : server stops after 1 hour of inactivity, 0 : server never stops
soap.max_keep_alive = 100; // max keep-alive sequence
struct soap *soap_thr[MAX_THR];
pthread_t tid[MAX_THR];
int port=NUM_PORT;
SOAP_SOCKET m,s;
int i;
m=soap_bind(&soap,NULL,port,BACKLOG);
if(!soap_valid_socket(m))
exit(1);
for(i=0;i<MAX_THR;i++)
soap_thr[i]=NULL;
for(;;)
{
for(i=0;i<MAX_THR;i++)
{
s=soap_accept(&soap);
if(!soap_valid_socket(s))
{
if(soap.errnum)
{
soap_print_fault(&soap,stderr);
continue;
}
else
{
fprintf(stderr,"Server timed out\n");
break;
}
}
fprintf(stderr,"S : Socket %d : IP %d.%d.%d.%d : Thread %d\n",s,(soap.ip>>24)&0xFF,(soap.ip>>16)&0xFF,(soap.ip>>8)&0xFF,soap.ip&0xFF,i);
if(!soap_thr[i])
{
soap_thr[i]=soap_copy(&soap);
if(!soap_thr[i]){
exit(1);
}
}
else
{
pthread_join(tid[i],NULL);
soap_destroy(soap_thr[i]);
soap_end(soap_thr[i]);
fprintf(stderr,"Thread %d completed\n",i);
}
soap_thr[i]->socket=s;
pthread_create(&tid[i],NULL,(void*(*)(void*))soap_serve,(void*)soap_thr[i]);
}
}
for(i=0;i<MAX_THR;i++)
if(soap_thr[i])
{
soap_destroy(soap_thr[i]);
soap_end(soap_thr[i]);
soap_done(soap_thr[i]);
free(soap_thr[i]);
}
return 0;
}
//la requete que le client peut appeler
int ns__request(struct soap *soap, xsd__base64Binary* _param1, xsd__base64Binary* _param2, xsd__base64Binary& result){
/* ... */
} |
Partager