فهرست منبع

Add `allow_sendfile_call` option

It seems the Linux `sendfile` system call is broken in some systems (operating system versions and/or file system types) - see #346
While it should be used if available as a default, there has to be a config option to disable it.
bel 8 سال پیش
والد
کامیت
249b6f1419
1فایلهای تغییر یافته به همراه12 افزوده شده و 1 حذف شده
  1. 12 1
      src/civetweb.c

+ 12 - 1
src/civetweb.c

@@ -1308,9 +1308,11 @@ enum {
 	SSL_CIPHER_LIST,
 	SSL_PROTOCOL_VERSION,
 	SSL_SHORT_TRUST,
+
 #if defined(USE_WEBSOCKET)
 	WEBSOCKET_TIMEOUT,
 #endif
+
 	DECODE_URL,
 
 #if defined(USE_LUA)
@@ -1328,6 +1330,7 @@ enum {
 #if defined(USE_LUA) && defined(USE_WEBSOCKET)
 	LUA_WEBSOCKET_EXTENSIONS,
 #endif
+
 	ACCESS_CONTROL_ALLOW_ORIGIN,
 	ERROR_PAGES,
 	CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the
@@ -1335,6 +1338,9 @@ enum {
 #if !defined(NO_CACHING)
 	STATIC_FILE_MAX_AGE,
 #endif
+#if defined(__linux__)
+	ALLOW_SENDFILE_CALL,
+#endif
 
 	NUM_OPTIONS
 };
@@ -1409,6 +1415,9 @@ static struct mg_option config_options[] = {
 #if !defined(NO_CACHING)
     {"static_file_max_age", CONFIG_TYPE_NUMBER, "3600"},
 #endif
+#if defined(__linux__)
+    {"allow_sendfile_call", CONFIG_TYPE_BOOLEAN, "yes"},
+#endif
 
     {NULL, CONFIG_TYPE_UNKNOWN, NULL}};
 
@@ -6754,7 +6763,9 @@ send_file_data(struct mg_connection *conn,
 /* file stored on disk */
 #if defined(__linux__)
 		/* sendfile is only available for Linux */
-		if (conn->throttle == 0 && conn->ssl == 0) {
+		if ((conn->ssl == 0) && (conn->throttle == 0)
+		    && (!mg_strcasecmp(conn->ctx->config[ALLOW_SENDFILE_CALL],
+		                       "yes"))) {
 			off_t sf_offs = (off_t)offset;
 			ssize_t sf_sent;
 			int sf_file = fileno(filep->fp);