mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 00:11:14 +02:00
Revert "nhttpd: let sendfile() support files >= 2GB"
This reverts commit 9842afecad8dfb91dfd7221aedbeaf5379a89534.
This commit is contained in:
committed by
[CST] Focus
parent
e98336658d
commit
cf0bf3fa20
@@ -1,6 +1,6 @@
|
|||||||
SUBDIRS = yhttpd_core yhttpd_mods tuxboxapi web
|
SUBDIRS = yhttpd_core yhttpd_mods tuxboxapi web
|
||||||
|
|
||||||
AM_CPPFLAGS = -fno-rtti -fno-exceptions -D_FILE_OFFSET_BITS=64
|
AM_CPPFLAGS = -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
-I$(srcdir) \
|
-I$(srcdir) \
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
AM_CPPFLAGS = -fno-rtti -fno-exceptions -D__STDC_FORMAT_MACROS -D_FILE_OFFSET_BITS=64
|
AM_CPPFLAGS = -fno-rtti -fno-exceptions -D__STDC_FORMAT_MACROS
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
-I$(top_builddir) \
|
-I$(top_builddir) \
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
AM_CPPFLAGS = -fno-rtti -fno-exceptions -D_FILE_OFFSET_BITS=64
|
AM_CPPFLAGS = -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
-I$(top_srcdir)/lib \
|
-I$(top_srcdir)/lib \
|
||||||
|
@@ -19,7 +19,7 @@ AM_CPPFLAGS += -I$(top_srcdir)/lib/libcoolstream
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
AM_CPPFLAGS += -fno-rtti -fno-exceptions -D_FILE_OFFSET_BITS=64
|
AM_CPPFLAGS += -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
noinst_LIBRARIES = libyhttpd.a
|
noinst_LIBRARIES = libyhttpd.a
|
||||||
|
|
||||||
|
@@ -304,8 +304,8 @@ std::string CyhookHandler::BuildHeader(bool cache) {
|
|||||||
|
|
||||||
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&mod_time));
|
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&mod_time));
|
||||||
result += string_printf(
|
result += string_printf(
|
||||||
"Last-Modified: %s\r\nContent-Length: %lld\r\n", timeStr,
|
"Last-Modified: %s\r\nContent-Length: %ld\r\n", timeStr,
|
||||||
(long long) GetContentLength());
|
GetContentLength());
|
||||||
}
|
}
|
||||||
result += "\r\n"; // End of Header
|
result += "\r\n"; // End of Header
|
||||||
break;
|
break;
|
||||||
|
@@ -47,7 +47,6 @@
|
|||||||
//=============================================================================
|
//=============================================================================
|
||||||
#ifndef __yhttpd_yhook_h__
|
#ifndef __yhttpd_yhook_h__
|
||||||
#define __yhttpd_yhook_h__
|
#define __yhttpd_yhook_h__
|
||||||
#include <unistd.h>
|
|
||||||
// C++
|
// C++
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
@@ -129,7 +128,7 @@ public:
|
|||||||
HttpResponseType httpStatus; // http-status code for response
|
HttpResponseType httpStatus; // http-status code for response
|
||||||
std::string ResponseMimeType; // mime-type for response
|
std::string ResponseMimeType; // mime-type for response
|
||||||
std::string NewURL; // new URL for Redirection
|
std::string NewURL; // new URL for Redirection
|
||||||
off_t ContentLength; // Length of Response Body
|
long ContentLength; // Length of Response Body
|
||||||
time_t LastModified; // Last Modified Time of Item to send / -1 dynamic content
|
time_t LastModified; // Last Modified Time of Item to send / -1 dynamic content
|
||||||
std::string Sendfile; // Path & Name (local os style) of file to send
|
std::string Sendfile; // Path & Name (local os style) of file to send
|
||||||
bool keep_alive;
|
bool keep_alive;
|
||||||
@@ -174,8 +173,8 @@ public:
|
|||||||
void SetError(HttpResponseType responseType, THandleStatus _status)
|
void SetError(HttpResponseType responseType, THandleStatus _status)
|
||||||
{SetError(responseType); status = _status;}
|
{SetError(responseType); status = _status;}
|
||||||
// others
|
// others
|
||||||
off_t GetContentLength()
|
long GetContentLength()
|
||||||
{return (status==HANDLED_SENDFILE)?ContentLength : (off_t)yresult.length();}
|
{return (status==HANDLED_SENDFILE)?ContentLength : (long)yresult.length();}
|
||||||
// output methods
|
// output methods
|
||||||
std::string BuildHeader(bool cache = false);
|
std::string BuildHeader(bool cache = false);
|
||||||
void addResult(const std::string& result) {yresult += result;}
|
void addResult(const std::string& result) {yresult += result;}
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -317,40 +316,25 @@ int CySocket::SendFile(int filed) {
|
|||||||
#ifdef Y_CONFIG_HAVE_SENDFILE
|
#ifdef Y_CONFIG_HAVE_SENDFILE
|
||||||
// does not work with SSL !!!
|
// does not work with SSL !!!
|
||||||
off_t start = 0;
|
off_t start = 0;
|
||||||
struct stat st;
|
off_t end = lseek(filed,0,SEEK_END);
|
||||||
fstat(filed, &st);
|
int written = 0;
|
||||||
size_t end = st.st_size;
|
if((written = ::sendfile(sock,filed,&start,end)) == -1)
|
||||||
off_t written = 0;
|
{
|
||||||
off_t left = end;
|
perror("sendfile failed\n");
|
||||||
while (left > 0) {
|
return false;
|
||||||
// Split sendfile() transfer to smaller chunks to reduce memory-mapping requirements --martii
|
}
|
||||||
if((written = ::sendfile(sock,filed,&start,0x8000000)) == -1) {
|
else
|
||||||
perror("sendfile failed");
|
BytesSend += written;
|
||||||
if (errno != EINVAL)
|
#else
|
||||||
return false;
|
char sbuf[1024];
|
||||||
break;
|
unsigned int r = 0;
|
||||||
} else {
|
while ((r = read(filed, sbuf, 1024)) > 0) {
|
||||||
BytesSend += written;
|
if (Send(sbuf, r) < 0) {
|
||||||
left -= written;
|
perror("sendfile failed\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (left) {
|
|
||||||
::lseek(filed, start, SEEK_SET);
|
|
||||||
#endif // Y_CONFIG_HAVE_SENDFILE
|
#endif // Y_CONFIG_HAVE_SENDFILE
|
||||||
|
|
||||||
char sbuf[65536];
|
|
||||||
int r;
|
|
||||||
while ((r = read(filed, sbuf, 65536)) > 0) {
|
|
||||||
if (Send(sbuf, r) < 0) {
|
|
||||||
perror("send failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BytesSend += written;
|
|
||||||
}
|
|
||||||
#ifdef Y_CONFIG_HAVE_SENDFILE
|
|
||||||
}
|
|
||||||
#endif // Y_CONFIG_HAVE_SENDFILE
|
|
||||||
|
|
||||||
log_level_printf(9, "<Sock:SendFile>: Bytes:%ld\n", BytesSend);
|
log_level_printf(9, "<Sock:SendFile>: Bytes:%ld\n", BytesSend);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir)/lib/libconfigfile \
|
-I$(top_srcdir)/lib/libconfigfile \
|
||||||
@FREETYPE_CFLAGS@
|
@FREETYPE_CFLAGS@
|
||||||
|
|
||||||
AM_CPPFLAGS += -fno-rtti -fno-exceptions -D_FILE_OFFSET_BITS=64
|
AM_CPPFLAGS += -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
noinst_LIBRARIES = libyhttpdmods.a
|
noinst_LIBRARIES = libyhttpdmods.a
|
||||||
|
|
||||||
|
@@ -74,7 +74,8 @@ bool CmWebLog::OpenLogFile() {
|
|||||||
if (LogFormat == "ELF") {
|
if (LogFormat == "ELF") {
|
||||||
printf("#Version: 1.0\n");
|
printf("#Version: 1.0\n");
|
||||||
printf("#Remarks: yhttpd" WEBSERVERNAME "\n");
|
printf("#Remarks: yhttpd" WEBSERVERNAME "\n");
|
||||||
printf("#Fields: c-ip username date time x-request cs-uri sc-status cs-method bytes time-taken x-time-request x-time-response cached\n");
|
printf(
|
||||||
|
"#Fields: c-ip username date time x-request cs-uri sc-status cs-method bytes time-taken x-time-request x-time-response cached\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&WebLog_mutex);
|
pthread_mutex_unlock(&WebLog_mutex);
|
||||||
@@ -146,7 +147,7 @@ void CmWebLog::AddLogEntry_CLF(CyhookHandler *hh)
|
|||||||
std::string c_ip = hh->UrlData["clientaddr"].c_str();
|
std::string c_ip = hh->UrlData["clientaddr"].c_str();
|
||||||
std::string request_startline = hh->UrlData["startline"].c_str();
|
std::string request_startline = hh->UrlData["startline"].c_str();
|
||||||
int s_status = hh->httpStatus;
|
int s_status = hh->httpStatus;
|
||||||
off_t bytes = hh->GetContentLength();
|
int bytes = hh->GetContentLength();
|
||||||
|
|
||||||
struct tm *time_now;
|
struct tm *time_now;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
@@ -155,12 +156,12 @@ void CmWebLog::AddLogEntry_CLF(CyhookHandler *hh)
|
|||||||
time_now = localtime(&now);
|
time_now = localtime(&now);
|
||||||
strftime(request_time, 80, "[%d/%b/%Y:%H:%M:%S]", time_now);
|
strftime(request_time, 80, "[%d/%b/%Y:%H:%M:%S]", time_now);
|
||||||
|
|
||||||
printf("%s - - %s \"%s\" %d %lld\n",
|
printf("%s - - %s \"%s\" %d %d\n",
|
||||||
c_ip.c_str(),
|
c_ip.c_str(),
|
||||||
request_time,
|
request_time,
|
||||||
request_startline.c_str(),
|
request_startline.c_str(),
|
||||||
s_status,
|
s_status,
|
||||||
(long long) bytes);
|
bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -318,7 +319,7 @@ void CmWebLog::AddLogEntry_ELF(CyhookHandler *hh)
|
|||||||
std::string request_startline = hh->UrlData["startline"].c_str();
|
std::string request_startline = hh->UrlData["startline"].c_str();
|
||||||
std::string cs_uri = hh->UrlData["fullurl"];
|
std::string cs_uri = hh->UrlData["fullurl"];
|
||||||
int sc_status = hh->httpStatus;
|
int sc_status = hh->httpStatus;
|
||||||
off_t bytes = hh->GetContentLength();
|
int bytes = hh->GetContentLength();
|
||||||
int cached = (hh->HookVarList["CacheCategory"].empty()) ? 0 : 1;
|
int cached = (hh->HookVarList["CacheCategory"].empty()) ? 0 : 1;
|
||||||
|
|
||||||
struct tm *time_now;
|
struct tm *time_now;
|
||||||
@@ -338,7 +339,7 @@ void CmWebLog::AddLogEntry_ELF(CyhookHandler *hh)
|
|||||||
std::string time_taken_response = hh->HookVarList["enlapsed_response"];
|
std::string time_taken_response = hh->HookVarList["enlapsed_response"];
|
||||||
long time_taken = atoi(time_taken_request.c_str()) + atoi(time_taken_response.c_str());
|
long time_taken = atoi(time_taken_request.c_str()) + atoi(time_taken_response.c_str());
|
||||||
|
|
||||||
printf("%s %s %s \"%s\" %s %d %s %d %ld %s %s %lld\n",
|
printf("%s %s %s \"%s\" %s %d %s %d %ld %s %s %d\n",
|
||||||
c_ip.c_str(),
|
c_ip.c_str(),
|
||||||
_date,
|
_date,
|
||||||
_time,
|
_time,
|
||||||
@@ -346,7 +347,7 @@ void CmWebLog::AddLogEntry_ELF(CyhookHandler *hh)
|
|||||||
cs_uri.c_str(),
|
cs_uri.c_str(),
|
||||||
sc_status,
|
sc_status,
|
||||||
cs_method.c_str(),
|
cs_method.c_str(),
|
||||||
(long long) bytes,
|
bytes,
|
||||||
time_taken,
|
time_taken,
|
||||||
time_taken_request.c_str(),
|
time_taken_request.c_str(),
|
||||||
time_taken_response.c_str(),
|
time_taken_response.c_str(),
|
||||||
|
Reference in New Issue
Block a user