On Unix systems, a socket disconnection no longer stops the program with signal SIGPIPE (#72)

This commit is contained in:
Laurent Gomila 2013-06-14 15:18:08 +02:00
parent 7051d43c72
commit 94fc605a70
3 changed files with 21 additions and 2 deletions

View file

@ -38,6 +38,16 @@
#endif
namespace
{
// Define the low-level send/receive flags, which depend on the OS
#ifdef SFML_SYSTEM_LINUX
const int flags = MSG_NOSIGNAL;
#else
const int flags = 0;
#endif
}
namespace sf
{
////////////////////////////////////////////////////////////
@ -221,7 +231,7 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size)
for (int length = 0; length < sizeToSend; length += sent)
{
// Send a chunk of data
sent = ::send(getHandle(), static_cast<const char*>(data) + length, sizeToSend - length, 0);
sent = ::send(getHandle(), static_cast<const char*>(data) + length, sizeToSend - length, flags);
// Check for errors
if (sent < 0)
@ -246,7 +256,7 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec
}
// Receive a chunk of bytes
int sizeReceived = recv(getHandle(), static_cast<char*>(data), static_cast<int>(size), 0);
int sizeReceived = recv(getHandle(), static_cast<char*>(data), static_cast<int>(size), flags);
// Check the number of bytes received
if (sizeReceived > 0)