aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/minimal_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/minimal_example.c')
-rw-r--r--src/daemon/minimal_example.c67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/daemon/minimal_example.c b/src/daemon/minimal_example.c
index 10b54aac..8de0064e 100644
--- a/src/daemon/minimal_example.c
+++ b/src/daemon/minimal_example.c
@@ -35,50 +35,43 @@
35 35
36#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 36#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
37 37
38static int ahc_echo(void * cls, 38static int
39 struct MHD_Connection * connection, 39ahc_echo (void *cls,
40 const char * url, 40 struct MHD_Connection *connection,
41 const char * method, 41 const char *url,
42 const char * upload_data, 42 const char *method,
43 const char * version, 43 const char *upload_data,
44 unsigned int * upload_data_size) { 44 const char *version, unsigned int *upload_data_size)
45 const char * me = cls; 45{
46 struct MHD_Response * response; 46 const char *me = cls;
47 struct MHD_Response *response;
47 int ret; 48 int ret;
48 49
49 if (0 != strcmp(method, "GET")) 50 if (0 != strcmp (method, "GET"))
50 return MHD_NO; /* unexpected method */ 51 return MHD_NO; /* unexpected method */
51 response = MHD_create_response_from_data(strlen(me), 52 response = MHD_create_response_from_data (strlen (me),
52 (void*) me, 53 (void *) me, MHD_NO, MHD_NO);
53 MHD_NO, 54 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
54 MHD_NO); 55 MHD_destroy_response (response);
55 ret = MHD_queue_response(connection,
56 MHD_HTTP_OK,
57 response);
58 MHD_destroy_response(response);
59 return ret; 56 return ret;
60} 57}
61 58
62int main(int argc, 59int
63 char * const * argv) { 60main (int argc, char *const *argv)
64 struct MHD_Daemon * d; 61{
62 struct MHD_Daemon *d;
65 63
66 if (argc != 3) { 64 if (argc != 3)
67 printf("%s PORT SECONDS-TO-RUN\n", 65 {
68 argv[0]); 66 printf ("%s PORT SECONDS-TO-RUN\n", argv[0]);
69 return 1; 67 return 1;
70 } 68 }
71 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 69 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
72 atoi(argv[1]), 70 atoi (argv[1]),
73 NULL, 71 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
74 NULL,
75 &ahc_echo,
76 PAGE,
77 MHD_OPTION_END);
78 if (d == NULL) 72 if (d == NULL)
79 return 1; 73 return 1;
80 sleep(atoi(argv[2])); 74 sleep (atoi (argv[2]));
81 MHD_stop_daemon(d); 75 MHD_stop_daemon (d);
82 return 0; 76 return 0;
83} 77}
84