aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon/Makefile.am13
-rw-r--r--src/daemon/daemon.c2
-rw-r--r--src/daemon/minimal_example.c86
3 files changed, 99 insertions, 2 deletions
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 6cf42f56..c86ed072 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -15,7 +15,18 @@ libmicrohttpd_la_SOURCES = \
15 response.c response.h \ 15 response.c response.h \
16 session.c session.h 16 session.c session.h
17 17
18# No curl, not testcases 18
19# example programs
20
21noinst_PROGRAMS = minimal_example
22
23minimal_example_SOURCES = \
24 minimal_example.c
25minimal_example_LDADD = \
26 $(top_builddir)/src/daemon/libmicrohttpd.la
27
28
29# No curl, no testcases
19if HAVE_CURL 30if HAVE_CURL
20 31
21check_PROGRAMS = \ 32check_PROGRAMS = \
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 58e2e058..1b882a08 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -504,7 +504,7 @@ MHD_start_daemon(unsigned int options,
504 (0 != pthread_create(&retVal->pid, 504 (0 != pthread_create(&retVal->pid,
505 NULL, 505 NULL,
506 &MHD_select_thread, 506 &MHD_select_thread,
507 daemon)) ) { 507 retVal)) ) {
508 MHD_DLOG(retVal, 508 MHD_DLOG(retVal,
509 "Failed to create listen thread: %s\n", 509 "Failed to create listen thread: %s\n",
510 strerror(errno)); 510 strerror(errno));
diff --git a/src/daemon/minimal_example.c b/src/daemon/minimal_example.c
new file mode 100644
index 00000000..189c557e
--- /dev/null
+++ b/src/daemon/minimal_example.c
@@ -0,0 +1,86 @@
1/*
2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff
4
5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file minimal_example.c
23 * @brief minimal example for how to use libmicrohttpd
24 * @author Christian Grothoff
25 */
26
27#include "config.h"
28#include <microhttpd.h>
29#include <stdlib.h>
30#include <unistd.h>
31#include <string.h>
32#include <stdio.h>
33
34#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
35
36static int apc_all(void * cls,
37 const struct sockaddr * addr,
38 socklen_t addrlen) {
39 return MHD_YES;
40}
41
42static int ahc_echo(void * cls,
43 struct MHD_Session * session,
44 const char * url,
45 const char * method,
46 const char * upload_data,
47 unsigned int * upload_data_size) {
48 const char * me = cls;
49 struct MHD_Response * response;
50 int ret;
51
52 if (0 != strcmp(me, "GET"))
53 return MHD_NO; /* unexpected method */
54 response = MHD_create_response_from_data(strlen(me),
55 (void*) me,
56 MHD_NO,
57 MHD_NO);
58 ret = MHD_queue_response(session,
59 MHD_HTTP_OK,
60 response);
61 MHD_destroy_response(response);
62 return ret;
63}
64
65int main(int argc,
66 char * const * argv) {
67 struct MHD_Daemon * d;
68
69 if (argc != 3) {
70 printf("%s PORT SECONDS-TO-RUN\n",
71 argv[0]);
72 return 1;
73 }
74 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv4 | MHD_USE_DEBUG,
75 atoi(argv[1]),
76 &apc_all,
77 NULL,
78 &ahc_echo,
79 PAGE);
80 if (d == NULL)
81 return 1;
82 sleep(atoi(argv[2]));
83 MHD_stop_daemon(d);
84 return 0;
85}
86