Forráskód Böngészése

mhd_send: fixed broken sendfile() on FreeBSD, v0.9.67 regression

Evgeny Grin (Karlson2k) 5 éve
szülő
commit
16d9f9e426

+ 0 - 41
src/microhttpd/connection.c

@@ -125,47 +125,6 @@
  */
 #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000)
 
-#ifdef HAVE_FREEBSD_SENDFILE
-#ifdef SF_FLAGS
-/**
- * FreeBSD sendfile() flags
- */
-static int freebsd_sendfile_flags_;
-
-/**
- * FreeBSD sendfile() flags for thread-per-connection
- */
-static int freebsd_sendfile_flags_thd_p_c_;
-#endif /* SF_FLAGS */
-/**
- * Initialises static variables
- */
-void
-MHD_conn_init_static_ (void)
-{
-/* FreeBSD 11 and later allow to specify read-ahead size
- * and handles SF_NODISKIO differently.
- * SF_FLAGS defined only on FreeBSD 11 and later. */
-#ifdef SF_FLAGS
-  long sys_page_size = sysconf (_SC_PAGESIZE);
-  if (0 > sys_page_size)
-  {   /* Failed to get page size. */
-    freebsd_sendfile_flags_ = SF_NODISKIO;
-    freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO;
-  }
-  else
-  {
-    freebsd_sendfile_flags_ =
-      SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_ / sys_page_size), SF_NODISKIO);
-    freebsd_sendfile_flags_thd_p_c_ =
-      SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_THR_P_C_ / sys_page_size),
-                SF_NODISKIO);
-  }
-#endif /* SF_FLAGS */
-}
-
-
-#endif /* HAVE_FREEBSD_SENDFILE */
 /**
  * Callback for receiving data from the socket.
  *

+ 0 - 10
src/microhttpd/connection.h

@@ -62,16 +62,6 @@
 #define MHD_ERR_INVAL_ (-3078)
 
 
-#ifdef HAVE_FREEBSD_SENDFILE
-/**
- * Initialises static variables
- */
-void
-MHD_conn_init_static_ (void);
-
-#endif /* HAVE_FREEBSD_SENDFILE */
-
-
 /**
  * Set callbacks for this connection to those for HTTP.
  *

+ 2 - 1
src/microhttpd/daemon.c

@@ -42,6 +42,7 @@
 #include "mhd_sockets.h"
 #include "mhd_itc.h"
 #include "mhd_compat.h"
+#include "mhd_send.h"
 
 #if HAVE_SEARCH_H
 #include <search.h>
@@ -7496,7 +7497,7 @@ MHD_init (void)
 #endif /* HTTPS_SUPPORT */
   MHD_monotonic_sec_counter_init ();
 #ifdef HAVE_FREEBSD_SENDFILE
-  MHD_conn_init_static_ ();
+  MHD_send_init_static_vars_ ();
 #endif /* HAVE_FREEBSD_SENDFILE */
   MHD_init_mem_pools_ ();
 }

+ 66 - 25
src/microhttpd/mhd_send.c

@@ -36,8 +36,74 @@
  * and every place where sendfile(), sendfile64(), setsockopt()
  * are used. */
 
+#ifdef MHD_LINUX_SOLARIS_SENDFILE
+#include <sys/sendfile.h>
+#endif /* MHD_LINUX_SOLARIS_SENDFILE */
+#if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE)
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#endif /* HAVE_FREEBSD_SENDFILE || HAVE_DARWIN_SENDFILE */
+#ifdef HAVE_SYS_PARAM_H
+/* For FreeBSD version identification */
+#include <sys/param.h>
+#endif /* HAVE_SYS_PARAM_H */
 #include "mhd_send.h"
 
+
+/**
+ * sendfile() chuck size
+ */
+#define MHD_SENFILE_CHUNK_         (0x20000)
+
+/**
+ * sendfile() chuck size for thread-per-connection
+ */
+#define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000)
+
+#ifdef HAVE_FREEBSD_SENDFILE
+#ifdef SF_FLAGS
+/**
+ * FreeBSD sendfile() flags
+ */
+static int freebsd_sendfile_flags_;
+
+/**
+ * FreeBSD sendfile() flags for thread-per-connection
+ */
+static int freebsd_sendfile_flags_thd_p_c_;
+#endif /* SF_FLAGS */
+/**
+ * Initialises static variables
+ */
+void
+MHD_send_init_static_vars_ (void)
+{
+/* FreeBSD 11 and later allow to specify read-ahead size
+ * and handles SF_NODISKIO differently.
+ * SF_FLAGS defined only on FreeBSD 11 and later. */
+#ifdef SF_FLAGS
+  long sys_page_size = sysconf (_SC_PAGESIZE);
+  if (0 > sys_page_size)
+  {   /* Failed to get page size. */
+    freebsd_sendfile_flags_ = SF_NODISKIO;
+    freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO;
+  }
+  else
+  {
+    freebsd_sendfile_flags_ =
+      SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_ / sys_page_size), SF_NODISKIO);
+    freebsd_sendfile_flags_thd_p_c_ =
+      SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_THR_P_C_ / sys_page_size),
+                SF_NODISKIO);
+  }
+#endif /* SF_FLAGS */
+}
+
+
+#endif /* HAVE_FREEBSD_SENDFILE */
+
+
 /**
  * Handle setsockopt calls.
  *
@@ -471,31 +537,6 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
 }
 
 
-/**
- * sendfile() chuck size
- */
-#define MHD_SENFILE_CHUNK_         (0x20000)
-
-/**
- * sendfile() chuck size for thread-per-connection
- */
-#define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000)
-
-#ifdef HAVE_FREEBSD_SENDFILE
-#ifdef SF_FLAGS
-/**
- * FreeBSD sendfile() flags
- */
-static int freebsd_sendfile_flags_;
-
-/**
- * FreeBSD sendfile() flags for thread-per-connection
- */
-static int freebsd_sendfile_flags_thd_p_c_;
-#endif /* SF_FLAGS */
-
-#endif /* HAVE_FREEBSD_SENDFILE */
-
 #if defined(_MHD_HAVE_SENDFILE)
 /**
  * Function for sending responses backed by file FD.

+ 8 - 13
src/microhttpd/mhd_send.h

@@ -39,19 +39,14 @@
 #include "connection_https.h"
 #endif
 
-#ifdef MHD_LINUX_SOLARIS_SENDFILE
-#include <sys/sendfile.h>
-#endif /* MHD_LINUX_SOLARIS_SENDFILE */
-#if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE)
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#endif /* HAVE_FREEBSD_SENDFILE || HAVE_DARWIN_SENDFILE */
-
-#ifdef HAVE_SYS_PARAM_H
-/* For FreeBSD version identification */
-#include <sys/param.h>
-#endif /* HAVE_SYS_PARAM_H */
+#ifdef HAVE_FREEBSD_SENDFILE
+/**
+ * Initialises static variables
+ */
+void
+MHD_send_init_static_vars_ (void);
+
+#endif /* HAVE_FREEBSD_SENDFILE */
 
 /**
  * The enumeration of send socket options.