You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2019/02/06 15:11:53 UTC
[ignite] branch master updated: IGNITE-10728: CPP: Moved networking
into separate lib
This is an automated email from the ASF dual-hosted git repository.
isapego pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 3a8cb3a IGNITE-10728: CPP: Moved networking into separate lib
3a8cb3a is described below
commit 3a8cb3ab2c0e05996588cdc767b6725876e9249c
Author: Igor Sapego <is...@apache.org>
AuthorDate: Wed Feb 6 18:06:52 2019 +0300
IGNITE-10728: CPP: Moved networking into separate lib
This closes #5847
---
modules/platforms/cpp/Makefile.am | 4 +
modules/platforms/cpp/Makefile.amrel | 4 +
modules/platforms/cpp/README.md | 4 +-
modules/platforms/cpp/README.txt | 3 +-
.../platforms/cpp/{common => binary}/configure.ac | 4 +-
modules/platforms/cpp/common/configure.ac | 2 +-
.../cpp/common/include/ignite/common/utils.h | 56 ++
.../cpp/common/include/ignite/ignite_error.h | 7 +
modules/platforms/cpp/configure.ac | 2 +
modules/platforms/cpp/configure.acrel | 2 +
modules/platforms/cpp/{common => jni}/configure.ac | 4 +-
modules/platforms/cpp/network/Makefile.am | 63 ++
.../platforms/cpp/{common => network}/configure.ac | 4 +-
.../include/Makefile.am} | 43 +-
.../cpp/network/include/ignite/network/end_point.h | 155 +++++
.../cpp/network/include/ignite/network/network.h | 61 ++
.../include/ignite/network}/socket_client.h | 32 +-
.../cpp/network/include/ignite/network/tcp_range.h | 171 +++++
.../include/ignite/network/utils.h} | 22 +-
.../cpp/network/os/linux/src/network/sockets.cpp | 115 ++++
.../cpp/network/os/linux/src/network/sockets.h | 83 +++
.../os/linux/src/network/tcp_socket_client.cpp | 222 +++++++
.../cpp/network/os/linux/src/network/utils.cpp | 103 +++
.../cpp/network/os/win/src/network/sockets.cpp | 137 ++++
.../cpp/network/os/win/src/network/sockets.h | 89 +++
.../os/win/src/network/tcp_socket_client.cpp | 255 ++++++++
.../cpp/network/os/win/src/network/utils.cpp | 100 +++
.../project/vs/network.vcxproj} | 178 +++---
.../cpp/network/project/vs/network.vcxproj.filters | 63 ++
.../src/network/network.cpp} | 28 +-
.../src/network}/ssl/secure_socket_client.cpp | 296 +++------
.../src/network}/ssl/secure_socket_client.h | 40 +-
.../src/network}/ssl/ssl_gateway.cpp | 60 +-
.../odbc => network/src/network}/ssl/ssl_gateway.h | 21 +-
.../src/network/tcp_socket_client.h} | 94 ++-
modules/platforms/cpp/odbc-test/Makefile.am | 4 +-
.../cpp/odbc-test/project/vs/odbc-test.vcxproj | 10 +-
.../odbc-test/project/vs/odbc-test.vcxproj.filters | 6 +-
.../cpp/odbc-test/src/attributes_test.cpp | 7 +-
.../platforms/cpp/odbc-test/src/queries_test.cpp | 2 +
.../platforms/cpp/odbc-test/src/streaming_test.cpp | 1 -
modules/platforms/cpp/odbc/Makefile.am | 14 +-
.../platforms/cpp/{common => odbc}/configure.ac | 4 +-
modules/platforms/cpp/odbc/include/Makefile.am | 6 +-
.../include/ignite/odbc/config/configuration.h | 2 +-
.../cpp/odbc/include/ignite/odbc/connection.h | 19 +-
.../cpp/odbc/include/ignite/odbc/ssl/ssl_api.h | 32 -
.../odbc/include/ignite/odbc/{ssl => }/ssl_mode.h | 0
.../include/ignite/odbc/system/tcp_socket_client.h | 156 -----
.../odbc/os/linux/src/system/tcp_socket_client.cpp | 376 -----------
.../odbc/os/win/src/system/tcp_socket_client.cpp | 469 --------------
.../win/src/system/ui/dsn_configuration_window.cpp | 2 +-
modules/platforms/cpp/odbc/project/vs/odbc.vcxproj | 24 +-
.../cpp/odbc/project/vs/odbc.vcxproj.filters | 38 +-
.../odbc/src/config/connection_string_parser.cpp | 3 +-
modules/platforms/cpp/odbc/src/connection.cpp | 80 ++-
.../platforms/cpp/odbc/src/{ssl => }/ssl_mode.cpp | 5 +-
modules/platforms/cpp/project/vs/ignite.sln | 10 +
modules/platforms/cpp/thin-client-test/Makefile.am | 3 +
modules/platforms/cpp/thin-client/Makefile.am | 15 +-
.../cpp/thin-client/os/linux/src/net/net_utils.cpp | 109 ----
.../os/linux/src/net/tcp_socket_client.cpp | 361 -----------
.../cpp/thin-client/os/win/src/net/net_utils.cpp | 106 ---
.../os/win/src/net/tcp_socket_client.cpp | 417 ------------
.../cpp/thin-client/project/vs/thin-client.vcxproj | 28 +-
.../project/vs/thin-client.vcxproj.filters | 53 +-
.../src/impl/cache/cache_affinity_info.cpp | 2 +-
.../src/impl/cache/cache_affinity_info.h | 5 +-
.../src/impl/connectable_node_partitions.h | 8 +-
.../cpp/thin-client/src/impl/data_channel.cpp | 19 +-
.../cpp/thin-client/src/impl/data_channel.h | 11 +-
.../cpp/thin-client/src/impl/data_router.cpp | 54 +-
.../cpp/thin-client/src/impl/data_router.h | 22 +-
.../cpp/thin-client/src/impl/net/end_point.h | 161 -----
.../cpp/thin-client/src/impl/net/net_utils.h | 46 --
.../cpp/thin-client/src/impl/net/tcp_range.h | 177 -----
.../thin-client/src/impl/net/tcp_socket_client.h | 157 -----
.../src/impl/{net => }/remote_type_updater.cpp | 2 +-
.../src/impl/{net => }/remote_type_updater.h | 0
.../cpp/thin-client/src/impl/socket_client.h | 105 ---
.../src/impl/ssl/secure_socket_client.cpp | 454 -------------
.../src/impl/ssl/secure_socket_client.h | 187 ------
.../cpp/thin-client/src/impl/ssl/ssl_api.cpp | 36 --
.../cpp/thin-client/src/impl/ssl/ssl_gateway.cpp | 709 ---------------------
.../cpp/thin-client/src/impl/ssl/ssl_gateway.h | 281 --------
.../platforms/cpp/thin-client/src/impl/utility.cpp | 9 +-
.../platforms/cpp/thin-client/src/impl/utility.h | 8 +-
87 files changed, 2288 insertions(+), 5054 deletions(-)
diff --git a/modules/platforms/cpp/Makefile.am b/modules/platforms/cpp/Makefile.am
index 8471259..4a5b774 100644
--- a/modules/platforms/cpp/Makefile.am
+++ b/modules/platforms/cpp/Makefile.am
@@ -19,6 +19,7 @@ ACLOCAL_AMFLAGS =-I m4
if COND_THIN_CLIENT
MAYBE_THIN_CLIENT = thin-client
+ MAYBE_NETWORK = network
if COND_TESTS
MAYBE_THIN_CLIENT_TESTS = thin-client-test
@@ -27,6 +28,7 @@ endif
if COND_ODBC
MAYBE_ODBC = odbc
+ MAYBE_NETWORK = network
if COND_TESTS
MAYBE_ODBC_TESTS = odbc-test
@@ -51,6 +53,7 @@ endif
SUBDIRS = \
common \
binary \
+ $(MAYBE_NETWORK) \
$(MAYBE_JNI) \
$(MAYBE_ODBC) \
$(MAYBE_CORE) \
@@ -63,6 +66,7 @@ SUBDIRS = \
DIST_SUBDIRS = \
common \
binary \
+ network \
jni \
odbc \
core \
diff --git a/modules/platforms/cpp/Makefile.amrel b/modules/platforms/cpp/Makefile.amrel
index 522e2fc..12222f7 100644
--- a/modules/platforms/cpp/Makefile.amrel
+++ b/modules/platforms/cpp/Makefile.amrel
@@ -19,10 +19,12 @@ ACLOCAL_AMFLAGS =-I m4
if COND_THIN_CLIENT
MAYBE_THIN_CLIENT = thin-client
+ MAYBE_NETWORK = network
endif
if COND_ODBC
MAYBE_ODBC = odbc
+ MAYBE_NETWORK = network
endif
if COND_CORE
@@ -39,6 +41,7 @@ endif
SUBDIRS = \
common \
binary \
+ $(MAYBE_NETWORK) \
$(MAYBE_JNI) \
$(MAYBE_ODBC) \
$(MAYBE_CORE) \
@@ -48,6 +51,7 @@ SUBDIRS = \
DIST_SUBDIRS = \
common \
binary \
+ network \
jni \
odbc \
core \
diff --git a/modules/platforms/cpp/README.md b/modules/platforms/cpp/README.md
index 97022e7..8d0f6d2 100644
--- a/modules/platforms/cpp/README.md
+++ b/modules/platforms/cpp/README.md
@@ -67,9 +67,9 @@ Ignite is an elastic, horizontally scalable distributed system that supports add
[Read More](https://apacheignite-cpp.readme.io/docs/cluster)
-## Ignite and Ignite С++
+## Ignite and Ignite C++
* Ignite C++ is built on top of Ignite.
-* Ignite С++ starts the JVM in the same process and communicates with it via JNI.
+* Ignite C++ starts the JVM in the same process and communicates with it via JNI.
* .NET, C++ and Java nodes can join the same cluster, use the same caches, and interoperate using common binary protocol.
* Java compute jobs can execute on any node (Java, .NET, C++).
diff --git a/modules/platforms/cpp/README.txt b/modules/platforms/cpp/README.txt
index c758343..a0a35d4 100644
--- a/modules/platforms/cpp/README.txt
+++ b/modules/platforms/cpp/README.txt
@@ -73,9 +73,10 @@ Development:
* Update Library Directories with path to the built binaries
* Update Linker\Input\Additional Dependencies in Project Properties with path to
* ignite.common.lib
- * ignite.jni.lib
* ignite.binary.lib
+ * ignite.jni.lib to use thick client
* ignite.core.lib to use thick client
+ * ignite.network.lib to use thin client
* ignite.thin-client.lib to use thin client
* Make sure that your application is aware about ignite.jni.dll and ignite.core.dll or
ignite.thin-client.dll libraries. The easiest way to achieve this is to either make
diff --git a/modules/platforms/cpp/common/configure.ac b/modules/platforms/cpp/binary/configure.ac
similarity index 88%
copy from modules/platforms/cpp/common/configure.ac
copy to modules/platforms/cpp/binary/configure.ac
index eb49d02..8486256 100644
--- a/modules/platforms/cpp/common/configure.ac
+++ b/modules/platforms/cpp/binary/configure.ac
@@ -19,7 +19,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([Apache Ignite JNI bridge for C++], [2.8.0.34042], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
+AC_INIT([Apache Ignite binary protocol library for C++], [2.7.0.30114], [dev@ignite.apache.org], [ignite-binary], [ignite.apache.org])
AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
@@ -57,6 +57,6 @@ AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
-AC_CONFIG_FILES(Makefile include/Makefile os/linux/include/Makefile ignite-common.pc)
+AC_CONFIG_FILES(Makefile include/Makefile ignite-binary.pc)
AC_OUTPUT
diff --git a/modules/platforms/cpp/common/configure.ac b/modules/platforms/cpp/common/configure.ac
index eb49d02..1efdc26 100644
--- a/modules/platforms/cpp/common/configure.ac
+++ b/modules/platforms/cpp/common/configure.ac
@@ -19,7 +19,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([Apache Ignite JNI bridge for C++], [2.8.0.34042], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
+AC_INIT([Apache Ignite common library for C++], [2.8.0.34042], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
diff --git a/modules/platforms/cpp/common/include/ignite/common/utils.h b/modules/platforms/cpp/common/include/ignite/common/utils.h
index cbcc10c..f4b5147 100644
--- a/modules/platforms/cpp/common/include/ignite/common/utils.h
+++ b/modules/platforms/cpp/common/include/ignite/common/utils.h
@@ -605,6 +605,62 @@ namespace ignite
};
/**
+ * Deinit guard class template.
+ *
+ * Upon destruction calls provided deinit function on provided instance.
+ *
+ * @tparam T Value type.
+ */
+ template<typename T>
+ class DeinitGuard
+ {
+ public:
+ /** Value type. */
+ typedef T ValueType;
+
+ /** Deinit function type. */
+ typedef void (*FuncType)(ValueType*);
+
+ /**
+ * Constructor.
+ *
+ * @param val Instance, to call method on.
+ * @param method Method to call.
+ */
+ DeinitGuard(ValueType* val, FuncType method) :
+ val(val),
+ func(method)
+ {
+ // No-op.
+ }
+
+ /**
+ * Destructor.
+ */
+ ~DeinitGuard()
+ {
+ if (val && func)
+ (func)(val);
+ }
+
+ /**
+ * Release control over object.
+ */
+ void Release()
+ {
+ val = 0;
+ func = 0;
+ }
+
+ private:
+ /** Instance, to call method on. */
+ ValueType* val;
+
+ /** Method to call. */
+ FuncType func;
+ };
+
+ /**
* Get dynamic library full name.
* @param name Name without extension.
* @return Full name.
diff --git a/modules/platforms/cpp/common/include/ignite/ignite_error.h b/modules/platforms/cpp/common/include/ignite/ignite_error.h
index 59bb0c4..0f46d5a 100644
--- a/modules/platforms/cpp/common/include/ignite/ignite_error.h
+++ b/modules/platforms/cpp/common/include/ignite/ignite_error.h
@@ -201,6 +201,13 @@ namespace ignite
/** Future state error. */
static const int IGNITE_ERR_FUTURE_STATE = 2024;
+
+ /** Networking error. */
+ static const int IGNITE_ERR_NETWORK_FAILURE = 2025;
+
+ /** SSL/TLS error. */
+ static const int IGNITE_ERR_SECURE_CONNECTION_FAILURE = 2026;
+
/** Unknown error. */
static const int IGNITE_ERR_UNKNOWN = -1;
diff --git a/modules/platforms/cpp/configure.ac b/modules/platforms/cpp/configure.ac
index 2febd9e..a1e6351 100644
--- a/modules/platforms/cpp/configure.ac
+++ b/modules/platforms/cpp/configure.ac
@@ -105,6 +105,8 @@ AC_CONFIG_FILES([ \
common/Makefile \
binary/include/Makefile \
binary/Makefile \
+ network/include/Makefile \
+ network/Makefile \
odbc/include/Makefile \
odbc/Makefile \
odbc-test/include/Makefile \
diff --git a/modules/platforms/cpp/configure.acrel b/modules/platforms/cpp/configure.acrel
index a38d357..fc2ae02 100644
--- a/modules/platforms/cpp/configure.acrel
+++ b/modules/platforms/cpp/configure.acrel
@@ -92,6 +92,8 @@ AC_CONFIG_FILES([ \
common/Makefile \
binary/include/Makefile \
binary/Makefile \
+ network/include/Makefile \
+ network/Makefile \
odbc/include/Makefile \
odbc/Makefile \
core/include/Makefile \
diff --git a/modules/platforms/cpp/common/configure.ac b/modules/platforms/cpp/jni/configure.ac
similarity index 88%
copy from modules/platforms/cpp/common/configure.ac
copy to modules/platforms/cpp/jni/configure.ac
index eb49d02..602a476 100644
--- a/modules/platforms/cpp/common/configure.ac
+++ b/modules/platforms/cpp/jni/configure.ac
@@ -19,7 +19,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([Apache Ignite JNI bridge for C++], [2.8.0.34042], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
+AC_INIT([Apache Ignite JNI bridge for C++], [2.7.0.30114], [dev@ignite.apache.org], [ignite-jni], [ignite.apache.org])
AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
@@ -57,6 +57,6 @@ AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
-AC_CONFIG_FILES(Makefile include/Makefile os/linux/include/Makefile ignite-common.pc)
+AC_CONFIG_FILES(Makefile include/Makefile ignite-jni.pc)
AC_OUTPUT
diff --git a/modules/platforms/cpp/network/Makefile.am b/modules/platforms/cpp/network/Makefile.am
new file mode 100644
index 0000000..2db45f4
--- /dev/null
+++ b/modules/platforms/cpp/network/Makefile.am
@@ -0,0 +1,63 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+
+ACLOCAL_AMFLAGS =-I m4
+
+lib_LTLIBRARIES = libignite-network.la
+
+SUBDIRS = \
+ include
+
+AM_CPPFLAGS = \
+ -I$(srcdir)/include \
+ -I$(srcdir)/src \
+ -I$(srcdir)/os/linux/include \
+ -I$(srcdir)/os/linux/src \
+ -I@top_srcdir@/common/include \
+ -I@top_srcdir@/common/os/linux/include \
+ -DIGNITE_IMPL \
+ -D__STDC_LIMIT_MACROS \
+ -D__STDC_CONSTANT_MACROS
+
+AM_CXXFLAGS = \
+ -Wall \
+ -std=c++03
+
+libignite_network_la_LIBADD = \
+ @top_srcdir@/common/libignite-common.la
+
+libignite_network_la_LDFLAGS = \
+ -no-undefined \
+ -version-info 0:0:0 \
+ -release $(PACKAGE_VERSION)
+
+libignite_network_la_DEPENDENCIES = \
+ @top_srcdir@/common/libignite-common.la
+
+libignite_network_la_SOURCES = \
+ os/linux/src/network/utils.cpp \
+ os/linux/src/network/tcp_socket_client.cpp \
+ os/linux/src/network/sockets.cpp \
+ src/network/network.cpp \
+ src/network/ssl/secure_socket_client.cpp \
+ src/network/ssl/ssl_gateway.cpp
+
+clean-local:
+ $(RM) *.gcno *.gcda
+
+clean-docs:
+ $(RM) $(DX_CLEANFILES)
diff --git a/modules/platforms/cpp/common/configure.ac b/modules/platforms/cpp/network/configure.ac
similarity index 88%
copy from modules/platforms/cpp/common/configure.ac
copy to modules/platforms/cpp/network/configure.ac
index eb49d02..5d23f22 100644
--- a/modules/platforms/cpp/common/configure.ac
+++ b/modules/platforms/cpp/network/configure.ac
@@ -19,7 +19,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([Apache Ignite JNI bridge for C++], [2.8.0.34042], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
+AC_INIT([Apache Ignite network library for C++], [2.7.0.30114], [dev@ignite.apache.org], [ignite-network], [ignite.apache.org])
AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
@@ -57,6 +57,6 @@ AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
-AC_CONFIG_FILES(Makefile include/Makefile os/linux/include/Makefile ignite-common.pc)
+AC_CONFIG_FILES(Makefile include/Makefile ignite-network.pc)
AC_OUTPUT
diff --git a/modules/platforms/cpp/Makefile.amrel b/modules/platforms/cpp/network/include/Makefile.am
similarity index 63%
copy from modules/platforms/cpp/Makefile.amrel
copy to modules/platforms/cpp/network/include/Makefile.am
index 522e2fc..da4b1c2 100644
--- a/modules/platforms/cpp/Makefile.amrel
+++ b/modules/platforms/cpp/network/include/Makefile.am
@@ -17,39 +17,12 @@
ACLOCAL_AMFLAGS =-I m4
-if COND_THIN_CLIENT
- MAYBE_THIN_CLIENT = thin-client
-endif
+nobase_include_HEADERS = \
+ ignite/network/end_point.h \
+ ignite/network/network.h \
+ ignite/network/socket_client.h \
+ ignite/network/tcp_range.h \
+ ignite/network/utils.h
-if COND_ODBC
- MAYBE_ODBC = odbc
-endif
-
-if COND_CORE
- MAYBE_CORE = core
- MAYBE_JNI = jni
-endif
-
-if COND_NODE
- MAYBE_CORE = core
- MAYBE_JNI = jni
- MAYBE_NODE = ignite
-endif
-
-SUBDIRS = \
- common \
- binary \
- $(MAYBE_JNI) \
- $(MAYBE_ODBC) \
- $(MAYBE_CORE) \
- $(MAYBE_THIN_CLIENT) \
- $(MAYBE_NODE)
-
-DIST_SUBDIRS = \
- common \
- binary \
- jni \
- odbc \
- core \
- thin-client \
- ignite
+uninstall-hook:
+ if [ -d ${includedir}/ignite ]; then find ${includedir}/ignite -type d -empty -delete; fi
diff --git a/modules/platforms/cpp/network/include/ignite/network/end_point.h b/modules/platforms/cpp/network/include/ignite/network/end_point.h
new file mode 100644
index 0000000..6e89cc9
--- /dev/null
+++ b/modules/platforms/cpp/network/include/ignite/network/end_point.h
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IGNITE_NETWORK_END_POINT
+#define _IGNITE_NETWORK_END_POINT
+
+#include <stdint.h>
+#include <string>
+
+namespace ignite
+{
+ namespace network
+ {
+ /**
+ * Connection end point structure.
+ */
+ struct EndPoint
+ {
+ /**
+ * Default constructor.
+ */
+ EndPoint() :
+ port(0)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param host Host.
+ * @param port Port.
+ */
+ EndPoint(const std::string& host, uint16_t port) :
+ host(host),
+ port(port)
+ {
+ // No-op.
+ }
+
+ /**
+ * Compare to another instance.
+ *
+ * @param other Another instance.
+ * @return Negative value if less, positive if larger and
+ * zero, if equals another instance.
+ */
+ int Compare(const EndPoint& other) const
+ {
+ if (port < other.port)
+ return -1;
+
+ if (port > other.port)
+ return 1;
+
+ return host.compare(other.host);
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if equal.
+ */
+ friend bool operator==(const EndPoint& val1, const EndPoint& val2)
+ {
+ return val1.port == val2.port && val1.host == val2.host;
+ }
+
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if not equal.
+ */
+ friend bool operator!=(const EndPoint& val1, const EndPoint& val2)
+ {
+ return !(val1 == val2);
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if less.
+ */
+ friend bool operator<(const EndPoint& val1, const EndPoint& val2)
+ {
+ return val1.Compare(val2) < 0;
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if less or equal.
+ */
+ friend bool operator<=(const EndPoint& val1, const EndPoint& val2)
+ {
+ return val1.Compare(val2) <= 0;
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if gretter.
+ */
+ friend bool operator>(const EndPoint& val1, const EndPoint& val2)
+ {
+ return val1.Compare(val2) > 0;
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if gretter or equal.
+ */
+ friend bool operator>=(const EndPoint& val1, const EndPoint& val2)
+ {
+ return val1.Compare(val2) >= 0;
+ }
+
+ /** Remote host. */
+ std::string host;
+
+ /** TCP port. */
+ uint16_t port;
+ };
+ }
+}
+
+#endif //_IGNITE_NETWORK_END_POINT
\ No newline at end of file
diff --git a/modules/platforms/cpp/network/include/ignite/network/network.h b/modules/platforms/cpp/network/include/ignite/network/network.h
new file mode 100644
index 0000000..6bb07b3
--- /dev/null
+++ b/modules/platforms/cpp/network/include/ignite/network/network.h
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IGNITE_NETWORK_SSL_SSL_API
+#define _IGNITE_NETWORK_SSL_SSL_API
+
+#include <string>
+
+#include <ignite/network/socket_client.h>
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace ssl
+ {
+ /**
+ * Ensure that SSL library is loaded.
+ *
+ * Called implicitly when SecureSocket is created, so there is no
+ * need to call this function explicitly.
+ *
+ * @throw IgniteError if it is not possible to load SSL library.
+ */
+ void EnsureSslLoaded();
+
+ /**
+ * Make basic TCP socket.
+ */
+ SocketClient* MakeTcpSocketClient();
+
+ /**
+ * Make secure socket for SSL/TLS connection.
+ *
+ * @param certPath Certificate file path.
+ * @param keyPath Private key file path.
+ * @param caPath Certificate authority file path.
+ *
+ * @throw IgniteError if it is not possible to load SSL library.
+ */
+ SocketClient* MakeSecureSocketClient(const std::string& certPath,
+ const std::string& keyPath, const std::string& caPath);
+ }
+ }
+}
+
+#endif //_IGNITE_NETWORK_SSL_SSL_API
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/socket_client.h b/modules/platforms/cpp/network/include/ignite/network/socket_client.h
similarity index 83%
copy from modules/platforms/cpp/odbc/include/ignite/odbc/socket_client.h
copy to modules/platforms/cpp/network/include/ignite/network/socket_client.h
index f16674f..eb1d481 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/socket_client.h
+++ b/modules/platforms/cpp/network/include/ignite/network/socket_client.h
@@ -15,16 +15,16 @@
* limitations under the License.
*/
-#ifndef _IGNITE_ODBC_SOCKET_CLIENT
-#define _IGNITE_ODBC_SOCKET_CLIENT
+#ifndef _IGNITE_NETWORK_SOCKET_CLIENT
+#define _IGNITE_NETWORK_SOCKET_CLIENT
#include <stdint.h>
-#include "ignite/odbc/diagnostic/diagnosable.h"
+#include <ignite/ignite_error.h>
namespace ignite
{
- namespace odbc
+ namespace network
{
/**
* Socket client implementation.
@@ -32,9 +32,6 @@ namespace ignite
class SocketClient
{
public:
- /** Connection establishment timeout in seconds. */
- enum { DEFALT_CONNECT_TIMEOUT = 5 };
-
/**
* Non-negative timeout operation result.
*/
@@ -64,11 +61,9 @@ namespace ignite
* @param hostname Remote host name.
* @param port Service port.
* @param timeout Timeout.
- * @param diag Diagnostics collector.
- * @return True on success.
+ * @return @c true on success and @c false on timeout.
*/
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout,
- diagnostic::Diagnosable& diag) = 0;
+ virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout) = 0;
/**
* Close established connection.
@@ -81,7 +76,7 @@ namespace ignite
* @param data Pointer to data to be sent.
* @param size Size of the data in bytes.
* @param timeout Timeout.
- * @return Number of bytes that have been sent on success,
+ * @return Number of bytes that have been sent on success,
* WaitResult::TIMEOUT on timeout and -errno on failure.
*/
virtual int Send(const int8_t* data, size_t size, int32_t timeout) = 0;
@@ -102,8 +97,19 @@ namespace ignite
* @return @c true if the socket is blocking and false otherwise.
*/
virtual bool IsBlocking() const = 0;
+
+ protected:
+ /**
+ * Throw connection error.
+ *
+ * @param err Error message.
+ */
+ static void ThrowNetworkError(const std::string& err)
+ {
+ throw IgniteError(IgniteError::IGNITE_ERR_NETWORK_FAILURE, err.c_str());
+ }
};
}
}
-#endif //_IGNITE_ODBC_SYSTEM_SOCKET_CLIENT
\ No newline at end of file
+#endif //_IGNITE_NETWORK_SOCKET_CLIENT
\ No newline at end of file
diff --git a/modules/platforms/cpp/network/include/ignite/network/tcp_range.h b/modules/platforms/cpp/network/include/ignite/network/tcp_range.h
new file mode 100644
index 0000000..8644d46
--- /dev/null
+++ b/modules/platforms/cpp/network/include/ignite/network/tcp_range.h
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IGNITE_NETWORK_TCP_RANGE
+#define _IGNITE_NETWORK_TCP_RANGE
+
+#include <stdint.h>
+#include <string>
+
+namespace ignite
+{
+ namespace network
+ {
+ /**
+ * TCP port range.
+ */
+ struct TcpRange
+ {
+ /**
+ * Default constructor.
+ */
+ TcpRange() :
+ port(0),
+ range(0)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param host Host.
+ * @param port Port.
+ * @param range Number of ports after the @c port that
+ * should be tried if the previous are unavailable.
+ */
+ TcpRange(const std::string& host, uint16_t port, uint16_t range = 0) :
+ host(host),
+ port(port),
+ range(range)
+ {
+ // No-op.
+ }
+
+ /**
+ * Compare to another instance.
+ *
+ * @param other Another instance.
+ * @return Negative value if less, positive if larger and
+ * zero, if equals another instance.
+ */
+ int Compare(const TcpRange& other) const
+ {
+ if (port < other.port)
+ return -1;
+
+ if (port > other.port)
+ return 1;
+
+ if (range < other.range)
+ return -1;
+
+ if (range > other.range)
+ return 1;
+
+ return host.compare(other.host);
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if equal.
+ */
+ friend bool operator==(const TcpRange& val1, const TcpRange& val2)
+ {
+ return val1.port == val2.port && val1.range == val2.range && val1.host == val2.host;
+ }
+
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if not equal.
+ */
+ friend bool operator!=(const TcpRange& val1, const TcpRange& val2)
+ {
+ return !(val1 == val2);
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if less.
+ */
+ friend bool operator<(const TcpRange& val1, const TcpRange& val2)
+ {
+ return val1.Compare(val2) < 0;
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if less or equal.
+ */
+ friend bool operator<=(const TcpRange& val1, const TcpRange& val2)
+ {
+ return val1.Compare(val2) <= 0;
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if gretter.
+ */
+ friend bool operator>(const TcpRange& val1, const TcpRange& val2)
+ {
+ return val1.Compare(val2) > 0;
+ }
+
+ /**
+ * Comparison operator.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if gretter or equal.
+ */
+ friend bool operator>=(const TcpRange& val1, const TcpRange& val2)
+ {
+ return val1.Compare(val2) >= 0;
+ }
+
+ /** Remote host. */
+ std::string host;
+
+ /** TCP port. */
+ uint16_t port;
+
+ /**
+ * Number of ports after the port that should be tried if
+ * the previous are unavailable.
+ */
+ uint16_t range;
+ };
+ }
+}
+
+#endif //_IGNITE_NETWORK_TCP_RANGE
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_api.h b/modules/platforms/cpp/network/include/ignite/network/utils.h
similarity index 70%
rename from modules/platforms/cpp/thin-client/src/impl/ssl/ssl_api.h
rename to modules/platforms/cpp/network/include/ignite/network/utils.h
index 8d6b72d..f195784 100644
--- a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_api.h
+++ b/modules/platforms/cpp/network/include/ignite/network/utils.h
@@ -15,22 +15,26 @@
* limitations under the License.
*/
-#ifndef _IGNITE_IMPL_THIN_SSL_SSL_API
-#define _IGNITE_IMPL_THIN_SSL_SSL_API
+#ifndef _IGNITE_NETWORK_UTILS
+#define _IGNITE_NETWORK_UTILS
+#include <set>
+#include <string>
namespace ignite
{
- namespace impl
+ namespace network
{
- namespace thin
+ namespace utils
{
- namespace ssl
- {
- void EnsureSslLoaded();
- }
+ /**
+ * Get set of local addresses.
+ *
+ * @param addrs Addresses set.
+ */
+ void GetLocalAddresses(std::set<std::string>& addrs);
}
}
}
-#endif //_IGNITE_IMPL_THIN_SSL_SSL_API
\ No newline at end of file
+#endif //_IGNITE_NETWORK_UTILS
\ No newline at end of file
diff --git a/modules/platforms/cpp/network/os/linux/src/network/sockets.cpp b/modules/platforms/cpp/network/os/linux/src/network/sockets.cpp
new file mode 100644
index 0000000..08e0b5e
--- /dev/null
+++ b/modules/platforms/cpp/network/os/linux/src/network/sockets.cpp
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/socket.h>
+#include <poll.h>
+
+#include <errno.h>
+#include <string.h>
+
+#include <sstream>
+
+#include "network/sockets.h"
+#include <ignite/network/socket_client.h>
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace sockets
+ {
+ int GetLastSocketError()
+ {
+ return errno;
+ }
+
+ int GetLastSocketError(int handle)
+ {
+ int lastError = 0;
+ socklen_t size = sizeof(lastError);
+ int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
+
+ return res == SOCKET_ERROR ? 0 : lastError;
+ }
+
+ std::string GetSocketErrorMessage(int error)
+ {
+ std::stringstream res;
+
+ res << "error_code=" << error;
+
+ if (error == 0)
+ return res.str();
+
+ char buffer[1024] = "";
+
+ if (!strerror_r(error, buffer, sizeof(buffer)))
+ res << ", msg=" << buffer;
+
+ return res.str();
+ }
+
+ std::string GetLastSocketErrorMessage()
+ {
+ int lastError = errno;
+
+ return GetSocketErrorMessage(lastError);
+ }
+
+ int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd)
+ {
+ int32_t timeout0 = timeout == 0 ? -1 : timeout;
+
+ int lastError = 0;
+ int ret;
+
+ do
+ {
+ struct pollfd fds[1];
+
+ fds[0].fd = socket;
+ fds[0].events = rd ? POLLIN : POLLOUT;
+
+ ret = poll(fds, 1, timeout0 * 1000);
+
+ if (ret == SOCKET_ERROR)
+ lastError = GetLastSocketError();
+
+ } while (ret == SOCKET_ERROR && IsSocketOperationInterrupted(lastError));
+
+ if (ret == SOCKET_ERROR)
+ return -lastError;
+
+ socklen_t size = sizeof(lastError);
+ int res = getsockopt(socket, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
+
+ if (res != SOCKET_ERROR && lastError != 0)
+ return -lastError;
+
+ if (ret == 0)
+ return SocketClient::WaitResult::TIMEOUT;
+
+ return SocketClient::WaitResult::SUCCESS;
+ }
+
+ bool IsSocketOperationInterrupted(int errorCode)
+ {
+ return errorCode == EINTR;
+ }
+ }
+ }
+}
diff --git a/modules/platforms/cpp/network/os/linux/src/network/sockets.h b/modules/platforms/cpp/network/os/linux/src/network/sockets.h
new file mode 100644
index 0000000..aad7bb2
--- /dev/null
+++ b/modules/platforms/cpp/network/os/linux/src/network/sockets.h
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IGNITE_NETWORK_SOCKETS
+#define _IGNITE_NETWORK_SOCKETS
+
+#include <stdint.h>
+#include <string>
+
+#define SOCKET_ERROR (-1)
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace sockets
+ {
+ /** Socket handle type. */
+ typedef int SocketHandle;
+
+ /**
+ * Get socket error.
+ * @return Last socket error.
+ */
+ int GetLastSocketError();
+
+ /**
+ * Get socket error.
+ * @param handle Socket handle.
+ * @return Last socket error.
+ */
+ int GetLastSocketError(int handle);
+
+ /**
+ * Get socket error message for the error code.
+ * @param error Error code.
+ * @return Socket error message string.
+ */
+ std::string GetSocketErrorMessage(int error);
+
+ /**
+ * Get last socket error message.
+ * @return Last socket error message string.
+ */
+ std::string GetLastSocketErrorMessage();
+
+ /**
+ * Check whether socket operation was interupted.
+ * @return @c true if the socket operation was interupted.
+ */
+ bool IsSocketOperationInterrupted(int errorCode);
+
+ /**
+ * Wait on the socket for any event for specified time.
+ * This function uses poll to achive timeout functionality
+ * for every separate socket operation.
+ *
+ * @param socket Socket handle.
+ * @param timeout Timeout.
+ * @param rd Wait for read if @c true, or for write if @c false.
+ * @return -errno on error, WaitResult::TIMEOUT on timeout and
+ * WaitResult::SUCCESS on success.
+ */
+ int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd);
+ }
+ }
+}
+
+#endif //_IGNITE_NETWORK_SOCKETS
\ No newline at end of file
diff --git a/modules/platforms/cpp/network/os/linux/src/network/tcp_socket_client.cpp b/modules/platforms/cpp/network/os/linux/src/network/tcp_socket_client.cpp
new file mode 100644
index 0000000..e6fff91
--- /dev/null
+++ b/modules/platforms/cpp/network/os/linux/src/network/tcp_socket_client.cpp
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <cstring>
+
+#include <sstream>
+
+#include <ignite/common/concurrent.h>
+
+#include <ignite/ignite_error.h>
+#include "network/tcp_socket_client.h"
+
+namespace ignite
+{
+ namespace network
+ {
+ TcpSocketClient::TcpSocketClient() :
+ socketHandle(SOCKET_ERROR),
+ blocking(true)
+ {
+ // No-op.
+ }
+
+ TcpSocketClient::~TcpSocketClient()
+ {
+ InternalClose();
+ }
+
+ bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
+ {
+ addrinfo hints = { 0 };
+
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ std::stringstream converter;
+ converter << port;
+ std::string strPort = converter.str();
+
+ // Resolve the server address and port
+ addrinfo *result = NULL;
+ int res = getaddrinfo(hostname, strPort.c_str(), &hints, &result);
+
+ if (res != 0)
+ ThrowNetworkError("Can not resolve host: " + std::string(hostname) + ":" + strPort);
+
+ std::string lastErrorMsg = "Failed to resolve host";
+ bool isTimeout = false;
+
+ // Attempt to connect to an address until one succeeds
+ for (addrinfo *it = result; it != NULL; it = it->ai_next)
+ {
+ lastErrorMsg = "Failed to establish connection with the host";
+ isTimeout = false;
+
+ // Create a SOCKET for connecting to server
+ socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
+
+ if (socketHandle == SOCKET_ERROR)
+ {
+ std::string err = "Socket creation failed: " + sockets::GetLastSocketErrorMessage();
+
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
+ }
+
+ TrySetOptions();
+
+ // Connect to server.
+ res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
+ if (SOCKET_ERROR == res)
+ {
+ int lastError = errno;
+
+ if (lastError != EWOULDBLOCK && lastError != EINPROGRESS)
+ {
+ lastErrorMsg.append(": ").append(sockets::GetSocketErrorMessage(lastError));
+
+ Close();
+
+ continue;
+ }
+
+ res = WaitOnSocket(timeout, false);
+
+ if (res < 0 || res == WaitResult::TIMEOUT)
+ {
+ isTimeout = true;
+
+ Close();
+
+ continue;
+ }
+ }
+
+ break;
+ }
+
+ freeaddrinfo(result);
+
+ if (socketHandle == SOCKET_ERROR)
+ {
+ if (isTimeout)
+ return false;
+
+ ThrowNetworkError(lastErrorMsg);
+ }
+
+ return true;
+ }
+
+ void TcpSocketClient::Close()
+ {
+ InternalClose();
+ }
+
+ void TcpSocketClient::InternalClose()
+ {
+ if (socketHandle != SOCKET_ERROR)
+ {
+ close(socketHandle);
+
+ socketHandle = SOCKET_ERROR;
+ }
+ }
+
+ int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
+ {
+ if (!blocking)
+ {
+ int res = WaitOnSocket(timeout, false);
+
+ if (res < 0 || res == WaitResult::TIMEOUT)
+ return res;
+ }
+
+ return send(socketHandle, reinterpret_cast<const char*>(data), static_cast<int>(size), 0);
+ }
+
+ int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
+ {
+ if (!blocking)
+ {
+ int res = WaitOnSocket(timeout, true);
+
+ if (res < 0 || res == WaitResult::TIMEOUT)
+ return res;
+ }
+
+ return recv(socketHandle, reinterpret_cast<char*>(buffer), static_cast<int>(size), 0);
+ }
+
+ bool TcpSocketClient::IsBlocking() const
+ {
+ return blocking;
+ }
+
+ void TcpSocketClient::TrySetOptions()
+ {
+ int trueOpt = 1;
+
+ int idleOpt = KEEP_ALIVE_IDLE_TIME;
+ int idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD;
+ int bufSizeOpt = BUFFER_SIZE;
+
+ setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
+
+ setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
+
+ setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
+
+ setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE, reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
+
+ blocking = false;
+
+ int flags;
+ blocking = ((flags = fcntl(socketHandle, F_GETFL, 0)) < 0) ||
+ (fcntl(socketHandle, F_SETFL, flags | O_NONBLOCK) < 0);
+
+ int res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE,
+ reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
+
+ if (SOCKET_ERROR == res)
+ {
+ // There is no sense in configuring keep alive params if we faileed to set up keep alive mode.
+ return;
+ }
+
+ setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE, reinterpret_cast<char*>(&idleOpt), sizeof(idleOpt));
+
+ setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL,
+ reinterpret_cast<char*>(&idleRetryOpt), sizeof(idleRetryOpt));
+ }
+
+ int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd)
+ {
+ return sockets::WaitOnSocket(socketHandle, timeout, rd);
+ }
+ }
+}
+
diff --git a/modules/platforms/cpp/network/os/linux/src/network/utils.cpp b/modules/platforms/cpp/network/os/linux/src/network/utils.cpp
new file mode 100644
index 0000000..c719f85
--- /dev/null
+++ b/modules/platforms/cpp/network/os/linux/src/network/utils.cpp
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdio>
+#include <cstdlib>
+
+#include <set>
+#include <string>
+#include <iostream>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <ifaddrs.h>
+#include <errno.h>
+
+#include <ignite/ignite_error.h>
+
+#include <ignite/network/utils.h>
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace utils
+ {
+ void GetLocalAddresses(std::set<std::string>& addrs)
+ {
+ struct ifaddrs *outAddrs;
+ if(getifaddrs(&outAddrs) != 0)
+ {
+ freeifaddrs(outAddrs);
+
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list");
+ }
+
+ for (struct ifaddrs *outAddr = outAddrs; outAddr != NULL; outAddr = outAddr->ifa_next)
+ {
+ if (outAddr->ifa_addr == NULL)
+ continue;
+
+ if (outAddr->ifa_flags & IFF_LOOPBACK)
+ continue;
+
+ if (!(outAddr->ifa_flags & IFF_UP))
+ continue;
+
+ void *inAddr;
+
+ char strBuffer[INET6_ADDRSTRLEN];
+
+ int saFamily = outAddr->ifa_addr->sa_family;
+
+ switch (saFamily)
+ {
+ case AF_INET:
+ {
+ sockaddr_in *s4 = reinterpret_cast<sockaddr_in*>(outAddr->ifa_addr);
+ inAddr = &s4->sin_addr;
+ break;
+ }
+
+ case AF_INET6:
+ {
+ sockaddr_in6 *s6 = reinterpret_cast<sockaddr_in6*>(outAddr->ifa_addr);
+ inAddr = &s6->sin6_addr;
+ break;
+ }
+
+ default:
+ continue;
+ }
+
+ inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer));
+
+ std::string strAddr(strBuffer);
+
+ if (!strAddr.empty())
+ addrs.insert(strAddr);
+ }
+
+ freeifaddrs(outAddrs);
+ }
+ }
+ }
+}
+
diff --git a/modules/platforms/cpp/network/os/win/src/network/sockets.cpp b/modules/platforms/cpp/network/os/win/src/network/sockets.cpp
new file mode 100644
index 0000000..a6b6bb1
--- /dev/null
+++ b/modules/platforms/cpp/network/os/win/src/network/sockets.cpp
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "network/sockets.h"
+
+#include <sstream>
+
+#include <ignite/network/socket_client.h>
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace sockets
+ {
+ int GetLastSocketError()
+ {
+ return WSAGetLastError();
+ }
+
+ int GetLastSocketError(int handle)
+ {
+ int lastError = 0;
+ socklen_t size = sizeof(lastError);
+ int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
+
+ return res == SOCKET_ERROR ? 0 : lastError;
+ }
+
+ std::string GetSocketErrorMessage(HRESULT error)
+ {
+ std::stringstream res;
+
+ res << "error_code=" << error;
+
+ if (error == 0)
+ return res.str();
+
+ LPTSTR errorText = NULL;
+
+ DWORD len = FormatMessage(
+ // use system message tables to retrieve error text
+ FORMAT_MESSAGE_FROM_SYSTEM
+ // allocate buffer on local heap for error text
+ | FORMAT_MESSAGE_ALLOCATE_BUFFER
+ // We're not passing insertion parameters
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ // unused with FORMAT_MESSAGE_FROM_SYSTEM
+ NULL,
+ error,
+ MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
+ // output
+ reinterpret_cast<LPTSTR>(&errorText),
+ // minimum size for output buffer
+ 0,
+ // arguments - see note
+ NULL);
+
+ if (NULL != errorText && len > 0)
+ {
+ std::string msg(reinterpret_cast<const char*>(errorText), static_cast<size_t>(len));
+
+ if (len != 0)
+ res << ", msg=" << msg;
+
+ LocalFree(errorText);
+ }
+
+ return res.str();
+ }
+
+ std::string GetLastSocketErrorMessage()
+ {
+ HRESULT lastError = WSAGetLastError();
+
+ return GetSocketErrorMessage(lastError);
+ }
+
+ int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd)
+ {
+ int ready = 0;
+ int lastError = 0;
+
+ fd_set fds;
+
+ do {
+ struct timeval tv = { 0 };
+ tv.tv_sec = timeout;
+
+ FD_ZERO(&fds);
+ FD_SET(socket, &fds);
+
+ fd_set* readFds = 0;
+ fd_set* writeFds = 0;
+
+ if (rd)
+ readFds = &fds;
+ else
+ writeFds = &fds;
+
+ ready = select(static_cast<int>(socket) + 1, readFds, writeFds, NULL, timeout == 0 ? NULL : &tv);
+
+ if (ready == SOCKET_ERROR)
+ lastError = GetLastSocketError();
+
+ } while (ready == SOCKET_ERROR && IsSocketOperationInterrupted(lastError));
+
+ if (ready == SOCKET_ERROR)
+ return -lastError;
+
+ if (ready == 0)
+ return SocketClient::WaitResult::TIMEOUT;
+
+ return SocketClient::WaitResult::SUCCESS;
+ }
+
+ bool IsSocketOperationInterrupted(int errorCode)
+ {
+ return errorCode == WSAEINTR;
+ }
+ }
+ }
+}
diff --git a/modules/platforms/cpp/network/os/win/src/network/sockets.h b/modules/platforms/cpp/network/os/win/src/network/sockets.h
new file mode 100644
index 0000000..8da1fc0
--- /dev/null
+++ b/modules/platforms/cpp/network/os/win/src/network/sockets.h
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IGNITE_NETWORK_SOCKETS
+#define _IGNITE_NETWORK_SOCKETS
+
+#define WIN32_LEAN_AND_MEAN
+#define _WINSOCKAPI_
+
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <mstcpip.h>
+
+#include <stdint.h>
+#include <string>
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace sockets
+ {
+ /** Socket handle type. */
+ typedef SOCKET SocketHandle;
+
+ /**
+ * Get socket error.
+ * @return Last socket error.
+ */
+ int GetLastSocketError();
+
+ /**
+ * Get socket error.
+ * @param handle Socket handle.
+ * @return Last socket error.
+ */
+ int GetLastSocketError(int handle);
+
+ /**
+ * Get socket error message for the error code.
+ * @param error Error code.
+ * @return Socket error message string.
+ */
+ std::string GetSocketErrorMessage(HRESULT error);
+
+ /**
+ * Get last socket error message.
+ * @return Last socket error message string.
+ */
+ std::string GetLastSocketErrorMessage();
+
+ /**
+ * Check whether socket operation was interupted.
+ * @return @c true if the socket operation was interupted.
+ */
+ bool IsSocketOperationInterrupted(int errorCode);
+
+ /**
+ * Wait on the socket for any event for specified time.
+ * This function uses poll to achive timeout functionality
+ * for every separate socket operation.
+ *
+ * @param socket Socket handle.
+ * @param timeout Timeout.
+ * @param rd Wait for read if @c true, or for write if @c false.
+ * @return -errno on error, WaitResult::TIMEOUT on timeout and
+ * WaitResult::SUCCESS on success.
+ */
+ int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd);
+ }
+ }
+}
+
+#endif //_IGNITE_NETWORK_SOCKETS
\ No newline at end of file
diff --git a/modules/platforms/cpp/network/os/win/src/network/tcp_socket_client.cpp b/modules/platforms/cpp/network/os/win/src/network/tcp_socket_client.cpp
new file mode 100644
index 0000000..af8f3c4
--- /dev/null
+++ b/modules/platforms/cpp/network/os/win/src/network/tcp_socket_client.cpp
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "network/sockets.h"
+
+#include <sstream>
+
+#include <ignite/ignite_error.h>
+
+#include <ignite/common/concurrent.h>
+
+#include "network/tcp_socket_client.h"
+
+namespace ignite
+{
+ namespace network
+ {
+ TcpSocketClient::TcpSocketClient() :
+ socketHandle(INVALID_SOCKET),
+ blocking(true)
+ {
+ // No-op.
+ }
+
+ TcpSocketClient::~TcpSocketClient()
+ {
+ InternalClose();
+ }
+
+ bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
+ {
+ static common::concurrent::CriticalSection initCs;
+ static bool networkInited = false;
+
+ // Initing networking if is not inited.
+ if (!networkInited)
+ {
+ common::concurrent::CsLockGuard lock(initCs);
+ if (!networkInited)
+ {
+ WSADATA wsaData;
+
+ networkInited = WSAStartup(MAKEWORD(2, 2), &wsaData) == 0;
+
+ if (!networkInited)
+ ThrowNetworkError("Networking initialisation failed: " + sockets::GetLastSocketErrorMessage());
+ }
+ }
+
+ addrinfo hints = { 0 };
+
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ std::stringstream converter;
+ converter << port;
+ std::string strPort = converter.str();
+
+ // Resolve the server address and port
+ addrinfo *result = NULL;
+ int res = getaddrinfo(hostname, strPort.c_str(), &hints, &result);
+
+ if (res != 0)
+ ThrowNetworkError("Can not resolve host: " + std::string(hostname) + ":" + strPort);
+
+ std::string lastErrorMsg = "Failed to resolve host";
+ bool isTimeout = false;
+
+ // Attempt to connect to an address until one succeeds
+ for (addrinfo *it = result; it != NULL; it = it->ai_next)
+ {
+ lastErrorMsg = "Failed to establish connection with the host";
+ isTimeout = false;
+
+ // Create a SOCKET for connecting to server
+ socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
+
+ if (socketHandle == INVALID_SOCKET)
+ ThrowNetworkError("Socket creation failed: " + sockets::GetLastSocketErrorMessage());
+
+ TrySetOptions();
+
+ // Connect to server.
+ res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
+ if (SOCKET_ERROR == res)
+ {
+ int lastError = WSAGetLastError();
+
+ if (lastError != WSAEWOULDBLOCK)
+ {
+ lastErrorMsg.append(": ").append(sockets::GetSocketErrorMessage(lastError));
+
+ Close();
+
+ continue;
+ }
+
+ res = WaitOnSocket(timeout, false);
+
+ if (res < 0 || res == WaitResult::TIMEOUT)
+ {
+ isTimeout = true;
+
+ Close();
+
+ continue;
+ }
+ }
+
+ break;
+ }
+
+ freeaddrinfo(result);
+
+ if (socketHandle == INVALID_SOCKET)
+ {
+ if (isTimeout)
+ return false;
+
+ ThrowNetworkError(lastErrorMsg);
+ }
+
+ return true;
+ }
+
+ void TcpSocketClient::Close()
+ {
+ InternalClose();
+ }
+
+ void TcpSocketClient::InternalClose()
+ {
+ if (socketHandle != INVALID_SOCKET)
+ {
+ closesocket(socketHandle);
+
+ socketHandle = INVALID_SOCKET;
+ }
+ }
+
+ int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
+ {
+ if (!blocking)
+ {
+ int res = WaitOnSocket(timeout, false);
+
+ if (res < 0 || res == WaitResult::TIMEOUT)
+ return res;
+ }
+
+ return send(socketHandle, reinterpret_cast<const char*>(data), static_cast<int>(size), 0);
+ }
+
+ int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
+ {
+ if (!blocking)
+ {
+ int res = WaitOnSocket(timeout, true);
+
+ if (res < 0 || res == WaitResult::TIMEOUT)
+ return res;
+ }
+
+ return recv(socketHandle, reinterpret_cast<char*>(buffer), static_cast<int>(size), 0);
+ }
+
+ bool TcpSocketClient::IsBlocking() const
+ {
+ return blocking;
+ }
+
+ void TcpSocketClient::TrySetOptions()
+ {
+ BOOL trueOpt = TRUE;
+ ULONG uTrueOpt = TRUE;
+ int bufSizeOpt = BUFFER_SIZE;
+
+ setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
+
+ setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
+
+ setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
+
+ setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE, reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
+
+ blocking = ioctlsocket(socketHandle, FIONBIO, &uTrueOpt) == SOCKET_ERROR;
+
+ int res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE,
+ reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
+
+ if (SOCKET_ERROR == res)
+ {
+ // There is no sense in configuring keep alive params if we faileed to set up keep alive mode.
+ return;
+ }
+
+ // This option is available starting with Windows 10, version 1709.
+#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL)
+ DWORD idleOpt = KEEP_ALIVE_IDLE_TIME;
+ DWORD idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD;
+
+ setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE, reinterpret_cast<char*>(&idleOpt), sizeof(idleOpt));
+
+ setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL,
+ reinterpret_cast<char*>(&idleRetryOpt), sizeof(idleRetryOpt));
+#else // use old hardcore WSAIoctl
+
+ // WinSock structure for KeepAlive timing settings
+ struct tcp_keepalive settings = { 0 };
+ settings.onoff = 1;
+ settings.keepalivetime = KEEP_ALIVE_IDLE_TIME * 1000;
+ settings.keepaliveinterval = KEEP_ALIVE_PROBES_PERIOD * 1000;
+
+ // pointers for WinSock call
+ DWORD bytesReturned;
+ WSAOVERLAPPED overlapped;
+ overlapped.hEvent = NULL;
+
+ // Set KeepAlive settings
+ WSAIoctl(
+ socketHandle,
+ SIO_KEEPALIVE_VALS,
+ &settings,
+ sizeof(struct tcp_keepalive),
+ NULL,
+ 0,
+ &bytesReturned,
+ &overlapped,
+ NULL
+ );
+#endif
+ }
+
+ int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd)
+ {
+ return sockets::WaitOnSocket(socketHandle, timeout, rd);
+ }
+ }
+}
+
diff --git a/modules/platforms/cpp/network/os/win/src/network/utils.cpp b/modules/platforms/cpp/network/os/win/src/network/utils.cpp
new file mode 100644
index 0000000..1ff1aca
--- /dev/null
+++ b/modules/platforms/cpp/network/os/win/src/network/utils.cpp
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstddef>
+
+#include <string>
+#include <set>
+#include <iostream>
+
+#include <winsock2.h>
+#include <ws2ipdef.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#include <iphlpapi.h>
+
+#include <ignite/ignite_error.h>
+
+#include <ignite/network/utils.h>
+
+namespace ignite
+{
+ namespace network
+ {
+ namespace utils
+ {
+ void GetLocalAddresses(std::set<std::string>& addrs)
+ {
+ IP_ADAPTER_ADDRESSES outAddrs[64];
+
+ DWORD outAddrsSize = sizeof(outAddrs);
+
+ DWORD error = ::GetAdaptersAddresses(AF_UNSPEC, 0, NULL, &outAddrs[0], &outAddrsSize);
+
+ if (ERROR_SUCCESS != error)
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list");
+
+ for (IP_ADAPTER_ADDRESSES* outAddr = &outAddrs[0]; NULL != outAddr; outAddr = outAddr->Next)
+ {
+ if (IF_TYPE_SOFTWARE_LOOPBACK == outAddr->IfType)
+ continue;
+
+ for (IP_ADAPTER_UNICAST_ADDRESS* addr = outAddr->FirstUnicastAddress;
+ NULL != addr;
+ addr = addr->Next)
+ {
+ void *inAddr = 0;
+
+ char strBuffer[INET6_ADDRSTRLEN] = { 0 };
+
+ int saFamily = addr->Address.lpSockaddr->sa_family;
+
+ switch (saFamily)
+ {
+ case AF_INET:
+ {
+ SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(addr->Address.lpSockaddr);
+ inAddr = &ipv4->sin_addr;
+
+ break;
+ }
+
+ case AF_INET6:
+ {
+ SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(addr->Address.lpSockaddr);
+ inAddr = &ipv6->sin6_addr;
+
+ break;
+ }
+
+ default:
+ continue;
+ }
+
+ inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer));
+
+ std::string strAddr(strBuffer);
+
+ if (!strAddr.empty())
+ addrs.insert(strAddr);
+ }
+ }
+ }
+ }
+ }
+}
+
diff --git a/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj b/modules/platforms/cpp/network/project/vs/network.vcxproj
similarity index 54%
copy from modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj
copy to modules/platforms/cpp/network/project/vs/network.vcxproj
index 9c00913..18a8e8a 100644
--- a/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj
+++ b/modules/platforms/cpp/network/project/vs/network.vcxproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@@ -19,36 +19,38 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
- <ProjectGuid>{5C037386-B5F5-4A58-9EE2-3D3A508AA866}</ProjectGuid>
- <RootNamespace>ignite.thinclient</RootNamespace>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <ProjectGuid>{CB77AC4D-88D4-4A8C-922C-A28C19060A97}</ProjectGuid>
+ <RootNamespace>network</RootNamespace>
+ <ProjectName>network</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v100</PlatformToolset>
- <CharacterSet>MultiByte</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v100</PlatformToolset>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v100</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -69,144 +71,134 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <TargetName>ignite.network</TargetName>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
- <TargetName>ignite.thin-client</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <TargetName>ignite.network</TargetName>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
- <TargetName>ignite.thin-client</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <TargetName>ignite.network</TargetName>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
- <TargetName>ignite.thin-client</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <TargetName>ignite.network</TargetName>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
- <TargetName>ignite.thin-client</TargetName>
</PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";_DEBUG";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\os\win\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <BufferSecurityCheck>true</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>Ws2_32.lib;Mswsock.lib;Advapi32.lib;Shlwapi.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <DelayLoadDLLs>
- </DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\os\win\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <BufferSecurityCheck>true</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>Ws2_32.lib;Mswsock.lib;Advapi32.lib;Shlwapi.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <DelayLoadDLLs>
- </DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
- <Optimization>MaxSpeed</Optimization>
+ <Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\os\win\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <AdditionalDependencies>Ws2_32.lib;Mswsock.lib;Advapi32.lib;Shlwapi.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\os\win\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <AdditionalDependencies>Ws2_32.lib;Mswsock.lib;Advapi32.lib;Shlwapi.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="..\..\os\win\src\net\tcp_socket_client.cpp" />
- <ClCompile Include="..\..\os\win\src\net\net_utils.cpp" />
- <ClCompile Include="..\..\src\ignite_client.cpp" />
- <ClCompile Include="..\..\src\impl\cache\cache_affinity_info.cpp" />
- <ClCompile Include="..\..\src\impl\cache\cache_client_impl.cpp" />
- <ClCompile Include="..\..\src\impl\cache\cache_client_proxy.cpp" />
- <ClCompile Include="..\..\src\impl\data_channel.cpp" />
- <ClCompile Include="..\..\src\impl\data_router.cpp" />
- <ClCompile Include="..\..\src\impl\ignite_client_impl.cpp" />
- <ClCompile Include="..\..\src\impl\message.cpp" />
- <ClCompile Include="..\..\src\impl\net\remote_type_updater.cpp" />
- <ClCompile Include="..\..\src\impl\protocol_version.cpp" />
- <ClCompile Include="..\..\src\impl\ssl\secure_socket_client.cpp" />
- <ClCompile Include="..\..\src\impl\ssl\ssl_api.cpp" />
- <ClCompile Include="..\..\src\impl\ssl\ssl_gateway.cpp" />
- <ClCompile Include="..\..\src\impl\utility.cpp" />
+ <ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
+ <Project>{b63f2e01-5157-4719-8491-0e1c7cd3b701}</Project>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="..\..\include\ignite\impl\thin\cache\cache_client_proxy.h" />
- <ClInclude Include="..\..\include\ignite\impl\thin\readable.h" />
- <ClInclude Include="..\..\include\ignite\impl\thin\writable.h" />
- <ClInclude Include="..\..\include\ignite\impl\thin\writable_key.h" />
- <ClInclude Include="..\..\include\ignite\thin\cache\cache_client.h" />
- <ClInclude Include="..\..\include\ignite\thin\cache\cache_peek_mode.h" />
- <ClInclude Include="..\..\include\ignite\thin\ignite_client.h" />
- <ClInclude Include="..\..\include\ignite\thin\ignite_client_configuration.h" />
- <ClInclude Include="..\..\include\ignite\thin\ssl_mode.h" />
- <ClInclude Include="..\..\src\impl\cache\cache_affinity_info.h" />
- <ClInclude Include="..\..\src\impl\cache\cache_client_impl.h" />
- <ClInclude Include="..\..\src\impl\connectable_node_partitions.h" />
- <ClInclude Include="..\..\src\impl\data_channel.h" />
- <ClInclude Include="..\..\src\impl\data_router.h" />
- <ClInclude Include="..\..\src\impl\ignite_client_impl.h" />
- <ClInclude Include="..\..\src\impl\message.h" />
- <ClInclude Include="..\..\src\impl\net\end_point.h" />
- <ClInclude Include="..\..\src\impl\net\net_utils.h" />
- <ClInclude Include="..\..\src\impl\net\remote_type_updater.h" />
- <ClInclude Include="..\..\src\impl\net\tcp_range.h" />
- <ClInclude Include="..\..\src\impl\net\tcp_socket_client.h" />
- <ClInclude Include="..\..\src\impl\protocol_version.h" />
- <ClInclude Include="..\..\src\impl\response_status.h" />
- <ClInclude Include="..\..\src\impl\socket_client.h" />
- <ClInclude Include="..\..\src\impl\ssl\secure_socket_client.h" />
- <ClInclude Include="..\..\src\impl\ssl\ssl_api.h" />
- <ClInclude Include="..\..\src\impl\ssl\ssl_gateway.h" />
- <ClInclude Include="..\..\src\impl\utility.h" />
+ <ClInclude Include="..\..\include\ignite\network\end_point.h" />
+ <ClInclude Include="..\..\include\ignite\network\network.h" />
+ <ClInclude Include="..\..\include\ignite\network\utils.h" />
+ <ClInclude Include="..\..\include\ignite\network\socket_client.h" />
+ <ClInclude Include="..\..\include\ignite\network\tcp_range.h" />
+ <ClInclude Include="..\..\os\win\src\network\sockets.h" />
+ <ClInclude Include="..\..\src\network\ssl\secure_socket_client.h" />
+ <ClInclude Include="..\..\src\network\ssl\ssl_gateway.h" />
+ <ClInclude Include="..\..\src\network\tcp_socket_client.h" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\..\..\binary\project\vs\binary.vcxproj">
- <Project>{4f15669b-92eb-49f0-b774-8f19bae0b960}</Project>
- </ProjectReference>
- <ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
- <Project>{b63f2e01-5157-4719-8491-0e1c7cd3b701}</Project>
- </ProjectReference>
+ <ClCompile Include="..\..\os\win\src\network\sockets.cpp" />
+ <ClCompile Include="..\..\os\win\src\network\tcp_socket_client.cpp" />
+ <ClCompile Include="..\..\os\win\src\network\utils.cpp" />
+ <ClCompile Include="..\..\src\network\network.cpp" />
+ <ClCompile Include="..\..\src\network\ssl\secure_socket_client.cpp" />
+ <ClCompile Include="..\..\src\network\ssl\ssl_gateway.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/modules/platforms/cpp/network/project/vs/network.vcxproj.filters b/modules/platforms/cpp/network/project/vs/network.vcxproj.filters
new file mode 100644
index 0000000..707b6db
--- /dev/null
+++ b/modules/platforms/cpp/network/project/vs/network.vcxproj.filters
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Code">
+ <UniqueIdentifier>{89eb3c72-85c7-4c46-ba6d-a668ab852e02}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\network">
+ <UniqueIdentifier>{383a382d-5683-417b-87f5-702df88a791a}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\network\ssl">
+ <UniqueIdentifier>{1bb8ce28-5b9b-4735-88b3-9d979de21d10}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\ignite\network\end_point.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\network\socket_client.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\network\tcp_range.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\network\utils.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\src\network\ssl\secure_socket_client.h">
+ <Filter>Code\network\ssl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\src\network\ssl\ssl_gateway.h">
+ <Filter>Code\network\ssl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\src\network\tcp_socket_client.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\network\network.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\os\win\src\network\sockets.h">
+ <Filter>Code\network</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\src\network\ssl\secure_socket_client.cpp">
+ <Filter>Code\network\ssl</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\network\ssl\ssl_gateway.cpp">
+ <Filter>Code\network\ssl</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\network\network.cpp">
+ <Filter>Code\network</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\os\win\src\network\tcp_socket_client.cpp">
+ <Filter>Code\network</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\os\win\src\network\utils.cpp">
+ <Filter>Code\network</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\os\win\src\network\sockets.cpp">
+ <Filter>Code\network</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc/src/ssl/ssl_api.cpp b/modules/platforms/cpp/network/src/network/network.cpp
similarity index 56%
rename from modules/platforms/cpp/odbc/src/ssl/ssl_api.cpp
rename to modules/platforms/cpp/network/src/network/network.cpp
index 4a1d692..b2ef23c 100644
--- a/modules/platforms/cpp/odbc/src/ssl/ssl_api.cpp
+++ b/modules/platforms/cpp/network/src/network/network.cpp
@@ -15,18 +15,36 @@
* limitations under the License.
*/
-#include "ignite/odbc/ssl/ssl_gateway.h"
-#include "ignite/odbc/ssl/ssl_api.h"
+#include "network/sockets.h"
+
+#include <ignite/network/network.h>
+
+#include "network/ssl/ssl_gateway.h"
+#include "network/ssl/secure_socket_client.h"
+#include "network/tcp_socket_client.h"
namespace ignite
{
- namespace odbc
+ namespace network
{
namespace ssl
{
- bool EnsureSslLoaded()
+ void EnsureSslLoaded()
+ {
+ SslGateway::GetInstance().LoadAll();
+ }
+
+ SocketClient* MakeTcpSocketClient()
{
- return SslGateway::GetInstance().LoadAll();
+ return new TcpSocketClient;
+ }
+
+ SocketClient* MakeSecureSocketClient(const std::string& certPath,
+ const std::string& keyPath, const std::string& caPath)
+ {
+ EnsureSslLoaded();
+
+ return new SecureSocketClient(certPath, keyPath, caPath);
}
}
}
diff --git a/modules/platforms/cpp/odbc/src/ssl/secure_socket_client.cpp b/modules/platforms/cpp/network/src/network/ssl/secure_socket_client.cpp
similarity index 54%
rename from modules/platforms/cpp/odbc/src/ssl/secure_socket_client.cpp
rename to modules/platforms/cpp/network/src/network/ssl/secure_socket_client.cpp
index f7811fb..9c304b3 100644
--- a/modules/platforms/cpp/odbc/src/ssl/secure_socket_client.cpp
+++ b/modules/platforms/cpp/network/src/network/ssl/secure_socket_client.cpp
@@ -15,25 +15,45 @@
* limitations under the License.
*/
+#include "network/sockets.h"
+
#include <sstream>
-#include <cstdio>
+#include <cassert>
-#include "ignite/odbc/log.h"
-#include "ignite/common/concurrent.h"
-#include "ignite/odbc/system/tcp_socket_client.h"
-#include "ignite/odbc/ssl/secure_socket_client.h"
-#include "ignite/odbc/ssl/ssl_gateway.h"
-#include "ignite/common/utils.h"
+#include <ignite/common/utils.h>
+#include <ignite/common/concurrent.h>
+#include <ignite/ignite_error.h>
-#ifndef SOCKET_ERROR
-# define SOCKET_ERROR (-1)
-#endif // SOCKET_ERROR
+#include "network/ssl/secure_socket_client.h"
+#include "network/ssl/ssl_gateway.h"
enum { OPERATION_SUCCESS = 1 };
+void FreeContext(SSL_CTX* ctx)
+{
+ using namespace ignite::network::ssl;
+
+ SslGateway &sslGateway = SslGateway::GetInstance();
+
+ assert(sslGateway.Loaded());
+
+ sslGateway.SSL_CTX_free_(ctx);
+}
+
+void FreeBio(BIO* bio)
+{
+ using namespace ignite::network::ssl;
+
+ SslGateway &sslGateway = SslGateway::GetInstance();
+
+ assert(sslGateway.Loaded());
+
+ sslGateway.BIO_free_all_(bio);
+}
+
namespace ignite
{
- namespace odbc
+ namespace network
{
namespace ssl
{
@@ -57,8 +77,7 @@ namespace ignite
SslGateway::GetInstance().SSL_CTX_free_(reinterpret_cast<SSL_CTX*>(context));
}
- bool SecureSocketClient::Connect(const char* hostname, uint16_t port, int32_t,
- diagnostic::Diagnosable& diag)
+ bool SecureSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
{
SslGateway &sslGateway = SslGateway::GetInstance();
@@ -66,71 +85,46 @@ namespace ignite
if (!context)
{
- context = MakeContext(certPath, keyPath, caPath, diag);
+ context = MakeContext(certPath, keyPath, caPath);
if (!context)
- {
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not create SSL context. Aborting connect.");
-
- return false;
- }
+ ThrowSecureError("Can not create SSL context. Aborting connect");
}
- SSL* ssl0 = reinterpret_cast<SSL*>(MakeSsl(context, hostname, port, blocking, diag));
- if (!ssl0)
- return false;
+ ssl = MakeSsl(context, hostname, port, blocking);
- int res = sslGateway.SSL_set_tlsext_host_name_(ssl0, hostname);
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_free_(ssl0);
+ assert(ssl != 0);
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not set host name for secure connection: " + GetSslError(ssl0, res));
+ common::MethodGuard<SecureSocketClient> guard(this, &SecureSocketClient::CloseInteral);
- return false;
- }
+ SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
+
+ int res = sslGateway.SSL_set_tlsext_host_name_(ssl0, hostname);
+
+ if (res != OPERATION_SUCCESS)
+ ThrowSecureError("Can not set host name for secure connection: " + GetSslError(ssl0, res));
sslGateway.SSL_set_connect_state_(ssl0);
- bool connected = CompleteConnectInternal(ssl0, DEFALT_CONNECT_TIMEOUT, diag);
+ bool connected = CompleteConnectInternal(ssl0, timeout);
if (!connected)
- {
- sslGateway.SSL_free_(ssl0);
-
return false;
- }
// Verify a server certificate was presented during the negotiation
X509* cert = sslGateway.SSL_get_peer_certificate_(ssl0);
if (cert)
sslGateway.X509_free_(cert);
else
- {
- sslGateway.SSL_free_(ssl0);
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Remote host did not provide certificate: " + GetSslError(ssl0, res));
-
- return false;
- }
+ ThrowSecureError("Remote host did not provide certificate: " + GetSslError(ssl0, res));
// Verify the result of chain verification
// Verification performed according to RFC 4158
res = sslGateway.SSL_get_verify_result_(ssl0);
if (X509_V_OK != res)
- {
- sslGateway.SSL_free_(ssl0);
+ ThrowSecureError("Certificate chain verification failed: " + GetSslError(ssl0, res));
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Certificate chain verification failed: " + GetSslError(ssl0, res));
-
- return false;
- }
-
- ssl = reinterpret_cast<void*>(ssl0);
+ guard.Release();
return true;
}
@@ -140,24 +134,18 @@ namespace ignite
CloseInteral();
}
- int SecureSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
+ int SecureSocketClient::Send(const int8_t* data, size_t size, int32_t)
{
SslGateway &sslGateway = SslGateway::GetInstance();
assert(sslGateway.Loaded());
if (!ssl)
- {
- LOG_MSG("Trying to send data using closed connection");
-
- return -1;
- }
+ ThrowNetworkError("Trying to send data using closed connection");
SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
- int res = sslGateway.SSL_write_(ssl0, data, static_cast<int>(size));
-
- return res;
+ return sslGateway.SSL_write_(ssl0, data, static_cast<int>(size));
}
int SecureSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
@@ -167,11 +155,7 @@ namespace ignite
assert(sslGateway.Loaded());
if (!ssl)
- {
- LOG_MSG("Trying to receive data using closed connection");
-
- return -1;
- }
+ ThrowNetworkError("Trying to receive data using closed connection");
SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
@@ -185,9 +169,7 @@ namespace ignite
return res;
}
- res = sslGateway.SSL_read_(ssl0, buffer, static_cast<int>(size));
-
- return res;
+ return sslGateway.SSL_read_(ssl0, buffer, static_cast<int>(size));
}
bool SecureSocketClient::IsBlocking() const
@@ -196,7 +178,7 @@ namespace ignite
}
void* SecureSocketClient::MakeContext(const std::string& certPath, const std::string& keyPath,
- const std::string& caPath, diagnostic::Diagnosable& diag)
+ const std::string& caPath)
{
SslGateway &sslGateway = SslGateway::GetInstance();
@@ -204,19 +186,13 @@ namespace ignite
const SSL_METHOD* method = sslGateway.SSLv23_client_method_();
if (!method)
- {
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not get SSL method.");
-
- return 0;
- }
+ ThrowSecureError("Can not get SSL method");
SSL_CTX* ctx = sslGateway.SSL_CTX_new_(method);
if (!ctx)
- {
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not create new SSL context.");
+ ThrowSecureError("Can not create new SSL context");
- return 0;
- }
+ common::DeinitGuard<SSL_CTX> guard(ctx, &FreeContext);
sslGateway.SSL_CTX_set_verify_(ctx, SSL_VERIFY_PEER, 0);
@@ -228,54 +204,27 @@ namespace ignite
long res = sslGateway.SSL_CTX_load_verify_locations_(ctx, cCaPath, 0);
if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not set Certificate Authority path for secure connection.");
-
- return 0;
- }
+ ThrowSecureError("Can not set Certificate Authority path for secure connection");
res = sslGateway.SSL_CTX_use_certificate_chain_file_(ctx, certPath.c_str());
if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not set client certificate file for secure connection.");
-
- return 0;
- }
+ ThrowSecureError("Can not set client certificate file for secure connection");
res = sslGateway.SSL_CTX_use_RSAPrivateKey_file_(ctx, keyPath.c_str(), SSL_FILETYPE_PEM);
if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not set private key file for secure connection.");
-
- return 0;
- }
+ ThrowSecureError("Can not set private key file for secure connection");
const char* const PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4";
res = sslGateway.SSL_CTX_set_cipher_list_(ctx, PREFERRED_CIPHERS);
if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
+ ThrowSecureError("Can not set ciphers list for secure connection");
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not set ciphers list for secure connection.");
-
- return 0;
- }
+ guard.Release();
return ctx;
}
- void* SecureSocketClient::MakeSsl(void* context, const char* hostname, uint16_t port,
- bool& blocking, diagnostic::Diagnosable& diag)
+ void* SecureSocketClient::MakeSsl(void* context, const char* hostname, uint16_t port, bool& blocking)
{
SslGateway &sslGateway = SslGateway::GetInstance();
@@ -283,52 +232,32 @@ namespace ignite
BIO* bio = sslGateway.BIO_new_ssl_connect_(reinterpret_cast<SSL_CTX*>(context));
if (!bio)
- {
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not create SSL connection.");
+ ThrowSecureError("Can not create SSL connection");
- return 0;
- }
+ common::DeinitGuard<BIO> guard(bio, &FreeBio);
- blocking = false;
- long res = sslGateway.BIO_set_nbio_(bio, 1);
- if (res != OPERATION_SUCCESS)
- {
- blocking = true;
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up non-blocking mode. Timeouts are not available.");
- }
+ blocking = sslGateway.BIO_set_nbio_(bio, 1) != OPERATION_SUCCESS;
std::stringstream stream;
stream << hostname << ":" << port;
std::string address = stream.str();
- res = sslGateway.BIO_set_conn_hostname_(bio, address.c_str());
+ long res = sslGateway.BIO_set_conn_hostname_(bio, address.c_str());
if (res != OPERATION_SUCCESS)
- {
- sslGateway.BIO_free_all_(bio);
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not set SSL connection hostname.");
-
- return 0;
- }
+ ThrowSecureError("Can not set SSL connection hostname");
SSL* ssl = 0;
sslGateway.BIO_get_ssl_(bio, &ssl);
if (!ssl)
- {
- sslGateway.BIO_free_all_(bio);
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not get SSL instance from BIO.");
+ ThrowSecureError("Can not get SSL instance from BIO");
- return 0;
- }
+ guard.Release();
return ssl;
}
- bool SecureSocketClient::CompleteConnectInternal(void* ssl, int timeout, diagnostic::Diagnosable& diag)
+ bool SecureSocketClient::CompleteConnectInternal(void* ssl, int timeout)
{
SslGateway &sslGateway = SslGateway::GetInstance();
@@ -345,38 +274,18 @@ namespace ignite
int sslError = sslGateway.SSL_get_error_(ssl0, res);
- LOG_MSG("wait res=" << res << ", sslError=" << sslError);
-
if (IsActualError(sslError))
- {
- diag.AddStatusRecord(SqlState::S08001_CANNOT_CONNECT,
- "Can not establish secure connection: " + GetSslError(ssl0, res));
-
- return false;
- }
+ ThrowSecureError("Can not establish secure connection: " + GetSslError(ssl0, res));
int want = sslGateway.SSL_want_(ssl0);
res = WaitOnSocket(ssl, timeout, want == SSL_READING);
- LOG_MSG("wait res=" << res << ", want=" << want);
-
if (res == WaitResult::TIMEOUT)
- {
- diag.AddStatusRecord(SqlState::SHYT01_CONNECTION_TIMEOUT,
- "Can not establish secure connection: Timeout expired (" +
- common::LexicalCast<std::string>(timeout) + " seconds)");
-
return false;
- }
if (res != WaitResult::SUCCESS)
- {
- diag.AddStatusRecord(SqlState::S08001_CANNOT_CONNECT,
- "Can not establish secure connection due to internal error");
-
- return false;
- }
+ ThrowSecureError("Error while establishing secure connection: " + GetSslError(ssl0, res));
}
}
@@ -390,8 +299,6 @@ namespace ignite
int sslError = sslGateway.SSL_get_error_(ssl0, ret);
- LOG_MSG("ssl_error: " << sslError);
-
switch (sslError)
{
case SSL_ERROR_NONE:
@@ -399,7 +306,7 @@ namespace ignite
case SSL_ERROR_WANT_WRITE:
return std::string("SSL_connect wants write");
-
+
case SSL_ERROR_WANT_READ:
return std::string("SSL_connect wants read");
@@ -437,9 +344,7 @@ namespace ignite
{
SslGateway &sslGateway = SslGateway::GetInstance();
- assert(sslGateway.Loaded());
-
- if (ssl)
+ if (sslGateway.Loaded() && ssl)
{
sslGateway.SSL_free_(reinterpret_cast<SSL*>(ssl));
@@ -447,61 +352,30 @@ namespace ignite
}
}
+ void SecureSocketClient::ThrowSecureError(const std::string& err)
+ {
+ throw IgniteError(IgniteError::IGNITE_ERR_SECURE_CONNECTION_FAILURE, err.c_str());
+ }
+
int SecureSocketClient::WaitOnSocket(void* ssl, int32_t timeout, bool rd)
{
SslGateway &sslGateway = SslGateway::GetInstance();
assert(sslGateway.Loaded());
-
- int ready = 0;
- int lastError = 0;
+
SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
-
- fd_set fds;
-
int fd = sslGateway.SSL_get_fd_(ssl0);
if (fd < 0)
{
- LOG_MSG("Can not get file descriptor from the SSL socket: " << fd << ", " << GetSslError(ssl, fd));
-
- return fd;
- }
-
- do {
- struct timeval tv = { 0 };
- tv.tv_sec = timeout;
-
- FD_ZERO(&fds);
- FD_SET(static_cast<long>(fd), &fds);
-
- fd_set* readFds = 0;
- fd_set* writeFds = 0;
-
- if (rd)
- readFds = &fds;
- else
- writeFds = &fds;
+ std::stringstream ss;
- ready = select(fd + 1, readFds, writeFds, NULL, (timeout == 0 ? NULL : &tv));
+ ss << "Can not get file descriptor from the SSL socket: " << fd << ", " << GetSslError(ssl, fd);
- if (ready == SOCKET_ERROR)
- lastError = system::TcpSocketClient::GetLastSocketError();
-
- } while (ready == SOCKET_ERROR && system::TcpSocketClient::IsSocketOperationInterrupted(lastError));
-
- if (ready == SOCKET_ERROR)
- return -lastError;
-
- lastError = system::TcpSocketClient::GetLastSocketError(fd);
-
- if (lastError != 0)
- return -lastError;
-
- if (ready == 0)
- return WaitResult::TIMEOUT;
+ ThrowNetworkError(ss.str());
+ }
- return WaitResult::SUCCESS;
+ return sockets::WaitOnSocket(fd, timeout, rd);
}
}
}
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/secure_socket_client.h b/modules/platforms/cpp/network/src/network/ssl/secure_socket_client.h
similarity index 86%
rename from modules/platforms/cpp/odbc/include/ignite/odbc/ssl/secure_socket_client.h
rename to modules/platforms/cpp/network/src/network/ssl/secure_socket_client.h
index f8ca0be..29551c9 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/secure_socket_client.h
+++ b/modules/platforms/cpp/network/src/network/ssl/secure_socket_client.h
@@ -15,18 +15,17 @@
* limitations under the License.
*/
-#ifndef _IGNITE_ODBC_SSL_SECURE_SOCKET_CLIENT
-#define _IGNITE_ODBC_SSL_SECURE_SOCKET_CLIENT
+#ifndef _IGNITE_NETWORK_SSL_SECURE_SOCKET_CLIENT
+#define _IGNITE_NETWORK_SSL_SECURE_SOCKET_CLIENT
#include <stdint.h>
#include <string>
-#include "ignite/odbc/diagnostic/diagnosable.h"
-#include "ignite/odbc/socket_client.h"
+#include <ignite/network/socket_client.h>
namespace ignite
{
- namespace odbc
+ namespace network
{
namespace ssl
{
@@ -56,11 +55,9 @@ namespace ignite
* @param hostname Host name or address.
* @param port TCP port.
* @param timeout Timeout in seconds.
- * @param diag Diagnostics collector to use for error-reporting.
- * @return @c true on success and @c false on fail.
+ * @return @c true on success and @c false on timeout.
*/
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout,
- diagnostic::Diagnosable& diag);
+ virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout);
/**
* Close the connection.
@@ -72,7 +69,7 @@ namespace ignite
* @param data Data to send.
* @param size Number of bytes to send.
* @param timeout Timeout in seconds.
- * @return Number of bytes that have been sent on success,
+ * @return Number of bytes that have been sent on success,
* WaitResult::TIMEOUT on timeout and -errno on failure.
*/
virtual int Send(const int8_t* data, size_t size, int32_t timeout);
@@ -102,6 +99,13 @@ namespace ignite
void CloseInteral();
/**
+ * Throw SSL-related error.
+ *
+ * @param err Error message.
+ */
+ static void ThrowSecureError(const std::string& err);
+
+ /**
* Wait on the socket for any event for specified time.
* This function uses poll to achive timeout functionality
* for every separate socket operation.
@@ -120,11 +124,10 @@ namespace ignite
* @param certPath Certificate file path.
* @param keyPath Private key file path.
* @param caPath Certificate authority file path.
- * @param diag Diagnostics collector to use for error-reporting.
* @return New context instance on success and null-pointer on fail.
*/
static void* MakeContext(const std::string& certPath, const std::string& keyPath,
- const std::string& caPath, diagnostic::Diagnosable& diag);
+ const std::string& caPath);
/**
* Make new SSL instance.
@@ -133,21 +136,18 @@ namespace ignite
* @param hostname Host name or address.
* @param port TCP port.
* @param blocking Indicates if the resulted SSL is blocking or not.
- * @param diag Diagnostics collector to use for error-reporting.
* @return New SSL instance on success and null-pointer on fail.
*/
- static void* MakeSsl(void* context, const char* hostname, uint16_t port,
- bool& blocking, diagnostic::Diagnosable& diag);
+ static void* MakeSsl(void* context, const char* hostname, uint16_t port, bool& blocking);
/**
* Complete async connect.
*
* @param ssl SSL instance.
* @param timeout Timeout in seconds.
- * @param diag Diagnostics collector to use for error-reporting.
- * @return @c true on success.
+ * @return @c true on success and @c false on timeout.
*/
- static bool CompleteConnectInternal(void* ssl, int timeout, diagnostic::Diagnosable& diag);
+ static bool CompleteConnectInternal(void* ssl, int timeout);
/**
* Get SSL error.
@@ -157,7 +157,7 @@ namespace ignite
* @return Error string.
*/
static std::string GetSslError(void* ssl, int ret);
-
+
/**
* Check if a actual error occured.
*
@@ -188,4 +188,4 @@ namespace ignite
}
}
-#endif //_IGNITE_ODBC_SSL_SECURE_SOCKET_CLIENT
\ No newline at end of file
+#endif //_IGNITE_NETWORK_SSL_SECURE_SOCKET_CLIENT
diff --git a/modules/platforms/cpp/odbc/src/ssl/ssl_gateway.cpp b/modules/platforms/cpp/network/src/network/ssl/ssl_gateway.cpp
similarity index 94%
rename from modules/platforms/cpp/odbc/src/ssl/ssl_gateway.cpp
rename to modules/platforms/cpp/network/src/network/ssl/ssl_gateway.cpp
index 6116a76..e3139c1 100644
--- a/modules/platforms/cpp/odbc/src/ssl/ssl_gateway.cpp
+++ b/modules/platforms/cpp/network/src/network/ssl/ssl_gateway.cpp
@@ -17,10 +17,10 @@
#include <sstream>
-#include "ignite/common/utils.h"
+#include <ignite/ignite_error.h>
+#include <ignite/common/utils.h>
-#include "ignite/odbc/ssl/ssl_gateway.h"
-#include "ignite/odbc/log.h"
+#include "network/ssl/ssl_gateway.h"
#ifndef ADDITIONAL_OPENSSL_HOME_ENV
# define ADDITIONAL_OPENSSL_HOME_ENV "OPEN_SSL_HOME"
@@ -40,7 +40,7 @@
namespace ignite
{
- namespace odbc
+ namespace network
{
namespace ssl
{
@@ -90,12 +90,12 @@ namespace ignite
if (mod.IsLoaded())
return mod;
- }
+ }
- return LoadModule(fullName);
+ return LoadModule(fullName);
}
- bool SslGateway::LoadSslLibraries()
+ void SslGateway::LoadSslLibraries()
{
libssl = LoadSslLibrary("libssl");
@@ -113,19 +113,24 @@ namespace ignite
if (!libssl.IsLoaded() && (!libeay32.IsLoaded() || !ssleay32.IsLoaded()))
{
+ if (!libssl.IsLoaded())
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Can not load neccessary OpenSSL library: libssl");
+
+ std::stringstream ss;
+
+ ss << "Can not load neccessary OpenSSL libraries:";
+
if (!libeay32.IsLoaded())
- LOG_MSG("Can not load libeay32.");
+ ss << " libeay32";
if (!ssleay32.IsLoaded())
- LOG_MSG("Can not load ssleay32.");
+ ss << " ssleay32";
- if (!libssl.IsLoaded())
- LOG_MSG("Can not load libssl.");
+ std::string res = ss.str();
- return false;
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, res.c_str());
}
-
- return true;
}
void SslGateway::LoadMandatoryMethods()
@@ -189,26 +194,21 @@ namespace ignite
return self;
}
- bool SslGateway::LoadAll()
+ void SslGateway::LoadAll()
{
using namespace common::dynamic;
if (inited)
- return true;
+ return;
common::concurrent::CsLockGuard lock(initCs);
if (inited)
- return true;
+ return;
common::MethodGuard<SslGateway> guard(this, &SslGateway::UnloadAll);
- if (!LoadSslLibraries())
- {
- LOG_MSG("Can not load neccessary OpenSSL libraries.");
-
- return false;
- }
+ LoadSslLibraries();
LoadMandatoryMethods();
@@ -224,8 +224,6 @@ namespace ignite
guard.Release();
inited = true;
-
- return true;
}
void* SslGateway::TryLoadSslMethod(const char* name)
@@ -249,7 +247,15 @@ namespace ignite
void* fp = TryLoadSslMethod(name);
if (!fp)
- LOG_MSG("Can not load function " << name);
+ {
+ std::stringstream ss;
+
+ ss << "Can not load function " << name;
+
+ std::string res = ss.str();
+
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, res.c_str());
+ }
return fp;
}
@@ -460,7 +466,7 @@ namespace ignite
long SslGateway::SSL_set_tlsext_host_name_(SSL* s, const char* name)
{
return SSL_ctrl_(s, SSL_CTRL_SET_TLSEXT_HOSTNAME,
- TLSEXT_NAMETYPE_host_name, const_cast<char*>(name));
+ TLSEXT_NAMETYPE_host_name, const_cast<char*>(name));
}
void SslGateway::SSL_set_connect_state_(SSL* s)
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_gateway.h b/modules/platforms/cpp/network/src/network/ssl/ssl_gateway.h
similarity index 95%
rename from modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_gateway.h
rename to modules/platforms/cpp/network/src/network/ssl/ssl_gateway.h
index 02761b2..30134f3 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_gateway.h
+++ b/modules/platforms/cpp/network/src/network/ssl/ssl_gateway.h
@@ -15,19 +15,20 @@
* limitations under the License.
*/
-#ifndef _IGNITE_ODBC_SSL_SSL_LIBRARY
-#define _IGNITE_ODBC_SSL_SSL_LIBRARY
+#ifndef _IGNITE_NETWORK_SSL_SSL_GATEWAY
+#define _IGNITE_NETWORK_SSL_SSL_GATEWAY
#include <openssl/ssl.h>
#include <openssl/conf.h>
#include <openssl/err.h>
-#include "ignite/common/concurrent.h"
-#include "ignite/common/dynamic_load_os.h"
+#include <ignite/common/concurrent.h>
+#include <ignite/common/dynamic_load_os.h>
+
namespace ignite
{
- namespace odbc
+ namespace network
{
namespace ssl
{
@@ -92,9 +93,8 @@ namespace ignite
/**
* Try loading SSL library.
- * @return @c true if loaded successfully, and false otherwise.
*/
- bool LoadAll();
+ void LoadAll();
/**
* Get functions.
@@ -222,7 +222,7 @@ namespace ignite
/**
* Load all SSL libraries.
*/
- bool LoadSslLibraries();
+ void LoadSslLibraries();
/**
* Load mandatory SSL methods.
@@ -241,8 +241,11 @@ namespace ignite
/**
* Load SSL method.
+ *
* @param name Name.
* @return Method pointer.
+ *
+ * @throw IgniteError if the method is not present.
*/
void* LoadSslMethod(const char* name);
@@ -271,4 +274,4 @@ namespace ignite
}
}
-#endif //_IGNITE_ODBC_SSL_SSL_LIBRARY
\ No newline at end of file
+#endif //_IGNITE_NETWORK_SSL_SSL_GATEWAY
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/socket_client.h b/modules/platforms/cpp/network/src/network/tcp_socket_client.h
similarity index 55%
rename from modules/platforms/cpp/odbc/include/ignite/odbc/socket_client.h
rename to modules/platforms/cpp/network/src/network/tcp_socket_client.h
index f16674f..c4bd1da 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/socket_client.h
+++ b/modules/platforms/cpp/network/src/network/tcp_socket_client.h
@@ -15,65 +15,60 @@
* limitations under the License.
*/
-#ifndef _IGNITE_ODBC_SOCKET_CLIENT
-#define _IGNITE_ODBC_SOCKET_CLIENT
+#ifndef _IGNITE_NETWORK_TCP_SOCKET_CLIENT
+#define _IGNITE_NETWORK_TCP_SOCKET_CLIENT
+
+#include "network/sockets.h"
#include <stdint.h>
-#include "ignite/odbc/diagnostic/diagnosable.h"
+#include <ignite/common/common.h>
+
+#include <ignite/network/socket_client.h>
namespace ignite
{
- namespace odbc
+ namespace network
{
/**
* Socket client implementation.
*/
- class SocketClient
+ class TcpSocketClient : public SocketClient
{
public:
- /** Connection establishment timeout in seconds. */
- enum { DEFALT_CONNECT_TIMEOUT = 5 };
+ /** Buffers size */
+ enum { BUFFER_SIZE = 0x10000 };
+
+ /** The time in seconds the connection needs to remain idle before starts sending keepalive probes. */
+ enum { KEEP_ALIVE_IDLE_TIME = 60 };
+
+ /** The time in seconds between individual keepalive probes. */
+ enum { KEEP_ALIVE_PROBES_PERIOD = 1 };
/**
- * Non-negative timeout operation result.
+ * Constructor.
*/
- struct WaitResult
- {
- enum T
- {
- /** Timeout. */
- TIMEOUT = 0,
-
- /** Success. */
- SUCCESS = 1
- };
- };
+ TcpSocketClient();
/**
* Destructor.
*/
- virtual ~SocketClient()
- {
- // No-op.
- }
+ virtual ~TcpSocketClient();
/**
- * Establish connection with remote service.
+ * Establish connection with remote TCP service.
*
* @param hostname Remote host name.
- * @param port Service port.
+ * @param port TCP service port.
* @param timeout Timeout.
- * @param diag Diagnostics collector.
* @return True on success.
*/
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout,
- diagnostic::Diagnosable& diag) = 0;
+ virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout);
/**
* Close established connection.
*/
- virtual void Close() = 0;
+ virtual void Close();
/**
* Send data by established connection.
@@ -81,10 +76,10 @@ namespace ignite
* @param data Pointer to data to be sent.
* @param size Size of the data in bytes.
* @param timeout Timeout.
- * @return Number of bytes that have been sent on success,
+ * @return Number of bytes that have been sent on success,
* WaitResult::TIMEOUT on timeout and -errno on failure.
*/
- virtual int Send(const int8_t* data, size_t size, int32_t timeout) = 0;
+ virtual int Send(const int8_t* data, size_t size, int32_t timeout);
/**
* Receive data from established connection.
@@ -95,15 +90,46 @@ namespace ignite
* @return Number of bytes that have been received on success,
* WaitResult::TIMEOUT on timeout and -errno on failure.
*/
- virtual int Receive(int8_t* buffer, size_t size, int32_t timeout) = 0;
+ virtual int Receive(int8_t* buffer, size_t size, int32_t timeout);
/**
* Check if the socket is blocking or not.
* @return @c true if the socket is blocking and false otherwise.
*/
- virtual bool IsBlocking() const = 0;
+ virtual bool IsBlocking() const;
+
+ private:
+ /**
+ * Close established connection.
+ */
+ void InternalClose();
+
+ /**
+ * Tries set socket options.
+ */
+ void TrySetOptions();
+
+ /**
+ * Wait on the socket for any event for specified time.
+ * This function uses poll to achive timeout functionality
+ * for every separate socket operation.
+ *
+ * @param timeout Timeout.
+ * @param rd Wait for read if @c true, or for write if @c false.
+ * @return -errno on error, WaitResult::TIMEOUT on timeout and
+ * WaitResult::SUCCESS on success.
+ */
+ int WaitOnSocket(int32_t timeout, bool rd);
+
+ /** Handle. */
+ sockets::SocketHandle socketHandle;
+
+ /** Blocking flag. */
+ bool blocking;
+
+ IGNITE_NO_COPY_ASSIGNMENT(TcpSocketClient)
};
}
}
-#endif //_IGNITE_ODBC_SYSTEM_SOCKET_CLIENT
\ No newline at end of file
+#endif //_IGNITE_NETWORK_TCP_SOCKET_CLIENT
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc-test/Makefile.am b/modules/platforms/cpp/odbc-test/Makefile.am
index 58f72a8..6c84d91 100644
--- a/modules/platforms/cpp/odbc-test/Makefile.am
+++ b/modules/platforms/cpp/odbc-test/Makefile.am
@@ -27,6 +27,8 @@ AM_CPPFLAGS = \
-I@top_srcdir@/common/include \
-I@top_srcdir@/common/os/linux/include \
-I@top_srcdir@/binary/include \
+ -I@top_srcdir@/network/include \
+ -I@top_srcdir@/network/os/linux/include \
-I@top_srcdir@/odbc/include \
-I@top_srcdir@/jni/include \
-I@top_srcdir@/jni/os/linux/include \
@@ -102,7 +104,7 @@ ignite_odbc_tests_SOURCES = \
../odbc/src/config/connection_info.cpp \
../odbc/src/config/connection_string_parser.cpp \
../odbc/src/app/application_data_buffer.cpp \
- ../odbc/src/ssl/ssl_mode.cpp \
+ ../odbc/src/ssl_mode.cpp \
../odbc/src/sql/sql_parser.cpp \
../odbc/src/sql/sql_lexer.cpp \
../odbc/src/sql/sql_set_streaming_command.cpp \
diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
index 602f449..53a68b8 100644
--- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
+++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
@@ -91,7 +91,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
- <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\src;$(BOOST_HOME); [...]
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(Projec [...]
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;IGNITE_TESTS_32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<WholeProgramOptimization>false</WholeProgramOptimization>
@@ -107,7 +107,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
- <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\src;$(BOOST_HOME); [...]
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(Projec [...]
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
@@ -124,7 +124,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
- <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\src;$(BOOST_HOME); [...]
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(Projec [...]
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;IGNITE_TESTS_32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
@@ -143,7 +143,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
- <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\src;$(BOOST_HOME); [...]
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\jni\include;$(ProjectDir)\..\..\..\jni\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\odbc\include;$(Projec [...]
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
@@ -175,7 +175,7 @@
<ClCompile Include="..\..\..\odbc\src\sql\sql_parser.cpp" />
<ClCompile Include="..\..\..\odbc\src\sql\sql_set_streaming_command.cpp" />
<ClCompile Include="..\..\..\odbc\src\sql\sql_utils.cpp" />
- <ClCompile Include="..\..\..\odbc\src\ssl\ssl_mode.cpp" />
+ <ClCompile Include="..\..\..\odbc\src\ssl_mode.cpp" />
<ClCompile Include="..\..\..\odbc\src\utility.cpp" />
<ClCompile Include="..\..\src\api_robustness_test.cpp" />
<ClCompile Include="..\..\src\application_data_buffer_test.cpp" />
diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
index 1d54f07..3af88e2 100644
--- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
+++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
@@ -154,9 +154,6 @@
<ClCompile Include="..\..\..\odbc\src\config\config_tools.cpp">
<Filter>Externals</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\odbc\src\ssl\ssl_mode.cpp">
- <Filter>Externals</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\odbc\src\diagnostic\diagnostic_record_storage.cpp">
<Filter>Externals</Filter>
</ClCompile>
@@ -190,6 +187,9 @@
<ClCompile Include="..\..\src\streaming_test.cpp">
<Filter>Code</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\odbc\src\ssl_mode.cpp">
+ <Filter>Externals</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\test_type.h">
diff --git a/modules/platforms/cpp/odbc-test/src/attributes_test.cpp b/modules/platforms/cpp/odbc-test/src/attributes_test.cpp
index 73127f4..9384003 100644
--- a/modules/platforms/cpp/odbc-test/src/attributes_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/attributes_test.cpp
@@ -27,14 +27,17 @@
#include <boost/test/unit_test.hpp>
+#include <ignite/network/socket_client.h>
+
#include "ignite/ignite.h"
#include "ignite/ignition.h"
#include "ignite/impl/binary/binary_utils.h"
+#include "ignite/odbc/connection.h"
+
#include "test_type.h"
#include "test_utils.h"
#include "odbc_test_suite.h"
-#include "ignite/odbc/socket_client.h"
using namespace ignite;
using namespace ignite::cache;
@@ -226,7 +229,7 @@ BOOST_AUTO_TEST_CASE(ConnectionAttributeLoginTimeout)
SQLRETURN ret = SQLGetConnectAttr(dbc, SQL_ATTR_LOGIN_TIMEOUT, &timeout, 0, 0);
ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_DBC, dbc);
- BOOST_REQUIRE_EQUAL(timeout, odbc::SocketClient::DEFALT_CONNECT_TIMEOUT);
+ BOOST_REQUIRE_EQUAL(timeout, odbc::Connection::DEFAULT_CONNECT_TIMEOUT);
ret = SQLSetConnectAttr(dbc, SQL_ATTR_LOGIN_TIMEOUT, reinterpret_cast<SQLPOINTER>(42), 0);
diff --git a/modules/platforms/cpp/odbc-test/src/queries_test.cpp b/modules/platforms/cpp/odbc-test/src/queries_test.cpp
index ac71676..82b02db 100644
--- a/modules/platforms/cpp/odbc-test/src/queries_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/queries_test.cpp
@@ -2117,6 +2117,8 @@ BOOST_AUTO_TEST_CASE(TestManyCursors2)
if (!SQL_SUCCEEDED(ret))
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
+
+ stmt = NULL;
}
}
diff --git a/modules/platforms/cpp/odbc-test/src/streaming_test.cpp b/modules/platforms/cpp/odbc-test/src/streaming_test.cpp
index d09b94f..1d74338 100644
--- a/modules/platforms/cpp/odbc-test/src/streaming_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/streaming_test.cpp
@@ -34,7 +34,6 @@
#include "test_type.h"
#include "test_utils.h"
#include "odbc_test_suite.h"
-#include "ignite/odbc/socket_client.h"
using namespace ignite;
using namespace ignite::common;
diff --git a/modules/platforms/cpp/odbc/Makefile.am b/modules/platforms/cpp/odbc/Makefile.am
index 5230a2c..ee88009 100644
--- a/modules/platforms/cpp/odbc/Makefile.am
+++ b/modules/platforms/cpp/odbc/Makefile.am
@@ -27,6 +27,8 @@ AM_CPPFLAGS = \
-I@top_srcdir@/common/include \
-I@top_srcdir@/common/os/linux/include \
-I@top_srcdir@/binary/include \
+ -I@top_srcdir@/network/include \
+ -I@top_srcdir@/network/os/linux/include \
-DIGNITE_IMPL \
-D__STDC_LIMIT_MACROS \
-D__STDC_CONSTANT_MACROS
@@ -37,6 +39,7 @@ AM_CXXFLAGS = \
libignite_odbc_la_LIBADD = \
@top_srcdir@/binary/libignite-binary.la \
+ @top_srcdir@/network/libignite-network.la \
-lodbcinst
libignite_odbc_la_LDFLAGS = \
@@ -46,10 +49,10 @@ libignite_odbc_la_LDFLAGS = \
-release $(PACKAGE_VERSION)
libignite_odbc_la_DEPENDENCIES = \
- @top_srcdir@/binary/libignite-binary.la
+ @top_srcdir@/binary/libignite-binary.la \
+ @top_srcdir@/network/libignite-network.la
libignite_odbc_la_SOURCES = \
- os/linux/src/system/tcp_socket_client.cpp \
src/app/application_data_buffer.cpp \
src/app/parameter.cpp \
src/app/parameter_set.cpp \
@@ -78,16 +81,13 @@ libignite_odbc_la_SOURCES = \
src/query/type_info_query.cpp \
src/query/special_columns_query.cpp \
src/query/streaming_query.cpp \
- src/ssl/ssl_gateway.cpp \
- src/ssl/secure_socket_client.cpp \
- src/ssl/ssl_mode.cpp \
- src/ssl/ssl_api.cpp \
- src/sql/sql_lexer.cpp \
src/sql/sql_parser.cpp \
+ src/sql/sql_lexer.cpp \
src/sql/sql_set_streaming_command.cpp \
src/sql/sql_utils.cpp \
src/streaming/streaming_batch.cpp \
src/streaming/streaming_context.cpp \
+ src/ssl_mode.cpp \
src/protocol_version.cpp \
src/result_page.cpp \
src/row.cpp \
diff --git a/modules/platforms/cpp/common/configure.ac b/modules/platforms/cpp/odbc/configure.ac
similarity index 88%
copy from modules/platforms/cpp/common/configure.ac
copy to modules/platforms/cpp/odbc/configure.ac
index eb49d02..0239cf7 100644
--- a/modules/platforms/cpp/common/configure.ac
+++ b/modules/platforms/cpp/odbc/configure.ac
@@ -19,7 +19,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([Apache Ignite JNI bridge for C++], [2.8.0.34042], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
+AC_INIT([Apache Ignite ODBC driver for C++], [2.7.0.30114], [dev@ignite.apache.org], [ignite-odbc], [ignite.apache.org])
AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
@@ -57,6 +57,6 @@ AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
-AC_CONFIG_FILES(Makefile include/Makefile os/linux/include/Makefile ignite-common.pc)
+AC_CONFIG_FILES(Makefile include/Makefile ignite-odbc.pc)
AC_OUTPUT
diff --git a/modules/platforms/cpp/odbc/include/Makefile.am b/modules/platforms/cpp/odbc/include/Makefile.am
index a3f6995..f34205e 100644
--- a/modules/platforms/cpp/odbc/include/Makefile.am
+++ b/modules/platforms/cpp/odbc/include/Makefile.am
@@ -44,7 +44,6 @@ noinst_HEADERS = \
ignite/odbc/environment.h \
ignite/odbc/dsn_config.h \
ignite/odbc/system/odbc_constants.h \
- ignite/odbc/system/tcp_socket_client.h \
ignite/odbc/meta/primary_key_meta.h \
ignite/odbc/meta/column_meta.h \
ignite/odbc/meta/table_meta.h \
@@ -52,10 +51,6 @@ noinst_HEADERS = \
ignite/odbc/diagnostic/diagnostic_record_storage.h \
ignite/odbc/diagnostic/diagnosable.h \
ignite/odbc/diagnostic/diagnosable_adapter.h \
- ignite/odbc/ssl/ssl_mode.h \
- ignite/odbc/ssl/ssl_api.h \
- ignite/odbc/ssl/secure_socket_client.h \
- ignite/odbc/ssl/ssl_gateway.h \
ignite/odbc/sql/sql_command.h \
ignite/odbc/sql/sql_lexer.h \
ignite/odbc/sql/sql_parser.h \
@@ -66,6 +61,7 @@ noinst_HEADERS = \
ignite/odbc/streaming/streaming_context.h \
ignite/odbc/connection.h \
ignite/odbc/odbc_error.h \
+ ignite/odbc/ssl_mode.h \
ignite/odbc/message.h \
ignite/odbc/cursor.h \
ignite/odbc/common_types.h \
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h b/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h
index 27de7e8..69f41b3 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h
+++ b/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h
@@ -24,7 +24,7 @@
#include "ignite/odbc/protocol_version.h"
#include "ignite/odbc/config/settable_value.h"
-#include "ignite/odbc/ssl/ssl_mode.h"
+#include "ignite/odbc/ssl_mode.h"
#include "ignite/odbc/end_point.h"
#include "ignite/odbc/nested_tx_mode.h"
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
index 27336cf..6b4339f 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
+++ b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
@@ -22,8 +22,9 @@
#include <vector>
+#include <ignite/network/socket_client.h>
+
#include "ignite/odbc/parser.h"
-#include "ignite/odbc/socket_client.h"
#include "ignite/odbc/config/connection_info.h"
#include "ignite/odbc/config/configuration.h"
#include "ignite/odbc/diagnostic/diagnosable_adapter.h"
@@ -57,6 +58,12 @@ namespace ignite
};
};
+ /** Default connection timeout in seconds. */
+ enum
+ {
+ DEFAULT_CONNECT_TIMEOUT = 5,
+ };
+
/**
* Destructor.
*/
@@ -309,6 +316,13 @@ namespace ignite
IGNITE_NO_COPY_ASSIGNMENT(Connection);
/**
+ * Init connection socket, using configuration.
+ *
+ * @return Operation result.
+ */
+ SqlResult::Type InitSocket();
+
+ /**
* Synchronously send request message and receive response.
* Uses provided timeout. Does not try to restore connection on
* fail.
@@ -469,6 +483,7 @@ namespace ignite
/**
* Try to restore connection to the cluster.
*
+ * @throw IgniteError on failure.
* @return @c true on success and @c false otherwise.
*/
bool TryRestoreConnection();
@@ -498,7 +513,7 @@ namespace ignite
Environment* env;
/** Client Socket. */
- std::auto_ptr<SocketClient> socket;
+ std::auto_ptr<network::SocketClient> socket;
/** Connection timeout in seconds. */
int32_t timeout;
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_api.h b/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_api.h
deleted file mode 100644
index 69c7ab5..0000000
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_api.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_ODBC_SSL_SSL_API
-#define _IGNITE_ODBC_SSL_SSL_API
-
-namespace ignite
-{
- namespace odbc
- {
- namespace ssl
- {
- bool EnsureSslLoaded();
- }
- }
-}
-
-#endif //_IGNITE_ODBC_SSL_SSL_API
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_mode.h b/modules/platforms/cpp/odbc/include/ignite/odbc/ssl_mode.h
similarity index 100%
rename from modules/platforms/cpp/odbc/include/ignite/odbc/ssl/ssl_mode.h
rename to modules/platforms/cpp/odbc/include/ignite/odbc/ssl_mode.h
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/system/tcp_socket_client.h b/modules/platforms/cpp/odbc/include/ignite/odbc/system/tcp_socket_client.h
deleted file mode 100644
index ce8ecc0..0000000
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/system/tcp_socket_client.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_ODBC_SYSTEM_TCP_SOCKET_CLIENT
-#define _IGNITE_ODBC_SYSTEM_TCP_SOCKET_CLIENT
-
-#include <stdint.h>
-
-#include "ignite/common/common.h"
-#include "ignite/odbc/diagnostic/diagnosable.h"
-#include "ignite/odbc/socket_client.h"
-
-namespace ignite
-{
- namespace odbc
- {
- namespace system
- {
- /**
- * Socket client implementation.
- */
- class TcpSocketClient : public SocketClient
- {
- public:
- /** Buffers size */
- enum { BUFFER_SIZE = 0x10000 };
-
- /** The time in seconds the connection needs to remain idle before starts sending keepalive probes. */
- enum { KEEP_ALIVE_IDLE_TIME = 60 };
-
- /** The time in seconds between individual keepalive probes. */
- enum { KEEP_ALIVE_PROBES_PERIOD = 1 };
-
- /**
- * Constructor.
- */
- TcpSocketClient();
-
- /**
- * Destructor.
- */
- virtual ~TcpSocketClient();
-
- /**
- * Establish connection with remote TCP service.
- *
- * @param hostname Remote host name.
- * @param port TCP service port.
- * @param timeout Timeout.
- * @param diag Diagnostics collector.
- * @return True on success.
- */
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout,
- diagnostic::Diagnosable& diag);
-
- /**
- * Close established connection.
- */
- virtual void Close();
-
- /**
- * Send data by established connection.
- *
- * @param data Pointer to data to be sent.
- * @param size Size of the data in bytes.
- * @param timeout Timeout.
- * @return Number of bytes that have been sent on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Send(const int8_t* data, size_t size, int32_t timeout);
-
- /**
- * Receive data from established connection.
- *
- * @param buffer Pointer to data buffer.
- * @param size Size of the buffer in bytes.
- * @param timeout Timeout.
- * @return Number of bytes that have been received on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Receive(int8_t* buffer, size_t size, int32_t timeout);
-
- /**
- * Check if the socket is blocking or not.
- * @return @c true if the socket is blocking and false otherwise.
- */
- virtual bool IsBlocking() const;
-
- /**
- * Get socket error.
- * @return Last socket error.
- */
- static int GetLastSocketError();
-
- /**
- * Get socket error.
- * @param handle Socket handle.
- * @return Last socket error.
- */
- static int GetLastSocketError(int handle);
-
- /**
- * Check whether socket operation was interupted.
- * @return @c true if the socket operation was interupted.
- */
- static bool IsSocketOperationInterrupted(int errorCode);
- private:
- /**
- * Close established connection.
- */
- void InternalClose();
-
- /**
- * Tries set socket options.
- */
- void TrySetOptions(diagnostic::Diagnosable& diag);
-
- /**
- * Wait on the socket for any event for specified time.
- * This function uses poll to achive timeout functionality
- * for every separate socket operation.
- *
- * @param timeout Timeout.
- * @param rd Wait for read if @c true, or for write if @c false.
- * @return -errno on error, WaitResult::TIMEOUT on timeout and
- * WaitResult::SUCCESS on success.
- */
- int WaitOnSocket(int32_t timeout, bool rd);
-
- /** Handle. */
- intptr_t socketHandle;
-
- /** Blocking flag. */
- bool blocking;
-
- IGNITE_NO_COPY_ASSIGNMENT(TcpSocketClient)
- };
- }
- }
-}
-
-#endif //_IGNITE_ODBC_SYSTEM_SOCKET_CLIENT
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc/os/linux/src/system/tcp_socket_client.cpp b/modules/platforms/cpp/odbc/os/linux/src/system/tcp_socket_client.cpp
deleted file mode 100644
index 0b849f7..0000000
--- a/modules/platforms/cpp/odbc/os/linux/src/system/tcp_socket_client.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/poll.h>
-
-#include <cstring>
-
-#include <sstream>
-
-#include "ignite/odbc/system/tcp_socket_client.h"
-#include "ignite/odbc/utility.h"
-#include "ignite/odbc/log.h"
-
-#define SOCKET_ERROR (-1)
-
-namespace
-{
- /**
- * Get last socket error message.
- * @param error Error code.
- * @return Last socket error message string.
- */
- std::string GetSocketErrorMessage(int error)
- {
- std::stringstream res;
-
- res << "error_code=" << error;
-
- if (error == 0)
- return res.str();
-
- char buffer[1024] = "";
-
- if (!strerror_r(error, buffer, sizeof(buffer)))
- res << ", msg=" << buffer;
-
- return res.str();
- }
-
- /**
- * Get last socket error message.
- * @return Last socket error message string.
- */
- std::string GetLastSocketErrorMessage()
- {
- int lastError = errno;
-
- return GetSocketErrorMessage(lastError);
- }
-}
-
-namespace ignite
-{
- namespace odbc
- {
- namespace system
- {
-
- TcpSocketClient::TcpSocketClient() :
- socketHandle(SOCKET_ERROR),
- blocking(true)
- {
- // No-op.
- }
-
- TcpSocketClient::~TcpSocketClient()
- {
- Close();
- }
-
- bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout,
- diagnostic::Diagnosable& diag)
- {
- LOG_MSG("Host: " << hostname << ", port: " << port);
-
- addrinfo hints;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- std::stringstream converter;
- converter << port;
-
- std::string strPort = converter.str();
-
- // Resolve the server address and port
- addrinfo *result = NULL;
- int res = getaddrinfo(hostname, strPort.c_str(), &hints, &result);
-
- if (res != 0)
- {
- LOG_MSG("Address resolving failed: " << gai_strerror(res));
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not resolve host address.");
-
- return false;
- }
-
- // Attempt to connect to an address until one succeeds
- for (addrinfo *it = result; it != NULL; it = it->ai_next)
- {
- LOG_MSG("Addr: " << (it->ai_addr->sa_data[2] & 0xFF) << "."
- << (it->ai_addr->sa_data[3] & 0xFF) << "."
- << (it->ai_addr->sa_data[4] & 0xFF) << "."
- << (it->ai_addr->sa_data[5] & 0xFF));
-
- // Create a SOCKET for connecting to server
- socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
-
- if (socketHandle == SOCKET_ERROR)
- {
- LOG_MSG("Socket creation failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not create new socket.");
-
- return false;
- }
-
- diag.GetDiagnosticRecords().Reset();
-
- TrySetOptions(diag);
-
- // Connect to server.
- res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
- if (SOCKET_ERROR == res)
- {
- int lastError = errno;
-
- if (lastError != EWOULDBLOCK && lastError != EINPROGRESS)
- {
- LOG_MSG("Connection failed: " << GetSocketErrorMessage(lastError));
-
- Close();
-
- continue;
- }
-
- res = WaitOnSocket(timeout == 0 ? -1 : timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- {
- LOG_MSG("Connection timeout expired: " << GetSocketErrorMessage(-res));
-
- Close();
-
- continue;
- }
- }
- break;
- }
-
- freeaddrinfo(result);
-
- return socketHandle != SOCKET_ERROR;
- }
-
- void TcpSocketClient::Close()
- {
- if (socketHandle != SOCKET_ERROR)
- {
- close(socketHandle);
-
- socketHandle = SOCKET_ERROR;
- }
- }
-
- int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout == 0 ? -1 : timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return send(socketHandle, reinterpret_cast<const char*>(data), static_cast<int>(size), 0);
- }
-
- int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout == 0 ? -1 : timeout, true);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return recv(socketHandle, reinterpret_cast<char*>(buffer), static_cast<int>(size), 0);
- }
-
- bool TcpSocketClient::IsBlocking() const
- {
- return blocking;
- }
-
- void TcpSocketClient::TrySetOptions(diagnostic::Diagnosable& diag)
- {
- int trueOpt = 1;
- int bufSizeOpt = BUFFER_SIZE;
- int idleOpt = KEEP_ALIVE_IDLE_TIME;
- int idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD;
-
- int res = setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP socket send buffer size setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP socket send buffer size");
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP socket receive buffer size setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP socket receive buffer size");
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP no-delay mode setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP no-delay mode");
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP out-of-bound data inlining setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP out-of-bound data inlining");
- }
-
- blocking = false;
-
- int flags;
- if (((flags = fcntl(socketHandle, F_GETFL, 0)) < 0) ||
- (fcntl(socketHandle, F_SETFL, flags | O_NONBLOCK) < 0))
- {
- blocking = true;
- LOG_MSG("Non-blocking mode setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up non-blocking mode. Timeouts are not available.");
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive mode setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive mode");
-
- // There is no sense in configuring keep alive params if we faileed to set up keep alive mode.
- return;
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE,
- reinterpret_cast<char*>(&idleOpt), sizeof(idleOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive idle timeout setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive idle timeout");
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL,
- reinterpret_cast<char*>(&idleRetryOpt), sizeof(idleRetryOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive probes period setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive probes period");
- }
-
- }
-
- int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd)
- {
- int lastError = 0;
- int ret;
- do
- {
- struct pollfd fds[1];
-
- fds[0].fd = socketHandle;
- fds[0].events = rd ? POLLIN : POLLOUT;
-
- ret = poll(fds, 1, timeout * 1000);
-
- if (ret == SOCKET_ERROR)
- lastError = GetLastSocketError();
-
- } while (ret == SOCKET_ERROR && IsSocketOperationInterrupted(lastError));
-
- if (ret == SOCKET_ERROR)
- return -lastError;
-
- socklen_t size = sizeof(lastError);
- int res = getsockopt(socketHandle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
-
- if (res != SOCKET_ERROR && lastError != 0)
- return -lastError;
-
- if (ret == 0)
- return WaitResult::TIMEOUT;
-
- return WaitResult::SUCCESS;
- }
-
- int TcpSocketClient::GetLastSocketError()
- {
- return errno;
- }
-
- int TcpSocketClient::GetLastSocketError(int handle)
- {
- int lastError = 0;
- socklen_t size = sizeof(lastError);
- int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
-
- return res == SOCKET_ERROR ? 0 : lastError;
- }
-
- bool TcpSocketClient::IsSocketOperationInterrupted(int errorCode)
- {
- return errorCode == EINTR;
- }
- }
- }
-}
-
diff --git a/modules/platforms/cpp/odbc/os/win/src/system/tcp_socket_client.cpp b/modules/platforms/cpp/odbc/os/win/src/system/tcp_socket_client.cpp
deleted file mode 100644
index 2783403..0000000
--- a/modules/platforms/cpp/odbc/os/win/src/system/tcp_socket_client.cpp
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define WIN32_LEAN_AND_MEAN
-#define _WINSOCKAPI_
-
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <mstcpip.h>
-
-#include <cstring>
-
-#include <sstream>
-
-#include "ignite/common/concurrent.h"
-#include "ignite/odbc/system/tcp_socket_client.h"
-#include "ignite/odbc/utility.h"
-#include "ignite/odbc/log.h"
-
-namespace
-{
- /**
- * Get socket error message for the error code.
- * @param error Error code.
- * @return Socket error message string.
- */
- std::string GetSocketErrorMessage(HRESULT error)
- {
- std::stringstream res;
-
- res << "error_code=" << error;
-
- if (error == 0)
- return res.str();
-
- LPTSTR errorText = NULL;
-
- DWORD len = FormatMessage(
- // use system message tables to retrieve error text
- FORMAT_MESSAGE_FROM_SYSTEM
- // allocate buffer on local heap for error text
- | FORMAT_MESSAGE_ALLOCATE_BUFFER
- // We're not passing insertion parameters
- | FORMAT_MESSAGE_IGNORE_INSERTS,
- // unused with FORMAT_MESSAGE_FROM_SYSTEM
- NULL,
- error,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- // output
- reinterpret_cast<LPTSTR>(&errorText),
- // minimum size for output buffer
- 0,
- // arguments - see note
- NULL);
-
- if (NULL != errorText)
- {
- if (len != 0)
- res << ", msg=" << std::string(errorText, len);
-
- LocalFree(errorText);
- }
-
- return res.str();
- }
-
- /**
- * Get last socket error message.
- * @return Last socket error message string.
- */
- std::string GetLastSocketErrorMessage()
- {
- HRESULT lastError = WSAGetLastError();
-
- return GetSocketErrorMessage(lastError);
- }
-}
-
-namespace ignite
-{
- namespace odbc
- {
- namespace system
- {
- TcpSocketClient::TcpSocketClient() :
- socketHandle(INVALID_SOCKET),
- blocking(true)
- {
- // No-op.
- }
-
- TcpSocketClient::~TcpSocketClient()
- {
- InternalClose();
- }
-
- bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout,
- diagnostic::Diagnosable& diag)
- {
- static common::concurrent::CriticalSection initCs;
- static bool networkInited = false;
-
- // Initing networking if is not inited.
- if (!networkInited)
- {
- common::concurrent::CsLockGuard lock(initCs);
- if (!networkInited)
- {
- WSADATA wsaData;
-
- networkInited = (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0);
-
- if (!networkInited)
- {
- LOG_MSG("Networking initialisation failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not initialize Windows networking.");
-
- return false;
- }
- }
- }
-
- addrinfo hints;
-
- LOG_MSG("Host: " << hostname << " port: " << port);
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- std::stringstream converter;
- converter << port;
-
- std::string strPort = converter.str();
-
- // Resolve the server address and port
- addrinfo *result = NULL;
- int res = getaddrinfo(hostname, strPort.c_str(), &hints, &result);
-
- if (res != 0)
- {
- LOG_MSG("Address resolving failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not resolve host address.");
-
- return false;
- }
-
- // Attempt to connect to an address until one succeeds
- for (addrinfo *it = result; it != NULL; it = it->ai_next)
- {
- LOG_MSG("Addr: " << (it->ai_addr->sa_data[2] & 0xFF) << "."
- << (it->ai_addr->sa_data[3] & 0xFF) << "."
- << (it->ai_addr->sa_data[4] & 0xFF) << "."
- << (it->ai_addr->sa_data[5] & 0xFF));
-
- // Create a SOCKET for connecting to server
- socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
-
- if (socketHandle == INVALID_SOCKET)
- {
- LOG_MSG("Socket creation failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::SHY000_GENERAL_ERROR, "Can not create new socket.");
-
- return false;
- }
-
- diag.GetDiagnosticRecords().Reset();
-
- TrySetOptions(diag);
-
- // Connect to server.
- res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
- if (SOCKET_ERROR == res)
- {
- int lastError = WSAGetLastError();
-
- if (lastError != WSAEWOULDBLOCK)
- {
- LOG_MSG("Connection failed: " << GetSocketErrorMessage(lastError));
-
- Close();
-
- continue;
- }
-
- res = WaitOnSocket(timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- {
- LOG_MSG("Connection timeout expired: " << GetSocketErrorMessage(-res));
-
- Close();
-
- continue;
- }
- }
- break;
- }
-
- freeaddrinfo(result);
-
- return socketHandle != INVALID_SOCKET;
- }
-
- void TcpSocketClient::Close()
- {
- InternalClose();
- }
-
- void TcpSocketClient::InternalClose()
- {
- if (socketHandle != INVALID_SOCKET)
- {
- closesocket(socketHandle);
-
- socketHandle = INVALID_SOCKET;
- }
- }
-
- int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return send(socketHandle, reinterpret_cast<const char*>(data), static_cast<int>(size), 0);
- }
-
- int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout, true);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return recv(socketHandle, reinterpret_cast<char*>(buffer), static_cast<int>(size), 0);
- }
-
- bool TcpSocketClient::IsBlocking() const
- {
- return blocking;
- }
-
- void TcpSocketClient::TrySetOptions(diagnostic::Diagnosable& diag)
- {
- BOOL trueOpt = TRUE;
- ULONG uTrueOpt = TRUE;
- int bufSizeOpt = BUFFER_SIZE;
-
-
- int res = setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP socket send buffer size setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP socket send buffer size");
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP socket receive buffer size setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP socket receive buffer size");
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP no-delay mode setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP no-delay mode");
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP out-of-bound data inlining setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP out-of-bound data inlining");
- }
-
- blocking = false;
- res = ioctlsocket(socketHandle, FIONBIO, &uTrueOpt);
-
- if (res == SOCKET_ERROR)
- {
- blocking = true;
- LOG_MSG("Non-blocking mode setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up non-blocking mode. Timeouts are not available.");
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive mode setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive mode");
-
- // There is no sense in configuring keep alive params if we faileed to set up keep alive mode.
- return;
- }
-
- // This option is available starting with Windows 10, version 1709.
-#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL)
- DWORD idleOpt = KEEP_ALIVE_IDLE_TIME;
- DWORD idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD;
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE,
- reinterpret_cast<char*>(&idleOpt), sizeof(idleOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive idle timeout setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive idle timeout");
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL,
- reinterpret_cast<char*>(&idleRetryOpt), sizeof(idleRetryOpt));
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive probes period setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive probes period");
- }
-#else // use old hardcore WSAIoctl
-
- // WinSock structure for KeepAlive timing settings
- struct tcp_keepalive settings = {0};
- settings.onoff = 1;
- settings.keepalivetime = KEEP_ALIVE_IDLE_TIME * 1000;
- settings.keepaliveinterval = KEEP_ALIVE_PROBES_PERIOD * 1000;
-
- // pointers for WinSock call
- DWORD bytesReturned;
- WSAOVERLAPPED overlapped;
- overlapped.hEvent = NULL;
-
- // Set KeepAlive settings
- res = WSAIoctl(
- socketHandle,
- SIO_KEEPALIVE_VALS,
- &settings,
- sizeof(struct tcp_keepalive),
- NULL,
- 0,
- &bytesReturned,
- &overlapped,
- NULL
- );
-
- if (SOCKET_ERROR == res)
- {
- LOG_MSG("TCP keep-alive params setup failed: " << GetLastSocketErrorMessage());
-
- diag.AddStatusRecord(SqlState::S01S02_OPTION_VALUE_CHANGED,
- "Can not set up TCP keep-alive idle timeout and probes period");
- }
-#endif
- }
-
- int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd)
- {
- int ready = 0;
- int lastError = 0;
-
- fd_set fds;
-
- do {
- struct timeval tv = { 0 };
- tv.tv_sec = timeout;
-
- FD_ZERO(&fds);
- FD_SET(socketHandle, &fds);
-
- fd_set* readFds = 0;
- fd_set* writeFds = 0;
-
- if (rd)
- readFds = &fds;
- else
- writeFds = &fds;
-
- ready = select(static_cast<int>((socketHandle) + 1),
- readFds, writeFds, NULL, (timeout == 0 ? NULL : &tv));
-
- if (ready == SOCKET_ERROR)
- lastError = GetLastSocketError();
-
- } while (ready == SOCKET_ERROR && IsSocketOperationInterrupted(lastError));
-
- if (ready == SOCKET_ERROR)
- return -lastError;
-
- if (ready == 0)
- return WaitResult::TIMEOUT;
-
- return WaitResult::SUCCESS;
- }
-
- int TcpSocketClient::GetLastSocketError()
- {
- return WSAGetLastError();
- }
-
- int TcpSocketClient::GetLastSocketError(int handle)
- {
- int lastError = 0;
- socklen_t size = sizeof(lastError);
- int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
-
- return res == SOCKET_ERROR ? 0 : lastError;
- }
-
- bool TcpSocketClient::IsSocketOperationInterrupted(int errorCode)
- {
- return errorCode == WSAEINTR;
- }
- }
- }
-}
-
diff --git a/modules/platforms/cpp/odbc/os/win/src/system/ui/dsn_configuration_window.cpp b/modules/platforms/cpp/odbc/os/win/src/system/ui/dsn_configuration_window.cpp
index 812d56f7..38496d9 100644
--- a/modules/platforms/cpp/odbc/os/win/src/system/ui/dsn_configuration_window.cpp
+++ b/modules/platforms/cpp/odbc/os/win/src/system/ui/dsn_configuration_window.cpp
@@ -19,7 +19,7 @@
#include <Shlwapi.h>
#include "ignite/odbc/log.h"
-#include "ignite/odbc/ssl/ssl_mode.h"
+#include "ignite/odbc/ssl_mode.h"
#include "ignite/odbc/system/ui/dsn_configuration_window.h"
#include "ignite/odbc/config/config_tools.h"
diff --git a/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj b/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj
index b583c11..b4db4c5 100644
--- a/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj
+++ b/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj
@@ -93,7 +93,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
- <AdditionalIncludeDirectories>$(OPENSSL_HOME_X86)\include;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@@ -109,7 +109,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
- <AdditionalIncludeDirectories>$(OPENSSL_HOME)\include;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@@ -126,7 +126,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(OPENSSL_HOME_X86)\include;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
@@ -144,7 +144,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(OPENSSL_HOME)\include;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
@@ -158,7 +158,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\os\win\src\system_dsn.cpp" />
- <ClCompile Include="..\..\os\win\src\system\tcp_socket_client.cpp" />
<ClCompile Include="..\..\os\win\src\system\ui\custom_window.cpp" />
<ClCompile Include="..\..\os\win\src\system\ui\dsn_configuration_window.cpp" />
<ClCompile Include="..\..\os\win\src\system\ui\window.cpp" />
@@ -200,10 +199,7 @@
<ClCompile Include="..\..\src\sql\sql_parser.cpp" />
<ClCompile Include="..\..\src\sql\sql_set_streaming_command.cpp" />
<ClCompile Include="..\..\src\sql\sql_utils.cpp" />
- <ClCompile Include="..\..\src\ssl\secure_socket_client.cpp" />
- <ClCompile Include="..\..\src\ssl\ssl_api.cpp" />
- <ClCompile Include="..\..\src\ssl\ssl_gateway.cpp" />
- <ClCompile Include="..\..\src\ssl\ssl_mode.cpp" />
+ <ClCompile Include="..\..\src\ssl_mode.cpp" />
<ClCompile Include="..\..\src\statement.cpp" />
<ClCompile Include="..\..\src\streaming\streaming_batch.cpp" />
<ClCompile Include="..\..\src\streaming\streaming_context.cpp" />
@@ -256,22 +252,17 @@
<ClInclude Include="..\..\include\ignite\odbc\query\type_info_query.h" />
<ClInclude Include="..\..\include\ignite\odbc\result_page.h" />
<ClInclude Include="..\..\include\ignite\odbc\row.h" />
- <ClInclude Include="..\..\include\ignite\odbc\socket_client.h" />
<ClInclude Include="..\..\include\ignite\odbc\sql\sql_command.h" />
<ClInclude Include="..\..\include\ignite\odbc\sql\sql_lexer.h" />
<ClInclude Include="..\..\include\ignite\odbc\sql\sql_parser.h" />
<ClInclude Include="..\..\include\ignite\odbc\sql\sql_set_streaming_command.h" />
<ClInclude Include="..\..\include\ignite\odbc\sql\sql_token.h" />
<ClInclude Include="..\..\include\ignite\odbc\sql\sql_utils.h" />
- <ClInclude Include="..\..\include\ignite\odbc\ssl\secure_socket_client.h" />
- <ClInclude Include="..\..\include\ignite\odbc\ssl\ssl_api.h" />
- <ClInclude Include="..\..\include\ignite\odbc\ssl\ssl_gateway.h" />
- <ClInclude Include="..\..\include\ignite\odbc\ssl\ssl_mode.h" />
+ <ClInclude Include="..\..\include\ignite\odbc\ssl_mode.h" />
<ClInclude Include="..\..\include\ignite\odbc\statement.h" />
<ClInclude Include="..\..\include\ignite\odbc\streaming\streaming_batch.h" />
<ClInclude Include="..\..\include\ignite\odbc\streaming\streaming_context.h" />
<ClInclude Include="..\..\include\ignite\odbc\system\odbc_constants.h" />
- <ClInclude Include="..\..\include\ignite\odbc\system\tcp_socket_client.h" />
<ClInclude Include="..\..\include\ignite\odbc\system\ui\dsn_configuration_window.h" />
<ClInclude Include="..\..\include\ignite\odbc\type_traits.h" />
<ClInclude Include="..\..\include\ignite\odbc\utility.h" />
@@ -286,6 +277,9 @@
<ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
<Project>{b63f2e01-5157-4719-8491-0e1c7cd3b701}</Project>
</ProjectReference>
+ <ProjectReference Include="..\..\..\network\project\vs\network.vcxproj">
+ <Project>{cb77ac4d-88d4-4a8c-922c-a28c19060a97}</Project>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj.filters b/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj.filters
index 5fe3bd3..0c5d97c 100644
--- a/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj.filters
+++ b/modules/platforms/cpp/odbc/project/vs/odbc.vcxproj.filters
@@ -29,9 +29,6 @@
<Filter Include="Code\system\ui">
<UniqueIdentifier>{ff144e89-0a10-42c3-97dd-d22bfdbc7abb}</UniqueIdentifier>
</Filter>
- <Filter Include="Code\ssl">
- <UniqueIdentifier>{857734a3-6b29-412a-b75e-7fcc9d3fef8c}</UniqueIdentifier>
- </Filter>
<Filter Include="Code\sql">
<UniqueIdentifier>{7f412a6b-279a-4a22-b87f-eafb1545a8d0}</UniqueIdentifier>
</Filter>
@@ -154,18 +151,6 @@
<ClCompile Include="..\..\src\message.cpp">
<Filter>Code</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\ssl\secure_socket_client.cpp">
- <Filter>Code\ssl</Filter>
- </ClCompile>
- <ClCompile Include="..\..\os\win\src\system\tcp_socket_client.cpp">
- <Filter>Code\system</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\ssl\ssl_mode.cpp">
- <Filter>Code\ssl</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\ssl\ssl_gateway.cpp">
- <Filter>Code\ssl</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\config\connection_string_parser.cpp">
<Filter>Code\config</Filter>
</ClCompile>
@@ -196,8 +181,8 @@
<ClCompile Include="..\..\src\streaming\streaming_context.cpp">
<Filter>Code\streaming</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\ssl\ssl_api.cpp">
- <Filter>Code\ssl</Filter>
+ <ClCompile Include="..\..\src\ssl_mode.cpp">
+ <Filter>Code</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@@ -332,21 +317,6 @@
<ClInclude Include="..\..\include\ignite\odbc\odbc_error.h">
<Filter>Code</Filter>
</ClInclude>
- <ClInclude Include="..\..\include\ignite\odbc\ssl\secure_socket_client.h">
- <Filter>Code\ssl</Filter>
- </ClInclude>
- <ClInclude Include="..\..\include\ignite\odbc\socket_client.h">
- <Filter>Code</Filter>
- </ClInclude>
- <ClInclude Include="..\..\include\ignite\odbc\system\tcp_socket_client.h">
- <Filter>Code\system</Filter>
- </ClInclude>
- <ClInclude Include="..\..\include\ignite\odbc\ssl\ssl_mode.h">
- <Filter>Code\ssl</Filter>
- </ClInclude>
- <ClInclude Include="..\..\include\ignite\odbc\ssl\ssl_gateway.h">
- <Filter>Code\ssl</Filter>
- </ClInclude>
<ClInclude Include="..\..\include\ignite\odbc\config\connection_string_parser.h">
<Filter>Code\config</Filter>
</ClInclude>
@@ -392,8 +362,8 @@
<ClInclude Include="..\..\include\ignite\odbc\streaming\streaming_context.h">
<Filter>Code\streaming</Filter>
</ClInclude>
- <ClInclude Include="..\..\include\ignite\odbc\ssl\ssl_api.h">
- <Filter>Code\ssl</Filter>
+ <ClInclude Include="..\..\include\ignite\odbc\ssl_mode.h">
+ <Filter>Code</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/modules/platforms/cpp/odbc/src/config/connection_string_parser.cpp b/modules/platforms/cpp/odbc/src/config/connection_string_parser.cpp
index 17165e2..b8c8d7e 100644
--- a/modules/platforms/cpp/odbc/src/config/connection_string_parser.cpp
+++ b/modules/platforms/cpp/odbc/src/config/connection_string_parser.cpp
@@ -20,8 +20,7 @@
#include "ignite/common/utils.h"
#include "ignite/odbc/utility.h"
-#include "ignite/odbc/odbc_error.h"
-#include "ignite/odbc/ssl/ssl_mode.h"
+#include "ignite/odbc/ssl_mode.h"
#include "ignite/odbc/config/connection_string_parser.h"
#include "ignite/odbc/config/config_tools.h"
#include "ignite/odbc/nested_tx_mode.h"
diff --git a/modules/platforms/cpp/odbc/src/connection.cpp b/modules/platforms/cpp/odbc/src/connection.cpp
index 1953a16..abce23d 100644
--- a/modules/platforms/cpp/odbc/src/connection.cpp
+++ b/modules/platforms/cpp/odbc/src/connection.cpp
@@ -23,16 +23,15 @@
#include <ignite/common/fixed_size_array.h>
+#include <ignite/network/network.h>
+
#include "ignite/odbc/log.h"
#include "ignite/odbc/utility.h"
#include "ignite/odbc/environment.h"
#include "ignite/odbc/statement.h"
#include "ignite/odbc/connection.h"
#include "ignite/odbc/message.h"
-#include "ignite/odbc/ssl/ssl_mode.h"
-#include "ignite/odbc/ssl/ssl_api.h"
-#include "ignite/odbc/ssl/secure_socket_client.h"
-#include "ignite/odbc/system/tcp_socket_client.h"
+#include "ignite/odbc/ssl_mode.h"
#include "ignite/odbc/dsn_config.h"
#include "ignite/odbc/config/configuration.h"
#include "ignite/odbc/config/connection_string_parser.h"
@@ -59,7 +58,7 @@ namespace ignite
env(env),
socket(),
timeout(0),
- loginTimeout(SocketClient::DEFALT_CONNECT_TIMEOUT),
+ loginTimeout(DEFAULT_CONNECT_TIMEOUT),
autoCommit(true),
parser(),
config(),
@@ -131,6 +130,37 @@ namespace ignite
IGNITE_ODBC_API_CALL(InternalEstablish(cfg));
}
+ SqlResult::Type Connection::InitSocket()
+ {
+ ssl::SslMode::Type sslMode = config.GetSslMode();
+
+ if (sslMode == ssl::SslMode::DISABLE)
+ {
+ socket.reset(network::ssl::MakeTcpSocketClient());
+
+ return SqlResult::AI_SUCCESS;
+ }
+
+ try
+ {
+ network::ssl::EnsureSslLoaded();
+ }
+ catch (const IgniteError &err)
+ {
+ LOG_MSG("Can not load OpenSSL library: " << err.GetText());
+
+ AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
+ "Can not load OpenSSL library (did you set OPENSSL_HOME environment variable?).");
+
+ return SqlResult::AI_ERROR;
+ }
+
+ socket.reset(network::ssl::MakeSecureSocketClient(
+ config.GetSslCertFile(), config.GetSslKeyFile(), config.GetSslCaFile()));
+
+ return SqlResult::AI_SUCCESS;
+ }
+
SqlResult::Type Connection::InternalEstablish(const config::Configuration& cfg)
{
using ssl::SslMode;
@@ -151,26 +181,6 @@ namespace ignite
return SqlResult::AI_ERROR;
}
- SslMode::Type sslMode = config.GetSslMode();
-
- if (sslMode != SslMode::DISABLE)
- {
- bool loaded = ssl::EnsureSslLoaded();
-
- if (!loaded)
- {
- AddStatusRecord(SqlState::SHY000_GENERAL_ERROR,
- "Can not load OpenSSL library (did you set OPENSSL_HOME environment variable?).");
-
- return SqlResult::AI_ERROR;
- }
-
- socket.reset(new ssl::SecureSocketClient(config.GetSslCertFile(),
- config.GetSslKeyFile(), config.GetSslCaFile()));
- }
- else
- socket.reset(new system::TcpSocketClient());
-
bool connected = TryRestoreConnection();
if (!connected)
@@ -282,7 +292,7 @@ namespace ignite
LOG_MSG("Sent: " << res);
- if (res < 0 || res == SocketClient::WaitResult::TIMEOUT)
+ if (res < 0 || res == network::SocketClient::WaitResult::TIMEOUT)
{
Close();
@@ -353,7 +363,7 @@ namespace ignite
int res = socket->Receive(buffer + received, remain, timeout);
LOG_MSG("Receive res: " << res << " remain: " << remain);
- if (res < 0 || res == SocketClient::WaitResult::TIMEOUT)
+ if (res < 0 || res == network::SocketClient::WaitResult::TIMEOUT)
{
Close();
@@ -703,7 +713,12 @@ namespace ignite
CollectAddresses(config, addrs);
if (socket.get() == 0)
- socket.reset(new system::TcpSocketClient());
+ {
+ SqlResult::Type res = InitSocket();
+
+ if (res != SqlResult::AI_SUCCESS)
+ return false;
+ }
bool connected = false;
@@ -713,7 +728,14 @@ namespace ignite
for (uint16_t port = addr.port; port <= addr.port + addr.range; ++port)
{
- connected = socket->Connect(addr.host.c_str(), port, loginTimeout, *this);
+ try
+ {
+ connected = socket->Connect(addr.host.c_str(), port, loginTimeout);
+ }
+ catch (const IgniteError& err)
+ {
+ LOG_MSG("Error while trying connect to " << addr.host << ":" << addr.port <<", " << err.GetText());
+ }
if (connected)
{
diff --git a/modules/platforms/cpp/odbc/src/ssl/ssl_mode.cpp b/modules/platforms/cpp/odbc/src/ssl_mode.cpp
similarity index 96%
rename from modules/platforms/cpp/odbc/src/ssl/ssl_mode.cpp
rename to modules/platforms/cpp/odbc/src/ssl_mode.cpp
index 3a8e923..70fd058 100644
--- a/modules/platforms/cpp/odbc/src/ssl/ssl_mode.cpp
+++ b/modules/platforms/cpp/odbc/src/ssl_mode.cpp
@@ -15,8 +15,9 @@
* limitations under the License.
*/
-#include "ignite/common/utils.h"
-#include "ignite/odbc/ssl/ssl_mode.h"
+#include <ignite/common/utils.h>
+
+#include "ignite/odbc/ssl_mode.h"
namespace ignite
{
diff --git a/modules/platforms/cpp/project/vs/ignite.sln b/modules/platforms/cpp/project/vs/ignite.sln
index cf2e487..3be196e9 100644
--- a/modules/platforms/cpp/project/vs/ignite.sln
+++ b/modules/platforms/cpp/project/vs/ignite.sln
@@ -30,6 +30,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "thin-client", "..\..\thin-c
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "thin-client-test", "..\..\thin-client-test\project\vs\thin-client-test.vcxproj", "{5662F10A-9C40-45D6-AFF8-E93573FEAABA}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "network", "..\..\network\project\vs\network.vcxproj", "{CB77AC4D-88D4-4A8C-922C-A28C19060A97}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -118,6 +120,14 @@ Global
{5662F10A-9C40-45D6-AFF8-E93573FEAABA}.Release|Win32.Build.0 = Release|Win32
{5662F10A-9C40-45D6-AFF8-E93573FEAABA}.Release|x64.ActiveCfg = Release|x64
{5662F10A-9C40-45D6-AFF8-E93573FEAABA}.Release|x64.Build.0 = Release|x64
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Debug|Win32.ActiveCfg = Debug|Win32
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Debug|Win32.Build.0 = Debug|Win32
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Debug|x64.ActiveCfg = Debug|x64
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Debug|x64.Build.0 = Debug|x64
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Release|Win32.ActiveCfg = Release|Win32
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Release|Win32.Build.0 = Release|Win32
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Release|x64.ActiveCfg = Release|x64
+ {CB77AC4D-88D4-4A8C-922C-A28C19060A97}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/modules/platforms/cpp/thin-client-test/Makefile.am b/modules/platforms/cpp/thin-client-test/Makefile.am
index 6d02c38..8dce61b 100644
--- a/modules/platforms/cpp/thin-client-test/Makefile.am
+++ b/modules/platforms/cpp/thin-client-test/Makefile.am
@@ -29,6 +29,8 @@ AM_CPPFLAGS = \
-I@top_srcdir@/common/include \
-I@top_srcdir@/common/os/linux/include \
-I@top_srcdir@/binary/include \
+ -I@top_srcdir@/network/include \
+ -I@top_srcdir@/network/os/linux/include \
-I@top_srcdir@/jni/include \
-I@top_srcdir@/jni/os/linux/include \
-I@top_srcdir@/thin-client/include \
@@ -46,6 +48,7 @@ AM_CXXFLAGS = \
ignite_thin_client_tests_LDADD = \
@top_srcdir@/core/libignite.la \
+ @top_srcdir@/network/libignite-network.la \
@top_srcdir@/thin-client/libignite-thin-client.la \
-lpthread \
-lboost_thread \
diff --git a/modules/platforms/cpp/thin-client/Makefile.am b/modules/platforms/cpp/thin-client/Makefile.am
index 1efff8e..72dd7bc 100644
--- a/modules/platforms/cpp/thin-client/Makefile.am
+++ b/modules/platforms/cpp/thin-client/Makefile.am
@@ -28,6 +28,8 @@ AM_CPPFLAGS = \
-I@top_srcdir@/common/include \
-I@top_srcdir@/common/os/linux/include \
-I@top_srcdir@/binary/include \
+ -I@top_srcdir@/network/include \
+ -I@top_srcdir@/network/os/linux/include \
-DIGNITE_IMPL \
-D__STDC_LIMIT_MACROS \
-D__STDC_CONSTANT_MACROS
@@ -37,7 +39,8 @@ AM_CXXFLAGS = \
-std=c++03
libignite_thin_client_la_LIBADD = \
- @top_srcdir@/binary/libignite-binary.la
+ @top_srcdir@/binary/libignite-binary.la \
+ @top_srcdir@/network/libignite-network.la
libignite_thin_client_la_LDFLAGS = \
-no-undefined \
@@ -46,24 +49,20 @@ libignite_thin_client_la_LDFLAGS = \
-release $(PACKAGE_VERSION)
libignite_thin_client_la_DEPENDENCIES = \
- @top_srcdir@/binary/libignite-binary.la
+ @top_srcdir@/binary/libignite-binary.la \
+ @top_srcdir@/network/libignite-network.la
libignite_thin_client_la_SOURCES = \
- os/linux/src/net/net_utils.cpp \
- os/linux/src/net/tcp_socket_client.cpp \
src/impl/utility.cpp \
src/impl/protocol_version.cpp \
src/impl/data_channel.cpp \
- src/impl/net/remote_type_updater.cpp \
+ src/impl/remote_type_updater.cpp \
src/impl/message.cpp \
src/impl/ignite_client_impl.cpp \
src/impl/cache/cache_client_proxy.cpp \
src/impl/cache/cache_client_impl.cpp \
src/impl/cache/cache_affinity_info.cpp \
src/impl/data_router.cpp \
- src/impl/ssl/ssl_gateway.cpp \
- src/impl/ssl/secure_socket_client.cpp \
- src/impl/ssl/ssl_api.cpp \
src/ignite_client.cpp
clean-local:
diff --git a/modules/platforms/cpp/thin-client/os/linux/src/net/net_utils.cpp b/modules/platforms/cpp/thin-client/os/linux/src/net/net_utils.cpp
deleted file mode 100644
index acd3ca3..0000000
--- a/modules/platforms/cpp/thin-client/os/linux/src/net/net_utils.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <cstdio>
-#include <cstdlib>
-
-#include <set>
-#include <string>
-#include <iostream>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <ifaddrs.h>
-#include <errno.h>
-
-#include <ignite/ignite_error.h>
-
-#include "impl/net/net_utils.h"
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- namespace net_utils
- {
- void GetLocalAddresses(std::set<std::string>& addrs)
- {
- struct ifaddrs *outAddrs;
- if(getifaddrs(&outAddrs) != 0)
- {
- freeifaddrs(outAddrs);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list");
- }
-
- for (struct ifaddrs *outAddr = outAddrs; outAddr != NULL; outAddr = outAddr->ifa_next)
- {
- if (outAddr->ifa_addr == NULL)
- continue;
-
- if (outAddr->ifa_flags & IFF_LOOPBACK)
- continue;
-
- if (!(outAddr->ifa_flags & IFF_UP))
- continue;
-
- void *inAddr;
-
- char strBuffer[INET6_ADDRSTRLEN];
-
- int saFamily = outAddr->ifa_addr->sa_family;
-
- switch (saFamily)
- {
- case AF_INET:
- {
- sockaddr_in *s4 = reinterpret_cast<sockaddr_in*>(outAddr->ifa_addr);
- inAddr = &s4->sin_addr;
- break;
- }
-
- case AF_INET6:
- {
- sockaddr_in6 *s6 = reinterpret_cast<sockaddr_in6*>(outAddr->ifa_addr);
- inAddr = &s6->sin6_addr;
- break;
- }
-
- default:
- continue;
- }
-
- inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer));
-
- std::string strAddr(strBuffer);
-
- if (!strAddr.empty())
- addrs.insert(strAddr);
- }
-
- freeifaddrs(outAddrs);
- }
- }
- }
- }
- }
-}
-
diff --git a/modules/platforms/cpp/thin-client/os/linux/src/net/tcp_socket_client.cpp b/modules/platforms/cpp/thin-client/os/linux/src/net/tcp_socket_client.cpp
deleted file mode 100644
index fba5069..0000000
--- a/modules/platforms/cpp/thin-client/os/linux/src/net/tcp_socket_client.cpp
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <cstring>
-
-#include <sstream>
-
-#include <ignite/common/concurrent.h>
-
-#include <ignite/ignite_error.h>
-#include "impl/net/tcp_socket_client.h"
-
-#define SOCKET_ERROR (-1)
-
-namespace
-{
- /**
- * Get last socket error message.
- * @param error Error code.
- * @return Last socket error message string.
- */
- std::string GetSocketErrorMessage(int error)
- {
- std::stringstream res;
-
- res << "error_code=" << error;
-
- if (error == 0)
- return res.str();
-
- char buffer[1024] = "";
-
- if (!strerror_r(error, buffer, sizeof(buffer)))
- res << ", msg=" << buffer;
-
- return res.str();
- }
-
- /**
- * Get last socket error message.
- * @return Last socket error message string.
- */
- std::string GetLastSocketErrorMessage()
- {
- int lastError = errno;
-
- return GetSocketErrorMessage(lastError);
- }
-}
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- TcpSocketClient::TcpSocketClient() :
- socketHandle(SOCKET_ERROR),
- blocking(true)
- {
- // No-op.
- }
-
- TcpSocketClient::~TcpSocketClient()
- {
- Close();
- }
-
- bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
- {
-
- addrinfo hints = { 0 };
-
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- std::stringstream converter;
- converter << port;
-
- // Resolve the server address and port
- addrinfo *result = NULL;
- int res = getaddrinfo(hostname, converter.str().c_str(), &hints, &result);
-
- if (res != 0)
- {
- // TODO implement logging.
- //std::string err = "Address resolving failed: " + GetLastSocketErrorMessage();
- //std::cout << err << std::endl;
-
- return false;
- }
-
- // Attempt to connect to an address until one succeeds
- for (addrinfo *it = result; it != NULL; it = it->ai_next)
- {
- // Create a SOCKET for connecting to server
- socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
-
- if (socketHandle == SOCKET_ERROR)
- {
- std::string err = "Socket creation failed: " + GetLastSocketErrorMessage();
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
- }
-
- TrySetOptions();
-
- // Connect to server.
- res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
- if (SOCKET_ERROR == res)
- {
- int lastError = errno;
-
- if (lastError != EWOULDBLOCK && lastError != EINPROGRESS)
- {
- // TODO implement logging.
- //std::string err = "Connection failed: " + GetSocketErrorMessage(lastError);
- //std::cout << err << std::endl;
-
- Close();
-
- continue;
- }
-
- res = WaitOnSocket(timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- {
- // TODO implement logging.
- //std::string err = "Connection timeout expired: " + GetSocketErrorMessage(-res);
- //std::cout << err << std::endl;
-
- Close();
-
- continue;
- }
- }
- break;
- }
-
- freeaddrinfo(result);
-
- return socketHandle != SOCKET_ERROR;
- }
-
- void TcpSocketClient::Close()
- {
- InternalClose();
- }
-
- void TcpSocketClient::InternalClose()
- {
- if (socketHandle != SOCKET_ERROR)
- {
- close(socketHandle);
-
- socketHandle = SOCKET_ERROR;
- }
- }
-
- int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return send(socketHandle, reinterpret_cast<const char*>(data), static_cast<int>(size), 0);
- }
-
- int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout, true);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return recv(socketHandle, reinterpret_cast<char*>(buffer), static_cast<int>(size), 0);
- }
-
- bool TcpSocketClient::IsBlocking() const
- {
- return blocking;
- }
-
- void TcpSocketClient::TrySetOptions()
- {
- int trueOpt = 1;
- int bufSizeOpt = BUFFER_SIZE;
- int idleOpt = KEEP_ALIVE_IDLE_TIME;
- int idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD;
-
- int res = setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP socket send buffer size setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP socket receive buffer size setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP no-delay mode setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP out-of-bound data inlining setup failed: " + GetLastSocketErrorMessage();
- }
-
- blocking = false;
-
- int flags;
- if (((flags = fcntl(socketHandle, F_GETFL, 0)) < 0) ||
- (fcntl(socketHandle, F_SETFL, flags | O_NONBLOCK) < 0))
- {
- blocking = true;
-// std::string err = "Non-blocking mode setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive mode setup failed: " + GetLastSocketErrorMessage();
-
- // There is no sense in configuring keep alive params if we faileed to set up keep alive mode.
- return;
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE,
- reinterpret_cast<char*>(&idleOpt), sizeof(idleOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive idle timeout setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL,
- reinterpret_cast<char*>(&idleRetryOpt), sizeof(idleRetryOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive probes period setup failed: " + GetLastSocketErrorMessage();
- }
-
- }
-
- int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd)
- {
- int ready = 0;
- int lastError = 0;
-
- fd_set fds;
-
- do {
- struct timeval tv = { 0 };
- tv.tv_sec = timeout;
-
- FD_ZERO(&fds);
- FD_SET(socketHandle, &fds);
-
- fd_set* readFds = 0;
- fd_set* writeFds = 0;
-
- if (rd)
- readFds = &fds;
- else
- writeFds = &fds;
-
- ready = select(static_cast<int>((socketHandle) + 1),
- readFds, writeFds, NULL, (timeout == 0 ? NULL : &tv));
-
- if (ready == SOCKET_ERROR)
- lastError = GetLastSocketError();
-
- } while (ready == SOCKET_ERROR && IsSocketOperationInterrupted(lastError));
-
- if (ready == SOCKET_ERROR)
- return -lastError;
-
- socklen_t size = sizeof(lastError);
- int res = getsockopt(socketHandle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
-
- if (res != SOCKET_ERROR && lastError != 0)
- return -lastError;
-
- if (ready == 0)
- return WaitResult::TIMEOUT;
-
- return WaitResult::SUCCESS;
- }
-
- int TcpSocketClient::GetLastSocketError()
- {
- return errno;
- }
-
- int TcpSocketClient::GetLastSocketError(int handle)
- {
- int lastError = 0;
- socklen_t size = sizeof(lastError);
- int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
-
- return res == SOCKET_ERROR ? 0 : lastError;
- }
-
- bool TcpSocketClient::IsSocketOperationInterrupted(int errorCode)
- {
- return errorCode == EINTR;
- }
- }
- }
- }
-}
-
diff --git a/modules/platforms/cpp/thin-client/os/win/src/net/net_utils.cpp b/modules/platforms/cpp/thin-client/os/win/src/net/net_utils.cpp
deleted file mode 100644
index 57f59b4..0000000
--- a/modules/platforms/cpp/thin-client/os/win/src/net/net_utils.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <cstddef>
-
-#include <string>
-#include <set>
-#include <iostream>
-
-#include <winsock2.h>
-#include <ws2ipdef.h>
-#include <ws2tcpip.h>
-#include <windows.h>
-#include <iphlpapi.h>
-
-#include <ignite/ignite_error.h>
-
-#include "impl/net/net_utils.h"
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- namespace net_utils
- {
- void GetLocalAddresses(std::set<std::string>& addrs)
- {
- IP_ADAPTER_ADDRESSES outAddrs[64];
-
- DWORD outAddrsSize = sizeof(outAddrs);
-
- DWORD error = ::GetAdaptersAddresses(AF_UNSPEC, 0, NULL, &outAddrs[0], &outAddrsSize);
-
- if (ERROR_SUCCESS != error)
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list");
-
- for (IP_ADAPTER_ADDRESSES* outAddr = &outAddrs[0]; NULL != outAddr; outAddr = outAddr->Next)
- {
- if (IF_TYPE_SOFTWARE_LOOPBACK == outAddr->IfType)
- continue;
-
- for (IP_ADAPTER_UNICAST_ADDRESS* addr = outAddr->FirstUnicastAddress;
- NULL != addr;
- addr = addr->Next)
- {
- void *inAddr = 0;
-
- char strBuffer[INET6_ADDRSTRLEN] = { 0 };
-
- int saFamily = addr->Address.lpSockaddr->sa_family;
-
- switch (saFamily)
- {
- case AF_INET:
- {
- SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(addr->Address.lpSockaddr);
- inAddr = &ipv4->sin_addr;
-
- break;
- }
-
- case AF_INET6:
- {
- SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(addr->Address.lpSockaddr);
- inAddr = &ipv6->sin6_addr;
-
- break;
- }
-
- default:
- continue;
- }
-
- inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer));
-
- std::string strAddr(strBuffer);
-
- if (!strAddr.empty())
- addrs.insert(strAddr);
- }
- }
- }
- }
- }
- }
- }
-}
-
diff --git a/modules/platforms/cpp/thin-client/os/win/src/net/tcp_socket_client.cpp b/modules/platforms/cpp/thin-client/os/win/src/net/tcp_socket_client.cpp
deleted file mode 100644
index b8d7e15..0000000
--- a/modules/platforms/cpp/thin-client/os/win/src/net/tcp_socket_client.cpp
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define WIN32_LEAN_AND_MEAN
-#define _WINSOCKAPI_
-
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <mstcpip.h>
-
-#include <sstream>
-
-#include <ignite/ignite_error.h>
-
-#include <ignite/common/concurrent.h>
-
-#include "impl/net/tcp_socket_client.h"
-
-namespace
-{
- /**
- * Get socket error message for the error code.
- * @param error Error code.
- * @return Socket error message string.
- */
- std::string GetSocketErrorMessage(HRESULT error)
- {
- std::stringstream res;
-
- res << "error_code=" << error;
-
- if (error == 0)
- return res.str();
-
- LPTSTR errorText = NULL;
-
- DWORD len = FormatMessage(
- // use system message tables to retrieve error text
- FORMAT_MESSAGE_FROM_SYSTEM
- // allocate buffer on local heap for error text
- | FORMAT_MESSAGE_ALLOCATE_BUFFER
- // We're not passing insertion parameters
- | FORMAT_MESSAGE_IGNORE_INSERTS,
- // unused with FORMAT_MESSAGE_FROM_SYSTEM
- NULL,
- error,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- // output
- reinterpret_cast<LPTSTR>(&errorText),
- // minimum size for output buffer
- 0,
- // arguments - see note
- NULL);
-
- if (NULL != errorText)
- {
- if (len != 0)
- res << ", msg=" << std::string(errorText, len);
-
- LocalFree(errorText);
- }
-
- return res.str();
- }
-
- /**
- * Get last socket error message.
- * @return Last socket error message string.
- */
- std::string GetLastSocketErrorMessage()
- {
- HRESULT lastError = WSAGetLastError();
-
- return GetSocketErrorMessage(lastError);
- }
-}
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- TcpSocketClient::TcpSocketClient() :
- socketHandle(INVALID_SOCKET),
- blocking(true)
- {
- // No-op.
- }
-
- TcpSocketClient::~TcpSocketClient()
- {
- InternalClose();
- }
-
- bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
- {
- static common::concurrent::CriticalSection initCs;
- static bool networkInited = false;
-
- // Initing networking if is not inited.
- if (!networkInited)
- {
- common::concurrent::CsLockGuard lock(initCs);
- if (!networkInited)
- {
- WSADATA wsaData;
-
- networkInited = (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0);
-
- if (!networkInited)
- {
- std::string err = "Networking initialisation failed: " + GetLastSocketErrorMessage();
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
- }
- }
- }
-
- addrinfo hints = { 0 };
-
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- std::stringstream converter;
- converter << port;
-
- // Resolve the server address and port
- addrinfo *result = NULL;
- int res = getaddrinfo(hostname, converter.str().c_str(), &hints, &result);
-
- if (res != 0)
- return false;
-
- // Attempt to connect to an address until one succeeds
- for (addrinfo *it = result; it != NULL; it = it->ai_next)
- {
- // Create a SOCKET for connecting to server
- socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
-
- if (socketHandle == INVALID_SOCKET)
- {
- std::string err = "Socket creation failed: " + GetLastSocketErrorMessage();
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
- }
-
- TrySetOptions();
-
- // Connect to server.
- res = connect(socketHandle, it->ai_addr, static_cast<int>(it->ai_addrlen));
- if (SOCKET_ERROR == res)
- {
- int lastError = WSAGetLastError();
-
- if (lastError != WSAEWOULDBLOCK)
- {
- Close();
-
- continue;
- }
-
- res = WaitOnSocket(timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- {
- Close();
-
- continue;
- }
- }
- break;
- }
-
- freeaddrinfo(result);
-
- return socketHandle != INVALID_SOCKET;
- }
-
- void TcpSocketClient::Close()
- {
- InternalClose();
- }
-
- void TcpSocketClient::InternalClose()
- {
- if (socketHandle != INVALID_SOCKET)
- {
- closesocket(socketHandle);
-
- socketHandle = INVALID_SOCKET;
- }
- }
-
- int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout, false);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return send(socketHandle, reinterpret_cast<const char*>(data), static_cast<int>(size), 0);
- }
-
- int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
- {
- if (!blocking)
- {
- int res = WaitOnSocket(timeout, true);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- return recv(socketHandle, reinterpret_cast<char*>(buffer), static_cast<int>(size), 0);
- }
-
- bool TcpSocketClient::IsBlocking() const
- {
- return blocking;
- }
-
- void TcpSocketClient::TrySetOptions()
- {
- BOOL trueOpt = TRUE;
- ULONG uTrueOpt = TRUE;
- int bufSizeOpt = BUFFER_SIZE;
-
-
- int res = setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP socket send buffer size setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<char*>(&bufSizeOpt), sizeof(bufSizeOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP socket receive buffer size setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP no-delay mode setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP out-of-bound data inlining setup failed: " + GetLastSocketErrorMessage();
- }
-
- blocking = false;
- res = ioctlsocket(socketHandle, FIONBIO, &uTrueOpt);
-
- if (res == SOCKET_ERROR)
- {
- blocking = true;
-// std::string err = "Non-blocking mode setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE,
- reinterpret_cast<char*>(&trueOpt), sizeof(trueOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive mode setup failed: " + GetLastSocketErrorMessage();
-
- // There is no sense in configuring keep alive params if we faileed to set up keep alive mode.
- return;
- }
-
- // This option is available starting with Windows 10, version 1709.
-#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL)
- DWORD idleOpt = KEEP_ALIVE_IDLE_TIME;
- DWORD idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD;
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE,
- reinterpret_cast<char*>(&idleOpt), sizeof(idleOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive idle timeout setup failed: " + GetLastSocketErrorMessage();
- }
-
- res = setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL,
- reinterpret_cast<char*>(&idleRetryOpt), sizeof(idleRetryOpt));
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive probes period setup failed: " + GetLastSocketErrorMessage();
- }
-#else // use old hardcore WSAIoctl
-
- // WinSock structure for KeepAlive timing settings
- struct tcp_keepalive settings = { 0 };
- settings.onoff = 1;
- settings.keepalivetime = KEEP_ALIVE_IDLE_TIME * 1000;
- settings.keepaliveinterval = KEEP_ALIVE_PROBES_PERIOD * 1000;
-
- // pointers for WinSock call
- DWORD bytesReturned;
- WSAOVERLAPPED overlapped;
- overlapped.hEvent = NULL;
-
- // Set KeepAlive settings
- res = WSAIoctl(
- socketHandle,
- SIO_KEEPALIVE_VALS,
- &settings,
- sizeof(struct tcp_keepalive),
- NULL,
- 0,
- &bytesReturned,
- &overlapped,
- NULL
- );
-
- if (SOCKET_ERROR == res)
- {
-// std::string err = "TCP keep-alive params setup failed: " + GetLastSocketErrorMessage();
- }
-#endif
- }
-
- int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd)
- {
- int ready = 0;
- int lastError = 0;
-
- fd_set fds;
-
- do {
- struct timeval tv = { 0 };
- tv.tv_sec = timeout;
-
- FD_ZERO(&fds);
- FD_SET(socketHandle, &fds);
-
- fd_set* readFds = 0;
- fd_set* writeFds = 0;
-
- if (rd)
- readFds = &fds;
- else
- writeFds = &fds;
-
- ready = select(static_cast<int>((socketHandle) + 1),
- readFds, writeFds, NULL, (timeout == 0 ? NULL : &tv));
-
- if (ready == SOCKET_ERROR)
- lastError = GetLastSocketError();
-
- } while (ready == SOCKET_ERROR && IsSocketOperationInterrupted(lastError));
-
- if (ready == SOCKET_ERROR)
- return -lastError;
-
- if (ready == 0)
- return WaitResult::TIMEOUT;
-
- return WaitResult::SUCCESS;
- }
-
- int TcpSocketClient::GetLastSocketError()
- {
- return WSAGetLastError();
- }
-
- int TcpSocketClient::GetLastSocketError(int handle)
- {
- int lastError = 0;
- socklen_t size = sizeof(lastError);
- int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&lastError), &size);
-
- return res == SOCKET_ERROR ? 0 : lastError;
- }
-
- bool TcpSocketClient::IsSocketOperationInterrupted(int errorCode)
- {
- return errorCode == WSAEINTR;
- }
- }
- }
- }
-}
-
diff --git a/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj b/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj
index 9c00913..155c394 100644
--- a/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj
+++ b/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj
@@ -93,7 +93,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";_DEBUG";%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@@ -108,7 +108,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@@ -124,7 +124,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME_X86)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
@@ -141,7 +141,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\network\include;$(ProjectDir)\..\..\..\network\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\src;$(OPENSSL_HOME)\include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;TARGET_MODULE_FULL_NAME="$(TargetFileName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
@@ -153,8 +153,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="..\..\os\win\src\net\tcp_socket_client.cpp" />
- <ClCompile Include="..\..\os\win\src\net\net_utils.cpp" />
<ClCompile Include="..\..\src\ignite_client.cpp" />
<ClCompile Include="..\..\src\impl\cache\cache_affinity_info.cpp" />
<ClCompile Include="..\..\src\impl\cache\cache_client_impl.cpp" />
@@ -163,11 +161,8 @@
<ClCompile Include="..\..\src\impl\data_router.cpp" />
<ClCompile Include="..\..\src\impl\ignite_client_impl.cpp" />
<ClCompile Include="..\..\src\impl\message.cpp" />
- <ClCompile Include="..\..\src\impl\net\remote_type_updater.cpp" />
<ClCompile Include="..\..\src\impl\protocol_version.cpp" />
- <ClCompile Include="..\..\src\impl\ssl\secure_socket_client.cpp" />
- <ClCompile Include="..\..\src\impl\ssl\ssl_api.cpp" />
- <ClCompile Include="..\..\src\impl\ssl\ssl_gateway.cpp" />
+ <ClCompile Include="..\..\src\impl\remote_type_updater.cpp" />
<ClCompile Include="..\..\src\impl\utility.cpp" />
</ItemGroup>
<ItemGroup>
@@ -187,17 +182,9 @@
<ClInclude Include="..\..\src\impl\data_router.h" />
<ClInclude Include="..\..\src\impl\ignite_client_impl.h" />
<ClInclude Include="..\..\src\impl\message.h" />
- <ClInclude Include="..\..\src\impl\net\end_point.h" />
- <ClInclude Include="..\..\src\impl\net\net_utils.h" />
- <ClInclude Include="..\..\src\impl\net\remote_type_updater.h" />
- <ClInclude Include="..\..\src\impl\net\tcp_range.h" />
- <ClInclude Include="..\..\src\impl\net\tcp_socket_client.h" />
<ClInclude Include="..\..\src\impl\protocol_version.h" />
+ <ClInclude Include="..\..\src\impl\remote_type_updater.h" />
<ClInclude Include="..\..\src\impl\response_status.h" />
- <ClInclude Include="..\..\src\impl\socket_client.h" />
- <ClInclude Include="..\..\src\impl\ssl\secure_socket_client.h" />
- <ClInclude Include="..\..\src\impl\ssl\ssl_api.h" />
- <ClInclude Include="..\..\src\impl\ssl\ssl_gateway.h" />
<ClInclude Include="..\..\src\impl\utility.h" />
</ItemGroup>
<ItemGroup>
@@ -207,6 +194,9 @@
<ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
<Project>{b63f2e01-5157-4719-8491-0e1c7cd3b701}</Project>
</ProjectReference>
+ <ProjectReference Include="..\..\..\network\project\vs\network.vcxproj">
+ <Project>{cb77ac4d-88d4-4a8c-922c-a28c19060a97}</Project>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj.filters b/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj.filters
index a5cad74..2650c86 100644
--- a/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj.filters
+++ b/modules/platforms/cpp/thin-client/project/vs/thin-client.vcxproj.filters
@@ -8,12 +8,6 @@
<Filter Include="Code\impl">
<UniqueIdentifier>{9bc8816b-8ec1-4da2-9381-d194f811280c}</UniqueIdentifier>
</Filter>
- <Filter Include="Code\impl\net">
- <UniqueIdentifier>{a9e3beb1-9215-4edc-b0ea-eddd868bbc93}</UniqueIdentifier>
- </Filter>
- <Filter Include="Code\impl\ssl">
- <UniqueIdentifier>{46739e07-2e4d-400b-bba2-902d96158c44}</UniqueIdentifier>
- </Filter>
<Filter Include="Code\cache">
<UniqueIdentifier>{143c6ccd-4c0a-4ac3-a6a5-23aa030288db}</UniqueIdentifier>
</Filter>
@@ -34,15 +28,6 @@
<ClCompile Include="..\..\src\impl\protocol_version.cpp">
<Filter>Code\impl</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\impl\ssl\secure_socket_client.cpp">
- <Filter>Code\impl\ssl</Filter>
- </ClCompile>
- <ClCompile Include="..\..\src\impl\ssl\ssl_gateway.cpp">
- <Filter>Code\impl\ssl</Filter>
- </ClCompile>
- <ClCompile Include="..\..\os\win\src\net\tcp_socket_client.cpp">
- <Filter>Code\impl\net</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\impl\message.cpp">
<Filter>Code\impl</Filter>
</ClCompile>
@@ -55,20 +40,14 @@
<ClCompile Include="..\..\src\impl\cache\cache_client_impl.cpp">
<Filter>Code\impl\cache</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\impl\net\remote_type_updater.cpp">
- <Filter>Code\impl\net</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\impl\data_channel.cpp">
<Filter>Code\impl</Filter>
</ClCompile>
- <ClCompile Include="..\..\os\win\src\net\net_utils.cpp">
- <Filter>Code\impl\net</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\impl\cache\cache_affinity_info.cpp">
<Filter>Code\impl\cache</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\impl\ssl\ssl_api.cpp">
- <Filter>Code\impl\ssl</Filter>
+ <ClCompile Include="..\..\src\impl\remote_type_updater.cpp">
+ <Filter>Code\impl</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@@ -117,33 +96,9 @@
<ClInclude Include="..\..\src\impl\response_status.h">
<Filter>Code\impl</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\impl\socket_client.h">
- <Filter>Code\impl</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\impl\utility.h">
<Filter>Code\impl</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\impl\ssl\secure_socket_client.h">
- <Filter>Code\impl\ssl</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\impl\ssl\ssl_gateway.h">
- <Filter>Code\impl\ssl</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\impl\net\end_point.h">
- <Filter>Code\impl\net</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\impl\net\net_utils.h">
- <Filter>Code\impl\net</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\impl\net\remote_type_updater.h">
- <Filter>Code\impl\net</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\impl\net\tcp_range.h">
- <Filter>Code\impl\net</Filter>
- </ClInclude>
- <ClInclude Include="..\..\src\impl\net\tcp_socket_client.h">
- <Filter>Code\impl\net</Filter>
- </ClInclude>
<ClInclude Include="..\..\src\impl\cache\cache_client_impl.h">
<Filter>Code\impl\cache</Filter>
</ClInclude>
@@ -153,8 +108,8 @@
<ClInclude Include="..\..\src\impl\cache\cache_affinity_info.h">
<Filter>Code\impl\cache</Filter>
</ClInclude>
- <ClInclude Include="..\..\src\impl\ssl\ssl_api.h">
- <Filter>Code\impl\ssl</Filter>
+ <ClInclude Include="..\..\src\impl\remote_type_updater.h">
+ <Filter>Code\impl</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.cpp b/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.cpp
index 2daa6f3..48e203d 100644
--- a/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.cpp
+++ b/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.cpp
@@ -35,7 +35,7 @@ namespace ignite
for (it = info.begin(); it != info.end(); ++it)
{
const std::vector<int32_t>& parts = it->GetPartitions();
- const std::vector<net::EndPoint>& endPoints = it->GetEndPoints();
+ const std::vector<network::EndPoint>& endPoints = it->GetEndPoints();
for (size_t i = 0; i < parts.size(); ++i)
{
diff --git a/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.h b/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.h
index 8394516..789a64f 100644
--- a/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.h
+++ b/modules/platforms/cpp/thin-client/src/impl/cache/cache_affinity_info.h
@@ -23,8 +23,7 @@
#include <vector>
#include <ignite/common/concurrent.h>
-
-#include "impl/net/end_point.h"
+#include <ignite/network/end_point.h>
namespace ignite
{
@@ -41,7 +40,7 @@ namespace ignite
namespace cache
{
/** End point collection. */
- typedef std::vector<net::EndPoint> EndPoints;
+ typedef std::vector<network::EndPoint> EndPoints;
/**
* Cache Affinity Info.
diff --git a/modules/platforms/cpp/thin-client/src/impl/connectable_node_partitions.h b/modules/platforms/cpp/thin-client/src/impl/connectable_node_partitions.h
index a6bbb86..8367a79 100644
--- a/modules/platforms/cpp/thin-client/src/impl/connectable_node_partitions.h
+++ b/modules/platforms/cpp/thin-client/src/impl/connectable_node_partitions.h
@@ -20,7 +20,7 @@
#include <stdint.h>
-#include "impl/net/end_point.h"
+#include <ignite/network/end_point.h>
namespace ignite
{
@@ -58,7 +58,7 @@ namespace ignite
*
* @return End points.
*/
- const std::vector<net::EndPoint>& GetEndPoints() const
+ const std::vector<network::EndPoint>& GetEndPoints() const
{
return endPoints;
}
@@ -92,7 +92,7 @@ namespace ignite
std::string addr;
reader.ReadString(addr);
- endPoints.push_back(net::EndPoint(addr, static_cast<uint16_t>(port)));
+ endPoints.push_back(network::EndPoint(addr, static_cast<uint16_t>(port)));
}
int32_t partsNum = reader.ReadInt32();
@@ -106,7 +106,7 @@ namespace ignite
private:
/** Node end points. */
- std::vector<net::EndPoint> endPoints;
+ std::vector<network::EndPoint> endPoints;
/** Cache partitions. */
std::vector<int32_t> partitions;
diff --git a/modules/platforms/cpp/thin-client/src/impl/data_channel.cpp b/modules/platforms/cpp/thin-client/src/impl/data_channel.cpp
index 592dba3..6eea8c4 100644
--- a/modules/platforms/cpp/thin-client/src/impl/data_channel.cpp
+++ b/modules/platforms/cpp/thin-client/src/impl/data_channel.cpp
@@ -21,13 +21,10 @@
#include <sstream>
#include <ignite/common/fixed_size_array.h>
+#include <ignite/network/network.h>
#include "impl/message.h"
-#include "impl/ssl/ssl_api.h"
-#include "impl/ssl/secure_socket_client.h"
-#include "impl/net/tcp_socket_client.h"
-#include "impl/net/remote_type_updater.h"
-
+#include "impl/remote_type_updater.h"
#include "impl/data_channel.h"
namespace ignite
@@ -81,13 +78,11 @@ namespace ignite
if (sslMode != SslMode::DISABLE)
{
- ssl::EnsureSslLoaded();
-
- socket.reset(new ssl::SecureSocketClient(config.GetSslCertFile(),
- config.GetSslKeyFile(), config.GetSslCaFile()));
+ socket.reset(network::ssl::MakeSecureSocketClient(
+ config.GetSslCertFile(), config.GetSslKeyFile(), config.GetSslCaFile()));
}
else
- socket.reset(new net::TcpSocketClient());
+ socket.reset(network::ssl::MakeTcpSocketClient());
address.host = host;
address.port = port;
@@ -147,7 +142,7 @@ namespace ignite
{
int res = socket->Send(data + sent, len - sent, timeout);
- if (res < 0 || res == SocketClient::WaitResult::TIMEOUT)
+ if (res < 0 || res == network::SocketClient::WaitResult::TIMEOUT)
{
Close();
@@ -222,7 +217,7 @@ namespace ignite
int res = socket->Receive(buffer + received, remain, timeout);
- if (res < 0 || res == SocketClient::WaitResult::TIMEOUT)
+ if (res < 0 || res == network::SocketClient::WaitResult::TIMEOUT)
{
Close();
diff --git a/modules/platforms/cpp/thin-client/src/impl/data_channel.h b/modules/platforms/cpp/thin-client/src/impl/data_channel.h
index 951f9f0..d399add 100644
--- a/modules/platforms/cpp/thin-client/src/impl/data_channel.h
+++ b/modules/platforms/cpp/thin-client/src/impl/data_channel.h
@@ -26,12 +26,13 @@
#include <ignite/common/concurrent.h>
+#include <ignite/network/end_point.h>
+#include <ignite/network/socket_client.h>
+
#include <ignite/impl/interop/interop_output_stream.h>
#include <ignite/impl/binary/binary_writer_impl.h>
#include "impl/protocol_version.h"
-#include "impl/net/end_point.h"
-#include "impl/socket_client.h"
namespace ignite
{
@@ -154,7 +155,7 @@ namespace ignite
* Get address.
* @return Address.
*/
- const net::EndPoint& GetAddress() const
+ const network::EndPoint& GetAddress() const
{
return address;
}
@@ -306,7 +307,7 @@ namespace ignite
common::concurrent::CriticalSection ioMutex;
/** Remote host address. */
- net::EndPoint address;
+ network::EndPoint address;
/** Configuration. */
const ignite::thin::IgniteClientConfiguration& config;
@@ -321,7 +322,7 @@ namespace ignite
int64_t reqIdCounter;
/** Client Socket. */
- std::auto_ptr<SocketClient> socket;
+ std::auto_ptr<network::SocketClient> socket;
};
/** Shared pointer type. */
diff --git a/modules/platforms/cpp/thin-client/src/impl/data_router.cpp b/modules/platforms/cpp/thin-client/src/impl/data_router.cpp
index 018e6df6..09aabe0 100644
--- a/modules/platforms/cpp/thin-client/src/impl/data_router.cpp
+++ b/modules/platforms/cpp/thin-client/src/impl/data_router.cpp
@@ -23,13 +23,13 @@
#include <iterator>
#include <algorithm>
+#include <ignite/network/utils.h>
+
#include "impl/utility.h"
#include "impl/data_router.h"
#include "impl/message.h"
#include "impl/response_status.h"
-#include "impl/ssl/ssl_gateway.h"
-#include "impl/net/remote_type_updater.h"
-#include "impl/net/net_utils.h"
+#include "impl/remote_type_updater.h"
#include "ignite/impl/thin/writable_key.h"
namespace ignite
@@ -40,7 +40,7 @@ namespace ignite
{
DataRouter::DataRouter(const ignite::thin::IgniteClientConfiguration& cfg) :
ioTimeout(DEFALT_IO_TIMEOUT),
- connectionTimeout(DEFALT_CONNECT_TIMEOUT),
+ connectionTimeout(DEFAULT_CONNECT_TIMEOUT),
config(cfg),
ranges(),
localAddresses(),
@@ -72,15 +72,24 @@ namespace ignite
if (config.GetEndPoints().empty())
throw IgniteError(IgniteError::IGNITE_ERR_ILLEGAL_ARGUMENT, "No valid address to connect.");
- for (std::vector<net::TcpRange>::iterator it = ranges.begin(); it != ranges.end(); ++it)
+ for (std::vector<network::TcpRange>::iterator it = ranges.begin(); it != ranges.end(); ++it)
{
- net::TcpRange& range = *it;
+ network::TcpRange& range = *it;
for (uint16_t port = range.port; port <= range.port + range.range; ++port)
{
SP_DataChannel channel(new DataChannel(config, typeMgr));
- bool connected = channel.Get()->Connect(range.host, port, connectionTimeout);
+ bool connected = false;
+
+ try
+ {
+ connected = channel.Get()->Connect(range.host, port, connectionTimeout);
+ }
+ catch (const IgniteError&)
+ {
+ // No-op.
+ }
if (connected)
{
@@ -104,7 +113,7 @@ namespace ignite
{
typeMgr.SetUpdater(0);
- std::map<net::EndPoint, SP_DataChannel>::iterator it;
+ std::map<network::EndPoint, SP_DataChannel>::iterator it;
common::concurrent::CsLockGuard lock(channelsMutex);
@@ -159,16 +168,16 @@ namespace ignite
size_t idx = r % channels.size();
- std::map<net::EndPoint, SP_DataChannel>::iterator it = channels.begin();
+ std::map<network::EndPoint, SP_DataChannel>::iterator it = channels.begin();
std::advance(it, idx);
return it->second;
}
- bool DataRouter::IsLocalHost(const std::vector<net::EndPoint>& hint)
+ bool DataRouter::IsLocalHost(const std::vector<network::EndPoint>& hint)
{
- for (std::vector<net::EndPoint>::const_iterator it = hint.begin(); it != hint.end(); ++it)
+ for (std::vector<network::EndPoint>::const_iterator it = hint.begin(); it != hint.end(); ++it)
{
const std::string& host = it->host;
@@ -194,9 +203,9 @@ namespace ignite
return host == "::1" || host == "0:0:0:0:0:0:0:1";
}
- bool DataRouter::IsProvidedByUser(const net::EndPoint& endPoint)
+ bool DataRouter::IsProvidedByUser(const network::EndPoint& endPoint)
{
- for (std::vector<net::TcpRange>::iterator it = ranges.begin(); it != ranges.end(); ++it)
+ for (std::vector<network::TcpRange>::iterator it = ranges.begin(); it != ranges.end(); ++it)
{
if (it->host == endPoint.host &&
endPoint.port >= it->port &&
@@ -207,14 +216,14 @@ namespace ignite
return false;
}
- SP_DataChannel DataRouter::GetBestChannel(const std::vector<net::EndPoint>& hint)
+ SP_DataChannel DataRouter::GetBestChannel(const std::vector<network::EndPoint>& hint)
{
if (hint.empty())
return GetRandomChannel();
bool localHost = IsLocalHost(hint);
- for (std::vector<net::EndPoint>::const_iterator it = hint.begin(); it != hint.end(); ++it)
+ for (std::vector<network::EndPoint>::const_iterator it = hint.begin(); it != hint.end(); ++it)
{
if (IsLocalAddress(it->host) && !localHost)
continue;
@@ -231,7 +240,16 @@ namespace ignite
SP_DataChannel channel(new DataChannel(config, typeMgr));
- bool connected = channel.Get()->Connect(it->host, it->port, connectionTimeout);
+ bool connected = false;
+
+ try
+ {
+ connected = channel.Get()->Connect(it->host, it->port, connectionTimeout);
+ }
+ catch (const IgniteError&)
+ {
+ // No-op.
+ }
if (connected)
{
@@ -248,10 +266,10 @@ namespace ignite
{
localAddresses.clear();
- net::net_utils::GetLocalAddresses(localAddresses);
+ network::utils::GetLocalAddresses(localAddresses);
}
- void DataRouter::CollectAddresses(const std::string& str, std::vector<net::TcpRange>& ranges)
+ void DataRouter::CollectAddresses(const std::string& str, std::vector<network::TcpRange>& ranges)
{
ranges.clear();
diff --git a/modules/platforms/cpp/thin-client/src/impl/data_router.h b/modules/platforms/cpp/thin-client/src/impl/data_router.h
index c3ca62d..4f3fbb0 100644
--- a/modules/platforms/cpp/thin-client/src/impl/data_router.h
+++ b/modules/platforms/cpp/thin-client/src/impl/data_router.h
@@ -29,11 +29,11 @@
#include <ignite/thin/ignite_client_configuration.h>
#include <ignite/common/concurrent.h>
+#include <ignite/network/end_point.h>
+#include <ignite/network/tcp_range.h>
#include <ignite/impl/binary/binary_writer_impl.h>
#include "impl/data_channel.h"
-#include "impl/net/end_point.h"
-#include "impl/net/tcp_range.h"
#include "impl/cache/cache_affinity_info.h"
namespace ignite
@@ -55,7 +55,7 @@ namespace ignite
{
public:
/** Connection establishment timeout in seconds. */
- enum { DEFALT_CONNECT_TIMEOUT = 5 };
+ enum { DEFAULT_CONNECT_TIMEOUT = 5 };
/** Network IO operation timeout in seconds. */
enum { DEFALT_IO_TIMEOUT = 5 };
@@ -120,7 +120,7 @@ namespace ignite
* @throw IgniteError on error.
*/
template<typename ReqT, typename RspT>
- void SyncMessage(const ReqT& req, RspT& rsp, const std::vector<net::EndPoint>& hint)
+ void SyncMessage(const ReqT& req, RspT& rsp, const std::vector<network::EndPoint>& hint)
{
SP_DataChannel channel = GetBestChannel(hint);
@@ -181,7 +181,7 @@ namespace ignite
IGNITE_NO_COPY_ASSIGNMENT(DataRouter);
/** End point collection. */
- typedef std::vector<net::EndPoint> EndPoints;
+ typedef std::vector<network::EndPoint> EndPoints;
/** Shared pointer to end points. */
typedef common::concurrent::SharedPointer<EndPoints> SP_EndPoints;
@@ -209,7 +209,7 @@ namespace ignite
* @param hint Hint.
* @return @c true if the local host.
*/
- bool IsLocalHost(const std::vector<net::EndPoint>& hint);
+ bool IsLocalHost(const std::vector<network::EndPoint>& hint);
/**
* Check whether the provided address is the local host.
@@ -225,7 +225,7 @@ namespace ignite
* @param endPoint End point to check.
* @return @c true if provided by user using configuration.
*/
- bool IsProvidedByUser(const net::EndPoint& endPoint);
+ bool IsProvidedByUser(const network::EndPoint& endPoint);
/**
* Get the best data channel.
@@ -233,7 +233,7 @@ namespace ignite
* @param hint End points of the preferred server node to use.
* @return The best available data channel.
*/
- SP_DataChannel GetBestChannel(const std::vector<net::EndPoint>& hint);
+ SP_DataChannel GetBestChannel(const std::vector<network::EndPoint>& hint);
/**
* Update local addresses.
@@ -246,7 +246,7 @@ namespace ignite
* @param str String with connection strings to parse.
* @param ranges Address ranges.
*/
- static void CollectAddresses(const std::string& str, std::vector<net::TcpRange>& ranges);
+ static void CollectAddresses(const std::string& str, std::vector<network::TcpRange>& ranges);
/** IO timeout in seconds. */
int32_t ioTimeout;
@@ -258,7 +258,7 @@ namespace ignite
ignite::thin::IgniteClientConfiguration config;
/** Address ranges. */
- std::vector<net::TcpRange> ranges;
+ std::vector<network::TcpRange> ranges;
/** Local addresses. */
std::set<std::string> localAddresses;
@@ -270,7 +270,7 @@ namespace ignite
binary::BinaryTypeManager typeMgr;
/** Data channels. */
- std::map<net::EndPoint, SP_DataChannel> channels;
+ std::map<network::EndPoint, SP_DataChannel> channels;
/** Channels mutex. */
common::concurrent::CriticalSection channelsMutex;
diff --git a/modules/platforms/cpp/thin-client/src/impl/net/end_point.h b/modules/platforms/cpp/thin-client/src/impl/net/end_point.h
deleted file mode 100644
index a7dbf18..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/net/end_point.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_NET_END_POINT
-#define _IGNITE_IMPL_THIN_NET_END_POINT
-
-#include <stdint.h>
-#include <string>
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- /**
- * Connection end point structure.
- */
- struct EndPoint
- {
- /**
- * Default constructor.
- */
- EndPoint() :
- port(0)
- {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param host Host.
- * @param port Port.
- */
- EndPoint(const std::string& host, uint16_t port) :
- host(host),
- port(port)
- {
- // No-op.
- }
-
- /**
- * Compare to another instance.
- *
- * @param other Another instance.
- * @return Negative value if less, positive if larger and
- * zero, if equals another instance.
- */
- int Compare(const EndPoint& other) const
- {
- if (port < other.port)
- return -1;
-
- if (port > other.port)
- return 1;
-
- return host.compare(other.host);
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if equal.
- */
- friend bool operator==(const EndPoint& val1, const EndPoint& val2)
- {
- return val1.port == val2.port && val1.host == val2.host;
- }
-
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if not equal.
- */
- friend bool operator!=(const EndPoint& val1, const EndPoint& val2)
- {
- return !(val1 == val2);
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if less.
- */
- friend bool operator<(const EndPoint& val1, const EndPoint& val2)
- {
- return val1.Compare(val2) < 0;
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if less or equal.
- */
- friend bool operator<=(const EndPoint& val1, const EndPoint& val2)
- {
- return val1.Compare(val2) <= 0;
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if gretter.
- */
- friend bool operator>(const EndPoint& val1, const EndPoint& val2)
- {
- return val1.Compare(val2) > 0;
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if gretter or equal.
- */
- friend bool operator>=(const EndPoint& val1, const EndPoint& val2)
- {
- return val1.Compare(val2) >= 0;
- }
-
- /** Remote host. */
- std::string host;
-
- /** TCP port. */
- uint16_t port;
- };
- }
- }
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_NET_END_POINT
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/net/net_utils.h b/modules/platforms/cpp/thin-client/src/impl/net/net_utils.h
deleted file mode 100644
index 73ee6e3..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/net/net_utils.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_NET_NET_UTILS
-#define _IGNITE_IMPL_THIN_NET_NET_UTILS
-
-#include <set>
-#include <string>
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- namespace net_utils
- {
- /**
- * Get set of local addresses.
- *
- * @param addrs Addresses set.
- */
- void GetLocalAddresses(std::set<std::string>& addrs);
- }
- }
- }
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_NET_NET_UTILS
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/net/tcp_range.h b/modules/platforms/cpp/thin-client/src/impl/net/tcp_range.h
deleted file mode 100644
index 18c162f..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/net/tcp_range.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_NET_TCP_RANGE
-#define _IGNITE_IMPL_THIN_NET_TCP_RANGE
-
-#include <stdint.h>
-#include <string>
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- /**
- * TCP port range.
- */
- struct TcpRange
- {
- /**
- * Default constructor.
- */
- TcpRange() :
- port(0),
- range(0)
- {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param host Host.
- * @param port Port.
- * @param range Number of ports after the @c port that
- * should be tried if the previous are unavailable.
- */
- TcpRange(const std::string& host, uint16_t port, uint16_t range = 0) :
- host(host),
- port(port),
- range(range)
- {
- // No-op.
- }
-
- /**
- * Compare to another instance.
- *
- * @param other Another instance.
- * @return Negative value if less, positive if larger and
- * zero, if equals another instance.
- */
- int Compare(const TcpRange& other) const
- {
- if (port < other.port)
- return -1;
-
- if (port > other.port)
- return 1;
-
- if (range < other.range)
- return -1;
-
- if (range > other.range)
- return 1;
-
- return host.compare(other.host);
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if equal.
- */
- friend bool operator==(const TcpRange& val1, const TcpRange& val2)
- {
- return val1.port == val2.port && val1.range == val2.range && val1.host == val2.host;
- }
-
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if not equal.
- */
- friend bool operator!=(const TcpRange& val1, const TcpRange& val2)
- {
- return !(val1 == val2);
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if less.
- */
- friend bool operator<(const TcpRange& val1, const TcpRange& val2)
- {
- return val1.Compare(val2) < 0;
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if less or equal.
- */
- friend bool operator<=(const TcpRange& val1, const TcpRange& val2)
- {
- return val1.Compare(val2) <= 0;
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if gretter.
- */
- friend bool operator>(const TcpRange& val1, const TcpRange& val2)
- {
- return val1.Compare(val2) > 0;
- }
-
- /**
- * Comparison operator.
- *
- * @param val1 First value.
- * @param val2 Second value.
- * @return True if gretter or equal.
- */
- friend bool operator>=(const TcpRange& val1, const TcpRange& val2)
- {
- return val1.Compare(val2) >= 0;
- }
-
- /** Remote host. */
- std::string host;
-
- /** TCP port. */
- uint16_t port;
-
- /**
- * Number of ports after the port that should be tried if
- * the previous are unavailable.
- */
- uint16_t range;
- };
- }
- }
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_NET_TCP_RANGE
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/net/tcp_socket_client.h b/modules/platforms/cpp/thin-client/src/impl/net/tcp_socket_client.h
deleted file mode 100644
index dc9263f..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/net/tcp_socket_client.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_NET_TCP_SOCKET_CLIENT
-#define _IGNITE_IMPL_THIN_NET_TCP_SOCKET_CLIENT
-
-#include <stdint.h>
-
-#include <ignite/common/common.h>
-
-#include "impl/socket_client.h"
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace net
- {
- /**
- * Socket client implementation.
- */
- class TcpSocketClient : public SocketClient
- {
- public:
- /** Buffers size */
- enum { BUFFER_SIZE = 0x10000 };
-
- /** The time in seconds the connection needs to remain idle before starts sending keepalive probes. */
- enum { KEEP_ALIVE_IDLE_TIME = 60 };
-
- /** The time in seconds between individual keepalive probes. */
- enum { KEEP_ALIVE_PROBES_PERIOD = 1 };
-
- /**
- * Constructor.
- */
- TcpSocketClient();
-
- /**
- * Destructor.
- */
- virtual ~TcpSocketClient();
-
- /**
- * Establish connection with remote TCP service.
- *
- * @param hostname Remote host name.
- * @param port TCP service port.
- * @param timeout Timeout.
- * @return True on success.
- */
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout);
-
- /**
- * Close established connection.
- */
- virtual void Close();
-
- /**
- * Send data by established connection.
- *
- * @param data Pointer to data to be sent.
- * @param size Size of the data in bytes.
- * @param timeout Timeout.
- * @return Number of bytes that have been sent on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Send(const int8_t* data, size_t size, int32_t timeout);
-
- /**
- * Receive data from established connection.
- *
- * @param buffer Pointer to data buffer.
- * @param size Size of the buffer in bytes.
- * @param timeout Timeout.
- * @return Number of bytes that have been received on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Receive(int8_t* buffer, size_t size, int32_t timeout);
-
- /**
- * Check if the socket is blocking or not.
- * @return @c true if the socket is blocking and false otherwise.
- */
- virtual bool IsBlocking() const;
-
- /**
- * Get socket error.
- * @return Last socket error.
- */
- static int GetLastSocketError();
-
- /**
- * Get socket error.
- * @param handle Socket handle.
- * @return Last socket error.
- */
- static int GetLastSocketError(int handle);
-
- /**
- * Check whether socket operation was interupted.
- * @return @c true if the socket operation was interupted.
- */
- static bool IsSocketOperationInterrupted(int errorCode);
- private:
- /**
- * Close established connection.
- */
- void InternalClose();
-
- /**
- * Tries set socket options.
- */
- void TrySetOptions();
-
- /**
- * Wait on the socket for any event for specified time.
- * This function uses poll to achive timeout functionality
- * for every separate socket operation.
- *
- * @param timeout Timeout.
- * @param rd Wait for read if @c true, or for write if @c false.
- * @return -errno on error, WaitResult::TIMEOUT on timeout and
- * WaitResult::SUCCESS on success.
- */
- int WaitOnSocket(int32_t timeout, bool rd);
-
- /** Handle. */
- intptr_t socketHandle;
-
- /** Blocking flag. */
- bool blocking;
-
- IGNITE_NO_COPY_ASSIGNMENT(TcpSocketClient)
- };
- }
- }
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_NET_TCP_SOCKET_CLIENT
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/net/remote_type_updater.cpp b/modules/platforms/cpp/thin-client/src/impl/remote_type_updater.cpp
similarity index 98%
rename from modules/platforms/cpp/thin-client/src/impl/net/remote_type_updater.cpp
rename to modules/platforms/cpp/thin-client/src/impl/remote_type_updater.cpp
index 9d05ae6..6c42bc0 100644
--- a/modules/platforms/cpp/thin-client/src/impl/net/remote_type_updater.cpp
+++ b/modules/platforms/cpp/thin-client/src/impl/remote_type_updater.cpp
@@ -18,7 +18,7 @@
#include "impl/data_router.h"
#include "impl/message.h"
-#include "impl/net/remote_type_updater.h"
+#include "impl/remote_type_updater.h"
namespace ignite
{
diff --git a/modules/platforms/cpp/thin-client/src/impl/net/remote_type_updater.h b/modules/platforms/cpp/thin-client/src/impl/remote_type_updater.h
similarity index 100%
rename from modules/platforms/cpp/thin-client/src/impl/net/remote_type_updater.h
rename to modules/platforms/cpp/thin-client/src/impl/remote_type_updater.h
diff --git a/modules/platforms/cpp/thin-client/src/impl/socket_client.h b/modules/platforms/cpp/thin-client/src/impl/socket_client.h
deleted file mode 100644
index c94146d..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/socket_client.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_SOCKET_CLIENT
-#define _IGNITE_IMPL_THIN_SOCKET_CLIENT
-
-#include <stdint.h>
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- /**
- * Socket client implementation.
- */
- class SocketClient
- {
- public:
- /**
- * Non-negative timeout operation result.
- */
- struct WaitResult
- {
- enum T
- {
- /** Timeout. */
- TIMEOUT = 0,
-
- /** Success. */
- SUCCESS = 1
- };
- };
-
- /**
- * Destructor.
- */
- virtual ~SocketClient()
- {
- // No-op.
- }
-
- /**
- * Establish connection with remote service.
- *
- * @param hostname Remote host name.
- * @param port Service port.
- * @param timeout Timeout.
- * @return True on success.
- */
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout) = 0;
-
- /**
- * Close established connection.
- */
- virtual void Close() = 0;
-
- /**
- * Send data by established connection.
- *
- * @param data Pointer to data to be sent.
- * @param size Size of the data in bytes.
- * @param timeout Timeout.
- * @return Number of bytes that have been sent on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Send(const int8_t* data, size_t size, int32_t timeout) = 0;
-
- /**
- * Receive data from established connection.
- *
- * @param buffer Pointer to data buffer.
- * @param size Size of the buffer in bytes.
- * @param timeout Timeout.
- * @return Number of bytes that have been received on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Receive(int8_t* buffer, size_t size, int32_t timeout) = 0;
-
- /**
- * Check if the socket is blocking or not.
- * @return @c true if the socket is blocking and false otherwise.
- */
- virtual bool IsBlocking() const = 0;
- };
- }
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_SOCKET_CLIENT
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/ssl/secure_socket_client.cpp b/modules/platforms/cpp/thin-client/src/impl/ssl/secure_socket_client.cpp
deleted file mode 100644
index 5a9b7f4..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/ssl/secure_socket_client.cpp
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sstream>
-#include <cassert>
-
-#include <ignite/common/utils.h>
-#include <ignite/common/concurrent.h>
-#include <ignite/ignite_error.h>
-
-#include "impl/net/tcp_socket_client.h"
-#include "impl/ssl/secure_socket_client.h"
-
-#include "impl/ssl/ssl_gateway.h"
-
-#ifndef SOCKET_ERROR
-# define SOCKET_ERROR (-1)
-#endif // SOCKET_ERROR
-
-enum { OPERATION_SUCCESS = 1 };
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace ssl
- {
- SecureSocketClient::SecureSocketClient(const std::string& certPath, const std::string& keyPath,
- const std::string& caPath):
- certPath(certPath),
- keyPath(keyPath),
- caPath(caPath),
- context(0),
- ssl(0),
- blocking(true)
- {
- // No-op.
- }
-
- SecureSocketClient::~SecureSocketClient()
- {
- CloseInteral();
-
- if (context)
- SslGateway::GetInstance().SSL_CTX_free_(reinterpret_cast<SSL_CTX*>(context));
- }
-
- bool SecureSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- if (!context)
- {
- context = MakeContext(certPath, keyPath, caPath);
-
- if (!context)
- {
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not create SSL context. Aborting connect.");
- }
- }
-
- SSL* ssl0 = reinterpret_cast<SSL*>(MakeSsl(context, hostname, port, blocking));
- if (!ssl0)
- return false;
-
- int res = sslGateway.SSL_set_tlsext_host_name_(ssl0, hostname);
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_free_(ssl0);
-
- std::string err = "Can not set host name for secure connection: " + GetSslError(ssl0, res);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
- }
-
- sslGateway.SSL_set_connect_state_(ssl0);
-
- bool connected = CompleteConnectInternal(ssl0, timeout);
-
- if (!connected)
- {
- sslGateway.SSL_free_(ssl0);
-
- return false;
- }
-
- // Verify a server certificate was presented during the negotiation
- X509* cert = sslGateway.SSL_get_peer_certificate_(ssl0);
- if (cert)
- sslGateway.X509_free_(cert);
- else
- {
- sslGateway.SSL_free_(ssl0);
-
-// std::string err = "Remote host did not provide certificate: " + GetSslError(ssl0, res);
-
- return false;
- }
-
- // Verify the result of chain verification
- // Verification performed according to RFC 4158
- res = sslGateway.SSL_get_verify_result_(ssl0);
- if (X509_V_OK != res)
- {
- sslGateway.SSL_free_(ssl0);
-
-// std::string err = "Certificate chain verification failed: " + GetSslError(ssl0, res);
-
- return false;
- }
-
- ssl = reinterpret_cast<void*>(ssl0);
-
- return true;
- }
-
- void SecureSocketClient::Close()
- {
- CloseInteral();
- }
-
- int SecureSocketClient::Send(const int8_t* data, size_t size, int32_t timeout)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- if (!ssl)
- {
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Trying to send data using closed connection");
- }
-
- SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
-
- int res = sslGateway.SSL_write_(ssl0, data, static_cast<int>(size));
-
- return res;
- }
-
- int SecureSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- if (!ssl)
- {
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Trying to receive data using closed connection");
- }
-
- SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
-
- int res = 0;
-
- if (!blocking && sslGateway.SSL_pending_(ssl0) == 0)
- {
- res = WaitOnSocket(ssl, timeout, true);
-
- if (res < 0 || res == WaitResult::TIMEOUT)
- return res;
- }
-
- res = sslGateway.SSL_read_(ssl0, buffer, static_cast<int>(size));
-
- return res;
- }
-
- bool SecureSocketClient::IsBlocking() const
- {
- return blocking;
- }
-
- void* SecureSocketClient::MakeContext(const std::string& certPath, const std::string& keyPath,
- const std::string& caPath)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- const SSL_METHOD* method = sslGateway.SSLv23_client_method_();
- if (!method)
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not get SSL method");
-
- SSL_CTX* ctx = sslGateway.SSL_CTX_new_(method);
- if (!ctx)
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not create new SSL context");
-
- sslGateway.SSL_CTX_set_verify_(ctx, SSL_VERIFY_PEER, 0);
-
- sslGateway.SSL_CTX_set_verify_depth_(ctx, 8);
-
- sslGateway.SSL_CTX_set_options_(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION);
-
- const char* cCaPath = caPath.empty() ? 0 : caPath.c_str();
-
- long res = sslGateway.SSL_CTX_load_verify_locations_(ctx, cCaPath, 0);
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not set Certificate Authority path for secure connection");
- }
-
- res = sslGateway.SSL_CTX_use_certificate_chain_file_(ctx, certPath.c_str());
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not set client certificate file for secure connection");
- }
-
- res = sslGateway.SSL_CTX_use_RSAPrivateKey_file_(ctx, keyPath.c_str(), SSL_FILETYPE_PEM);
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not set private key file for secure connection");
- }
-
- const char* const PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4";
- res = sslGateway.SSL_CTX_set_cipher_list_(ctx, PREFERRED_CIPHERS);
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.SSL_CTX_free_(ctx);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not set ciphers list for secure connection");
- }
-
- return ctx;
- }
-
- void* SecureSocketClient::MakeSsl(void* context, const char* hostname, uint16_t port, bool& blocking)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- BIO* bio = sslGateway.BIO_new_ssl_connect_(reinterpret_cast<SSL_CTX*>(context));
- if (!bio)
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not create SSL connection.");
-
- blocking = sslGateway.BIO_set_nbio_(bio, 1) != OPERATION_SUCCESS;
-
- std::stringstream stream;
- stream << hostname << ":" << port;
-
- std::string address = stream.str();
-
- long res = sslGateway.BIO_set_conn_hostname_(bio, address.c_str());
- if (res != OPERATION_SUCCESS)
- {
- sslGateway.BIO_free_all_(bio);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not set SSL connection hostname.");
- }
-
- SSL* ssl = 0;
- sslGateway.BIO_get_ssl_(bio, &ssl);
- if (!ssl)
- {
- sslGateway.BIO_free_all_(bio);
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not get SSL instance from BIO.");
- }
-
- return ssl;
- }
-
- bool SecureSocketClient::CompleteConnectInternal(void* ssl, int timeout)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
-
- while (true)
- {
- int res = sslGateway.SSL_connect_(ssl0);
-
- if (res == OPERATION_SUCCESS)
- return true;
-
- int sslError = sslGateway.SSL_get_error_(ssl0, res);
-
- if (IsActualError(sslError))
- return false;
-
- int want = sslGateway.SSL_want_(ssl0);
-
- res = WaitOnSocket(ssl, timeout, want == SSL_READING);
-
- if (res == WaitResult::TIMEOUT)
- return false;
-
- if (res != WaitResult::SUCCESS)
- return false;
- }
- }
-
- std::string SecureSocketClient::GetSslError(void* ssl, int ret)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
-
- int sslError = sslGateway.SSL_get_error_(ssl0, ret);
-
- switch (sslError)
- {
- case SSL_ERROR_NONE:
- break;
-
- case SSL_ERROR_WANT_WRITE:
- return std::string("SSL_connect wants write");
-
- case SSL_ERROR_WANT_READ:
- return std::string("SSL_connect wants read");
-
- default:
- return std::string("SSL error: ") + common::LexicalCast<std::string>(sslError);
- }
-
- long error = sslGateway.ERR_get_error_();
-
- char errBuf[1024] = { 0 };
-
- sslGateway.ERR_error_string_n_(error, errBuf, sizeof(errBuf));
-
- return std::string(errBuf);
- }
-
- bool SecureSocketClient::IsActualError(int err)
- {
- switch (err)
- {
- case SSL_ERROR_NONE:
- case SSL_ERROR_WANT_WRITE:
- case SSL_ERROR_WANT_READ:
- case SSL_ERROR_WANT_CONNECT:
- case SSL_ERROR_WANT_ACCEPT:
- case SSL_ERROR_WANT_X509_LOOKUP:
- return false;
-
- default:
- return true;
- }
- }
-
- void SecureSocketClient::CloseInteral()
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- if (ssl)
- {
- sslGateway.SSL_free_(reinterpret_cast<SSL*>(ssl));
-
- ssl = 0;
- }
- }
-
- int SecureSocketClient::WaitOnSocket(void* ssl, int32_t timeout, bool rd)
- {
- SslGateway &sslGateway = SslGateway::GetInstance();
-
- assert(sslGateway.Loaded());
-
- int ready = 0;
- int lastError = 0;
- SSL* ssl0 = reinterpret_cast<SSL*>(ssl);
-
- fd_set fds;
-
- int fd = sslGateway.SSL_get_fd_(ssl0);
-
- if (fd < 0)
- {
- std::stringstream ss;
-
- ss << "Can not get file descriptor from the SSL socket: " << fd << ", " << GetSslError(ssl, fd);
-
- std::string err = ss.str();
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str());
- }
-
- do {
- struct timeval tv = { 0 };
- tv.tv_sec = timeout;
-
- FD_ZERO(&fds);
- FD_SET(static_cast<long>(fd), &fds);
-
- fd_set* readFds = 0;
- fd_set* writeFds = 0;
-
- if (rd)
- readFds = &fds;
- else
- writeFds = &fds;
-
- ready = select(fd + 1, readFds, writeFds, NULL, (timeout == 0 ? NULL : &tv));
-
- if (ready == SOCKET_ERROR)
- lastError = net::TcpSocketClient::GetLastSocketError();
-
- } while (ready == SOCKET_ERROR && net::TcpSocketClient::IsSocketOperationInterrupted(lastError));
-
- if (ready == SOCKET_ERROR)
- return -lastError;
-
- lastError = net::TcpSocketClient::GetLastSocketError(fd);
-
- if (lastError != 0)
- return -lastError;
-
- if (ready == 0)
- return WaitResult::TIMEOUT;
-
- return WaitResult::SUCCESS;
- }
- }
- }
- }
-}
diff --git a/modules/platforms/cpp/thin-client/src/impl/ssl/secure_socket_client.h b/modules/platforms/cpp/thin-client/src/impl/ssl/secure_socket_client.h
deleted file mode 100644
index 9649135..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/ssl/secure_socket_client.h
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_SSL_SECURE_SOCKET_CLIENT
-#define _IGNITE_IMPL_THIN_SSL_SECURE_SOCKET_CLIENT
-
-#include <stdint.h>
-#include <string>
-
-#include "impl/socket_client.h"
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace ssl
- {
- /**
- * Secure socket client.
- */
- class SecureSocketClient : public SocketClient
- {
- public:
- /**
- * Constructor.
- *
- * @param certPath Certificate file path.
- * @param keyPath Private key file path.
- * @param caPath Certificate authority file path.
- */
- SecureSocketClient(const std::string& certPath, const std::string& keyPath, const std::string& caPath);
-
- /**
- * Destructor.
- */
- virtual ~SecureSocketClient();
-
- /**
- * Establish connection with the host.
- *
- * @param hostname Host name or address.
- * @param port TCP port.
- * @param timeout Timeout in seconds.
- * @return @c true on success and @c false on fail.
- */
- virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout);
-
- /**
- * Close the connection.
- */
- virtual void Close();
-
- /**
- * Send data using connection.
- * @param data Data to send.
- * @param size Number of bytes to send.
- * @param timeout Timeout in seconds.
- * @return Number of bytes that have been sent on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Send(const int8_t* data, size_t size, int32_t timeout);
-
- /**
- * Receive data from established connection.
- *
- * @param buffer Pointer to data buffer.
- * @param size Size of the buffer in bytes.
- * @param timeout Timeout in seconds.
- * @return Number of bytes that have been received on success,
- * WaitResult::TIMEOUT on timeout and -errno on failure.
- */
- virtual int Receive(int8_t* buffer, size_t size, int32_t timeout);
-
- /**
- * Check if the socket is blocking or not.
- * @return @c true if the socket is blocking and false otherwise.
- */
- virtual bool IsBlocking() const;
-
- private:
- /**
- * Close the connection.
- * Internal call.
- */
- void CloseInteral();
-
- /**
- * Wait on the socket for any event for specified time.
- * This function uses poll to achive timeout functionality
- * for every separate socket operation.
- *
- * @param ssl SSL instance.
- * @param timeout Timeout in seconds.
- * @param rd Wait for read if @c true, or for write if @c false.
- * @return -errno on error, WaitResult::TIMEOUT on timeout and
- * WaitResult::SUCCESS on success.
- */
- static int WaitOnSocket(void* ssl, int32_t timeout, bool rd);
-
- /**
- * Make new context instance.
- *
- * @param certPath Certificate file path.
- * @param keyPath Private key file path.
- * @param caPath Certificate authority file path.
- * @return New context instance on success and null-pointer on fail.
- */
- static void* MakeContext(const std::string& certPath, const std::string& keyPath,
- const std::string& caPath);
-
- /**
- * Make new SSL instance.
- *
- * @param context SSL context.
- * @param hostname Host name or address.
- * @param port TCP port.
- * @param blocking Indicates if the resulted SSL is blocking or not.
- * @return New SSL instance on success and null-pointer on fail.
- */
- static void* MakeSsl(void* context, const char* hostname, uint16_t port, bool& blocking);
-
- /**
- * Complete async connect.
- *
- * @param ssl SSL instance.
- * @param timeout Timeout in seconds.
- * @return @c true on success.
- */
- static bool CompleteConnectInternal(void* ssl, int timeout);
-
- /**
- * Get SSL error.
- *
- * @param ssl SSL instance.
- * @param ret Return value of the pervious operation.
- * @return Error string.
- */
- static std::string GetSslError(void* ssl, int ret);
-
- /**
- * Check if a actual error occured.
- *
- * @param err SSL error code.
- * @return @true if a actual error occured
- */
- static bool IsActualError(int err);
-
- /** Certificate file path. */
- std::string certPath;
-
- /** Private key file path. */
- std::string keyPath;
-
- /** Certificate authority file path. */
- std::string caPath;
-
- /** SSL context. */
- void* context;
-
- /** OpenSSL instance */
- void* ssl;
-
- /** Blocking flag. */
- bool blocking;
- };
- }
- }
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_SSL_SECURE_SOCKET_CLIENT
diff --git a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_api.cpp b/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_api.cpp
deleted file mode 100644
index a1da215..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_api.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "impl/ssl/ssl_gateway.h"
-#include "impl/ssl/ssl_api.h"
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace ssl
- {
- void EnsureSslLoaded()
- {
- SslGateway::GetInstance().LoadAll();
- }
- }
- }
- }
-}
diff --git a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_gateway.cpp b/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_gateway.cpp
deleted file mode 100644
index 42ed88d..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_gateway.cpp
+++ /dev/null
@@ -1,709 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sstream>
-
-#include <ignite/ignite_error.h>
-#include <ignite/common/utils.h>
-
-#include "impl/ssl/ssl_gateway.h"
-
-#ifndef ADDITIONAL_OPENSSL_HOME_ENV
-# define ADDITIONAL_OPENSSL_HOME_ENV "OPEN_SSL_HOME"
-#endif // ADDITIONAL_OPENSSL_HOME_ENV
-
-#ifndef SSL_CTRL_OPTIONS
-# define SSL_CTRL_OPTIONS 32
-#endif // SSL_CTRL_OPTIONS
-
-#ifndef OPENSSL_INIT_LOAD_SSL_STRINGS
-# define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L
-#endif // OPENSSL_INIT_LOAD_SSL_STRINGS
-
-#ifndef OPENSSL_INIT_LOAD_CRYPTO_STRINGS
-# define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L
-#endif // OPENSSL_INIT_LOAD_CRYPTO_STRINGS
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace ssl
- {
- SslGateway::SslGateway() :
- inited(false),
- functions()
- {
- memset(&functions, 0, sizeof(functions));
- }
-
- SslGateway::~SslGateway()
- {
- // No-op.
- }
-
- void SslGateway::UnloadAll()
- {
- libeay32.Unload();
- ssleay32.Unload();
- libssl.Unload();
- libcrypto.Unload();
-
- memset(&functions, 0, sizeof(functions));
- }
-
- common::dynamic::Module SslGateway::LoadSslLibrary(const char* name)
- {
- using namespace common;
- using namespace dynamic;
-
- std::string home = GetEnv(ADDITIONAL_OPENSSL_HOME_ENV);
-
- if (home.empty())
- home = GetEnv("OPENSSL_HOME");
-
- std::string fullName = GetDynamicLibraryName(name);
-
- if (!home.empty())
- {
- std::stringstream constructor;
-
- constructor << home << Fs << "bin" << Fs << fullName;
-
- std::string fullPath = constructor.str();
-
- Module mod = LoadModule(fullPath);
-
- if (mod.IsLoaded())
- return mod;
- }
-
- return LoadModule(fullName);
- }
-
- void SslGateway::LoadSslLibraries()
- {
- libssl = LoadSslLibrary("libssl");
-
- if (!libssl.IsLoaded())
- {
- libcrypto = LoadSslLibrary("libcrypto-1_1-x64");
- libssl = LoadSslLibrary("libssl-1_1-x64");
- }
-
- if (!libssl.IsLoaded())
- {
- libeay32 = LoadSslLibrary("libeay32");
- ssleay32 = LoadSslLibrary("ssleay32");
- }
-
- if (!libssl.IsLoaded() && (!libeay32.IsLoaded() || !ssleay32.IsLoaded()))
- {
- if (!libssl.IsLoaded())
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not load neccessary OpenSSL library: libssl");
-
- std::stringstream ss;
-
- ss << "Can not load neccessary OpenSSL libraries:";
-
- if (!libeay32.IsLoaded())
- ss << " libeay32";
-
- if (!ssleay32.IsLoaded())
- ss << " ssleay32";
-
- std::string res = ss.str();
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, res.c_str());
- }
- }
-
- void SslGateway::LoadMandatoryMethods()
- {
- functions.fpSSLeay_version = TryLoadSslMethod("SSLeay_version");
-
- if (!functions.fpSSLeay_version)
- functions.fpOpenSSL_version = LoadSslMethod("OpenSSL_version");
-
- functions.fpSSL_library_init = TryLoadSslMethod("SSL_library_init");
- functions.fpSSL_load_error_strings = TryLoadSslMethod("SSL_load_error_strings");
-
- if (!functions.fpSSL_library_init || !functions.fpSSL_load_error_strings)
- functions.fpOPENSSL_init_ssl = LoadSslMethod("OPENSSL_init_ssl");
-
- functions.fpSSLv23_client_method = TryLoadSslMethod("SSLv23_client_method");
-
- if (!functions.fpSSLv23_client_method)
- functions.fpTLS_client_method = LoadSslMethod("TLS_client_method");
-
- functions.fpSSL_CTX_new = LoadSslMethod("SSL_CTX_new");
- functions.fpSSL_CTX_free = LoadSslMethod("SSL_CTX_free");
- functions.fpSSL_CTX_set_verify = LoadSslMethod("SSL_CTX_set_verify");
- functions.fpSSL_CTX_set_verify_depth = LoadSslMethod("SSL_CTX_set_verify_depth");
- functions.fpSSL_CTX_load_verify_locations = LoadSslMethod("SSL_CTX_load_verify_locations");
- functions.fpSSL_CTX_use_certificate_chain_file = LoadSslMethod("SSL_CTX_use_certificate_chain_file");
- functions.fpSSL_CTX_use_RSAPrivateKey_file = LoadSslMethod("SSL_CTX_use_RSAPrivateKey_file");
- functions.fpSSL_CTX_set_cipher_list = LoadSslMethod("SSL_CTX_set_cipher_list");
-
- functions.fpSSL_get_verify_result = LoadSslMethod("SSL_get_verify_result");
-
- functions.fpSSL_get_peer_certificate = LoadSslMethod("SSL_get_peer_certificate");
- functions.fpSSL_ctrl = LoadSslMethod("SSL_ctrl");
- functions.fpSSL_CTX_ctrl = LoadSslMethod("SSL_CTX_ctrl");
-
- functions.fpSSL_set_connect_state = LoadSslMethod("SSL_set_connect_state");
- functions.fpSSL_connect = LoadSslMethod("SSL_connect");
- functions.fpSSL_get_error = LoadSslMethod("SSL_get_error");
- functions.fpSSL_want = LoadSslMethod("SSL_want");
- functions.fpSSL_write = LoadSslMethod("SSL_write");
- functions.fpSSL_read = LoadSslMethod("SSL_read");
- functions.fpSSL_pending = LoadSslMethod("SSL_pending");
- functions.fpSSL_get_fd = LoadSslMethod("SSL_get_fd");
- functions.fpSSL_free = LoadSslMethod("SSL_free");
- functions.fpBIO_new_ssl_connect = LoadSslMethod("BIO_new_ssl_connect");
-
- functions.fpOPENSSL_config = LoadSslMethod("OPENSSL_config");
- functions.fpX509_free = LoadSslMethod("X509_free");
-
- functions.fpBIO_free_all = LoadSslMethod("BIO_free_all");
- functions.fpBIO_ctrl = LoadSslMethod("BIO_ctrl");
-
- functions.fpERR_get_error = LoadSslMethod("ERR_get_error");
- functions.fpERR_error_string_n = LoadSslMethod("ERR_error_string_n");
- }
-
- SslGateway& SslGateway::GetInstance()
- {
- static SslGateway self;
-
- return self;
- }
-
- void SslGateway::LoadAll()
- {
- using namespace common::dynamic;
-
- if (inited)
- return;
-
- common::concurrent::CsLockGuard lock(initCs);
-
- if (inited)
- return;
-
- common::MethodGuard<SslGateway> guard(this, &SslGateway::UnloadAll);
-
- LoadSslLibraries();
-
- LoadMandatoryMethods();
-
- functions.fpSSL_CTX_set_options = TryLoadSslMethod("SSL_CTX_set_options");
- functions.fpERR_print_errors_fp = TryLoadSslMethod("ERR_print_errors_fp");
-
- (void)SSL_library_init_();
-
- SSL_load_error_strings_();
-
- OPENSSL_config_(0);
-
- guard.Release();
-
- inited = true;
- }
-
- void* SslGateway::TryLoadSslMethod(const char* name)
- {
- void* fp = libeay32.FindSymbol(name);
-
- if (!fp)
- fp = ssleay32.FindSymbol(name);
-
- if (!fp)
- fp = libcrypto.FindSymbol(name);
-
- if (!fp)
- fp = libssl.FindSymbol(name);
-
- return fp;
- }
-
- void* SslGateway::LoadSslMethod(const char* name)
- {
- void* fp = TryLoadSslMethod(name);
-
- if (!fp)
- {
- std::stringstream ss;
-
- ss << "Can not load function " << name;
-
- std::string res = ss.str();
-
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, res.c_str());
- }
-
- return fp;
- }
-
- char* SslGateway::SSLeay_version_(int type)
- {
- typedef char* (FuncType)(int);
-
- FuncType* fp = 0;
-
- if (functions.fpSSLeay_version)
- fp = reinterpret_cast<FuncType*>(functions.fpSSLeay_version);
- else
- fp = reinterpret_cast<FuncType*>(functions.fpOpenSSL_version);
-
- assert(fp != 0);
-
- return fp(type);
- }
-
- int SslGateway::OPENSSL_init_ssl_(uint64_t opts, const void* settings)
- {
- assert(functions.fpOPENSSL_init_ssl != 0);
-
- typedef int (FuncType)(uint64_t, const void*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpOPENSSL_init_ssl);
-
- return fp(opts, settings);
- }
-
- long SslGateway::SSL_CTX_set_options_(SSL_CTX* ctx, long options)
- {
- if (functions.fpSSL_CTX_set_options)
- {
- typedef long (FuncType)(SSL_CTX*, long);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_set_options);
-
- return fp(ctx, options);
- }
-
- return SSL_CTX_ctrl_(ctx, SSL_CTRL_OPTIONS, options, NULL);
- }
-
- long SslGateway::SSL_CTX_ctrl_(SSL_CTX* ctx, int cmd, long larg, void* parg)
- {
- assert(functions.fpSSL_CTX_ctrl != 0);
-
- typedef long (FuncType)(SSL_CTX*, int, long, void*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_ctrl);
-
- return fp(ctx, cmd, larg, parg);
- }
-
- SSL_CTX* SslGateway::SSL_CTX_new_(const SSL_METHOD* meth)
- {
- assert(functions.fpSSL_CTX_new != 0);
-
- typedef SSL_CTX*(FuncType)(const SSL_METHOD*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_new);
-
- return fp(meth);
- }
-
- void SslGateway::SSL_CTX_free_(SSL_CTX* ctx)
- {
- assert(functions.fpSSL_CTX_free != 0);
-
- typedef void (FuncType)(SSL_CTX*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_free);
-
- fp(ctx);
- }
-
- void SslGateway::SSL_CTX_set_verify_(SSL_CTX* ctx, int mode, int (* callback)(int, X509_STORE_CTX*))
- {
- assert(functions.fpSSL_CTX_set_verify != 0);
-
- typedef void (FuncType)(SSL_CTX*, int, int (*)(int, X509_STORE_CTX*));
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_set_verify);
-
- fp(ctx, mode, callback);
- }
-
- void SslGateway::SSL_CTX_set_verify_depth_(SSL_CTX* ctx, int depth)
- {
- assert(functions.fpSSL_CTX_set_verify_depth != 0);
-
- typedef void (FuncType)(SSL_CTX*, int);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_set_verify_depth);
-
- fp(ctx, depth);
- }
-
- int SslGateway::SSL_CTX_load_verify_locations_(SSL_CTX* ctx, const char* cAfile, const char* cApath)
- {
- assert(functions.fpSSL_CTX_load_verify_locations != 0);
-
- typedef int (FuncType)(SSL_CTX*, const char*, const char*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_load_verify_locations);
-
- return fp(ctx, cAfile, cApath);
- }
-
- int SslGateway::SSL_CTX_use_certificate_chain_file_(SSL_CTX* ctx, const char* file)
- {
- assert(functions.fpSSL_CTX_use_certificate_chain_file != 0);
-
- typedef int (FuncType)(SSL_CTX*, const char*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_use_certificate_chain_file);
-
- return fp(ctx, file);
- }
-
- int SslGateway::SSL_CTX_use_RSAPrivateKey_file_(SSL_CTX* ctx, const char* file, int type)
- {
- assert(functions.fpSSL_CTX_use_RSAPrivateKey_file != 0);
-
- typedef int (FuncType)(SSL_CTX*, const char*, int);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_use_RSAPrivateKey_file);
-
- return fp(ctx, file, type);
- }
-
- int SslGateway::SSL_CTX_set_cipher_list_(SSL_CTX* ctx, const char* str)
- {
- assert(functions.fpSSL_CTX_set_cipher_list != 0);
-
- typedef int (FuncType)(SSL_CTX*, const char*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_CTX_set_cipher_list);
-
- return fp(ctx, str);
- }
-
- long SslGateway::SSL_get_verify_result_(const SSL* s)
- {
- assert(functions.fpSSL_get_verify_result != 0);
-
- typedef long (FuncType)(const SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_get_verify_result);
-
- return fp(s);
- }
-
- int SslGateway::SSL_library_init_()
- {
- typedef int (FuncType)();
-
- if (functions.fpSSL_library_init)
- {
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_library_init);
-
- return fp();
- }
-
- return OPENSSL_init_ssl_(0, NULL);
- }
-
- void SslGateway::SSL_load_error_strings_()
- {
- typedef void (FuncType)();
-
- if (functions.fpSSL_load_error_strings)
- {
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_load_error_strings);
-
- fp();
-
- return;
- }
-
- OPENSSL_init_ssl_(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
- }
-
- X509* SslGateway::SSL_get_peer_certificate_(const SSL* s)
- {
- assert(functions.fpSSL_get_peer_certificate != 0);
-
- typedef X509*(FuncType)(const SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_get_peer_certificate);
-
- return fp(s);
- }
-
- long SslGateway::SSL_ctrl_(SSL* s, int cmd, long larg, void* parg)
- {
- assert(functions.fpSSL_ctrl != 0);
-
- typedef long (FuncType)(SSL*, int, long, void*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_ctrl);
-
- return fp(s, cmd, larg, parg);
- }
-
- long SslGateway::SSL_set_tlsext_host_name_(SSL* s, const char* name)
- {
- return SSL_ctrl_(s, SSL_CTRL_SET_TLSEXT_HOSTNAME,
- TLSEXT_NAMETYPE_host_name, const_cast<char*>(name));
- }
-
- void SslGateway::SSL_set_connect_state_(SSL* s)
- {
- assert(functions.fpSSL_set_connect_state != 0);
-
- typedef void (FuncType)(SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_set_connect_state);
-
- return fp(s);
- }
-
- int SslGateway::SSL_connect_(SSL* s)
- {
- assert(functions.fpSSL_connect != 0);
-
- typedef int (FuncType)(SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_connect);
-
- return fp(s);
- }
-
- int SslGateway::SSL_get_error_(const SSL* s, int ret)
- {
- assert(functions.fpSSL_get_error != 0);
-
- typedef int (FuncType)(const SSL*, int);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_get_error);
-
- return fp(s, ret);
- }
-
- int SslGateway::SSL_want_(const SSL* s)
- {
- assert(functions.fpSSL_want != 0);
-
- typedef int (FuncType)(const SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_want);
-
- return fp(s);
- }
-
- int SslGateway::SSL_write_(SSL* s, const void* buf, int num)
- {
- assert(functions.fpSSL_write != 0);
-
- typedef int (FuncType)(SSL*, const void*, int);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_write);
-
- return fp(s, buf, num);
- }
-
- int SslGateway::SSL_read_(SSL* s, void* buf, int num)
- {
- assert(functions.fpSSL_read != 0);
-
- typedef int (FuncType)(SSL*, void*, int);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_read);
-
- return fp(s, buf, num);
- }
-
- int SslGateway::SSL_pending_(const SSL* ssl)
- {
- assert(functions.fpSSL_pending != 0);
-
- typedef int (FuncType)(const SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_pending);
-
- return fp(ssl);
- }
-
- int SslGateway::SSL_get_fd_(const SSL* ssl)
- {
- assert(functions.fpSSL_get_fd != 0);
-
- typedef int (FuncType)(const SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_get_fd);
-
- return fp(ssl);
- }
-
- void SslGateway::SSL_free_(SSL* ssl)
- {
- assert(functions.fpSSL_free != 0);
-
- typedef void (FuncType)(SSL*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSL_free);
-
- fp(ssl);
- }
-
- const SSL_METHOD* SslGateway::SSLv23_client_method_()
- {
- if (functions.fpSSLv23_client_method)
- {
- typedef const SSL_METHOD*(FuncType)();
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpSSLv23_client_method);
-
- return fp();
- }
-
- return TLS_client_method_();
- }
-
- const SSL_METHOD* SslGateway::TLS_client_method_()
- {
- assert(functions.fpTLS_client_method != 0);
-
- typedef const SSL_METHOD*(FuncType)();
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpTLS_client_method);
-
- return fp();
- }
-
- void SslGateway::OPENSSL_config_(const char* configName)
- {
- assert(functions.fpOPENSSL_config != 0);
-
- typedef void (FuncType)(const char*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpOPENSSL_config);
-
- fp(configName);
- }
-
- void SslGateway::X509_free_(X509* a)
- {
- assert(functions.fpX509_free != 0);
-
- typedef void (FuncType)(X509*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpX509_free);
-
- fp(a);
- }
-
- BIO* SslGateway::BIO_new_ssl_connect_(SSL_CTX* ctx)
- {
- assert(functions.fpBIO_new_ssl_connect != 0);
-
- typedef BIO*(FuncType)(SSL_CTX*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpBIO_new_ssl_connect);
-
- return fp(ctx);
- }
-
- void SslGateway::BIO_free_all_(BIO* a)
- {
- assert(functions.fpBIO_free_all != 0);
-
- typedef void (FuncType)(BIO*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpBIO_free_all);
-
- fp(a);
- }
-
- long SslGateway::BIO_ctrl_(BIO* bp, int cmd, long larg, void* parg)
- {
- assert(functions.fpBIO_ctrl != 0);
-
- typedef long (FuncType)(BIO*, int, long, void*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpBIO_ctrl);
-
- return fp(bp, cmd, larg, parg);
- }
-
- long SslGateway::BIO_get_fd_(BIO* bp, int* fd)
- {
- return BIO_ctrl_(bp, BIO_C_GET_FD, 0, reinterpret_cast<void*>(fd));
- }
-
- long SslGateway::BIO_get_ssl_(BIO* bp, SSL** ssl)
- {
- return BIO_ctrl_(bp, BIO_C_GET_SSL, 0, reinterpret_cast<void*>(ssl));
- }
-
- long SslGateway::BIO_set_nbio_(BIO* bp, long n)
- {
- return BIO_ctrl_(bp, BIO_C_SET_NBIO, n, NULL);
- }
-
- long SslGateway::BIO_set_conn_hostname_(BIO* bp, const char* name)
- {
- return BIO_ctrl_(bp, BIO_C_SET_CONNECT, 0, const_cast<char*>(name));
- }
-
- unsigned long SslGateway::ERR_get_error_()
- {
- assert(functions.fpERR_get_error != 0);
-
- typedef unsigned long (FuncType)();
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpERR_get_error);
-
- return fp();
- }
-
- void SslGateway::ERR_error_string_n_(unsigned long e, char* buf, size_t len)
- {
- assert(functions.fpERR_error_string_n != 0);
-
- typedef void (FuncType)(unsigned long, char*, size_t);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpERR_error_string_n);
-
- fp(e, buf, len);
- }
-
- void SslGateway::ERR_print_errors_fp_(FILE* fd)
- {
- if (!functions.fpERR_print_errors_fp)
- return;
-
- typedef void (FuncType)(FILE*);
-
- FuncType* fp = reinterpret_cast<FuncType*>(functions.fpERR_print_errors_fp);
-
- fp(fd);
- }
- }
- }
- }
-}
diff --git a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_gateway.h b/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_gateway.h
deleted file mode 100644
index 0908c10..0000000
--- a/modules/platforms/cpp/thin-client/src/impl/ssl/ssl_gateway.h
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IGNITE_IMPL_THIN_SSL_SSL_LIBRARY
-#define _IGNITE_IMPL_THIN_SSL_SSL_LIBRARY
-
-#include <openssl/ssl.h>
-#include <openssl/conf.h>
-#include <openssl/err.h>
-
-#include <ignite/common/concurrent.h>
-#include <ignite/common/dynamic_load_os.h>
-
-
-namespace ignite
-{
- namespace impl
- {
- namespace thin
- {
- namespace ssl
- {
- /**
- * Functions collection.
- */
- struct SslFunctions
- {
- void *fpSSLeay_version;
- void *fpSSL_CTX_new;
- void *fpSSL_CTX_free;
- void *fpSSL_CTX_set_verify;
- void *fpSSL_CTX_set_verify_depth;
- void *fpSSL_CTX_load_verify_locations;
- void *fpSSL_CTX_use_certificate_chain_file;
- void *fpSSL_CTX_use_RSAPrivateKey_file;
- void *fpSSL_CTX_set_cipher_list;
- void *fpSSL_CTX_ctrl;
- void *fpSSL_get_verify_result;
- void *fpSSL_library_init;
- void *fpSSL_load_error_strings;
- void *fpSSL_get_peer_certificate;
- void *fpSSL_ctrl;
- void *fpSSLv23_client_method;
- void *fpSSL_set_connect_state;
- void *fpSSL_connect;
- void *fpSSL_get_error;
- void *fpSSL_want;
- void *fpSSL_write;
- void *fpSSL_read;
- void *fpSSL_pending;
- void *fpSSL_get_fd;
- void *fpSSL_free;
- void *fpOPENSSL_config;
- void *fpX509_free;
- void *fpBIO_new_ssl_connect;
- void *fpBIO_free_all;
- void *fpBIO_ctrl;
- void *fpERR_get_error;
- void *fpERR_error_string_n;
- void *fpERR_print_errors_fp;
-
- void *fpOpenSSL_version;
- void *fpSSL_CTX_set_options;
- void *fpOPENSSL_init_ssl;
- void *fpTLS_client_method;
- };
-
- /**
- * SSL Gateway abstraction.
- * Used as a factory for secure sockets. Needed for dynamic loading
- * of the SSL libraries.
- */
- class SslGateway
- {
- public:
- /**
- * Get class instance.
- * @return SslLibrary instance.
- */
- static SslGateway& GetInstance();
-
- /**
- * Try loading SSL library.
- */
- void LoadAll();
-
- /**
- * Get functions.
- * @return Functions structure.
- */
- SslFunctions& GetFunctions()
- {
- return functions;
- }
-
- /**
- * Check whether the libraries are loaded.
- * @return @c true if loaded.
- */
- bool Loaded() const
- {
- return inited;
- }
-
- char* SSLeay_version_(int type);
-
- int OPENSSL_init_ssl_(uint64_t opts, const void* settings);
-
- long SSL_CTX_set_options_(SSL_CTX* ctx, long options);
-
- long SSL_CTX_ctrl_(SSL_CTX* ctx, int cmd, long larg, void* parg);
-
- SSL_CTX* SSL_CTX_new_(const SSL_METHOD* meth);
-
- void SSL_CTX_free_(SSL_CTX* ctx);
-
- void SSL_CTX_set_verify_(SSL_CTX* ctx, int mode, int (*callback)(int, X509_STORE_CTX*));
-
- void SSL_CTX_set_verify_depth_(SSL_CTX* ctx, int depth);
-
- int SSL_CTX_load_verify_locations_(SSL_CTX* ctx, const char* cAfile, const char* cApath);
-
- int SSL_CTX_use_certificate_chain_file_(SSL_CTX* ctx, const char* file);
-
- int SSL_CTX_use_RSAPrivateKey_file_(SSL_CTX* ctx, const char* file, int type);
-
- int SSL_CTX_set_cipher_list_(SSL_CTX* ctx, const char* str);
-
- long SSL_get_verify_result_(const SSL* s);
-
- int SSL_library_init_();
-
- void SSL_load_error_strings_();
-
- X509* SSL_get_peer_certificate_(const SSL* s);
-
- long SSL_ctrl_(SSL* s, int cmd, long larg, void* parg);
-
- long SSL_set_tlsext_host_name_(SSL* s, const char* name);
-
- void SSL_set_connect_state_(SSL* s);
-
- int SSL_connect_(SSL* s);
-
- int SSL_get_error_(const SSL* s, int ret);
-
- int SSL_want_(const SSL* s);
-
- int SSL_write_(SSL* s, const void* buf, int num);
-
- int SSL_read_(SSL* s, void* buf, int num);
-
- int SSL_pending_(const SSL* ssl);
-
- int SSL_get_fd_(const SSL* ssl);
-
- void SSL_free_(SSL* ssl);
-
- const SSL_METHOD* SSLv23_client_method_();
-
- const SSL_METHOD* TLS_client_method_();
-
- void OPENSSL_config_(const char* configName);
-
- void X509_free_(X509* a);
-
- BIO* BIO_new_ssl_connect_(SSL_CTX* ctx);
-
- void BIO_free_all_(BIO* a);
-
- long BIO_ctrl_(BIO* bp, int cmd, long larg, void* parg);
-
- long BIO_get_fd_(BIO* bp, int* fd);
-
- long BIO_get_ssl_(BIO* bp, SSL** ssl);
-
- long BIO_set_nbio_(BIO* bp, long n);
-
- long BIO_set_conn_hostname_(BIO* bp, const char* name);
-
- unsigned long ERR_get_error_();
-
- void ERR_error_string_n_(unsigned long e, char* buf, size_t len);
-
- void ERR_print_errors_fp_(FILE *fd);
-
- private:
- /**
- * Constructor.
- */
- SslGateway();
-
- /**
- * Destructor.
- */
- ~SslGateway();
-
- /**
- * Unload all SSL symbols.
- */
- void UnloadAll();
-
- /**
- * Load SSL library.
- * @param name Name.
- * @return Module.
- */
- common::dynamic::Module LoadSslLibrary(const char* name);
-
- /**
- * Load all SSL libraries.
- */
- void LoadSslLibraries();
-
- /**
- * Load mandatory SSL methods.
- *
- * @throw IgniteError if can not load one of the functions.
- */
- void LoadMandatoryMethods();
-
- /**
- * Try load SSL method.
- *
- * @param name Name.
- * @return Method pointer.
- */
- void* TryLoadSslMethod(const char* name);
-
- /**
- * Load SSL method.
- *
- * @param name Name.
- * @return Method pointer.
- *
- * @throw IgniteError if the method is not present.
- */
- void* LoadSslMethod(const char* name);
-
- /** Indicates whether the library was inited. */
- bool inited;
-
- /** Critical section to prevent multiple instance creation. */
- common::concurrent::CriticalSection initCs;
-
- /** libeay32 module. */
- common::dynamic::Module libeay32;
-
- /** ssleay32 module. */
- common::dynamic::Module ssleay32;
-
- /** libcrypto module. */
- common::dynamic::Module libcrypto;
-
- /** libssl module. */
- common::dynamic::Module libssl;
-
- /** Functions. */
- SslFunctions functions;
- };
- }
- }
-
- }
-}
-
-#endif //_IGNITE_IMPL_THIN_SSL_SSL_LIBRARY
\ No newline at end of file
diff --git a/modules/platforms/cpp/thin-client/src/impl/utility.cpp b/modules/platforms/cpp/thin-client/src/impl/utility.cpp
index 7aa7d03..42882e2 100644
--- a/modules/platforms/cpp/thin-client/src/impl/utility.cpp
+++ b/modules/platforms/cpp/thin-client/src/impl/utility.cpp
@@ -33,7 +33,7 @@ namespace ignite
{
namespace utility
{
- bool ParseSingleAddress(const std::string& value, net::TcpRange& tcpRange, uint16_t dfltPort)
+ bool ParseSingleAddress(const std::string& value, network::TcpRange& tcpRange, uint16_t dfltPort)
{
int64_t colonNum = std::count(value.begin(), value.end(), ':');
@@ -61,7 +61,10 @@ namespace ignite
return ParsePortRange(portRange, tcpRange.port, tcpRange.range);
}
- void ParseAddress(const std::string& value, std::vector<net::TcpRange>& endPoints, uint16_t dfltPort)
+ void ParseAddress(
+ const std::string& value,
+ std::vector<network::TcpRange>& endPoints,
+ uint16_t dfltPort)
{
size_t addrNum = std::count(value.begin(), value.end(), ',') + 1;
@@ -85,7 +88,7 @@ namespace ignite
if (!addr.empty())
{
- net::TcpRange tcpRange;
+ network::TcpRange tcpRange;
bool success = ParseSingleAddress(addr, tcpRange, dfltPort);
diff --git a/modules/platforms/cpp/thin-client/src/impl/utility.h b/modules/platforms/cpp/thin-client/src/impl/utility.h
index 7945960..66010cb 100644
--- a/modules/platforms/cpp/thin-client/src/impl/utility.h
+++ b/modules/platforms/cpp/thin-client/src/impl/utility.h
@@ -20,7 +20,7 @@
#include <vector>
-#include "impl/net/tcp_range.h"
+#include <ignite/network/tcp_range.h>
namespace ignite
{
@@ -37,7 +37,9 @@ namespace ignite
* @param endPoints End ponts list.
* @param dfltPort Default port.
*/
- void ParseAddress(const std::string& value, std::vector<net::TcpRange>& endPoints, uint16_t dfltPort);
+ void ParseAddress(const std::string& value,
+ std::vector<network::TcpRange>& endPoints,
+ uint16_t dfltPort);
/**
* Parse single address.
@@ -47,7 +49,7 @@ namespace ignite
* @param dfltPort Default port.
* @return @c true, if parsed successfully, and @c false otherwise.
*/
- bool ParseSingleAddress(const std::string& value, net::TcpRange& tcpRange, uint16_t dfltPort);
+ bool ParseSingleAddress(const std::string& value, network::TcpRange& tcpRange, uint16_t dfltPort);
/**
* Parse single network port.