mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-31 01:11:12 +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
@@ -19,7 +19,7 @@ AM_CPPFLAGS += -I$(top_srcdir)/lib/libcoolstream
|
||||
endif
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS += -fno-rtti -fno-exceptions -D_FILE_OFFSET_BITS=64
|
||||
AM_CPPFLAGS += -fno-rtti -fno-exceptions
|
||||
|
||||
noinst_LIBRARIES = libyhttpd.a
|
||||
|
||||
|
@@ -304,8 +304,8 @@ std::string CyhookHandler::BuildHeader(bool cache) {
|
||||
|
||||
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&mod_time));
|
||||
result += string_printf(
|
||||
"Last-Modified: %s\r\nContent-Length: %lld\r\n", timeStr,
|
||||
(long long) GetContentLength());
|
||||
"Last-Modified: %s\r\nContent-Length: %ld\r\n", timeStr,
|
||||
GetContentLength());
|
||||
}
|
||||
result += "\r\n"; // End of Header
|
||||
break;
|
||||
|
@@ -47,7 +47,6 @@
|
||||
//=============================================================================
|
||||
#ifndef __yhttpd_yhook_h__
|
||||
#define __yhttpd_yhook_h__
|
||||
#include <unistd.h>
|
||||
// C++
|
||||
#include <string>
|
||||
#include <list>
|
||||
@@ -129,7 +128,7 @@ public:
|
||||
HttpResponseType httpStatus; // http-status code for response
|
||||
std::string ResponseMimeType; // mime-type for response
|
||||
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
|
||||
std::string Sendfile; // Path & Name (local os style) of file to send
|
||||
bool keep_alive;
|
||||
@@ -174,8 +173,8 @@ public:
|
||||
void SetError(HttpResponseType responseType, THandleStatus _status)
|
||||
{SetError(responseType); status = _status;}
|
||||
// others
|
||||
off_t GetContentLength()
|
||||
{return (status==HANDLED_SENDFILE)?ContentLength : (off_t)yresult.length();}
|
||||
long GetContentLength()
|
||||
{return (status==HANDLED_SENDFILE)?ContentLength : (long)yresult.length();}
|
||||
// output methods
|
||||
std::string BuildHeader(bool cache = false);
|
||||
void addResult(const std::string& result) {yresult += result;}
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
@@ -317,40 +316,25 @@ int CySocket::SendFile(int filed) {
|
||||
#ifdef Y_CONFIG_HAVE_SENDFILE
|
||||
// does not work with SSL !!!
|
||||
off_t start = 0;
|
||||
struct stat st;
|
||||
fstat(filed, &st);
|
||||
size_t end = st.st_size;
|
||||
off_t written = 0;
|
||||
off_t left = end;
|
||||
while (left > 0) {
|
||||
// Split sendfile() transfer to smaller chunks to reduce memory-mapping requirements --martii
|
||||
if((written = ::sendfile(sock,filed,&start,0x8000000)) == -1) {
|
||||
perror("sendfile failed");
|
||||
if (errno != EINVAL)
|
||||
return false;
|
||||
break;
|
||||
} else {
|
||||
BytesSend += written;
|
||||
left -= written;
|
||||
off_t end = lseek(filed,0,SEEK_END);
|
||||
int written = 0;
|
||||
if((written = ::sendfile(sock,filed,&start,end)) == -1)
|
||||
{
|
||||
perror("sendfile failed\n");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
BytesSend += written;
|
||||
#else
|
||||
char sbuf[1024];
|
||||
unsigned int r = 0;
|
||||
while ((r = read(filed, sbuf, 1024)) > 0) {
|
||||
if (Send(sbuf, r) < 0) {
|
||||
perror("sendfile failed\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (left) {
|
||||
::lseek(filed, start, SEEK_SET);
|
||||
#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);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user