int main(int argc, char **argv) { thread thread_obj; /* Allocate the room */ req = (REQ *) MALLOC(sizeof (REQ)); /* Command line parser */ if (!parse_cmdline(argc, argv, req)) { FREE(req); exit(0); } /* Check minimum configuration need */ if (!req->addr_ip && !req->addr_port && !req->url) { FREE(req); exit(0); } /* Init the reference timer */ req->ref_time = timer_tol(timer_now()); DBG("Reference timer = %lu\n", req->ref_time); /* Init SSL context */ init_ssl(); /* Signal handling initialization */ signal_init(); /* Create the master thread */ master = thread_make_master(); /* Register the GET request */ init_sock(); /* * Processing the master thread queues, * return and execute one ready thread. * Run until error, used for debuging only. * Note that not calling launch_scheduler() does * not activate SIGCHLD handling, however, this * is no issue here. */ while (thread_fetch(master, &thread_obj)) thread_call(&thread_obj); /* Finalize output informations */ if (req->verbose) printf("Global response time for [%s] =%lu\n", req->url, req->response_time - req->ref_time); /* exit cleanly */ SSL_CTX_free(req->ctx); free_sock(sock); FREE(req); exit(0); }
/* free allocated pieces */ static void free_all(thread_t * thread) { SOCK *sock_obj = THREAD_ARG(thread); DBG("Total read size read = %d Bytes, fd:%d\n", sock_obj->total_size, sock_obj->fd); if (sock_obj->buffer) FREE(sock_obj->buffer); /* * Decrement the current global get number. * => free the reserved thread */ req->response_time = timer_tol(timer_now()); thread_add_terminate_event(thread->master); }
/* print timer value */ void timer_dump(timeval_t a) { printf("=> %lu (usecs)\n", timer_tol(a)); }