Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit 0c94452

Browse files
authored
Change the network module of cpp-redis (#39)
* remove network module and now compile with tacopie * only async_read recursively if the client is still connected * disable shallow cloning for git submodules * ensure callbacks are cleared (finished to execute) before finishing to execute destructors * add header files to CMakelist (for VC++) * ensure notify_all is called in all appropriate contexts * do not call disconnection handler in receive handler: will be called by tacopie * update ref to tacopie submodule * remove CMake variable not used anymore * windows tests: WSAStartup & Cleanup * full integration of gtest+tacopie inside cpp_redis solution on windows * fix Cmake warnings under unix (cpp_redis integration) * install_deps update * fix cmakelist * fix cmakelist * clang-format * update ref to tacopie * update ref to tacopie * update CHANGELOG
1 parent 9dfb144 commit 0c94452

34 files changed

+270
-1688
lines changed

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "tacopie"]
2+
path = tacopie
3+
url = https://github.com/Cylix/tacopie.git
4+
branch = master

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## [v3.0](https://github.com/Cylix/cpp_redis/releases/tag/3.0)
4+
### Changes
5+
* Rewrite the network side of cpp_redis by using the [tacopie library](https://github.com/Cylix/tacopie)
6+
7+
### Additions
8+
* Tacopie is now a submodule of cpp_redis
9+
10+
### Removals
11+
* All network related code
12+
13+
314
## [v2.2](https://github.com/Cylix/cpp_redis/releases/tag/2.2)
415
### Changes
516
* Bug patch

CMakeLists.txt

+56-35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2015-2017 Simon Ninon <[email protected]>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
123
###
224
# config
325
###
@@ -23,6 +45,13 @@ project(${PROJECT} CXX)
2345
###
2446
IF (WIN32)
2547
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /O2")
48+
49+
# was causing conflics with gtest build
50+
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
51+
foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE)
52+
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
53+
endforeach()
54+
2655
add_definitions(-D_UNICODE)
2756
add_definitions(-DUNICODE)
2857
add_definitions(-DWIN32_LEAN_AND_MEAN)
@@ -34,40 +63,34 @@ ENDIF (WIN32)
3463
###
3564
# variables
3665
###
37-
set(DEPS_FOLDER ${PROJECT_SOURCE_DIR}/deps/build)
38-
set(GTEST_INCLUDES ${DEPS_FOLDER}/gtest/include)
39-
set(GTEST_LIBS ${DEPS_FOLDER}/gtest/lib)
66+
# gtest
67+
set(GTEST_INCLUDES ${PROJECT_SOURCE_DIR}/deps/src/googletest/googletest/include)
68+
# cpp_redis
4069
set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/includes)
70+
# tacopie
71+
set(TACOPIE_FOLDER ${PROJECT_SOURCE_DIR}/tacopie)
72+
set(TACOPIE_INCLUDES ${TACOPIE_FOLDER}/includes)
4173

4274

4375
###
4476
# includes
4577
###
46-
include_directories(${CPP_REDIS_INCLUDES})
47-
48-
49-
###
50-
# link
51-
###
52-
link_directories(${GTEST_LIBS})
78+
include_directories(${CPP_REDIS_INCLUDES}
79+
${TACOPIE_INCLUDES})
5380

5481

5582
###
5683
# sources
5784
###
58-
set(SRC_DIRS "sources" "sources/network" "sources/builders")
59-
60-
IF (WIN32)
61-
set(SRC_DIRS ${SRC_DIRS} "sources/network/windows_impl")
62-
ELSE ()
63-
set(SRC_DIRS ${SRC_DIRS} "sources/network/unix_impl")
64-
ENDIF (WIN32)
65-
85+
set(SRC_DIRS "sources" "sources/network" "sources/builders" "includes/cpp_redis" "includes/cpp_redis/builders" "includes/cpp_redis/network")
6686
foreach(dir ${SRC_DIRS})
67-
# get directory sources
87+
# get directory sources and headers
6888
file(GLOB s_${dir} "${dir}/*.cpp")
89+
file(GLOB h_${dir} "${dir}/*.hpp")
90+
file(GLOB i_${dir} "${dir}/*.ipp")
91+
6992
# set sources
70-
set(SOURCES ${SOURCES} ${s_${dir}})
93+
set(SOURCES ${SOURCES} ${s_${dir}} ${h_${dir}} ${i_${dir}})
7194
endforeach()
7295

7396

@@ -90,31 +113,21 @@ configure_file("cpp_redis.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/cpp_redis.
90113
add_library(${PROJECT} STATIC ${SOURCES})
91114

92115
IF (WIN32)
93-
target_link_libraries(${PROJECT} ws2_32)
116+
target_link_libraries(${PROJECT} ws2_32 tacopie)
94117
ELSE ()
95-
target_link_libraries(${PROJECT} pthread)
118+
target_link_libraries(${PROJECT} pthread tacopie)
96119
ENDIF (WIN32)
97120

98121
# __CPP_REDIS_READ_SIZE
99122
IF (READ_SIZE)
100-
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_READ_SIZE=${READ_SIZE}")
123+
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_READ_SIZE=${READ_SIZE}")
101124
ENDIF (READ_SIZE)
102125

103126
# __CPP_REDIS_LOGGING_ENABLED
104127
IF (LOGGING_ENABLED)
105-
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_LOGGING_ENABLED=${LOGGING_ENABLED}")
128+
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_LOGGING_ENABLED=${LOGGING_ENABLED}")
106129
ENDIF (LOGGING_ENABLED)
107130

108-
# _CPP_REDIS_MAX_NB_FDS
109-
IF (MAX_NB_FDS)
110-
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "_CPP_REDIS_MAX_NB_FDS=${MAX_NB_FDS}")
111-
ENDIF (MAX_NB_FDS)
112-
113-
# __CPP_REDIS_DEFAULT_NB_IO_SERVICE_WORKERS
114-
IF (DEFAULT_NB_IO_SERVICE_WORKERS)
115-
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_DEFAULT_NB_IO_SERVICE_WORKERS=${DEFAULT_NB_IO_SERVICE_WORKERS}")
116-
ENDIF (DEFAULT_NB_IO_SERVICE_WORKERS)
117-
118131

119132
###
120133
# install
@@ -128,17 +141,25 @@ install (DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION bin USE_SOURCE_PERMISSIO
128141
install (DIRECTORY ${CPP_REDIS_INCLUDES}/ DESTINATION include USE_SOURCE_PERMISSIONS)
129142

130143

144+
###
145+
# tacopie
146+
###
147+
add_subdirectory(tacopie)
148+
149+
131150
###
132151
# examples
133152
###
134153
IF (BUILD_EXAMPLES)
135154
add_subdirectory(examples)
136155
ENDIF(BUILD_EXAMPLES)
137156

138-
139157
###
140158
# tests
141159
###
142160
IF (BUILD_TESTS)
143161
add_subdirectory(tests)
162+
IF (EXISTS ${PROJECT_SOURCE_DIR}/deps/src/googletest)
163+
add_subdirectory(${PROJECT_SOURCE_DIR}/deps/src/googletest)
164+
ENDIF ()
144165
ENDIF(BUILD_TESTS)

examples/CMakeLists.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ include_directories(${PROJECT_SOURCE_DIR}/includes
3838
###
3939
# executable
4040
###
41-
add_executable(redis_client redis_client.cpp)
42-
target_link_libraries(redis_client cpp_redis)
41+
add_executable(cpp_redis_client redis_client.cpp)
42+
target_link_libraries(cpp_redis_client cpp_redis)
4343

44-
add_executable(future_client future_client.cpp)
45-
target_link_libraries(future_client cpp_redis)
44+
add_executable(cpp_redis_future_client future_client.cpp)
45+
target_link_libraries(cpp_redis_future_client cpp_redis)
4646

47-
add_executable(sync_client sync_client.cpp)
48-
target_link_libraries(sync_client cpp_redis)
47+
add_executable(cpp_redis_sync_client sync_client.cpp)
48+
target_link_libraries(cpp_redis_sync_client cpp_redis)
4949

50-
add_executable(redis_subscriber redis_subscriber.cpp)
51-
target_link_libraries(redis_subscriber cpp_redis)
50+
add_executable(cpp_redis_subscriber redis_subscriber.cpp)
51+
target_link_libraries(cpp_redis_subscriber cpp_redis)
5252

53-
add_executable(logger logger.cpp)
54-
target_link_libraries(logger cpp_redis)
53+
add_executable(cpp_redis_logger logger.cpp)
54+
target_link_libraries(cpp_redis_logger cpp_redis)

examples/future_client.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,23 @@
2424

2525
#include <iostream>
2626

27+
#ifdef _WIN32
28+
#include <Winsock2.h>
29+
#endif /* _WIN32 */
30+
2731
int
2832
main(void) {
33+
#ifdef _WIN32
34+
//! Windows netword DLL init
35+
WORD version = MAKEWORD(2, 2);
36+
WSADATA data;
37+
38+
if (WSAStartup(version, &data) != 0) {
39+
std::cerr << "WSAStartup() failure" << std::endl;
40+
return -1;
41+
}
42+
#endif /* _WIN32 */
43+
2944
//! Enable logging
3045
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
3146

@@ -48,5 +63,9 @@ main(void) {
4863
tok = client.get("hello");
4964
std::cout << "get 'hello': " << tok.get() << std::endl;
5065

66+
#ifdef _WIN32
67+
WSACleanup();
68+
#endif /* _WIN32 */
69+
5170
return 0;
5271
}

examples/redis_client.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,23 @@
2424

2525
#include <iostream>
2626

27+
#ifdef _WIN32
28+
#include <Winsock2.h>
29+
#endif /* _WIN32 */
30+
2731
int
2832
main(void) {
33+
#ifdef _WIN32
34+
//! Windows netword DLL init
35+
WORD version = MAKEWORD(2, 2);
36+
WSADATA data;
37+
38+
if (WSAStartup(version, &data) != 0) {
39+
std::cerr << "WSAStartup() failure" << std::endl;
40+
return -1;
41+
}
42+
#endif /* _WIN32 */
43+
2944
//! Enable logging
3045
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
3146

@@ -62,8 +77,12 @@ main(void) {
6277
// synchronous commit, no timeout
6378
client.sync_commit();
6479

65-
// synchronous commit, timeout
66-
// client.sync_commit(std::chrono::milliseconds(100));
80+
// synchronous commit, timeout
81+
// client.sync_commit(std::chrono::milliseconds(100));
82+
83+
#ifdef _WIN32
84+
WSACleanup();
85+
#endif /* _WIN32 */
6786

6887
return 0;
6988
}

examples/redis_subscriber.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <iostream>
2626
#include <signal.h>
2727

28+
#ifdef _WIN32
29+
#include <Winsock2.h>
30+
#endif /* _WIN32 */
31+
2832
volatile std::atomic_bool should_exit(false);
2933

3034
void
@@ -34,6 +38,17 @@ sigint_handler(int) {
3438

3539
int
3640
main(void) {
41+
#ifdef _WIN32
42+
//! Windows netword DLL init
43+
WORD version = MAKEWORD(2, 2);
44+
WSADATA data;
45+
46+
if (WSAStartup(version, &data) != 0) {
47+
std::cerr << "WSAStartup() failure" << std::endl;
48+
return -1;
49+
}
50+
#endif /* _WIN32 */
51+
3752
//! Enable logging
3853
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
3954

@@ -55,5 +70,9 @@ main(void) {
5570
signal(SIGINT, &sigint_handler);
5671
while (!should_exit) {}
5772

73+
#ifdef _WIN32
74+
WSACleanup();
75+
#endif /* _WIN32 */
76+
5877
return 0;
5978
}

examples/sync_client.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,23 @@
2424

2525
#include <iostream>
2626

27+
#ifdef _WIN32
28+
#include <Winsock2.h>
29+
#endif /* _WIN32 */
30+
2731
int
2832
main(void) {
33+
#ifdef _WIN32
34+
//! Windows netword DLL init
35+
WORD version = MAKEWORD(2, 2);
36+
WSADATA data;
37+
38+
if (WSAStartup(version, &data) != 0) {
39+
std::cerr << "WSAStartup() failure" << std::endl;
40+
return -1;
41+
}
42+
#endif /* _WIN32 */
43+
2944
//! Enable logging
3045
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
3146

@@ -44,5 +59,9 @@ main(void) {
4459
r = client.get("hello");
4560
std::cout << "get 'hello': " << r << std::endl;
4661

62+
#ifdef _WIN32
63+
WSACleanup();
64+
#endif /* _WIN32 */
65+
4766
return 0;
4867
}

includes/cpp_redis/future_client.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class future_client {
5858

5959
public:
6060
//! ctor & dtor
61-
future_client(const std::shared_ptr<network::io_service>& IO = nullptr);
62-
~future_client(void);
61+
future_client(void) = default;
62+
~future_client(void) = default;
6363

6464
void
6565
connect(const std::string& host = "127.0.0.1", std::size_t port = 6379,

0 commit comments

Comments
 (0)