title: c socket connect error close socket
body: <p>this is code </p>
  
  <pre><code>    tcp_sockfd = socket(AF_INET , SOCK_STREAM , 0);
      if (tcp_sockfd == -1) {
          printf("Could not create socket");
          return 1;                                                                                                                                           
      }
  
      if (connect(tcp_sockfd , (struct sockaddr *)&amp;config-&gt;tcp_srvaddr , sizeof(config-&gt;tcp_srvaddr)) &lt; 0) {
          printf("connect failed. return 1\n");
          return 1;
      }
  
      struct timeval tv = {30, 0};
      setsockopt(tcp_sockfd, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&amp;tv, sizeof(struct timeval));
  
      if(send(tcp_sockfd , data , len , 0) &lt; 0) {
          printf("send failed.\n");    
          return 1;
      }
      printf("Send complete\n");
  
      close(tcp_sockfd);
  </code></pre>
  
  <p>if socket send or connect fail, have I close socket?
  or if error clocket auto close?</p>