Forum Moderators: phranque
struct soap *tsoap;
pthread_t tid;
int port;
int m, s, i;
// port is first command line argument
port = atoi(argv[1]);
// bind to current host and specified port
m = soap_bind(&soap, NULL, port, BACKLOG);
// if we could not bind, exit
if (m < 0)
{
soap_print_fault(&soap, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful %d\n", m);
soap.accept_timeout = 0;
// IO timeouts
soap.send_timeout = 60;
soap.recv_timeout = 60;
// loop through requests
for (i = 1; ; i++)
{ // accept request
s = soap_accept(&soap);
// if timeout or error, report
if (s < 0)
{ if (soap.errnum)
else
fprintf(stderr, "Server timed out\n");
break;
}
fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n",
i, s, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
// copy soap environment and spawn thread
tsoap = soap_copy(&soap);
fprintf(stderr, "\ncalling PTHREAD CREATE ...\n");
pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap);