aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/StorageMongoDBSocketFactory.cpp
blob: ae20c39158c3516b2b199b073805280b31c95489 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "StorageMongoDBSocketFactory.h"

#include <Common/Exception.h>

#include "clickhouse_config.h"

#include <Poco/Net/IPAddress.h>
#include <Poco/Net/SocketAddress.h>

#if USE_SSL
#   include <Poco/Net/SecureStreamSocket.h>
#endif


namespace DB
{

namespace ErrorCodes
{
    extern const int FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME;
}

Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSocket(const std::string & host, int port, Poco::Timespan connectTimeout, bool secure)
{
    return secure ? createSecureSocket(host, port, connectTimeout) : createPlainSocket(host, port, connectTimeout);
}

Poco::Net::StreamSocket StorageMongoDBSocketFactory::createPlainSocket(const std::string & host, int port, Poco::Timespan connectTimeout)
{
    Poco::Net::SocketAddress address(host, port);
    Poco::Net::StreamSocket socket;

    socket.connect(address, connectTimeout);

    return socket;
}


Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSecureSocket(const std::string & host [[maybe_unused]], int port [[maybe_unused]], Poco::Timespan connectTimeout [[maybe_unused]])
{
#if USE_SSL
    Poco::Net::SocketAddress address(host, port);
    Poco::Net::SecureStreamSocket socket;

    socket.connect(address, connectTimeout);

    return socket;
#else
    throw Exception(ErrorCodes::FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME, "SSL is not enabled at build time.");
#endif
}

}