libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] Waiting daemon thread in main


From: Joan Puigcerver
Subject: [libmicrohttpd] Waiting daemon thread in main
Date: Wed, 10 Jun 2015 18:26:55 +0200

Hi,

I am trying to use libmicrohttpd to build a small HTTP server to run
in background in my Linux system. Right now, this is the structure of
the main function of my server:

----------
struct MHD_Daemon *daemon;
daemon = MHD_start_daemon(
      MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION |
      MHD_USE_SELECT_INTERNALLY,
      port_, NULL, NULL, &answer_to_connection, index_,
      MHD_OPTION_THREAD_POOL_SIZE, 8,
      MHD_OPTION_CONNECTION_TIMEOUT, 120,
      MHD_OPTION_END);
if (NULL == daemon) return 1;
getchar();
MHD_stop_daemon (daemon);
return 0;
----------

However, the previous approach does not work when I try to launch the
server in background, since getchar() read an EOF and the server
terminates. I just want to hang the main thread until the process is
killed (kill -9 or Ctrl+C).

I tried to do:

pthread_join(daemon->pid);

But MHD_Daemon is only declared in "microhttpd.h", and it is defined
in some other file, so I cannot access the pid attribute.

So, what is the proper way to do what I want?

Many thanks,
Joan.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]