From 29ed03b11b4d39f36f602ed7b2f73714214470ed Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期六, 30 一月 2021 14:40:16 +0800 Subject: [PATCH] update --- src/logger_factory.cpp | 11 --- test/test_assert.cpp | 18 ++++++ src/CMakeLists.txt | 75 ++++++++++++------------ CMakeLists.txt | 4 src/socket/shm_socket.cpp | 19 ++++++ test/CMakeLists.txt | 9 +++ src/logger_factory.h | 1 7 files changed, 85 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d9971d..8f59922 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,8 @@ # control where the static and shared libraries are built so that on windows # we don't need to tinker with the path to run the executable -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") #option(BUILD_SHARED_LIBS "Build using shared libraries" ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f3698d9..f6202ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,8 +5,9 @@ # to the source code configure_file(bus_config.h.in bus_config.h) -add_library(shm_queue - ./logger_factory.cpp + +list(APPEND _SOURCES_ +./logger_factory.cpp ./socket/bus_server_socket.cpp ./socket/bus_server_socket_wrapper.cpp ./socket/shm_stream_mod_socket.cpp @@ -26,12 +27,12 @@ ./shm/shm_mm_wrapper.cpp ./shm/mm.cpp ./shm/hashtable.cpp +) - ) -target_include_directories(shm_queue PUBLIC - ${EXTRA_INCLUDES} - ) +add_library(shm_queue ${_SOURCES_}) + +target_include_directories(shm_queue PUBLIC ${EXTRA_INCLUDES} ) target_include_directories(shm_queue PUBLIC ${PROJECT_BINARY_DIR}/src @@ -48,38 +49,36 @@ # install rules install(TARGETS shm_queue DESTINATION lib) install(FILES - ./socket/socket_def.h -./socket/bus_server_socket.h -./socket/shm_socket.h -./socket/shm_stream_mod_socket.h -./socket/shm_mod_socket.h -./socket/bus_server_socket_wrapper.h -./psem.h -./key_def.h -./time_util.h -./futex_sem.h -./bus_error.h -./bus_def.h -./logger_factory.h -./queue/linked_lock_free_queue.h -./queue/array_lock_free_queue.h -./queue/shm_queue.h -./queue/array_lock_free_sem_queue.h -./queue/lock_free_queue.h -./svsem.h -./net/net_conn_pool.h -./net/net_mod_socket.h -./net/net_mod_server_socket_wrapper.h -./net/net_mod_socket_io.h -./net/net_mod_server_socket.h -./net/net_mod_socket_wrapper.h -./shm/hashtable.h -./shm/mem_pool.h -./shm/mm.h -./shm/shm_mm_wrapper.h -./shm/shm_allocator.h - - + ./socket/socket_def.h + ./socket/bus_server_socket.h + ./socket/shm_socket.h + ./socket/shm_stream_mod_socket.h + ./socket/shm_mod_socket.h + ./socket/bus_server_socket_wrapper.h + ./psem.h + ./key_def.h + ./time_util.h + ./futex_sem.h + ./bus_error.h + ./bus_def.h + ./logger_factory.h + ./queue/linked_lock_free_queue.h + ./queue/array_lock_free_queue.h + ./queue/shm_queue.h + ./queue/array_lock_free_sem_queue.h + ./queue/lock_free_queue.h + ./svsem.h + ./net/net_conn_pool.h + ./net/net_mod_socket.h + ./net/net_mod_server_socket_wrapper.h + ./net/net_mod_socket_io.h + ./net/net_mod_server_socket.h + ./net/net_mod_socket_wrapper.h + ./shm/hashtable.h + ./shm/mem_pool.h + ./shm/mm.h + ./shm/shm_mm_wrapper.h + ./shm/shm_allocator.h DESTINATION include) diff --git a/src/logger_factory.cpp b/src/logger_factory.cpp index 0955fc2..001e7cc 100644 --- a/src/logger_factory.cpp +++ b/src/logger_factory.cpp @@ -23,13 +23,4 @@ return logger; } -void LoggerFactory::error(int s) { - Logger* logger = LoggerFactory::getLogger(); - if(s == EBUS_TIMEOUT) { - logger->error("shm_recvfrom failed, %s", bus_strerror(EBUS_TIMEOUT)); - - } else { - logger->error(s, "shm_recvfrom failed!"); - - } -} \ No newline at end of file + \ No newline at end of file diff --git a/src/logger_factory.h b/src/logger_factory.h index 37eaefd..e736e64 100644 --- a/src/logger_factory.h +++ b/src/logger_factory.h @@ -10,7 +10,6 @@ public: static Logger* getLogger(); - static void error(int s); }; #endif diff --git a/src/socket/shm_socket.cpp b/src/socket/shm_socket.cpp index dad77b8..785eb4d 100644 --- a/src/socket/shm_socket.cpp +++ b/src/socket/shm_socket.cpp @@ -2,6 +2,7 @@ #include "hashtable.h" #include "logger_factory.h" #include <map> +#include <cassert> #include "bus_error.h" static Logger *logger = LoggerFactory::getLogger(); @@ -518,6 +519,10 @@ if ((rv = shm_sendto(tmp_socket, send_buf, send_size, send_key, timeout, flags)) == 0) { rv = shm_recvfrom(tmp_socket, recv_buf, recv_size, &recv_key, timeout, flags); +printf("======send key =%d , recv key=%d\n", send_key, recv_key); + assert( send_key == recv_key); + if(send_key != recv_key) + err_exit(0, "send key need to equal to recv key! send key =%d , recv key=%d", send_key, recv_key); return rv; } else { return rv; @@ -546,6 +551,18 @@ if ((rv = shm_sendto(tmp_socket, send_buf, send_size, send_key, timeout, flags)) == 0) { rv = shm_recvfrom(tmp_socket, recv_buf, recv_size, &recv_key, timeout, flags); + printf("======send key =%d , recv key=%d\n", send_key, recv_key); + + if(rv != 0) { + printf("_shm_sendandrecv_alloc_new shm_recvfrom : %s\n", bus_strerror(rv)); + } + else if(rv == 0 ) { + assert( send_key == recv_key); + if(send_key != recv_key) { + err_exit(0, "send key need to equal to recv key! send key =%d , recv key=%d", send_key, recv_key); + } + + } } shm_close_socket(tmp_socket); @@ -556,7 +573,7 @@ int shm_sendandrecv(shm_socket_t *socket, const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size, const struct timespec *timeout, int flags) { - return _shm_sendandrecv_thread_local(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout, flags); + return _shm_sendandrecv_alloc_new(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout, flags); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 18e1408..1ac1383 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,5 +30,14 @@ ${EXTRA_INCLUDES} ) +add_executable(test_assert test_assert.cpp ) +target_link_libraries(test_assert PRIVATE ${EXTRA_LIBS} ) +target_include_directories(test_assert PRIVATE + "${PROJECT_BINARY_DIR}" + ${EXTRA_INCLUDES} + ) + + + diff --git a/test/test_assert.cpp b/test/test_assert.cpp new file mode 100644 index 0000000..608424d --- /dev/null +++ b/test/test_assert.cpp @@ -0,0 +1,18 @@ + +#include <iostream> +// uncomment to disable assert() +// #define NDEBUG +#include <cassert> + +// Use (void) to silent unused warnings. +#define assertm(exp, msg) assert(((void)msg, exp)) + +int main() +{ + assert(2+2==4); + std::cout << "Execution continues past the first assert\n"; + // assertm(2+2==5, "There are five lights"); + // std::cout << "Execution continues past the second assert\n"; + assert((2*2==4) && "Yet another way to add assert message"); + assert(("There are five lights", 2 + 2 == 5)); +} \ No newline at end of file -- Gitblit v1.8.0