//线程池中每个线程的执行函数 void* pthread_do_detail(void *arg) { ppool_data* data = (ppool_data*) arg; while(1) { if(data->enable == 1) { usleep(100); continue; } else if(data->using_fd == -1) { printf("using_fd error\n"); data->enable = 1; } else { //读取和写入数据 do_detail(data->using_fd); //读取和写入数据结束后,要将条件复原 data->enable = 1; data->using_fd = -1; listen_num--; printf("clear pthread, listened: [%d]\n", listen_num); } } return NULL; }
int main(int argc, char *const *argv) { int mode = MODE_SEND_MSG; int c; int rv; const char *detail = NULL; const char *usermsg = NULL; ckl_conf_t *conf = calloc(1, sizeof(ckl_conf_t)); curl_global_init(CURL_GLOBAL_ALL); while ((c = getopt(argc, argv, "hVslm:d:")) != -1) { switch (c) { case 'V': show_version(); break; case 'h': show_help(); break; case 'l': mode = MODE_LIST; break; case 'd': mode = MODE_DETAIL; detail = optarg; break; case 'm': usermsg = optarg; break; case 's': conf->script_mode = 1; break; case '?': ckl_error_out("See -h for correct options"); break; } } rv = ckl_conf_init(conf); if (rv < 0) { ckl_error_out("conf_init failed"); } switch (mode) { case MODE_SEND_MSG: rv = do_send_msg(conf, usermsg); break; case MODE_LIST: rv = do_list(conf); break; case MODE_DETAIL: rv = do_detail(conf, detail); break; } ckl_conf_free(conf); curl_global_cleanup(); return rv; }