ClickHouse/src/Storages/StorageMongoDBSocketFactory.cpp

56 lines
1.4 KiB
C++
Raw Normal View History

2021-03-23 15:01:13 +00:00
#include "StorageMongoDBSocketFactory.h"
#include <Common/Exception.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
{
namespace ErrorCodes
{
extern const int FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME;
}
2021-03-23 15:01:13 +00:00
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSocket(const std::string & host, int port, Poco::Timespan connectTimeout, bool secure)
{
2021-07-28 14:08:57 +00:00
return secure ? createSecureSocket(host, port, connectTimeout) : createPlainSocket(host, port, connectTimeout);
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-07-28 15:28:30 +00:00
2021-08-02 15:16:39 +00:00
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSecureSocket(const std::string & host [[maybe_unused]], int port [[maybe_unused]], Poco::Timespan connectTimeout [[maybe_unused]])
2021-03-23 15:01:13 +00:00
{
2021-07-28 15:28:30 +00:00
#if USE_SSL
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-07-28 15:28:30 +00:00
#else
throw Exception("SSL is not enabled at build time.", ErrorCodes::FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME);
2021-05-24 12:11:03 +00:00
#endif
2021-07-28 15:28:30 +00:00
}
2021-03-23 15:01:13 +00:00
}