wangzhengquan
2020-12-02 0c4748cdeb4b9f4c36f4222ccc1652d4d486cb0c
test_socket/dgram_mod_req_rep.c
@@ -20,7 +20,7 @@
}Targ;
LockFreeQueue<task_t, DM_Allocator> task_queue(128);
void *client;
void *worker(void *socket) {
   pthread_detach(pthread_self());
@@ -57,7 +57,7 @@
  dgram_mod_close_socket(socket);
}
void client(int port) {
void startClient(int port) {
  void *socket = dgram_mod_open_socket();
  int size;
  void *recvbuf;
@@ -94,7 +94,7 @@
  char sendbuf[512];
  int scale = 100000;
  int i;
  void *socket = dgram_mod_open_socket();
   
   char filename[512];
   sprintf(filename, "test%d.tmp", targ->id);
@@ -106,12 +106,12 @@
  for (i = 0; i < scale; i++) {
    sprintf(sendbuf, "thread(%d) %d", targ->id, i);
    fprintf(fp, "requst:%s\n", sendbuf);
    dgram_mod_sendandrecv(socket, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &recvsize);
    dgram_mod_sendandrecv(client, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &recvsize);
      fprintf(fp, "reply: %s\n", (char *)recvbuf);
      free(recvbuf);
  }
  fclose(fp);
  dgram_mod_close_socket(socket);
  return (void *)i;
}
@@ -124,6 +124,9 @@
  char sendbuf[512];
  struct timeval start;
  client = dgram_mod_open_socket();
  gettimeofday(&start, NULL);
  for (i = 0; i < processors; i++) {
    targs[i].port = port;
@@ -146,6 +149,7 @@
  long diffsec = (long) (difftime/1000000);
  long diffmsec = difftime - diffsec*1000000;
  printf("cost: %ld sec: %ld msc\n", diffsec, diffmsec);
  dgram_mod_close_socket(client);
}
 
@@ -166,7 +170,7 @@
  } else if (strcmp("mclient", argv[1]) == 0) {
    startClients(port);
  } else if (strcmp("client", argv[1]) == 0) {
    client(port);
    startClient(port);
  } else {
    printf("input invalidate arguments\n");
  }