| | |
| | | |
| | | }Targ; |
| | | |
| | | LockFreeQueue<task_t, DM_Allocator> task_queue(100); |
| | | LockFreeQueue<task_t, DM_Allocator> task_queue(128); |
| | | |
| | | |
| | | void *worker(void *socket) { |
| | |
| | | } |
| | | |
| | | void server(int port) { |
| | | void *socket = dgram_mod_open_socket(REQ_REP); |
| | | void *socket = dgram_mod_open_socket(); |
| | | dgram_mod_bind(socket, port); |
| | | initThreadPool(socket); |
| | | |
| | |
| | | } |
| | | |
| | | void client(int port) { |
| | | void *socket = dgram_mod_open_socket(REQ_REP); |
| | | void *socket = dgram_mod_open_socket(); |
| | | int size; |
| | | void *recvbuf; |
| | | char sendbuf[512]; |
| | | while (true) { |
| | | printf("request: "); |
| | | scanf("%s", sendbuf); |
| | | 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 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); |
| | |
| | | char sendbuf[512]; |
| | | int scale = 100000; |
| | | int i; |
| | | void *socket = dgram_mod_open_socket(REQ_REP); |
| | | void *socket = dgram_mod_open_socket(); |
| | | |
| | | char filename[512]; |
| | | sprintf(filename, "test%d.txt", targ->id); |
| | | sprintf(filename, "test%d.tmp", targ->id); |
| | | FILE *fp = NULL; |
| | | fp = fopen(filename, "w+"); |
| | | |
| | |
| | | |
| | | double difftime = end.tv_sec * 1000000 + end.tv_usec - (start.tv_sec * 1000000 + start.tv_usec); |
| | | long diffsec = (long) (difftime/1000000); |
| | | long diffmsec = difftime - diffsec; |
| | | long diffmsec = difftime - diffsec*1000000; |
| | | printf("cost: %ld sec: %ld msc\n", diffsec, diffmsec); |
| | | } |
| | | |
| | |
| | | port = atoi(argv[2]); |
| | | |
| | | if (strcmp("server", argv[1]) == 0) { |
| | | // int temp = shm_alloc_key(); |
| | | // printf("tmp=%d\n", temp); |
| | | server(port); |
| | | } |
| | | |
| | | if (strcmp("client", argv[1]) == 0) |
| | | } 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; |