The connected() method seems to do the trick, but I have two more questions:
1. Do I have to explicitly call it every time before I call send() and recv()? It looks silly. In C, I can immediately tell if the send or recv is successful or not by inspecting the return value. I can also catch SIGPIPE if I need to.
2. What will happen if the peer crashes right after the connected() check and before the send() or recv()? The send() or recv() will still fail and there seems to be no way to avoid this.