Permalink
Browse files

- lophttpd: more off_t cleanups and increasing size of cachable gener…

…ated index
  • Loading branch information...
stealth committed Feb 28, 2014
1 parent 8b938ba commit 8c5fccba938479030831723a682837e2d55a4059
Showing with 37 additions and 20 deletions.
  1. +1 −1 Makefile
  2. +1 −2 client.h
  3. +1 −1 flavor-android.cc
  4. +1 −1 flavor-bsd.cc
  5. +1 −1 flavor-linux.cc
  6. +1 −1 flavor-osx.cc
  7. +1 −1 flavor.h
  8. +28 −10 lonely.cc
  9. +1 −1 lonely.h
  10. +1 −1 misc.cc
View
@@ -30,7 +30,7 @@ lhttpd: lonely.o socket.o main.o misc.o log.o multicore.o config.o flavor.o clie
frontend: lonely.o socket.o frontend-main.o log.o multicore.o rproxy.o config.o misc.o flavor.o client.o
$(LD) $(LDFLAGS) lonely.o socket.o frontend-main.o misc.o log.o multicore.o rproxy.o\
config.o flavor.o client.o -o frontend -lrt $(LIBS)
config.o flavor.o client.o -o frontend $(LIBS)
frontend-main.o: frontend-main.cc
$(CXX) $(CFLAGS) -c frontend-main.cc
View
@@ -81,8 +81,7 @@ class http_client {
int file_fd, peer_fd;
time_t alive_time, header_time;
bool keep_alive;
off_t offset;
size_t copied, left;
off_t offset, copied, left;
dev_t dev;
ino_t ino;
std::string path, from_ip, first_line;
View
@@ -109,7 +109,7 @@ int in_send_queue(int fd)
}
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, size_t &left, size_t &copied, int ftype)
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, off_t &left, off_t &copied, int ftype)
{
if (n > MAX_SEND_SIZE)
return -1;
View
@@ -103,7 +103,7 @@ int in_send_queue(int peer)
}
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, size_t &left, size_t &copied, int ftype)
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, off_t &left, off_t &copied, int ftype)
{
if (n > MAX_SEND_SIZE)
return -1;
View
@@ -101,7 +101,7 @@ int in_send_queue(int fd)
}
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, size_t &left, size_t &copied, int ftype)
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, off_t &left, off_t &copied, int ftype)
{
if (n > MAX_SEND_SIZE)
return -1;
View
@@ -101,7 +101,7 @@ int in_send_queue(int fd)
}
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, size_t &left, size_t &copied, int ftype)
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, off_t &left, off_t &copied, int ftype)
{
if (n > MAX_SEND_SIZE)
return -1;
View
@@ -59,7 +59,7 @@ int in_send_queue(int);
// calls sendfile() if !is_dev indicates that. returns 0 on success, -1 on error.
// uses normal read/write if sendfile cannot be used. updates offset, left and copied accordingly
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, size_t &left, size_t &copied, int);
ssize_t sendfile(int peer, int fd, off_t *offset, size_t n, off_t &left, off_t &copied, int);
int sandbox();
View
@@ -640,27 +640,41 @@ int lonely_http::send_http_header()
int lonely_http::send_genindex()
{
int l = 0, r = 0;
const string &p = peer->path;
string idx = "";
map<string, string>::iterator i = misc::dir2index.find(p);
if (i != misc::dir2index.end())
idx = i->second;
int l = snprintf(hbuf, sizeof(hbuf), hdr_fmt.c_str(), gmt_date, idx.size(), "text/html");
if (l < 0 || l > (int)sizeof(hbuf))
return -1;
// First called on request?
if (peer->state() == STATE_CONNECTED) {
l = snprintf(hbuf, sizeof(hbuf), hdr_fmt.c_str(), gmt_date, idx.size(), "text/html");
if (l < 0 || l > (int)sizeof(hbuf))
return -1;
int r = peer->send(hbuf, l);
if ((r = peer->send(hbuf, l)) != l)
return -1;
if (r != l)
return -1;
peer->left = idx.size();
}
r = peer->send(idx.c_str(), idx.size());
if (peer->offset >= (off_t)idx.size())
return -1;
if (r != (int)idx.size())
if ((r = peer->send(idx.c_str() + peer->offset, idx.size() - peer->offset)) <= 0)
return -1;
peer->offset += r;
peer->left -= r;
peer->copied += r;
if (peer->left == 0)
peer->transition(STATE_CONNECTED);
else
peer->transition(STATE_DOWNLOADING);
return r;
}
@@ -1106,8 +1120,8 @@ int lonely_http::GETPOST()
if (cur_range_requested) {
if (cur_start_range < 0 ||
cur_start_range >= cur_stat.st_size ||
cur_end_range > (size_t)cur_stat.st_size ||
(size_t)cur_start_range >= cur_end_range) {
cur_end_range > cur_stat.st_size ||
cur_start_range >= cur_end_range) {
return send_error(HTTP_ERROR_416, -1);
}
}
@@ -1122,6 +1136,10 @@ int lonely_http::GETPOST()
rr = download();
} else if (r == 0 && S_ISDIR(cur_stat.st_mode)) {
peer->offset = 0;
peer->copied = 0;
//peer->left will be set in send_genindex()
// No Range: requests for directories
if (cur_range_requested)
return send_error(HTTP_ERROR_416, -1);
View
@@ -168,7 +168,7 @@ class lonely_http : public lonely<http_client> {
private:
struct stat cur_stat;
off_t cur_start_range;
size_t cur_end_range;
off_t cur_end_range;
bool cur_range_requested, forced_send_size;
http_request_t cur_request;
View
@@ -143,7 +143,7 @@ int find_ctype(const string &p)
// if generated indexes exceed this limit, they
// are written as index.html to disk
const unsigned int index_max_size = 10000;
const unsigned int index_max_size = 1<<24;
int ftw_helper(const char *fpath, const struct stat *st, int typeflag)

0 comments on commit 8c5fccb

Please sign in to comment.