options-example.c (1560B)
1 /* examples/options-example.c */ 2 3 #include <microhttpd2.h> 4 #include <assert.h> 5 6 7 static struct MHD_Action * 8 handle_request (void *cls, 9 struct MHD_Request *request, 10 const struct MHD_String *path, 11 enum MHD_HTTP_Method method, 12 uint_fast64_t upload_size) 13 { 14 struct MHD_String *host; 15 16 /* We passed NULL in main() for the closure */ 17 assert (NULL == cls); 18 /* This simply closes the connection after receiving 19 the HTTP header, never return actually returning 20 any data. */ 21 return MHD_action_abort_request (request); 22 } 23 24 25 int 26 main () 27 { 28 struct MHD_Daemon *d; 29 static const struct MHD_DaemonOptionAndValue bind_opt 30 = MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, 31 80); 32 33 /* Create an HTTP server and use "handle_request()" to 34 handle all requests. */ 35 d = MHD_daemon_create (&handle_request, 36 NULL); 37 if (MHD_SC_OK != 38 MHD_DAEMON_SET_OPTIONS (d, 39 MHD_D_OPTION_LISTEN_BACKLOG (5), 40 MHD_D_OPTION_SUPPRESS_DATE_HEADER ())) 41 fprintf (stderr, 42 "That's OK, we don't care too much about these\n"); 43 if (MHD_SC_OK != 44 MHD_daemon_set_option (d, 45 &bind_opt)) 46 { 47 fprintf (stderr, 48 "Failed to set port to bind to!\n"); 49 MHD_daemon_stop (d); 50 return 1; 51 } 52 MHD_daemon_start (d); 53 /* Wait for input on stdin */ 54 (void) getchar (); 55 /* Then just shut everything down */ 56 MHD_daemon_stop (d); 57 return 0; 58 }