View Issue Details

IDProjectCategoryView StatusLast Update
0001679libmicrohttpdotherpublic2011-05-20 22:19
Reportertommie Assigned ToChristian Grothoff  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.10 
Summary0001679: MHD_create_response_from_fd(_at_offset) does not complete in chunked mode.
DescriptionReading the code of src/daemon/response.c, I would expect

  MHD_create_response_from_fd(MHD_SIZE_UNKNOWN, ...)

to work since MHD_c_r_f_callback() allows MHD_SIZE_UNKNOWN. When testing, however, it seems that the response never completes. Data is transferred, but the final (empty) chunk is nowhere to be seen.

Looking at file_reader, I think the EOF case isn't handled correctly.
Simply returning the result of read(2) will not use the special MHD_CONTENT_READER_* values.

Given that the FD is in blocking mode, I suggest applying the attached patch. Adding a clarifying comment to MHD_c_r_f_fd(_at_offset) about the need for blocking mode is probably a nice extra.
Additional InformationTested on Linux 2.6 with internal select.
TagsNo tags attached.
Attached Files
response_fd.patch (534 bytes)   
Index: src/daemon/response.c
===================================================================
--- src/daemon/response.c	(revision 15147)
+++ src/daemon/response.c	(working copy)
@@ -272,7 +272,10 @@
   struct MHD_Response *response = cls;
 
   (void) lseek (response->fd, pos + response->fd_off, SEEK_SET);
-  return read (response->fd, buf, max);
+  ssize_t n = read (response->fd, buf, max);
+  if (n == 0) return MHD_CONTENT_READER_END_OF_STREAM;
+  if (n < 0) return MHD_CONTENT_READER_END_WITH_ERROR;
+  else return n;
 }
 
 
response_fd.patch (534 bytes)   

Activities

Christian Grothoff

2011-05-08 21:55

manager   ~0004326

Fixed as suggested in SVN 15192.

Issue History

Date Modified Username Field Change
2011-05-08 12:25 tommie New Issue
2011-05-08 12:25 tommie File Added: response_fd.patch
2011-05-08 21:55 Christian Grothoff Note Added: 0004326
2011-05-08 21:55 Christian Grothoff Status new => resolved
2011-05-08 21:55 Christian Grothoff Resolution open => fixed
2011-05-08 21:55 Christian Grothoff Assigned To => Christian Grothoff
2011-05-20 22:19 Christian Grothoff Status resolved => closed