wangzhengquan
2021-01-22 91ea20d03ebb5a8d20150d3ecc28a13c51ce93f1
update
4个文件已修改
28 ■■■■ 已修改文件
CMakeLists.txt 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/shm_mod_socket.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/svsem.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_socket/bus_test.cpp 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CMakeLists.txt
@@ -13,15 +13,13 @@
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
if (CMAKE_BUILD_TYPE EQUAL "Release")
#option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
endif()
option(BUILD_DOC "Build doc" OFF)
list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/include/usgcommon")
list(APPEND EXTRA_LIBS ${PROJECT_SOURCE_DIR}/lib/libusgcommon.a pthread rt)
list(APPEND EXTRA_LIBS ${PROJECT_SOURCE_DIR}/lib/libusgcommon.a rt pthread )
# build api doc
src/socket/shm_mod_socket.cpp
@@ -69,12 +69,12 @@
// 接受信息超时返回。 @sec 秒 , @nsec 纳秒
int ShmModSocket::recvfrom_timeout( void **buf, int *size, int *key, struct timespec *timeout) {
    int rv =  shm_recvfrom(shm_socket, buf, size, key, timeout, 0);
    int rv =  shm_recvfrom(shm_socket, buf, size, key, timeout, BUS_TIMEOUT_FLAG);
     return rv;
}
int ShmModSocket::recvfrom_nowait( void **buf, int *size, int *key){
    int rv =  shm_recvfrom(shm_socket, buf, size, key, NULL, (int)BUS_NOWAIT_FLAG);
    int rv =  shm_recvfrom(shm_socket, buf, size, key, NULL, BUS_NOWAIT_FLAG);
    // logger->error(rv, "ShmModSocket::recvfrom_nowait failed!");
  return rv;
}
src/svsem.cpp
@@ -96,7 +96,7 @@
  sops.sem_op = -1;
  sops.sem_flg = IPC_NOWAIT | 0;
  while (semop(semid, &sops, 1) == -1)
  if (semop(semid, &sops, 1) == -1)
    if (errno != EINTR) {
      // err_msg(errno, "svsem_dec_nowait");
      return errno;
test_socket/bus_test.cpp
@@ -24,14 +24,30 @@
  void *recvbuf;
  int size;
  int key;
  int rv;
  ShmModSocket *sk = (ShmModSocket *)skptr;
printf("run_recv\n");
  struct timespec timeout = {2, 0};
  while ( true) {
    sk->recvfrom( &recvbuf, &size, &key);
    printf("run_recv before\n");
    rv = sk->recvfrom_timeout( &recvbuf, &size, &key, &timeout);
    if(rv == 0) {
    printf("收到订阅消息:%s\n", recvbuf);
    free(recvbuf);
    } else {
      printf("recvfrom error %d\n", rv);
  }
  
}
  return NULL;
}
void client2(int key) {
  ShmModSocket *sk = new ShmModSocket();
  run_recv((void *)sk);
}
void client(int key) {
  ShmModSocket *sk = new ShmModSocket();