title: My linux application port is taken by another service when it's stopped
body: <p>I developed an application which contains a small http server.</p>
  
  <p>my application is launched in the boot. If I kill it (with <code>kill -9</code> for example), the http server port will be taken directly by another daemon(acsd from broadcom).</p>
  
  <p>I tried the same behavior with drop-bear, but the problem is not reproduced. If I kill drop-bear the acsd does not take its port.</p>
  
  <p>here after the code of my server:</p>
  
  <pre><code>void http_server_init(void)
  {
      struct sockaddr_in server;
      int cr_port;
  
      for(;;) {
          cr_port = conf.port;
          int i = (DEFAULT_PORT == cr_port)? 1 : 0;
          //Create socket
          cr_socket_desc = socket(AF_INET , SOCK_STREAM , 0);
          if (cr_socket_desc == -1)
          {
              LOG (ERROR,"Could not open server socket, Error no is : %d, Error description is : %s", errno, strerror(errno));
              sleep(1);
              continue;
          }
  
          /* enable SO_REUSEADDR */
          int reusaddr = 1;
          if (setsockopt(cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &amp;reusaddr, sizeof(int)) &lt; 0) {
              LOG (WARNING,"setsockopt(SO_REUSEADDR) failed");
          }
  
          //Prepare the sockaddr_in structure
          server.sin_family = AF_INET;
          server.sin_addr.s_addr = INADDR_ANY;
          for(;;i++) {
              server.sin_port = htons(cr_port);
              //Bind
              if( bind(cr_socket_desc,(struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)
              {
                  //print the error message
                  LOG (ERROR,"Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno));
                  cr_port = DEFAULT_PORT + i;
                  LOG (INFO,"Trying to use another port: %d", cr_port);
                  continue;
              }
              break;
          }
          break;
      }
      LOG (INFO,"server initiated with the port: %d", cr_port);
  }
  </code></pre>
  
  <p>What I'm doing wrong in my http server?</p>