I am doing some stress test to a simple HTTP redirect server in Python scripts. The script is set up with epoll (edge trigger mode) with non-blocking sockets. But I observed something that I don’t quite understand,
1) epoll can get both ECONNREFUSED and ETIMEOUT errno while the connect() is in process. Don’t they both indicates the remote server can’t accept the connection? How are they different, how does a client tell the difference?
2) sometimes when EPOLLIN is notified by epoll, socket.recv() returns empty string without any exception thrown (or errno in C), I can keep reading the socket without getting any exception or error, it just always returns empty string. Why is that?
Thanks,
ECONNREFUSEDsignals that the connection was refused by the server, whileETIMEOUTsignals that the attempt to connect has timed out, i.e. that no indication (positive or negative) about the connection attempt was received from the peer.socket.recv()returning an empty string without error is simply the EOF condition, corresponding to an empty read in C. This happens when the other side closes the connection, or shuts it down for writing. It is normal thatEPOLLINis notified when EOF occurs, because you want to know about the EOF (and because you can safelyrecvfrom the socket without it hanging).