[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] MHD_create_response_from_fd using a pipe
From: |
Denis Dowling |
Subject: |
Re: [libmicrohttpd] MHD_create_response_from_fd using a pipe |
Date: |
Wed, 3 Jun 2015 22:51:02 +0000 |
Hi Christian,
The manual page for popen is fairly explicit that pclose() must be used to
close the FILE returned from popen(). The pclose() call does some extra process
cleanup steps. I cannot see another way of doing this except using a hybrid of
MHD_create_response_from_callback and MHD_create_reponse_from_fd().
Regards,
Denis
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Christian Grothoff
Sent: Wednesday, 3 June 2015 3:58 PM
To: address@hidden
Subject: Re: [libmicrohttpd] MHD_create_response_from_fd using a pipe
On 06/03/2015 03:44 AM, Denis Dowling wrote:
> Then in my code when I want to return data from a process I do
> something like
>
> FILE *pf = popen(cmd, "r");
> int fd = fileno(pf);
>
> response = MHD_create_response_from_callback_fd(-1, 4096,
> &popen_reader, pf, &popen_free, fd);
Just do
int fd = dup (fileno (pf));
fclose (pf);
response = MHD_create_response_from_callback_fd(-1, 4096, &popen_reader, pf,
&popen_free, fd);
and you can avoid the awkward popen_free().
Happy hacking!
-Christian
________________________________
The information contained in this message and any attachments is strictly
confidential and intended solely for the use of the intended recipient(s). The
copyright in this communication belongs to (HSD). This message and any
attachments are confidential and may be subject to legal or other professional
privilege. Any confidentiality or privilege is not waived or lost because this
e-mail has been sent to you by mistake. If you have received this transmission
in error, please notify HSD on +61 3 9875 5900 immediately and destroy all
copies of this e-mail. The contents of this email message may not be quoted,
copied, reproduced or published in part or in whole, without the written
authorisation of HSD.