wangzhengquan
2021-01-25 6de74d5e60a9a5ecd417a5473a3b567e51ca2de8
update
5个文件已修改
51 ■■■■ 已修改文件
include/usgcommon/logger.h 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/libusgcommon.a 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/shm_socket.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_net_socket/test_net_mod_socket.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_socket/bus_test.cpp 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
include/usgcommon/logger.h
@@ -16,32 +16,7 @@
  LoggerConfig config;
  FILE *logFile;
  void dolog(const char *fmt, va_list ap, int level, int err = 0) {
    char buf[MAXLINE];
    struct timeval tv;
    struct tm *info;
    gettimeofday(&tv, NULL);
    info = localtime(&tv.tv_sec);
    strftime(buf, MAXBUF - 1, "%Y-%d-%m %H:%M:%S", info);
    snprintf(buf + strlen(buf), MAXBUF - strlen(buf) - 1, ",%ld [%s] ",  tv.tv_usec, strlevel(level));
    vsnprintf(buf + strlen(buf), MAXBUF - strlen(buf) - 1, fmt, ap);
    if (err != 0) {
      snprintf(buf + strlen(buf), MAXBUF - strlen(buf) - 1, ": %s", strerror(err));
    }
    strcat(buf, "\n");
    fflush(stdout); /* in case stdout and stderr are the same */
    if(logFile != NULL) {
      fputs(buf, logFile);
    }
    if(config.console) {
       fputs(buf, stdout);
    }
    fflush(NULL); /* flushes all stdio output streams */
  }
  void dolog(const char *fmt, va_list ap, int level, int err = 0);
  
  void init();
lib/libusgcommon.a
Binary files differ
src/socket/shm_socket.cpp
@@ -384,9 +384,6 @@
  }
}
int shm_recvfrom2(shm_socket_t *socket, void **buf, int *size, int *key,  const struct timespec *timeout,  int flag) {
  return 501;
}
// 短连接方式接受
int shm_recvfrom(shm_socket_t *sokt, void **buf, int *size, int *key,  const struct timespec *timeout,  int flag) {
@@ -423,9 +420,7 @@
  shm_msg_t src;
 
printf ("====== before ======\n");
  rv = sokt->queue->pop(src, timeout, flag);
printf ("====== after ======\n %d", rv);
  if (rv == 0) {
    if(buf != NULL) {
test_net_socket/test_net_mod_socket.cpp
@@ -268,7 +268,7 @@
    sprintf(sendbuf, "thread(%d) %d", targ->id, i);
    fprintf(fp, "requst:%s\n", sendbuf);
    // n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size);
     n = net_mod_socket_sendandrecv_timeout(client, node_arr, node_arr_size, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 1000);
    n = net_mod_socket_sendandrecv_timeout(client, node_arr, node_arr_size, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 1000);
    printf("send %d nodes\n", n);
    for(j=0; j < recv_arr_size; j++) {
        fprintf(fp, "reply: host:%s, port: %d, key:%d, content: %s\n", 
test_socket/bus_test.cpp
@@ -23,7 +23,7 @@
}
void *run_recv2(void *skptr) {
void *run_recv(void *skptr) {
  pthread_detach(pthread_self());
  void *recvbuf;
  int size;
@@ -35,7 +35,8 @@
  while (true) {
    printf("run_recv before\n");
    rv = sk->recvfrom_timeout( &recvbuf, &size, &key, &timeout);
    // rv = sk->recvfrom_timeout( &recvbuf, &size, &key, &timeout);
    rv = sk->recvfrom( &recvbuf, &size, &key);
    if(rv == 0) {
      printf("收到订阅消息:%s\n", recvbuf);
      free(recvbuf);
@@ -48,10 +49,11 @@
  
}
void *run_recv(void *skptr) {
void *run_recv2(void *skptr) {
  pthread_detach(pthread_self());
  while(true) {
    logger->debug("================run_recv\n");
    sleep(1);
    // sleep(1);
  }
}
@@ -77,9 +79,10 @@
  while (true) {
    //printf("Usage: pub <topic> [content] or sub <topic>\n");
    printf("Can I help you? sub, pub, desub or quit %d\n", i++);
    // sleep(100);
    scanf("%s", action);
    printf("client 1\n");
    // scanf("%s", action);
    std::cin >> action;
    printf("client 2\n");
    if(strcmp(action, "sub") == 0) {
      printf("Please input topic!\n");
      scanf("%s", topic);