clickhouse-native 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clickhouse_native/client.cpp +847 -0
  3. data/ext/clickhouse_native/extconf.rb +101 -0
  4. data/ext/clickhouse_native/vendor/clickhouse-cpp/.clang-format +11 -0
  5. data/ext/clickhouse_native/vendor/clickhouse-cpp/.git +1 -0
  6. data/ext/clickhouse_native/vendor/clickhouse-cpp/.gitattributes +63 -0
  7. data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/CODEOWNERS +1 -0
  8. data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/linux.yml +139 -0
  9. data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/macos.yml +87 -0
  10. data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/windows_mingw.yml +102 -0
  11. data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/windows_msvc.yml +74 -0
  12. data/ext/clickhouse_native/vendor/clickhouse-cpp/.gitignore +280 -0
  13. data/ext/clickhouse_native/vendor/clickhouse-cpp/.travis.yml +62 -0
  14. data/ext/clickhouse_native/vendor/clickhouse-cpp/CMakeLists.txt +157 -0
  15. data/ext/clickhouse_native/vendor/clickhouse-cpp/LICENSE +206 -0
  16. data/ext/clickhouse_native/vendor/clickhouse-cpp/README.md +260 -0
  17. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/CMakeLists.txt +246 -0
  18. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/buffer.h +10 -0
  19. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/compressed.cpp +258 -0
  20. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/compressed.h +48 -0
  21. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/endpoints_iterator.cpp +20 -0
  22. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/endpoints_iterator.h +34 -0
  23. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/input.cpp +96 -0
  24. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/input.h +103 -0
  25. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/open_telemetry.h +23 -0
  26. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/output.cpp +119 -0
  27. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/output.h +142 -0
  28. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/platform.cpp +1 -0
  29. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/platform.h +33 -0
  30. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/projected_iterator.h +55 -0
  31. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/singleton.h +11 -0
  32. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/socket.cpp +489 -0
  33. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/socket.h +177 -0
  34. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/sslsocket.cpp +307 -0
  35. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/sslsocket.h +111 -0
  36. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/string_utils.h +28 -0
  37. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/string_view.h +142 -0
  38. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/uuid.h +10 -0
  39. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/wire_format.cpp +177 -0
  40. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/wire_format.h +79 -0
  41. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/block.cpp +134 -0
  42. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/block.h +114 -0
  43. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/client.cpp +1269 -0
  44. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/client.h +320 -0
  45. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/array.cpp +175 -0
  46. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/array.h +321 -0
  47. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/column.cpp +24 -0
  48. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/column.h +107 -0
  49. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/date.cpp +365 -0
  50. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/date.h +245 -0
  51. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/decimal.cpp +255 -0
  52. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/decimal.h +50 -0
  53. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/enum.cpp +123 -0
  54. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/enum.h +65 -0
  55. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/factory.cpp +285 -0
  56. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/factory.h +14 -0
  57. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/geo.cpp +108 -0
  58. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/geo.h +79 -0
  59. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip4.cpp +117 -0
  60. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip4.h +71 -0
  61. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip6.cpp +108 -0
  62. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip6.h +66 -0
  63. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/itemview.cpp +101 -0
  64. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/itemview.h +86 -0
  65. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/lowcardinality.cpp +527 -0
  66. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/lowcardinality.h +221 -0
  67. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/lowcardinalityadaptor.h +63 -0
  68. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/map.cpp +87 -0
  69. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/map.h +257 -0
  70. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/nothing.h +87 -0
  71. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/nullable.cpp +109 -0
  72. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/nullable.h +153 -0
  73. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/numeric.cpp +126 -0
  74. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/numeric.h +88 -0
  75. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/string.cpp +333 -0
  76. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/string.h +145 -0
  77. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/time.cpp +155 -0
  78. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/time.h +118 -0
  79. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/tuple.cpp +106 -0
  80. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/tuple.h +178 -0
  81. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/utils.h +41 -0
  82. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/uuid.cpp +80 -0
  83. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/uuid.h +58 -0
  84. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/error_codes.h +595 -0
  85. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/exceptions.h +66 -0
  86. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/protocol.h +54 -0
  87. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/query.cpp +25 -0
  88. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/query.h +246 -0
  89. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/server_exception.h +16 -0
  90. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/type_parser.cpp +314 -0
  91. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/type_parser.h +89 -0
  92. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/types.cpp +484 -0
  93. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/types.h +397 -0
  94. data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/version.h +14 -0
  95. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/Findcityhash.cmake +26 -0
  96. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/Findlz4.cmake +39 -0
  97. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/Findzstd.cmake +39 -0
  98. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/cpp17.cmake +8 -0
  99. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/openssl.cmake +8 -0
  100. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/subdirs.cmake +5 -0
  101. data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/version.cmake +87 -0
  102. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/CMakeLists.txt +9 -0
  103. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/attributes.h +682 -0
  104. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/config.h +714 -0
  105. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/internal/bits.h +219 -0
  106. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/macros.h +147 -0
  107. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/optimization.h +241 -0
  108. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/options.h +238 -0
  109. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/policy_checks.h +111 -0
  110. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/port.h +26 -0
  111. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128.cc +390 -0
  112. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128.h +1092 -0
  113. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128_have_intrinsic.inc +302 -0
  114. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128_no_intrinsic.inc +308 -0
  115. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/BUCK +13 -0
  116. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/CMakeLists.txt +7 -0
  117. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/COPYING +19 -0
  118. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/city.cc +469 -0
  119. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/city.h +90 -0
  120. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/citycrc.h +43 -0
  121. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/config.h +118 -0
  122. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/BUCK +14 -0
  123. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/CMakeLists.txt +4 -0
  124. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/LICENSE +28 -0
  125. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/README.md +1 -0
  126. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-death-test.h +346 -0
  127. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-matchers.h +930 -0
  128. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-message.h +219 -0
  129. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-param-test.h +507 -0
  130. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-printers.h +1029 -0
  131. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-spi.h +238 -0
  132. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-test-part.h +184 -0
  133. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-typed-test.h +329 -0
  134. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest.h +2495 -0
  135. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest_pred_impl.h +359 -0
  136. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest_prod.h +61 -0
  137. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/README.md +56 -0
  138. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/gtest-port.h +37 -0
  139. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/gtest-printers.h +42 -0
  140. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/gtest.h +37 -0
  141. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-death-test-internal.h +304 -0
  142. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-filepath.h +211 -0
  143. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-internal.h +1560 -0
  144. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-param-util.h +947 -0
  145. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-port-arch.h +114 -0
  146. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-port.h +2389 -0
  147. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-string.h +175 -0
  148. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-type-util.h +183 -0
  149. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-all.cc +48 -0
  150. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-death-test.cc +1644 -0
  151. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-filepath.cc +369 -0
  152. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-internal-inl.h +1221 -0
  153. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-matchers.cc +97 -0
  154. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-port.cc +1433 -0
  155. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-printers.cc +533 -0
  156. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-test-part.cc +108 -0
  157. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-typed-test.cc +107 -0
  158. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest.cc +6746 -0
  159. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest_main.cc +54 -0
  160. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/BUCK +13 -0
  161. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/CMakeLists.txt +8 -0
  162. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/LICENSE +24 -0
  163. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4.c +2402 -0
  164. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4.h +764 -0
  165. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4hc.c +1554 -0
  166. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4hc.h +438 -0
  167. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/BUCK +232 -0
  168. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/CMakeLists.txt +115 -0
  169. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/LICENSE +30 -0
  170. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/allocations.h +55 -0
  171. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/bits.h +200 -0
  172. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/bitstream.h +437 -0
  173. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/compiler.h +358 -0
  174. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/cpu.h +213 -0
  175. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/debug.c +24 -0
  176. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/debug.h +107 -0
  177. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/entropy_common.c +340 -0
  178. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/error_private.c +63 -0
  179. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/error_private.h +159 -0
  180. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/fse.h +639 -0
  181. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/fse_decompress.c +311 -0
  182. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/huf.h +273 -0
  183. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/mem.h +435 -0
  184. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/pool.c +371 -0
  185. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/pool.h +90 -0
  186. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/portability_macros.h +156 -0
  187. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/threading.c +176 -0
  188. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/threading.h +150 -0
  189. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/xxhash.c +24 -0
  190. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/xxhash.h +5686 -0
  191. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_common.c +48 -0
  192. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_deps.h +111 -0
  193. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_internal.h +392 -0
  194. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_trace.h +163 -0
  195. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/clevels.h +134 -0
  196. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/fse_compress.c +624 -0
  197. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/hist.c +181 -0
  198. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/hist.h +75 -0
  199. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/huf_compress.c +1435 -0
  200. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress.c +7032 -0
  201. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_internal.h +1532 -0
  202. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_literals.c +235 -0
  203. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_literals.h +39 -0
  204. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_sequences.c +442 -0
  205. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_sequences.h +54 -0
  206. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_superblock.c +577 -0
  207. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_superblock.h +32 -0
  208. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_cwksp.h +742 -0
  209. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_double_fast.c +758 -0
  210. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_double_fast.h +39 -0
  211. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_fast.c +960 -0
  212. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_fast.h +38 -0
  213. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_lazy.c +2157 -0
  214. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_lazy.h +127 -0
  215. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_ldm.c +724 -0
  216. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_ldm.h +117 -0
  217. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_ldm_geartab.h +106 -0
  218. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_opt.c +1472 -0
  219. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_opt.h +56 -0
  220. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstdmt_compress.c +1867 -0
  221. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstdmt_compress.h +113 -0
  222. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/huf_decompress.c +1882 -0
  223. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/huf_decompress_amd64.S +576 -0
  224. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_ddict.c +244 -0
  225. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_ddict.h +44 -0
  226. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress.c +2355 -0
  227. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress_block.c +2192 -0
  228. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress_block.h +73 -0
  229. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress_internal.h +238 -0
  230. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/cover.c +1257 -0
  231. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/cover.h +158 -0
  232. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/divsufsort.c +1913 -0
  233. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/divsufsort.h +67 -0
  234. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/fastcover.c +766 -0
  235. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/zdict.c +1127 -0
  236. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_legacy.h +422 -0
  237. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v01.c +2125 -0
  238. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v01.h +94 -0
  239. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v02.c +3477 -0
  240. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v02.h +93 -0
  241. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v03.c +3117 -0
  242. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v03.h +93 -0
  243. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v04.c +3605 -0
  244. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v04.h +142 -0
  245. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v05.c +4004 -0
  246. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v05.h +162 -0
  247. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v06.c +4113 -0
  248. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v06.h +172 -0
  249. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v07.c +4498 -0
  250. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v07.h +187 -0
  251. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/zdict.h +474 -0
  252. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/zstd.h +3020 -0
  253. data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/zstd_errors.h +114 -0
  254. data/lib/clickhouse_native/clickhouse_native.bundle +0 -0
  255. data/lib/clickhouse_native/client.rb +50 -0
  256. data/lib/clickhouse_native/errors.rb +23 -0
  257. data/lib/clickhouse_native/pool.rb +49 -0
  258. data/lib/clickhouse_native/version.rb +3 -0
  259. data/lib/clickhouse_native.rb +8 -0
  260. metadata +369 -0
@@ -0,0 +1,489 @@
1
+ #include "socket.h"
2
+ #include "singleton.h"
3
+ #include "../client.h"
4
+
5
+ #include <assert.h>
6
+ #include <stdexcept>
7
+ #include <system_error>
8
+ #include <unordered_set>
9
+ #include <memory.h>
10
+ #include <thread>
11
+
12
+ #if !defined(_win_)
13
+ # include <errno.h>
14
+ # include <fcntl.h>
15
+ # include <netdb.h>
16
+ # include <netinet/tcp.h>
17
+ # include <signal.h>
18
+ # include <unistd.h>
19
+ #endif
20
+
21
+ namespace clickhouse {
22
+
23
+ #if defined(_win_)
24
+ char const* windowsErrorCategory::name() const noexcept {
25
+ return "WindowsSocketError";
26
+ }
27
+
28
+ std::string windowsErrorCategory::message(int c) const {
29
+ char error[UINT8_MAX];
30
+ auto len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, static_cast<DWORD>(c), 0, error, sizeof(error), nullptr);
31
+ if (len == 0) {
32
+ return "unknown";
33
+ }
34
+ while (len && (error[len - 1] == '\r' || error[len - 1] == '\n')) {
35
+ --len;
36
+ }
37
+ return std::string(error, len);
38
+ }
39
+
40
+ windowsErrorCategory const& windowsErrorCategory::category() {
41
+ static windowsErrorCategory c;
42
+ return c;
43
+ }
44
+ #endif
45
+
46
+ #if defined(_unix_)
47
+ char const* getaddrinfoErrorCategory::name() const noexcept {
48
+ return "getaddrinfoError";
49
+ }
50
+
51
+ std::string getaddrinfoErrorCategory::message(int c) const {
52
+ return gai_strerror(c);
53
+ }
54
+
55
+ getaddrinfoErrorCategory const& getaddrinfoErrorCategory::category() {
56
+ static getaddrinfoErrorCategory c;
57
+ return c;
58
+ }
59
+ #endif
60
+
61
+ namespace {
62
+
63
+ class LocalNames : public std::unordered_set<std::string> {
64
+ public:
65
+ LocalNames() {
66
+ emplace("localhost");
67
+ emplace("localhost.localdomain");
68
+ emplace("localhost6");
69
+ emplace("localhost6.localdomain6");
70
+ emplace("::1");
71
+ emplace("127.0.0.1");
72
+ }
73
+
74
+ inline bool IsLocalName(const std::string& name) const noexcept {
75
+ return find(name) != end();
76
+ }
77
+ };
78
+
79
+ inline int getSocketErrorCode() {
80
+ #if defined(_win_)
81
+ return WSAGetLastError();
82
+ #else
83
+ return errno;
84
+ #endif
85
+ }
86
+
87
+ const std::error_category& getErrorCategory() noexcept {
88
+ #if defined(_win_)
89
+ return windowsErrorCategory::category();
90
+ #else
91
+ return std::system_category();
92
+ #endif
93
+ }
94
+
95
+ void SetNonBlock(SOCKET fd, bool value) {
96
+ #if defined(_unix_) || defined(__CYGWIN__)
97
+ int flags;
98
+ int ret;
99
+ #if defined(O_NONBLOCK)
100
+ if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
101
+ flags = 0;
102
+ if (value) {
103
+ flags |= O_NONBLOCK;
104
+ } else {
105
+ flags &= ~O_NONBLOCK;
106
+ }
107
+ ret = fcntl(fd, F_SETFL, flags);
108
+ #else
109
+ flags = value;
110
+ return ioctl(fd, FIOBIO, &flags);
111
+ #endif
112
+ if (ret == -1) {
113
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to set nonblocking mode");
114
+ }
115
+ #elif defined(_win_)
116
+ unsigned long inbuf = value;
117
+ unsigned long outbuf = 0;
118
+ DWORD written = 0;
119
+
120
+ if (!inbuf) {
121
+ WSAEventSelect(fd, nullptr, 0);
122
+ }
123
+
124
+ if (WSAIoctl(fd, FIONBIO, &inbuf, sizeof(inbuf), &outbuf, sizeof(outbuf), &written, 0, 0) == SOCKET_ERROR) {
125
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to set nonblocking mode");
126
+ }
127
+ #endif
128
+ }
129
+
130
+ void SetTimeout(SOCKET fd, const SocketTimeoutParams& timeout_params) {
131
+ #if defined(_unix_)
132
+ timeval recv_timeout{ static_cast<time_t>(timeout_params.recv_timeout.count() / 1000), static_cast<suseconds_t>(timeout_params.recv_timeout.count() % 1000 * 1000) };
133
+ auto recv_ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &recv_timeout, sizeof(recv_timeout));
134
+
135
+ timeval send_timeout{ static_cast<time_t>(timeout_params.send_timeout.count() / 1000), static_cast<suseconds_t>(timeout_params.send_timeout.count() % 1000 * 1000) };
136
+ auto send_ret = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &send_timeout, sizeof(send_timeout));
137
+
138
+ if (recv_ret == -1 || send_ret == -1) {
139
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to set socket timeout");
140
+ }
141
+ #else
142
+ DWORD recv_timeout = static_cast<DWORD>(timeout_params.recv_timeout.count());
143
+ auto recv_ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&recv_timeout, sizeof(DWORD));
144
+
145
+ DWORD send_timeout = static_cast<DWORD>(timeout_params.send_timeout.count());
146
+ auto send_ret = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&send_timeout, sizeof(DWORD));
147
+
148
+ if (recv_ret == SOCKET_ERROR || send_ret == SOCKET_ERROR) {
149
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to set socket timeout");
150
+ }
151
+ #endif
152
+ };
153
+
154
+ ssize_t Poll(struct pollfd* fds, int nfds, int timeout) noexcept {
155
+ #if defined(_win_)
156
+ return WSAPoll(fds, nfds, timeout);
157
+ #else
158
+ return poll(fds, nfds, timeout);
159
+ #endif
160
+ }
161
+
162
+ #ifndef INVALID_SOCKET
163
+ const SOCKET INVALID_SOCKET = -1;
164
+ #endif
165
+
166
+ void CloseSocket(SOCKET socket) {
167
+ if (socket == INVALID_SOCKET)
168
+ return;
169
+
170
+ #if defined(_win_)
171
+ closesocket(socket);
172
+ #else
173
+ close(socket);
174
+ #endif
175
+ }
176
+
177
+ struct SocketRAIIWrapper {
178
+ SOCKET socket = INVALID_SOCKET;
179
+
180
+ ~SocketRAIIWrapper() {
181
+ CloseSocket(socket);
182
+ }
183
+
184
+ SOCKET operator*() const {
185
+ return socket;
186
+ }
187
+
188
+ SOCKET release() {
189
+ auto result = socket;
190
+ socket = INVALID_SOCKET;
191
+
192
+ return result;
193
+ }
194
+ };
195
+
196
+ SOCKET SocketConnect(const NetworkAddress& addr, const SocketTimeoutParams& timeout_params) {
197
+ int last_err = 0;
198
+ for (auto res = addr.Info(); res != nullptr; res = res->ai_next) {
199
+ SocketRAIIWrapper s{socket(res->ai_family, res->ai_socktype, res->ai_protocol)};
200
+
201
+ if (*s == INVALID_SOCKET) {
202
+ continue;
203
+ }
204
+
205
+ SetNonBlock(*s, true);
206
+ SetTimeout(*s, timeout_params);
207
+
208
+ if (connect(*s, res->ai_addr, (int)res->ai_addrlen) != 0) {
209
+ int err = getSocketErrorCode();
210
+ if (
211
+ err == EINPROGRESS || err == EAGAIN || err == EWOULDBLOCK
212
+ #if defined(_win_)
213
+ || err == WSAEWOULDBLOCK || err == WSAEINPROGRESS
214
+ #endif
215
+ ) {
216
+ pollfd fd;
217
+ fd.fd = *s;
218
+ fd.events = POLLOUT;
219
+ fd.revents = 0;
220
+ ssize_t rval = Poll(&fd, 1, static_cast<int>(timeout_params.connect_timeout.count()));
221
+
222
+ if (rval == -1) {
223
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to connect");
224
+ }
225
+ if (rval == 0) {
226
+ #if defined(_win_)
227
+ last_err = WSAETIMEDOUT;
228
+ #else
229
+ last_err = ETIMEDOUT;
230
+ #endif
231
+ }
232
+ if (rval > 0) {
233
+ socklen_t len = sizeof(err);
234
+ getsockopt(*s, SOL_SOCKET, SO_ERROR, (char*)&err, &len);
235
+
236
+ if (!err) {
237
+ SetNonBlock(*s, false);
238
+ return s.release();
239
+ }
240
+ last_err = err;
241
+ }
242
+ }
243
+ } else {
244
+ SetNonBlock(*s, false);
245
+ return s.release();
246
+ }
247
+ }
248
+ if (last_err > 0) {
249
+ throw std::system_error(last_err, getErrorCategory(), "fail to connect");
250
+ }
251
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to connect");
252
+ }
253
+
254
+ } // namespace
255
+
256
+ NetworkAddress::NetworkAddress(const std::string& host, const std::string& port)
257
+ : host_(host)
258
+ , info_(nullptr)
259
+ {
260
+ struct addrinfo hints;
261
+ memset(&hints, 0, sizeof(hints));
262
+
263
+ hints.ai_family = PF_UNSPEC;
264
+ hints.ai_socktype = SOCK_STREAM;
265
+ // using AI_ADDRCONFIG on windows will cause getaddrinfo to return WSAHOST_NOT_FOUND
266
+ // for more information, see https://github.com/ClickHouse/clickhouse-cpp/issues/195
267
+ #if defined(_unix_)
268
+ if (!Singleton<LocalNames>()->IsLocalName(host)) {
269
+ // https://linux.die.net/man/3/getaddrinfo
270
+ // If hints.ai_flags includes the AI_ADDRCONFIG flag,
271
+ // then IPv4 addresses are returned in the list pointed to by res only
272
+ // if the local system has at least one IPv4 address configured,
273
+ // and IPv6 addresses are only returned if the local system
274
+ // has at least one IPv6 address configured.
275
+ // The loopback address is not considered for this case
276
+ // as valid as a configured address.
277
+ hints.ai_flags |= AI_ADDRCONFIG;
278
+ }
279
+ #endif
280
+
281
+ const int error = getaddrinfo(host.c_str(), port.c_str(), &hints, &info_);
282
+
283
+ #if defined(_unix_)
284
+ if (error && error != EAI_SYSTEM) {
285
+ throw std::system_error(error, getaddrinfoErrorCategory::category());
286
+ }
287
+ #endif
288
+
289
+ if (error) {
290
+ throw std::system_error(getSocketErrorCode(), getErrorCategory());
291
+ }
292
+ }
293
+
294
+ NetworkAddress::~NetworkAddress() {
295
+ if (info_) {
296
+ freeaddrinfo(info_);
297
+ }
298
+ }
299
+
300
+ const struct addrinfo* NetworkAddress::Info() const {
301
+ return info_;
302
+ }
303
+
304
+ const std::string & NetworkAddress::Host() const {
305
+ return host_;
306
+ }
307
+
308
+
309
+ SocketBase::~SocketBase() = default;
310
+
311
+
312
+ SocketFactory::~SocketFactory() = default;
313
+
314
+ void SocketFactory::sleepFor(const std::chrono::milliseconds& duration) {
315
+ std::this_thread::sleep_for(duration);
316
+ }
317
+
318
+
319
+ Socket::Socket(const NetworkAddress& addr, const SocketTimeoutParams& timeout_params)
320
+ : handle_(SocketConnect(addr, timeout_params))
321
+ {}
322
+
323
+ Socket::Socket(const NetworkAddress & addr)
324
+ : handle_(SocketConnect(addr, SocketTimeoutParams{}))
325
+ {}
326
+
327
+ Socket::Socket(Socket&& other) noexcept
328
+ : handle_(other.handle_)
329
+ {
330
+ other.handle_ = INVALID_SOCKET;
331
+ }
332
+
333
+ Socket& Socket::operator=(Socket&& other) noexcept {
334
+ if (this != &other) {
335
+ Close();
336
+
337
+ handle_ = other.handle_;
338
+ other.handle_ = INVALID_SOCKET;
339
+ }
340
+
341
+ return *this;
342
+ }
343
+
344
+ Socket::~Socket() {
345
+ Close();
346
+ }
347
+
348
+ void Socket::Close() {
349
+ CloseSocket(handle_);
350
+ handle_ = INVALID_SOCKET;
351
+ }
352
+
353
+ void Socket::SetTcpKeepAlive(int idle, int intvl, int cnt) noexcept {
354
+ int val = 1;
355
+
356
+ #if defined(_unix_)
357
+ setsockopt(handle_, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
358
+ # if defined(_linux_)
359
+ setsockopt(handle_, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
360
+ # elif defined(_darwin_)
361
+ setsockopt(handle_, IPPROTO_TCP, TCP_KEEPALIVE, &idle, sizeof(idle));
362
+ # else
363
+ # error "platform is not supported"
364
+ # endif
365
+ setsockopt(handle_, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl));
366
+ setsockopt(handle_, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
367
+ #else
368
+ setsockopt(handle_, SOL_SOCKET, SO_KEEPALIVE, (const char*)&val, sizeof(val));
369
+ std::ignore = idle = intvl = cnt;
370
+ #endif
371
+ }
372
+
373
+ void Socket::SetTcpNoDelay(bool nodelay) noexcept {
374
+ int val = nodelay;
375
+ #if defined(_unix_)
376
+ setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
377
+ #else
378
+ setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, (const char*)&val, sizeof(val));
379
+ #endif
380
+ }
381
+
382
+ std::unique_ptr<InputStream> Socket::makeInputStream() const {
383
+ return std::make_unique<SocketInput>(handle_);
384
+ }
385
+
386
+ std::unique_ptr<OutputStream> Socket::makeOutputStream() const {
387
+ return std::make_unique<SocketOutput>(handle_);
388
+ }
389
+
390
+
391
+ NonSecureSocketFactory::~NonSecureSocketFactory() {}
392
+
393
+ std::unique_ptr<SocketBase> NonSecureSocketFactory::connect(const ClientOptions &opts, const Endpoint& endpoint) {
394
+
395
+ const auto address = NetworkAddress(endpoint.host, std::to_string(endpoint.port));
396
+ auto socket = doConnect(address, opts);
397
+ setSocketOptions(*socket, opts);
398
+
399
+ return socket;
400
+ }
401
+
402
+ std::unique_ptr<Socket> NonSecureSocketFactory::doConnect(const NetworkAddress& address, const ClientOptions& opts) {
403
+ SocketTimeoutParams timeout_params { opts.connection_connect_timeout, opts.connection_recv_timeout, opts.connection_send_timeout };
404
+ return std::make_unique<Socket>(address, timeout_params);
405
+ }
406
+
407
+ void NonSecureSocketFactory::setSocketOptions(Socket &socket, const ClientOptions &opts) {
408
+ if (opts.tcp_keepalive) {
409
+ socket.SetTcpKeepAlive(
410
+ static_cast<int>(opts.tcp_keepalive_idle.count()),
411
+ static_cast<int>(opts.tcp_keepalive_intvl.count()),
412
+ static_cast<int>(opts.tcp_keepalive_cnt));
413
+ }
414
+ if (opts.tcp_nodelay) {
415
+ socket.SetTcpNoDelay(opts.tcp_nodelay);
416
+ }
417
+ }
418
+
419
+
420
+ SocketInput::SocketInput(SOCKET s)
421
+ : s_(s)
422
+ {
423
+ }
424
+
425
+ SocketInput::~SocketInput() = default;
426
+
427
+ size_t SocketInput::DoRead(void* buf, size_t len) {
428
+ const ssize_t ret = ::recv(s_, (char*)buf, (int)len, 0);
429
+
430
+ if (ret > 0) {
431
+ return (size_t)ret;
432
+ }
433
+
434
+ if (ret == 0) {
435
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "closed");
436
+ }
437
+
438
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "can't receive string data");
439
+ }
440
+
441
+ bool SocketInput::Skip(size_t /*bytes*/) {
442
+ return false;
443
+ }
444
+
445
+
446
+ SocketOutput::SocketOutput(SOCKET s)
447
+ : s_(s)
448
+ {
449
+ }
450
+
451
+ SocketOutput::~SocketOutput() = default;
452
+
453
+ size_t SocketOutput::DoWrite(const void* data, size_t len) {
454
+ #if defined (_linux_)
455
+ static const int flags = MSG_NOSIGNAL;
456
+ #else
457
+ static const int flags = 0;
458
+ #endif
459
+
460
+ const ssize_t ret = ::send(s_, (const char*)data, (int)len, flags);
461
+ if (ret < 0) {
462
+ throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to send " + std::to_string(len) + " bytes of data");
463
+ }
464
+
465
+ return (size_t)ret;
466
+ }
467
+
468
+
469
+ NetrworkInitializer::NetrworkInitializer() {
470
+ struct NetrworkInitializerImpl {
471
+ NetrworkInitializerImpl() {
472
+ #if defined (_win_)
473
+ WSADATA data;
474
+ const int result = WSAStartup(MAKEWORD(2, 2), &data);
475
+ if (result) {
476
+ assert(false);
477
+ exit(-1);
478
+ }
479
+ #elif defined(_unix_)
480
+ signal(SIGPIPE, SIG_IGN);
481
+ #endif
482
+ }
483
+ };
484
+
485
+
486
+ (void)Singleton<NetrworkInitializerImpl>();
487
+ }
488
+
489
+ }
@@ -0,0 +1,177 @@
1
+ #pragma once
2
+
3
+ #include "platform.h"
4
+ #include "input.h"
5
+ #include "output.h"
6
+ #include "endpoints_iterator.h"
7
+
8
+ #include <cstddef>
9
+ #include <string>
10
+ #include <chrono>
11
+
12
+ #if defined(_win_)
13
+ # include <winsock2.h>
14
+ # include <ws2tcpip.h>
15
+ #else
16
+ # include <arpa/inet.h>
17
+ # include <sys/types.h>
18
+ # include <sys/socket.h>
19
+ # include <poll.h>
20
+
21
+ # if !defined(SOCKET)
22
+ # define SOCKET int
23
+ # endif
24
+ #endif
25
+
26
+ #include <memory>
27
+ #include <system_error>
28
+
29
+ struct addrinfo;
30
+
31
+ namespace clickhouse {
32
+
33
+ struct ClientOptions;
34
+
35
+ /** Address of a host to establish connection to.
36
+ *
37
+ */
38
+ class NetworkAddress {
39
+ public:
40
+ explicit NetworkAddress(const std::string& host,
41
+ const std::string& port = "0");
42
+ ~NetworkAddress();
43
+
44
+ const struct addrinfo* Info() const;
45
+ const std::string & Host() const;
46
+
47
+ private:
48
+ const std::string host_;
49
+ struct addrinfo* info_;
50
+ };
51
+
52
+ #if defined(_win_)
53
+
54
+ class windowsErrorCategory : public std::error_category {
55
+ public:
56
+ char const* name() const noexcept override final;
57
+ std::string message(int c) const override final;
58
+
59
+ static windowsErrorCategory const& category();
60
+ };
61
+
62
+ #endif
63
+
64
+ #if defined(_unix_)
65
+
66
+ class getaddrinfoErrorCategory : public std::error_category {
67
+ public:
68
+ char const* name() const noexcept override final;
69
+ std::string message(int c) const override final;
70
+
71
+ static getaddrinfoErrorCategory const& category();
72
+ };
73
+
74
+ #endif
75
+
76
+
77
+ class SocketBase {
78
+ public:
79
+ virtual ~SocketBase();
80
+
81
+ virtual std::unique_ptr<InputStream> makeInputStream() const = 0;
82
+ virtual std::unique_ptr<OutputStream> makeOutputStream() const = 0;
83
+ };
84
+
85
+
86
+ class SocketFactory {
87
+ public:
88
+ virtual ~SocketFactory();
89
+
90
+ // TODO: move connection-related options to ConnectionOptions structure.
91
+
92
+ virtual std::unique_ptr<SocketBase> connect(const ClientOptions& opts, const Endpoint& endpoint) = 0;
93
+
94
+ virtual void sleepFor(const std::chrono::milliseconds& duration);
95
+ };
96
+
97
+
98
+ struct SocketTimeoutParams {
99
+ std::chrono::milliseconds connect_timeout{ 5000 };
100
+ std::chrono::milliseconds recv_timeout{ 0 };
101
+ std::chrono::milliseconds send_timeout{ 0 };
102
+ };
103
+
104
+ class Socket : public SocketBase {
105
+ public:
106
+ Socket(const NetworkAddress& addr, const SocketTimeoutParams& timeout_params);
107
+ Socket(const NetworkAddress& addr);
108
+ Socket(Socket&& other) noexcept;
109
+ Socket& operator=(Socket&& other) noexcept;
110
+
111
+ ~Socket() override;
112
+
113
+ /// @params idle the time (in seconds) the connection needs to remain
114
+ /// idle before TCP starts sending keepalive probes.
115
+ /// @params intvl the time (in seconds) between individual keepalive probes.
116
+ /// @params cnt the maximum number of keepalive probes TCP should send
117
+ /// before dropping the connection.
118
+ void SetTcpKeepAlive(int idle, int intvl, int cnt) noexcept;
119
+
120
+ /// @params nodelay whether to enable TCP_NODELAY
121
+ void SetTcpNoDelay(bool nodelay) noexcept;
122
+
123
+ std::unique_ptr<InputStream> makeInputStream() const override;
124
+ std::unique_ptr<OutputStream> makeOutputStream() const override;
125
+
126
+ protected:
127
+ Socket(const Socket&) = delete;
128
+ Socket& operator = (const Socket&) = delete;
129
+ void Close();
130
+
131
+ SOCKET handle_;
132
+ };
133
+
134
+
135
+ class NonSecureSocketFactory : public SocketFactory {
136
+ public:
137
+ ~NonSecureSocketFactory() override;
138
+
139
+ std::unique_ptr<SocketBase> connect(const ClientOptions& opts, const Endpoint& endpoint) override;
140
+
141
+ protected:
142
+ virtual std::unique_ptr<Socket> doConnect(const NetworkAddress& address, const ClientOptions& opts);
143
+
144
+ void setSocketOptions(Socket& socket, const ClientOptions& opts);
145
+ };
146
+
147
+
148
+ class SocketInput : public InputStream {
149
+ public:
150
+ explicit SocketInput(SOCKET s);
151
+ ~SocketInput();
152
+
153
+ protected:
154
+ bool Skip(size_t bytes) override;
155
+ size_t DoRead(void* buf, size_t len) override;
156
+
157
+ private:
158
+ SOCKET s_;
159
+ };
160
+
161
+ class SocketOutput : public OutputStream {
162
+ public:
163
+ explicit SocketOutput(SOCKET s);
164
+ ~SocketOutput();
165
+
166
+ protected:
167
+ size_t DoWrite(const void* data, size_t len) override;
168
+
169
+ private:
170
+ SOCKET s_;
171
+ };
172
+
173
+ static struct NetrworkInitializer {
174
+ NetrworkInitializer();
175
+ } gNetrworkInitializer;
176
+
177
+ }