2021-03-23 15:01:13 +00:00
|
|
|
#include "StorageMongoDBSocketFactory.h"
|
|
|
|
|
2021-05-28 15:25:24 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include <Common/config.h>
|
|
|
|
#endif
|
|
|
|
|
2021-03-23 15:01:13 +00:00
|
|
|
#include <Poco/Net/IPAddress.h>
|
|
|
|
#include <Poco/Net/SocketAddress.h>
|
|
|
|
|
2021-05-24 12:11:03 +00:00
|
|
|
#if USE_SSL
|
|
|
|
# include <Poco/Net/SecureStreamSocket.h>
|
|
|
|
#endif
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSocket(const std::string & host, int port, Poco::Timespan connectTimeout, bool secure)
|
|
|
|
{
|
2021-05-24 12:11:03 +00:00
|
|
|
#if USE_SSL
|
2021-07-28 14:08:57 +00:00
|
|
|
return secure ? createSecureSocket(host, port, connectTimeout) : createPlainSocket(host, port, connectTimeout);
|
2021-05-24 12:11:03 +00:00
|
|
|
#else
|
2021-07-28 14:08:57 +00:00
|
|
|
return createPlainSocket(host, port, connectTimeout);
|
2021-05-24 12:11:03 +00:00
|
|
|
#endif
|
2021-03-23 15:01:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createPlainSocket(const std::string & host, int port, Poco::Timespan connectTimeout)
|
2021-03-23 15:01:13 +00:00
|
|
|
{
|
|
|
|
Poco::Net::SocketAddress address(host, port);
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::StreamSocket socket;
|
|
|
|
|
|
|
|
socket.connect(address, connectTimeout);
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
2021-05-24 12:11:03 +00:00
|
|
|
#if USE_SSL
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSecureSocket(const std::string & host, int port, Poco::Timespan connectTimeout)
|
2021-03-23 15:01:13 +00:00
|
|
|
{
|
|
|
|
Poco::Net::SocketAddress address(host, port);
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::SecureStreamSocket socket;
|
|
|
|
|
|
|
|
socket.connect(address, connectTimeout);
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
2021-05-24 12:11:03 +00:00
|
|
|
#endif
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
}
|