Skip to content

Commit

Permalink
Try with static libs
Browse files Browse the repository at this point in the history
  • Loading branch information
filimonov committed Jan 6, 2022
1 parent 5869999 commit 6b82e5a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows_msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build/ut
run: ./clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"
run: clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"
2 changes: 1 addition & 1 deletion contrib/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_LIBRARY (gtest-lib STATIC
"src/gtest-all.cc"
"src/gtest_main.cc"
)
)
2 changes: 1 addition & 1 deletion contrib/gtest/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google test, version release-1.11.0, stripped.
google test, version release-1.11.0, stripped.
2 changes: 1 addition & 1 deletion tests/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ ADD_EXECUTABLE (simple-test
)

TARGET_LINK_LIBRARIES (simple-test
clickhouse-cpp-lib
clickhouse-cpp-lib-static
)

2 changes: 1 addition & 1 deletion ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ ADD_EXECUTABLE (clickhouse-cpp-ut
)

TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
clickhouse-cpp-lib
clickhouse-cpp-lib-static
gtest-lib
)
2 changes: 1 addition & 1 deletion ut/performance_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ TYPED_TEST_P(ColumnPerformanceTest, InsertAndSelect) {
size_t total_rows = 0;
Timer timer;
Timer::DurationType inner_loop_duration{0};
client.Select("SELECT " + column_name + " FROM " + table_name, [&total_rows, &inner_loop_duration](const Block & block) {
client.Select("SELECT " + column_name + " FROM " + table_name, [&total_rows, &inner_loop_duration, &ITEMS_COUNT](const Block & block) {
Timer timer;
total_rows += block.GetRowCount();
if (block.GetRowCount() == 0) {
Expand Down
32 changes: 27 additions & 5 deletions ut/tcp_server.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#include "tcp_server.h"

#include <iostream>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>

#include <winsock2.h>
/*
#if defined(_win_)
# include <winsock2.h>
#else
# include <netinet/in.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
*/

#include <thread>
#include <unistd.h>

namespace clickhouse {

Expand All @@ -23,7 +32,7 @@ LocalTcpServer::~LocalTcpServer() {
void LocalTcpServer::start() {
//setup a socket
sockaddr_in servAddr;
bzero((char*)&servAddr, sizeof(servAddr));
memset((char*)&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(port_);
Expand All @@ -33,7 +42,14 @@ void LocalTcpServer::start() {
throw std::runtime_error("Error establishing server socket");
}
int enable = 1;
if (setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {

#if defined(_unix_)
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
#else
auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable));
#endif

if (res < 0) {
std::cerr << "setsockopt(SO_REUSEADDR) failed" << std::endl;
}
//bind the socket to its local address
Expand All @@ -47,8 +63,14 @@ void LocalTcpServer::start() {

void LocalTcpServer::stop() {
if(serverSd_ > 0) {

#if defined(_unix_)
shutdown(serverSd_, SHUT_RDWR);
close(serverSd_);
#else
shutdown(serverSd_, SD_BOTH);
closesocket(serverSd_);
#endif
serverSd_ = -1;
}
}
Expand Down
4 changes: 3 additions & 1 deletion ut/tcp_server.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <winsock2.h>

namespace clickhouse {

class LocalTcpServer {
Expand All @@ -15,7 +17,7 @@ class LocalTcpServer {

private:
int port_;
int serverSd_;
SOCKET serverSd_;
};

}
5 changes: 2 additions & 3 deletions ut/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ struct Timer
private:
static auto Now()
{
struct timespec ts;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
return std::chrono::nanoseconds(ts.tv_sec * 1000000000LL + ts.tv_nsec);
std::chrono::nanoseconds ns = std::chrono::high_resolution_clock::now().time_since_epoch();
return ns;
}

private:
Expand Down

0 comments on commit 6b82e5a

Please sign in to comment.