ctorrent stat collector
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.
 
 

51 lines
1.1 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "configfile.h"
  5. #include "connection.h"
  6. #include "event.h"
  7. #include "httpd.h"
  8. #include "list.h"
  9. #include "logging.h"
  10. #include "sockaddr.h"
  11. #include "tcpsocket.h"
  12. static int listen_cb(const char *parameter, void *privdata)
  13. {
  14. struct sockaddr_in addr;
  15. if (parse_sockaddr(parameter, &addr) < 0) {
  16. log_print(LOG_WARN, "listen_cb(): invalid address");
  17. return -1;
  18. }
  19. int sockfd = tcp_listen(&addr);
  20. if (sockfd < 0) {
  21. log_print(LOG_WARN, "listen_cb(): tcp_listen()");
  22. return -1;
  23. }
  24. log_print(LOG_INFO, "listen on %s", get_sockaddr_buf(&addr));
  25. event_add_readfd(NULL, sockfd, privdata, NULL);
  26. return 0;
  27. }
  28. int main(int argc, char *argv[])
  29. {
  30. if (config_parse("torrent-stats.conf") < 0)
  31. return 1;
  32. config_get_strings("global", "listen", listen_cb, ctcs_accept_handler);
  33. config_get_strings("global", "listen-http", listen_cb, httpd_accept_handler);
  34. httpd_add_cb("/quit", 0, ctcs_httpd_quit, NULL);
  35. httpd_add_cb("/", 1, ctcs_httpd_show, NULL);
  36. struct timeval tv = { .tv_sec = 10, .tv_usec = 0 };
  37. event_add_timeout(&tv, ctcs_trigger_status, NULL);
  38. event_loop();
  39. return 0;
  40. }