Prevent SIGPIPE-ing on Linux when clients drop (#3755)

`send()` can only write to connected sockets [1]. In case where client
drops out, a socket may become closed by OS but we can still enqueue
packets for its connection and eventually call `send()`, which will
generate a SIGPIPE and shut the server down, because there was no
`MSG_NOSIGNAL` set.

This commit makes sure `MSG_NOSIGNAL` is used on Linux.

[1] http://linux.die.net/man/2/send
This commit is contained in:
Michał Janiszewski authored and Ted John committed 2016-05-27 17:44:23 +01:00
1 parent 91443d0e75
commit 40253a7add
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -428,7 +428,7 @@ bool NetworkConnection::SendPacket(NetworkPacket& packet)
tosend.insert(tosend.end(), (uint8*)&sizen, (uint8*)&sizen + sizeof(sizen));
tosend.insert(tosend.end(), packet.data->begin(), packet.data->end());
while (1) {
int sentBytes = send(socket, (const char*)&tosend[packet.transferred], tosend.size() - packet.transferred, 0);
int sentBytes = send(socket, (const char*)&tosend[packet.transferred], tosend.size() - packet.transferred, FLAG_NO_PIPE);
if (sentBytes == SOCKET_ERROR) {
return false;
}