You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1 KiB

  1. /*
  2. * weighttp - a lightweight and simple webserver benchmarking tool
  3. *
  4. * Author:
  5. * Copyright (c) 2009 Thomas Porzelt
  6. *
  7. * License:
  8. * MIT, see COPYING file
  9. */
  10. #include "weighttp.h"
  11. Worker *worker_new(uint8_t id, Config *config, uint16_t num_clients, uint64_t num_requests) {
  12. Worker *worker;
  13. uint16_t i;
  14. worker = W_MALLOC(Worker, 1);
  15. worker->id = id;
  16. worker->loop = ev_loop_new(0);
  17. ev_ref(worker->loop);
  18. worker->config = config;
  19. worker->num_clients = num_clients;
  20. worker->stats.req_todo = num_requests;
  21. worker->clients = W_MALLOC(Client*, num_clients);
  22. for (i = 0; i < num_clients; i++) {
  23. if (NULL == (worker->clients[i] = client_new(worker)))
  24. return NULL;
  25. }
  26. return worker;
  27. }
  28. void worker_free(Worker *worker) {
  29. uint16_t i;
  30. for (i = 0; i < worker->num_clients; i++)
  31. client_free(worker->clients[i]);
  32. free(worker->clients);
  33. free(worker);
  34. }
  35. void *worker_thread(void* arg) {
  36. uint16_t i;
  37. Worker *worker = (Worker*)arg;
  38. /* start all clients */
  39. for (i = 0; i < worker->num_clients; i++) {
  40. client_state_machine(worker->clients[i]);
  41. }
  42. ev_loop(worker->loop, 0);
  43. ev_loop_destroy(worker->loop);
  44. return NULL;
  45. }