I'm trying to determine if a server socket was shut down gracefully or not in python.
The program received files and if some error occurs during the send the file should be removed.
I know your first suggestion will be to let the client send either the length of the file or some terminating data to let the server know that the file transfer is complete.
Sadly, I cannot change the client, it just dumps the file over raw tcp and there is nothing I can do about it. So please, no "but if you could change it" or "your protocol is flawed", I did not write the protocol and I will have to deal with it.
The script should work on both OSX and linux so epoll is out.
Any suggestions?
I can add that I don't care what error occurs, just that any error did.
It turns out that all I needed to do was to set the socket timeout to something lower, like 1 minute, the recv call will throw and exception after 1 minute.
Detecting graceful shut downs of sockets in python