Hi Keith (hopping its actually your first name),

Many thanks for pointing at that note on the 
MHD_create_reponse_from_fd_at_offset.
It might be my issue: I'm using the pre-build binaries on a Windows x64 system 
and it seems that those
binaries are compiled for 32 bits Oss.

I'll try to build my own binaries from the source code and see if this fixes my 
problem.
And having seen the email from Emmanual Engehlart I hope it will work ^^.

I'll get back to you if it worked or not,

Bruno Knittel
[email protected]<mailto:[email protected]>
+33 (0)6 88 75 94 32

De : [email protected] 
[mailto:[email protected]] De la part de Keith 
Mendoza
Envoyé : dimanche 20 mai 2012 19:18
À : libmicrohttpd development and user mailinglist
Objet : Re: [libmicrohttpd] Sending file as answer: Closing connection (Stream 
Error)

Bruno,
In the description for MHD_create_response_from_fd_at_offset in the 
libmicrohttpd manual 
(http://www.gnu.org/software/libmicrohttpd/microhttpd.html#microhttpd_002dresponses)
 it states that
Depending on your platform, MHD is likely to have been compiled with support 
for 64-bit files. When you compile your own application, you must make sure 
that off_t is also a 64-bit value

It also provides suggestions on what you can do to make sure that your 
application compiles with the proper off_t size. Some browsers have issues with 
data more than 4GB, and will simply close the TCP connection.

On Sat, May 19, 2012 at 6:11 AM, Bruno Knittel 
<[email protected]<mailto:[email protected]>> wrote:
Hi Everyone,

I'm new to libmicrohttpd and I'm having an issue I don't know at all how to 
start troubleshooting it.
I want to answer an HTTP GET request with the content of a file that is in the 
same directory as my executable.

I'm using the function MHD_create_response_from_fd_at_offset to create the 
MHD_Response.
I already checked the file descriptor and the size information I'm passing to 
this function and it is fine.
I also checked that reading the whole content of the file using the read 
function works.

However my request is not answered (at least the page does not load in the 
browser) and the following is
written to stderr: "Closing connection (stream error)".
At the end of this message you will find an extract of my code.

Do you have some hints about what is going wrong here?
Or ideas how I can troubleshoot this?

Many thanks in advance for your help !

My Code:

int main()
{
// Start the web server
       unsigned int flags = MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG;

       webDaemon = MHD_start_daemon (flags,
                                       80,
                                          NULL,         // No access policy 
handler: connections from any client are allowed
                                          NULL,
                                         &answer_to_connection, // Access 
handler: answers to requests
                                         NULL,
                                         MHD_OPTION_CONNECTION_TIMEOUT,
                                         (unsigned int) 120,
                                         MHD_OPTION_END);

}

int answer_to_connection(void *cls,
                            struct MHD_Connection *connection,
                               const char *url,
                               const char *method,
                               const char *version,
                               const char *upload_data,
                               size_t *upload_data_size,
                               void **ptr)
{
      struct MHD_Response *response = createMhdResponseForFile("index.html", 
"text/html");
      if (response == NULL)
      {
       // TODO Create default HTTP 404 Page
      }

      Int ret = MHD_queue_response(connection, httpStatusCode, response);
       MHD_destroy_response(response);
       return ret;

}


MHD_Response* createMhdResponseForFile(const char* path, const char* mime)
{
       struct stat fileStats;

       int fileDescriptor = open(path, O_RDONLY);
       if (fileDescriptor < 0)
       {
               return NULL;
       }

       if (fstat(fileDescriptor, &fileStats) != 0)
       {
               if (close(fileDescriptor) != 0)
               {
                       // TODO Some logging
               }

               return NULL;
       }

       MHD_Response* result = 
MHD_create_response_from_fd_at_offset(fileStats.st_size,
                                                                                
fileDescriptor,
                                                                                
0);
       MHD_add_response_header(result, "Content-Type", mime);

       return result;
}


Bruno Knittel
[email protected]<mailto:[email protected]>



Reply via email to