简体   繁体   中英

When send()/recv() fails. Where does the socket stands?

Suppose I have a socket which I have created by the socket() system call. After that I did a connect() and started sending and receiving data.

Similarly, on the other side, a socket was created with the socket() system call, and then bind() , listen() and accept() were called. Then this side also started communicating.

Now lets suppose one of the send() (and accordingly recv() on the other side) fails.

What I want to where would that socket stand after the fail?

To communicate again, should I create the socket again and do connect() ( bind() , listen() and accept() on the other side) or I can try send() and recv() again? And additionally, what is the best thing to be done in such a scenario?

NOTE: We do not know what is the reason for the send() / recv() to fail. It can be anything from a physical wire break to the other side refusing (maybe using iptables).

What to do depends entirely on why send or recv failed.

When an error is detected, check the value of errno to determine the reason. For example, if the error code is EAGAIN you would attempt the operation again, and if the error code is ECONNRESET you would need to reconnect.

See the man pages for send and recv for more details on what errors may be returned and what you should do about them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM