Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <cstdio>
  3. #include <csignal>
  4.  
  5. #include "webserver.hpp"
  6.  
  7. void handle_signal(int)
  8. {
  9.     printf("Caught signal\n");
  10. }
  11.  
  12. void myfunc(server * s, server::client_context ctx)
  13. {
  14.     printf("Recieved request for \"%s\"\n", ctx->get_request_url().c_str());
  15.  
  16.     ctx->queue_response(s, http::code::ok, "OK", "It works!\n");
  17. }
  18.  
  19. int main()
  20. {
  21.     signal(SIGINT, handle_signal);
  22.  
  23.     server s;
  24.  
  25.     printf("adding\n");
  26.     s.add_listening_address("localhost", 10001);
  27.     printf("removing\n");
  28.     s.remove_listening_address("localhost", 10001);
  29.  
  30.     fflush(stdout);
  31.  
  32.     std::this_thread::sleep_for(std::chrono::seconds(1));
  33.  
  34.     printf("adding next set\n");
  35.  
  36.     s.add_listening_address("", 10001);
  37.  
  38.     s.add_endpoint("/metrics", myfunc);
  39.  
  40.     pause();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement