Forum Moderators: phranque

Message Too Old, No Replies

one connection only

         

kmufasa

11:11 am on Sep 21, 2011 (gmt 0)

10+ Year Member



Hello all,

Can someone please give me a hint as to how I can change the following so it will only accept *one* thread per process? Basically, need some way to determine the number of threads associated with this process in the first place.

This code is from gsoap package.

Any help, hints or advice is greatly appreciated :-)

TIA


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);