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

Commit

Permalink
Change the network module of cpp-redis (#39)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Cylix authored Jan 29, 2017
1 parent 9dfb144 commit 0c94452
Show file tree
Hide file tree
Showing 34 changed files with 270 additions and 1,688 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "tacopie"]
path = tacopie
url = https://github.com/Cylix/tacopie.git
branch = master
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [v3.0](https://github.com/Cylix/cpp_redis/releases/tag/3.0)
### Changes
* Rewrite the network side of cpp_redis by using the [tacopie library](https://github.com/Cylix/tacopie)

### Additions
* Tacopie is now a submodule of cpp_redis

### Removals
* All network related code


## [v2.2](https://github.com/Cylix/cpp_redis/releases/tag/2.2)
### Changes
* Bug patch
Expand Down
91 changes: 56 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# The MIT License (MIT)
#
# Copyright (c) 2015-2017 Simon Ninon <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

###
# config
###
Expand All @@ -23,6 +45,13 @@ project(${PROJECT} CXX)
###
IF (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /O2")

# was causing conflics with gtest build
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE)
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
endforeach()

add_definitions(-D_UNICODE)
add_definitions(-DUNICODE)
add_definitions(-DWIN32_LEAN_AND_MEAN)
Expand All @@ -34,40 +63,34 @@ ENDIF (WIN32)
###
# variables
###
set(DEPS_FOLDER ${PROJECT_SOURCE_DIR}/deps/build)
set(GTEST_INCLUDES ${DEPS_FOLDER}/gtest/include)
set(GTEST_LIBS ${DEPS_FOLDER}/gtest/lib)
# gtest
set(GTEST_INCLUDES ${PROJECT_SOURCE_DIR}/deps/src/googletest/googletest/include)
# cpp_redis
set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/includes)
# tacopie
set(TACOPIE_FOLDER ${PROJECT_SOURCE_DIR}/tacopie)
set(TACOPIE_INCLUDES ${TACOPIE_FOLDER}/includes)


###
# includes
###
include_directories(${CPP_REDIS_INCLUDES})


###
# link
###
link_directories(${GTEST_LIBS})
include_directories(${CPP_REDIS_INCLUDES}
${TACOPIE_INCLUDES})


###
# sources
###
set(SRC_DIRS "sources" "sources/network" "sources/builders")

IF (WIN32)
set(SRC_DIRS ${SRC_DIRS} "sources/network/windows_impl")
ELSE ()
set(SRC_DIRS ${SRC_DIRS} "sources/network/unix_impl")
ENDIF (WIN32)

set(SRC_DIRS "sources" "sources/network" "sources/builders" "includes/cpp_redis" "includes/cpp_redis/builders" "includes/cpp_redis/network")
foreach(dir ${SRC_DIRS})
# get directory sources
# get directory sources and headers
file(GLOB s_${dir} "${dir}/*.cpp")
file(GLOB h_${dir} "${dir}/*.hpp")
file(GLOB i_${dir} "${dir}/*.ipp")

# set sources
set(SOURCES ${SOURCES} ${s_${dir}})
set(SOURCES ${SOURCES} ${s_${dir}} ${h_${dir}} ${i_${dir}})
endforeach()


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

IF (WIN32)
target_link_libraries(${PROJECT} ws2_32)
target_link_libraries(${PROJECT} ws2_32 tacopie)
ELSE ()
target_link_libraries(${PROJECT} pthread)
target_link_libraries(${PROJECT} pthread tacopie)
ENDIF (WIN32)

# __CPP_REDIS_READ_SIZE
IF (READ_SIZE)
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_READ_SIZE=${READ_SIZE}")
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_READ_SIZE=${READ_SIZE}")
ENDIF (READ_SIZE)

# __CPP_REDIS_LOGGING_ENABLED
IF (LOGGING_ENABLED)
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_LOGGING_ENABLED=${LOGGING_ENABLED}")
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_LOGGING_ENABLED=${LOGGING_ENABLED}")
ENDIF (LOGGING_ENABLED)

# _CPP_REDIS_MAX_NB_FDS
IF (MAX_NB_FDS)
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "_CPP_REDIS_MAX_NB_FDS=${MAX_NB_FDS}")
ENDIF (MAX_NB_FDS)

# __CPP_REDIS_DEFAULT_NB_IO_SERVICE_WORKERS
IF (DEFAULT_NB_IO_SERVICE_WORKERS)
set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "__CPP_REDIS_DEFAULT_NB_IO_SERVICE_WORKERS=${DEFAULT_NB_IO_SERVICE_WORKERS}")
ENDIF (DEFAULT_NB_IO_SERVICE_WORKERS)


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


###
# tacopie
###
add_subdirectory(tacopie)


###
# examples
###
IF (BUILD_EXAMPLES)
add_subdirectory(examples)
ENDIF(BUILD_EXAMPLES)


###
# tests
###
IF (BUILD_TESTS)
add_subdirectory(tests)
IF (EXISTS ${PROJECT_SOURCE_DIR}/deps/src/googletest)
add_subdirectory(${PROJECT_SOURCE_DIR}/deps/src/googletest)
ENDIF ()
ENDIF(BUILD_TESTS)
20 changes: 10 additions & 10 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ include_directories(${PROJECT_SOURCE_DIR}/includes
###
# executable
###
add_executable(redis_client redis_client.cpp)
target_link_libraries(redis_client cpp_redis)
add_executable(cpp_redis_client redis_client.cpp)
target_link_libraries(cpp_redis_client cpp_redis)

add_executable(future_client future_client.cpp)
target_link_libraries(future_client cpp_redis)
add_executable(cpp_redis_future_client future_client.cpp)
target_link_libraries(cpp_redis_future_client cpp_redis)

add_executable(sync_client sync_client.cpp)
target_link_libraries(sync_client cpp_redis)
add_executable(cpp_redis_sync_client sync_client.cpp)
target_link_libraries(cpp_redis_sync_client cpp_redis)

add_executable(redis_subscriber redis_subscriber.cpp)
target_link_libraries(redis_subscriber cpp_redis)
add_executable(cpp_redis_subscriber redis_subscriber.cpp)
target_link_libraries(cpp_redis_subscriber cpp_redis)

add_executable(logger logger.cpp)
target_link_libraries(logger cpp_redis)
add_executable(cpp_redis_logger logger.cpp)
target_link_libraries(cpp_redis_logger cpp_redis)
19 changes: 19 additions & 0 deletions examples/future_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@

#include <iostream>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;

if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */

//! Enable logging
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);

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

#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */

return 0;
}
23 changes: 21 additions & 2 deletions examples/redis_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@

#include <iostream>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;

if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */

//! Enable logging
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);

Expand Down Expand Up @@ -62,8 +77,12 @@ main(void) {
// synchronous commit, no timeout
client.sync_commit();

// synchronous commit, timeout
// client.sync_commit(std::chrono::milliseconds(100));
// synchronous commit, timeout
// client.sync_commit(std::chrono::milliseconds(100));

#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */

return 0;
}
19 changes: 19 additions & 0 deletions examples/redis_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <iostream>
#include <signal.h>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

volatile std::atomic_bool should_exit(false);

void
Expand All @@ -34,6 +38,17 @@ sigint_handler(int) {

int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;

if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */

//! Enable logging
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);

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

#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */

return 0;
}
19 changes: 19 additions & 0 deletions examples/sync_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@

#include <iostream>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;

if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */

//! Enable logging
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);

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

#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */

return 0;
}
4 changes: 2 additions & 2 deletions includes/cpp_redis/future_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class future_client {

public:
//! ctor & dtor
future_client(const std::shared_ptr<network::io_service>& IO = nullptr);
~future_client(void);
future_client(void) = default;
~future_client(void) = default;

void
connect(const std::string& host = "127.0.0.1", std::size_t port = 6379,
Expand Down
Loading

0 comments on commit 0c94452

Please sign in to comment.