title: multithread server doesn't continue to execute whenever a client get disconnected
body: <p>hi there i'm working on a multithread Server (TCP) in C and i have a little issue about it. Everything works fine, more than one thread can connect to the server but whenever a client writes "exit" (which is a condition for a client when he/she writes "exit" string he/she goes to disconnect from the server) serves shutsdown itself also. So the communication through other threads get lost. However, logically it should be waiting for other clients even some current clients get disconnected. Here is a part of main and server is in a endless loop for waiting clients. <code>hsock</code> is id of socket belongs to server and <code>csock</code> is the id of clients.</p>
  
  <pre><code>main(){
  .
  .
  .
  
  
  while(1){
  
      if(counter==0)
          printf("waiting for a connection\n");
  
      csock = (int*)malloc(sizeof(int));
  
      if((*csock = accept( hsock, (struct sockaddr*)&amp;sadr, &amp;addr_size))!= -1){
      printf("---------------------\nReceived connection from %s\n",inet_ntoa(sadr.sin_addr));
          pthread_create(&amp;thread_id,0,&amp;SocketHandler, (void*)csock );
          counter++;
      }
  
      else{
       fprintf(stderr, "Error accepting %d\n", errno);
      }
          }// end while
  .
  .
  .
  return 0
  }
  </code></pre>
  
  <p>As you can see whenever a client get disconnected, server should keep waiting for an another threads. On the other hand, this is the last part of <code>SocketHandler</code> function which is a thread function.</p>
  
  <pre><code>void* SocketHandler(void* csock){
  .
  .
  .
  
          printf("Client disconnected\n");
          free(csock);
          return 0;
      }
  </code></pre>
  
  <p>After <code>return 0</code> statement isn't it necessary to return back to <code>while(1)</code> loop in main. I will be glad if you can help and thanks anyway</p>