tags:

views:

837

answers:

1

I am using gsoap to create a soap server in C++. Messages are routed through a bus written in java. Both the server and the bus are multithreaded. Everything works well sending one message at a time through the system. If i start 3 clients each sending messages as fast as possible everything is fine for about 3500 messages. Then i begin receiving periodic "Only one socket connection allowed at a time." errors from the gsoap code. Typical about 3950 of 4000 messages make it through ok. With all 50 failures happening in the last 500 sends.

  1. Why would these errors occur after many sends, but not at the beginning of the sending. The rate of send does not increase?
  2. What is it talking about? I cannot find any explanation of the error, and it's meaning is not clear to me.
    1. Anyone successfully multithreaded a gsoap app?

Here is my server code.

long WINAPI threadGO(soap *x);

int main(int argc, char* argv[])
{
HANDLE thread1;
int m, s; /* master and slave sockets */
struct soap *soap = soap_new();
if (argc < 2)
soap_serve(soap); /* serve as CGI application */
else
{ 
  m = soap_bind(soap, NULL, atoi(argv[1]), 100); 
  if (m < 0)
  { 
      soap_print_fault(soap, stderr);
      exit(-1);
  }
  fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
  for (;;)
  {
     s = soap_accept(soap);
     thread1 =    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadGO,soap_copy(soap),0,NULL);
  }
}
soap_done(soap);
free(soap);
return 0;
}

long WINAPI threadGO(soap *x)
{
soap_serve(x);
soap_end(x);
return 0

; }

+1  A: 

I believe you've got a resource leak in threadGO.

After copying the soap struct with soap_copy(), I believe it needs to be freed by calling all of:

soap_destroy(x);
soap_end(x);
soap_free(x);

Specifically, the missing call to soap_done() (which is called from soap_free()) calls soap_closesock(), which closes the socket.

Dave