How to get EAGAIN error?
To get the EAGAIN error, you need to use non-blocking sockets. With non-blocking sockets, you need to write huge amounts of data (and stop receiving data on the peer side) so that your internal TCP buffer is full and returns this error.
How to get EPIPE error message?
To get an EPIPE error message, you need to send a large amount of data after closing the socket on the partner side. You can get more information about the EPIPE error from this SO Link . I asked the Broken Pipe error question in the link provided, and the accepted answer gives a detailed explanation. It is important to note that in order to receive an EPIPE error, you must set the flags parameter to be sent to MSG_NOSIGNAL. Without this, abnormal sending can generate a SIGPIPE signal.
Additional note
Note that it is difficult to simulate a write failure, since TCP usually stores the data that you are trying to write to its internal buffer. Thus, if the internal buffer has enough space, then you will not get an error immediately. Itβs best to try to write a lot of data. You can also try setting a smaller buffer size for sending with setsockopt with the SO_SNDBUF option
source share