mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 10:09:36 +02:00
fix(test): lock std:cerr to prevent data race in TCP server tests (reported by clang thread sanitizer) #4313
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "Poco/Net/StreamSocket.h"
|
#include "Poco/Net/StreamSocket.h"
|
||||||
#include "Poco/Net/ServerSocket.h"
|
#include "Poco/Net/ServerSocket.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
#include "Poco/Mutex.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ using Poco::Thread;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
static Poco::FastMutex cerrMutex;
|
||||||
|
|
||||||
class EchoConnection: public TCPServerConnection
|
class EchoConnection: public TCPServerConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -55,8 +58,10 @@ namespace
|
|||||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& exc)
|
catch (const Poco::Exception& exc)
|
||||||
{
|
{
|
||||||
|
Poco::FastMutex::ScopedLock l(cerrMutex);
|
||||||
|
|
||||||
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "Poco/Util/Application.h"
|
#include "Poco/Util/Application.h"
|
||||||
#include "Poco/Util/AbstractConfiguration.h"
|
#include "Poco/Util/AbstractConfiguration.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
#include "Poco/Mutex.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@ using Poco::Util::Application;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
static Poco::FastMutex cerrMutex;
|
||||||
|
|
||||||
class EchoConnection: public TCPServerConnection
|
class EchoConnection: public TCPServerConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -66,8 +69,10 @@ namespace
|
|||||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& exc)
|
catch (const Poco::Exception& exc)
|
||||||
{
|
{
|
||||||
|
Poco::FastMutex::ScopedLock l(cerrMutex);
|
||||||
|
|
||||||
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "Poco/Util/Application.h"
|
#include "Poco/Util/Application.h"
|
||||||
#include "Poco/Util/AbstractConfiguration.h"
|
#include "Poco/Util/AbstractConfiguration.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
#include "Poco/Mutex.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@@ -44,6 +45,8 @@ using Poco::Util::Application;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
static Poco::FastMutex cerrMutex;
|
||||||
|
|
||||||
class EchoConnection: public TCPServerConnection
|
class EchoConnection: public TCPServerConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -66,6 +69,8 @@ namespace
|
|||||||
}
|
}
|
||||||
catch (Poco::Exception& exc)
|
catch (Poco::Exception& exc)
|
||||||
{
|
{
|
||||||
|
Poco::FastMutex::ScopedLock l(cerrMutex);
|
||||||
|
|
||||||
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user