Commit 6c925574 authored by Marco Buttu's avatar Marco Buttu
Browse files

Fix #148: catch the broken pipe by givin MSG_NOSIGNAL to the send() system call

parent c033af3f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -339,7 +339,7 @@ int CSocket::Send(CError& Err,const void *Buff,WORD BuffLen,WORD Port,CString *A
		return FAIL;
	}
	if (getType()==STREAM) {   // stream sockets
		Res=send(m_iSocket,Buff,BuffLen,0);
		Res=send(m_iSocket,Buff,BuffLen,MSG_NOSIGNAL);
	}
	else { // datagram sockets
		if ((Addr==NULL) || (Port==0)) {
+41 −0
Original line number Diff line number Diff line
#include <IRA>

#include <stdlib.h>

namespace IRALibraryTest {

class IRALibrary_Socket : public ::testing::Test {

public:

    ::testing::AssertionResult sendWithoutConnection() {

        const BYTE *msg = (const BYTE *)("enniomorricone");
        size_t len = strlen((const char *)(msg));
        IRA::CError error;
        IRA::CSocket socket;
        socket.Create(error);
        socket.setSockMode(error, IRA::CSocket::BLOCKINGTIMEO, 3000000, 3000000);
        // Note: there is no call to socket.Connect()
        if(socket.Send(error, (const void *)(msg), len) == IRA::CSocket::FAIL)
            return ::testing::AssertionSuccess();
        else
            return ::testing::AssertionFailure();
    }

protected:
    static void TearDownTestCase() {
    }

    static void SetUpTestCase() {
    }

    virtual void SetUp() {
    }

    virtual void TearDown() {
    }

};

}
+4 −3
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

#include "IRATools_test.i"
#include "FastQueue_test.i"
#include "Socket_test.i"


using namespace IRALibraryTest;
@@ -58,6 +59,6 @@ TEST_F(IRALibrary_FastQueue,FastQueue_checkConsistency){
	EXPECT_TRUE(FastQueue_checkConsistency());
}



TEST_F(IRALibrary_Socket, sendWithoutConnection){
	EXPECT_TRUE(sendWithoutConnection());
}