Skip to content

Commit

Permalink
- lophttpd: more off_t cleanups and increasing size of cachable gener…
Browse files Browse the repository at this point in the history
…ated index
  • Loading branch information
stealth committed Feb 28, 2014
1 parent 8b938ba commit 8c5fccb
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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 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\ $(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 frontend-main.o: frontend-main.cc
$(CXX) $(CFLAGS) -c frontend-main.cc $(CXX) $(CFLAGS) -c frontend-main.cc
Expand Down
3 changes: 1 addition & 2 deletions client.h
Expand Up @@ -81,8 +81,7 @@ class http_client {
int file_fd, peer_fd; int file_fd, peer_fd;
time_t alive_time, header_time; time_t alive_time, header_time;
bool keep_alive; bool keep_alive;
off_t offset; off_t offset, copied, left;
size_t copied, left;
dev_t dev; dev_t dev;
ino_t ino; ino_t ino;
std::string path, from_ip, first_line; std::string path, from_ip, first_line;
Expand Down
2 changes: 1 addition & 1 deletion flavor-android.cc
Expand Up @@ -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) if (n > MAX_SEND_SIZE)
return -1; return -1;
Expand Down
2 changes: 1 addition & 1 deletion flavor-bsd.cc
Expand Up @@ -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) if (n > MAX_SEND_SIZE)
return -1; return -1;
Expand Down
2 changes: 1 addition & 1 deletion flavor-linux.cc
Expand Up @@ -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) if (n > MAX_SEND_SIZE)
return -1; return -1;
Expand Down
2 changes: 1 addition & 1 deletion flavor-osx.cc
Expand Up @@ -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) if (n > MAX_SEND_SIZE)
return -1; return -1;
Expand Down
2 changes: 1 addition & 1 deletion flavor.h
Expand Up @@ -59,7 +59,7 @@ int in_send_queue(int);


// calls sendfile() if !is_dev indicates that. returns 0 on success, -1 on error. // 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 // 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(); int sandbox();


Expand Down
38 changes: 28 additions & 10 deletions lonely.cc
Expand Up @@ -640,27 +640,41 @@ int lonely_http::send_http_header()


int lonely_http::send_genindex() int lonely_http::send_genindex()
{ {
int l = 0, r = 0;
const string &p = peer->path; const string &p = peer->path;
string idx = ""; string idx = "";


map<string, string>::iterator i = misc::dir2index.find(p); map<string, string>::iterator i = misc::dir2index.find(p);
if (i != misc::dir2index.end()) if (i != misc::dir2index.end())
idx = i->second; idx = i->second;


int l = snprintf(hbuf, sizeof(hbuf), hdr_fmt.c_str(), gmt_date, idx.size(), "text/html"); // First called on request?
if (l < 0 || l > (int)sizeof(hbuf)) if (peer->state() == STATE_CONNECTED) {
return -1; 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) peer->left = idx.size();
return -1; }


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; 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; return r;
} }


Expand Down Expand Up @@ -1106,8 +1120,8 @@ int lonely_http::GETPOST()
if (cur_range_requested) { if (cur_range_requested) {
if (cur_start_range < 0 || if (cur_start_range < 0 ||
cur_start_range >= cur_stat.st_size || cur_start_range >= cur_stat.st_size ||
cur_end_range > (size_t)cur_stat.st_size || cur_end_range > cur_stat.st_size ||
(size_t)cur_start_range >= cur_end_range) { cur_start_range >= cur_end_range) {
return send_error(HTTP_ERROR_416, -1); return send_error(HTTP_ERROR_416, -1);
} }
} }
Expand All @@ -1122,6 +1136,10 @@ int lonely_http::GETPOST()


rr = download(); rr = download();
} else if (r == 0 && S_ISDIR(cur_stat.st_mode)) { } 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 // No Range: requests for directories
if (cur_range_requested) if (cur_range_requested)
return send_error(HTTP_ERROR_416, -1); return send_error(HTTP_ERROR_416, -1);
Expand Down
2 changes: 1 addition & 1 deletion lonely.h
Expand Up @@ -168,7 +168,7 @@ class lonely_http : public lonely<http_client> {
private: private:
struct stat cur_stat; struct stat cur_stat;
off_t cur_start_range; off_t cur_start_range;
size_t cur_end_range; off_t cur_end_range;
bool cur_range_requested, forced_send_size; bool cur_range_requested, forced_send_size;
http_request_t cur_request; http_request_t cur_request;


Expand Down
2 changes: 1 addition & 1 deletion misc.cc
Expand Up @@ -143,7 +143,7 @@ int find_ctype(const string &p)


// if generated indexes exceed this limit, they // if generated indexes exceed this limit, they
// are written as index.html to disk // 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) int ftw_helper(const char *fpath, const struct stat *st, int typeflag)
Expand Down

0 comments on commit 8c5fccb

Please sign in to comment.