gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r13935 - in libmicrohttpd: . doc src/daemon src/include


From: gnunet
Subject: [GNUnet-SVN] r13935 - in libmicrohttpd: . doc src/daemon src/include
Date: Sun, 19 Dec 2010 19:54:44 +0100

Author: grothoff
Date: 2010-12-19 19:54:44 +0100 (Sun, 19 Dec 2010)
New Revision: 13935

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/doc/microhttpd.texi
   libmicrohttpd/src/daemon/daemon.c
   libmicrohttpd/src/daemon/internal.h
   libmicrohttpd/src/daemon/response.c
   libmicrohttpd/src/include/microhttpd.h
Log:
support for sendfile with offset

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2010-12-19 18:27:51 UTC (rev 13934)
+++ libmicrohttpd/ChangeLog     2010-12-19 18:54:44 UTC (rev 13935)
@@ -1,3 +1,6 @@
+Sun Dec 19 19:54:15 CET 2010
+       Added 'MHD_create_response_from_fd_at_offset'. -CG
+
 Sun Dec 19 15:16:16 CET 2010
        Fixing --enable and --disable configure options to behave properly. -CG
 

Modified: libmicrohttpd/doc/microhttpd.texi
===================================================================
--- libmicrohttpd/doc/microhttpd.texi   2010-12-19 18:27:51 UTC (rev 13934)
+++ libmicrohttpd/doc/microhttpd.texi   2010-12-19 18:54:44 UTC (rev 13935)
@@ -1287,17 +1287,43 @@
 
 @table @var
 @item size
-size of the data portion of the response, @code{-1} for unknown;
+size of the data portion of the response (should be smaller or equal to the
+size of the file)
 
 @item fd
 file descriptor referring to a file on disk with the data; will be
-closed when response is destroyed
+closed when response is destroyed; note that 'fd' must be an actual 
+file descriptor (not a pipe or socket) since MHD might use 'sendfile' 
+or 'seek' on it
 @end table
 
 Return @mynull{} on error (i.e. invalid arguments, out of memory).
 @end deftypefun
 
 
address@hidden {struct MHD_Response *} MHD_create_response_from_fd_at_offset 
(uint64_t size, int fd, off_t offset)
+Create a response object.  The response object can be extended with
+header information and then it can be used any number of times.
+
address@hidden @var
address@hidden size
+size of the data portion of the response (number of bytes to transmit from the
+file starting at offset).
+
address@hidden fd
+file descriptor referring to a file on disk with the data; will be
+closed when response is destroyed; note that 'fd' must be an actual 
+file descriptor (not a pipe or socket) since MHD might use 'sendfile' 
+or 'seek' on it
+
address@hidden offset
+offset to start reading from in the file
address@hidden table
+
+Return @mynull{} on error (i.e. invalid arguments, out of memory).
address@hidden deftypefun
+
+
 @deftypefun {struct MHD_Response *} MHD_create_response_from_data (size_t 
size, void *data, int must_free, int must_copy)
 Create a response object.  The response object can be extended with
 header information and then it can be used any number of times.

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2010-12-19 18:27:51 UTC (rev 13934)
+++ libmicrohttpd/src/daemon/daemon.c   2010-12-19 18:54:44 UTC (rev 13935)
@@ -701,7 +701,7 @@
        (-1 != (fd = connection->response->fd)) )
     {
       /* can use sendfile */
-      offset = (off_t) connection->response_write_position;
+      offset = (off_t) connection->response_write_position + 
connection->response->fd_off;
       ret = sendfile (connection->socket_fd, 
                      fd,
                      &offset,

Modified: libmicrohttpd/src/daemon/internal.h
===================================================================
--- libmicrohttpd/src/daemon/internal.h 2010-12-19 18:27:51 UTC (rev 13934)
+++ libmicrohttpd/src/daemon/internal.h 2010-12-19 18:54:44 UTC (rev 13935)
@@ -229,6 +229,11 @@
   uint64_t data_start;
 
   /**
+   * Offset to start reading from when using 'fd'.
+   */
+  off_t fd_off;
+
+  /**
    * Size of data.
    */
   size_t data_size;

Modified: libmicrohttpd/src/daemon/response.c
===================================================================
--- libmicrohttpd/src/daemon/response.c 2010-12-19 18:27:51 UTC (rev 13934)
+++ libmicrohttpd/src/daemon/response.c 2010-12-19 18:54:44 UTC (rev 13935)
@@ -273,7 +273,7 @@
   int ret;
 
   pthread_mutex_lock (&response->mutex);
-  (void) lseek (response->fd, pos, SEEK_SET);
+  (void) lseek (response->fd, pos + response->fd_off, SEEK_SET);
   ret = read (response->fd, buf, max);
   pthread_mutex_unlock (&response->mutex);
   return ret;
@@ -301,10 +301,12 @@
  *
  * @param size size of the data portion of the response
  * @param fd file descriptor referring to a file on disk with the data
+ * @param off offset to start reading from in the file
  * @return NULL on error (i.e. invalid arguments, out of memory)
  */
-struct MHD_Response *MHD_create_response_from_fd (size_t size,
-                                                 int fd)
+struct MHD_Response *MHD_create_response_from_fd_at_offset (size_t size,
+                                                           int fd,
+                                                           off_t offset)
 {
   struct MHD_Response *ret;
 
@@ -316,16 +318,34 @@
   if (ret == NULL)
     return NULL;
   ret->fd = fd;
+  ret->fd_off = offset;
   ret->crc_cls = ret;
   return ret;
 }
 
 
+
+
 /**
  * Create a response object.  The response object can be extended with
  * header information and then be used any number of times.
  *
  * @param size size of the data portion of the response
+ * @param fd file descriptor referring to a file on disk with the data
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ */
+struct MHD_Response *MHD_create_response_from_fd (size_t size,
+                                                 int fd)
+{
+  return MHD_create_response_from_fd_at_offset (size, fd, 0);
+}
+
+
+/**
+ * Create a response object.  The response object can be extended with
+ * header information and then be used any number of times.
+ *
+ * @param size size of the data portion of the response
  * @param data the data itself
  * @param must_free libmicrohttpd should free data when done
  * @param must_copy libmicrohttpd must make a copy of data

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2010-12-19 18:27:51 UTC (rev 
13934)
+++ libmicrohttpd/src/include/microhttpd.h      2010-12-19 18:54:44 UTC (rev 
13935)
@@ -1201,7 +1201,22 @@
 struct MHD_Response *MHD_create_response_from_fd (size_t size,
                                                  int fd);
 
+
 /**
+ * Create a response object.  The response object can be extended with
+ * header information and then be used any number of times.
+ *
+ * @param size size of the data portion of the response
+ * @param fd file descriptor referring to a file on disk with the data; will 
be closed when response is destroyed
+ * @param off offset to start reading from in the file
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ */
+struct MHD_Response *MHD_create_response_from_fd_at_offset (size_t size,
+                                                           int fd,
+                                                           off_t offset);
+
+
+/**
  * Destroy a response object and associated resources.  Note that
  * libmicrohttpd may keep some of the resources around if the response
  * is still in the queue for some clients, so the memory may not




reply via email to

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