1

I have a scenario to close the connection in server if the client is inactive for say about 120 sec. It is intended such that I could reuse the fd after certain time inactivity.so I wrote a code to close the file descripter using

 if ((int)time(NULL) - (int)value_data->timeout > 120)
        {

          zlog_warn(_c,"timeout of 120s for  device = %s",key);
          close(value_data->fd);

          g_hash_table_iter_remove (&iter);
          (*_collector_free_tcp_cache_cb)(value_data->device_ip, value_data->fd); 

          AFREE(value_data->device_ip);
          AFREE(value_data);



        }

using close(fd), in server side the connection fd is closed. The problem I am facing is after next time the client is connected, the server is crashed. The client is not able to send the data. While looking in the tcp client side, it gives information that the Tcp is in

TCP 192.168.2.138:50296->192.168.2.161:shell (CLOSE_WAIT)

how can i send the data starting next client again? is there certain time I need to wait such that the same fd can be reused to send the data.?

3
  • Your client should close the corresponding socket file descriptor either explicitly (by calling close(fd)) or implicitly (by terminating) to move the connection out of CLOSE_WAIT. However, this is unrelated to the crash. For your server the connection is completely finished after closing it. You need to provide more context to analyze the crash
    – Ctx
    Jan 13, 2016 at 9:41
  • @Ctx after the timeout is reached, the server fd is terminated. next i started the client, server accepts the msg and same msg is checked twice and enters in recv() 0 to terminate the server Jan 13, 2016 at 9:59
  • the posted code fails to 'clear' the array: value_data, That would be where I would start. After calling AFREE() (what is that function?) then need to set any left over pointer(s) to those `AFREE'd areas to NULL, so they can be checked and not accessed again. Jan 13, 2016 at 18:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.