Skip to content

Commit 6b82e5a

Browse files
committed
Try with static libs
1 parent 5869999 commit 6b82e5a

File tree

9 files changed

+38
-15
lines changed

9 files changed

+38
-15
lines changed

.github/workflows/windows_msvc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828

2929
- name: Test
3030
working-directory: ${{github.workspace}}/build/ut
31-
run: ./clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"
31+
run: clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"

contrib/gtest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ADD_LIBRARY (gtest-lib STATIC
22
"src/gtest-all.cc"
33
"src/gtest_main.cc"
4-
)
4+
)

contrib/gtest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google test, version release-1.11.0, stripped.
1+
google test, version release-1.11.0, stripped.

tests/simple/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ ADD_EXECUTABLE (simple-test
33
)
44

55
TARGET_LINK_LIBRARIES (simple-test
6-
clickhouse-cpp-lib
6+
clickhouse-cpp-lib-static
77
)
88

ut/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ ADD_EXECUTABLE (clickhouse-cpp-ut
2525
)
2626

2727
TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
28-
clickhouse-cpp-lib
28+
clickhouse-cpp-lib-static
2929
gtest-lib
3030
)

ut/performance_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ TYPED_TEST_P(ColumnPerformanceTest, InsertAndSelect) {
209209
size_t total_rows = 0;
210210
Timer timer;
211211
Timer::DurationType inner_loop_duration{0};
212-
client.Select("SELECT " + column_name + " FROM " + table_name, [&total_rows, &inner_loop_duration](const Block & block) {
212+
client.Select("SELECT " + column_name + " FROM " + table_name, [&total_rows, &inner_loop_duration, &ITEMS_COUNT](const Block & block) {
213213
Timer timer;
214214
total_rows += block.GetRowCount();
215215
if (block.GetRowCount() == 0) {

ut/tcp_server.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#include "tcp_server.h"
22

33
#include <iostream>
4-
#include <netinet/in.h>
54
#include <stdio.h>
65
#include <stdlib.h>
76
#include <string.h>
8-
#include <sys/socket.h>
7+
8+
#include <winsock2.h>
9+
/*
10+
#if defined(_win_)
11+
# include <winsock2.h>
12+
#else
13+
# include <netinet/in.h>
14+
# include <sys/socket.h>
15+
# include <unistd.h>
16+
#endif
17+
*/
18+
919
#include <thread>
10-
#include <unistd.h>
1120

1221
namespace clickhouse {
1322

@@ -23,7 +32,7 @@ LocalTcpServer::~LocalTcpServer() {
2332
void LocalTcpServer::start() {
2433
//setup a socket
2534
sockaddr_in servAddr;
26-
bzero((char*)&servAddr, sizeof(servAddr));
35+
memset((char*)&servAddr, 0, sizeof(servAddr));
2736
servAddr.sin_family = AF_INET;
2837
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
2938
servAddr.sin_port = htons(port_);
@@ -33,7 +42,14 @@ void LocalTcpServer::start() {
3342
throw std::runtime_error("Error establishing server socket");
3443
}
3544
int enable = 1;
36-
if (setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
45+
46+
#if defined(_unix_)
47+
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
48+
#else
49+
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable));
50+
#endif
51+
52+
if (res < 0) {
3753
std::cerr << "setsockopt(SO_REUSEADDR) failed" << std::endl;
3854
}
3955
//bind the socket to its local address
@@ -47,8 +63,14 @@ void LocalTcpServer::start() {
4763

4864
void LocalTcpServer::stop() {
4965
if(serverSd_ > 0) {
66+
67+
#if defined(_unix_)
5068
shutdown(serverSd_, SHUT_RDWR);
5169
close(serverSd_);
70+
#else
71+
shutdown(serverSd_, SD_BOTH);
72+
closesocket(serverSd_);
73+
#endif
5274
serverSd_ = -1;
5375
}
5476
}

ut/tcp_server.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <winsock2.h>
4+
35
namespace clickhouse {
46

57
class LocalTcpServer {
@@ -15,7 +17,7 @@ class LocalTcpServer {
1517

1618
private:
1719
int port_;
18-
int serverSd_;
20+
SOCKET serverSd_;
1921
};
2022

2123
}

ut/utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ struct Timer
3939
private:
4040
static auto Now()
4141
{
42-
struct timespec ts;
43-
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
44-
return std::chrono::nanoseconds(ts.tv_sec * 1000000000LL + ts.tv_nsec);
42+
std::chrono::nanoseconds ns = std::chrono::high_resolution_clock::now().time_since_epoch();
43+
return ns;
4544
}
4645

4746
private:

0 commit comments

Comments
 (0)