libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] Waiting daemon thread in main


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Waiting daemon thread in main
Date: Wed, 10 Jun 2015 23:53:49 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0

The most trivial hack you can do is replace 'getchar()' with
sleep(-1).  That should work for the minimal requirements you formulate.

Cleaner implementations would install a signal handler (sigaction()) and
send a message through a pipe(2) to unblock.

Happy hacking!

Christian

On 06/10/2015 06:26 PM, Joan Puigcerver wrote:
> 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.
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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