wangzhengquan
2021-01-30 29ed03b11b4d39f36f602ed7b2f73714214470ed
update
1个文件已添加
6个文件已修改
137 ■■■■■ 已修改文件
CMakeLists.txt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/CMakeLists.txt 75 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/logger_factory.cpp 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/logger_factory.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/shm_socket.cpp 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/CMakeLists.txt 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_assert.cpp 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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)
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)
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!");
  }
}
src/logger_factory.h
@@ -10,7 +10,6 @@
public:
    static Logger* getLogger();
    static void error(int s);
};
#endif
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);
}
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}
                            )
test/test_assert.cpp
New file
@@ -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));
}