wangzhengquan
2020-12-01 e994d555ba64d68d874099ed7c1b9e22c0b592b0
test_socket/dgram_mod_req_rep.c
@@ -1,5 +1,5 @@
#include "dgram_mod_socket.h"
#include "shm_mm.h"
#include "shm_mm_wraper.h"
#include "usg_common.h"
#include "lock_free_queue.h"
@@ -72,6 +72,20 @@
  dgram_mod_close_socket(socket);
}
void client2(int port) {
  void *socket = dgram_mod_open_socket();
  int size;
  void *recvbuf;
  char sendbuf[512];
  while (true) {
    sprintf(sendbuf, "hello\n" );
    dgram_mod_sendandrecv(socket, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &size);
    printf("reply: %s\n", (char *)recvbuf);
    free(recvbuf);
  }
  dgram_mod_close_socket(socket);
}
void *runclient(void *arg) {
@@ -136,7 +150,7 @@
 
int main(int argc, char *argv[]) {
  shm_init(512);
  shm_mm_wrapper_init(512);
  int port;
  if (argc < 3) {
    fprintf(stderr, "Usage: reqrep %s|%s <PORT> ...\n", "server", "client");
@@ -146,13 +160,16 @@
  port = atoi(argv[2]);
  if (strcmp("server", argv[1]) == 0) {
    int temp = shm_alloc_key();
    printf("tmp=%d\n", temp);
    server(temp);
  }
  if (strcmp("client", argv[1]) == 0)
    // int temp = shm_mm_wrapper_alloc_key();
    // printf("tmp=%d\n", temp);
    server(port);
  } else if (strcmp("mclient", argv[1]) == 0) {
    startClients(port);
  } else if (strcmp("client", argv[1]) == 0) {
    client(port);
  } else {
    printf("input invalidate arguments\n");
  }
  
  return 0;