I have written simple forward proxy server which accepts the connection on range of ports from the client and forwards them.
After the connection is established, I add them to a socket list which I monitor using select(). I do know better way could be using read() with one thread per fd.
I have some restrictions because of which I can not use one thread per connection and so am using select(). But then I dont get to know if client has closed the connection as select does not tell me. Is there any way to figure that out?
When select() tells you there is an event on the filedescriptors you have placed in the read set, you have to read the data by calling e.g. read() or recv().
If read() returns 0, the other end has closed its end of the connection.
If read() returns -1, some error has occured, and you have to inspect errno to see what it was. If errno is EAGAIN or EWOULDBLOCK, you should simply return to your select() loop, otherwise you should close the socket.