Advertisement
Guest User

Untitled

a guest
Dec 4th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <microhttpd.h>
  2. #include <stdio.h>
  3.  
  4. #define PORT 8080
  5.  
  6. static int answer_to_connection(void *cls, struct MHD_Connection *connection, const char *url, const char *method,
  7.                                 const char *version, const char *upload_data, size_t *upload_data_size,
  8.                                 void **con_cls) {
  9.     const char *page = "<html><body>Hello world!</body></html>";
  10.     struct MHD_Response *response;
  11.     int ret;
  12.     response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_PERSISTENT);
  13.     MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
  14.     ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
  15.     MHD_destroy_response(response);
  16.     return ret;
  17. }
  18.  
  19. int main() {
  20.     struct MHD_Daemon *daemon;
  21.     daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY
  22.                               | MHD_USE_THREAD_PER_CONNECTION // if you comment this line, the problem dies
  23.                               , PORT, NULL, NULL,
  24.                               &answer_to_connection, NULL,
  25.                               MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 3,
  26.                               MHD_OPTION_END);
  27.     if (NULL == daemon)
  28.         return 1;
  29.     getchar();
  30.     MHD_stop_daemon(daemon);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement