0

I have two processes communicating through the domain socket. Both server and client socket addresses are set to an abstract socket address. If client process crashes or be killed, the return value of recvmsg() in the server will get 0 or -1. My code handles these two returned value in the different ways, which are

  1. return 0 (work fine)

    server closes connection fd which generated by accept() and waits for another client connection (by accept())

  2. return -1

    I got the errno ECONNRESET and the server will close both fds (which generated by socket() and accept()). Then the server will try to restart all socket related connection ( socket() -> unlink() -> bind() -> listen() -> accept()). I fail to bind() the same address and get the errno EADDRINUSE.

My questions are

  1. Is my procedure to handle the ECONNRESET correct?
  2. Why I get EADDRINUSE even if I close the fd before? ( I've checked the return value of close(), it close successfully.)
  3. It is possible when the client side doesn't close the fd (generated by connect()). Then the server will see the address is used?

I want the know the correct way to handle the ECONNRESET without restarting the process. Thank you for your time!

hankyuan
  • 31
  • 3

0 Answers0