SIGPIPE TCP Client Server

I develop and test a client server program based on TCP sockets (Internet domain). I am currently testing it on my local machine and cannot understand the following about SIGPIPE.

*. SIGPIPE appears rather randomly. Could it be deterministic?

The first tests included one small (25 characters) send operation from the client and the corresponding reception on the server. The same code on the same computer runs successfully or not (SIGPIPE) completely out of control. The failure rate is about 45% times (quite high). In this way, I can configure the device in some way to minimize this.

**. The second round of testing was to send 40,000 small (25 characters) messages from the client to the server (1 MB of total data), and then the server responded to the total size of the data actually received. The client sends data in a narrow cycle, and there is a SINGLE reception on the server. It only works for a maximum of 1200 bytes of the total amount of data sent, and again, there are these non-deterministic SIGPIPEs, about 70% times (very bad).

Can someone suggest some improvement in my design (probably it will be on the server). The requirement is that the client should be able to send medium to very large amounts of data (again, about 25 characters each message) after one socket connection has been made to the server. I have the feeling that several shipments against one recipient will always be lost and very ineffective. Should we combine messages and send only one send () operation. Is this the only way to go?

+3
source share
2 answers

SIGPIPE is sent when trying to write to an unconnected channel / socket. Installing a signal handler will cause send () to return an error.

signal(SIGPIPE, SIG_IGN);

Alternatively, you can disable SIGPIPE for the socket:

int n = 1;
setsockopt(thesocket, SOL_SOCKET, SO_NOSIGPIPE, &n, sizeof(n));

, , , . , - , - , SIGPIPE.

+7

SIGPIPE , , . , , , .

SIGPIPE , , , . .

, . MSG_NOSIGNAL send()/sendto(), SIGPIPE. , send() -1 errno EPIPE. . . man send.

+1

Source: https://habr.com/ru/post/1796348/


All Articles