| | |
| | | |
| | | struct argument_t { |
| | | bool interactive; |
| | | bool force; |
| | | int bind; |
| | | int port; |
| | | int key; |
| | | char *sendlist; |
| | |
| | | } |
| | | } |
| | | |
| | | void start_reply(int mkey) { |
| | | void start_recvfrom(int mkey, bool force) { |
| | | logger->debug("start reply\n"); |
| | | signal(SIGINT, stop_replyserver_handler); |
| | | signal(SIGTERM, stop_replyserver_handler); |
| | | |
| | | serverSockt = net_mod_socket_open(); |
| | | net_mod_socket_bind(serverSockt, mkey); |
| | | if(force) { |
| | | net_mod_socket_force_bind(serverSockt, mkey); |
| | | } else { |
| | | net_mod_socket_bind(serverSockt, mkey); |
| | | } |
| | | |
| | | |
| | | int rv = 0 ; |
| | | while( true) { |
| | |
| | | if(rv == EBUS_STOPED) { |
| | | logger->debug("Stopping\n"); |
| | | break; |
| | | } else if(rv == EBUS_KEY_INUSED){ |
| | | printf("key已经被占用\n"); |
| | | exit(1); |
| | | } |
| | | logger->debug("net_mod_socket_recvandsend error.%s\n", bus_strerror(rv)); |
| | | |
| | |
| | | void list () { |
| | | LockFreeQueue<shm_packet_t> * mqueue; |
| | | hashtable_t *hashtable = mm_get_hashtable(); |
| | | printf("%10s \t %10s\n", "KEY", "LENGTH"); |
| | | printf("%10s \t %-10s \t %10s\n", "KEY", "LENGTH", "STATUS"); |
| | | hashtable_foreach(hashtable, [&](int key, void * value){ |
| | | if(key >= 100 ) { |
| | | mqueue = (LockFreeQueue<shm_packet_t> *)hashtable_get(hashtable, key); |
| | | printf("%d\n", key); |
| | | printf("%10d \t %10d\n", key, mqueue->size()); |
| | | if((long)mqueue == 0x1) { |
| | | printf("%10d \t %-10s\n", key, "Not In Used"); |
| | | } else { |
| | | printf("%10d \t %-10d\n", key, mqueue->size()); |
| | | } |
| | | |
| | | } else { |
| | | printf("%10d \t %10s\n", key, ""); |
| | | printf("%10d\n", key); |
| | | } |
| | | |
| | | }); |
| | |
| | | net_node_t node_arr[] = {NULL, 0, key}; |
| | | |
| | | void * client = net_mod_socket_open(); |
| | | n = net_mod_socket_sendandrecv_timeout(client, node_arr, 1, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 5); |
| | | n = net_mod_socket_sendandrecv_timeout(client, node_arr, 1, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 5000); |
| | | if(n == 0) { |
| | | printf("send failed\n"); |
| | | return; |
| | |
| | | fpe("# remove key 1001\n"); |
| | | fpe("./shm_util rm 1001\n"); |
| | | fpe("./shm_util info 1002\n"); |
| | | fpe("./shm_util recvfrom --bind 1002 [--force]\n") |
| | | fpe("\n"); |
| | | } |
| | | |
| | |
| | | {"key", required_argument, 0, 'k'}, |
| | | {"port", required_argument, 0, 'p'}, |
| | | {"interactive", no_argument, 0, 'i'}, |
| | | {"force", no_argument, 0, 'f'}, |
| | | {"bind", required_argument, (int *)mopt.bind, 0}, |
| | | {"sendlist", required_argument, (int *)mopt.sendlist, 0}, |
| | | {"publist", required_argument, (int *)mopt.publist, 0}, |
| | | {0, 0, 0, 0} |
| | |
| | | { |
| | | |
| | | |
| | | c = getopt_long (argc, argv, "+f:k:p:i", long_options, &option_index); |
| | | c = getopt_long (argc, argv, "+fk:p:i", long_options, &option_index); |
| | | |
| | | /* Detect the end of the options. */ |
| | | if (c == -1) |
| | |
| | | else if(strcmp(long_options[option_index].name, "publist") == 0) { |
| | | mopt.publist = optarg; |
| | | } |
| | | else if(strcmp(long_options[option_index].name, "bind") == 0) { |
| | | mopt.bind = atoi(optarg); |
| | | } |
| | | else { |
| | | printf ("option %s", long_options[option_index].name); |
| | | if (optarg) |
| | |
| | | |
| | | case 'i': |
| | | mopt.interactive = true; |
| | | break; |
| | | |
| | | case 'f': |
| | | mopt.force = true; |
| | | break; |
| | | |
| | | case 'p': |
| | |
| | | int i; |
| | | char *prog; |
| | | char * fun; |
| | | argument_t opt; |
| | | argument_t opt = {}; |
| | | |
| | | shm_mm_wrapper_init(512); |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | else if (strcmp("start_reply", fun) == 0) { |
| | | else if (strcmp("recvfrom", fun) == 0) { |
| | | opt = parse_args(argc, argv); |
| | | if(opt.key == 0) { |
| | | if(opt.bind == 0) { |
| | | usage(argv[0]); |
| | | exit(1); |
| | | } else { |
| | | start_recvfrom(opt.bind, opt.force); |
| | | } |
| | | start_reply(opt.key); |
| | | |
| | | } |
| | | else if (strcmp("start_net_client", fun) == 0) { |
| | | opt = parse_args(argc, argv); |