I'm working on a C++ TCP server - multi client program. The problem is why the return value of write() may be a number greater than 0 even a client has been disconnected (in this case, I test with localhost and press Ctrl+C so one of the client programs ends, but it forces the main program to close).
There are some questions: 1. How to detect if write to client failed 2. Why the return value of write() is not <= 0 when it failed? 3. How to prevent the server program force close caused by a client program closed?