mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-09 16:21:45 +00:00
Improve ff_write - save large blocks in chunks
This commit is contained in:
1 parent
1259ca9ac9
commit
4cd830a0bf
6 files changed
+38
-20
No files matched your search
+10
-9
@@ -495,10 +495,6 @@ bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...) {
|
||||
#if MG_ENABLE_FATFS
|
||||
#include <ff.h>
|
||||
|
||||
#if !defined(MG_FATFS_ROOT)
|
||||
#define MG_FATFS_ROOT "/"
|
||||
#endif
|
||||
|
||||
static int ff_stat(const char *path, size_t *size, time_t *mtime) {
|
||||
FILINFO fi;
|
||||
if (path[0] == '\0' || strcmp(path, MG_FATFS_ROOT) == 0) {
|
||||
@@ -554,9 +550,14 @@ static size_t ff_read(void *fp, void *buf, size_t len) {
|
||||
}
|
||||
|
||||
static size_t ff_write(void *fp, const void *buf, size_t len) {
|
||||
unsigned n = 0;
|
||||
f_write((FIL *) fp, buf, len, &n);
|
||||
return n;
|
||||
unsigned n, sum = 0, bs = MG_FATFS_BSIZE;
|
||||
while ((size_t) sum < len &&
|
||||
f_write((FIL *) fp, (char *) buf + sum,
|
||||
sum + bs > len ? len - sum : bs, &n) == FR_OK &&
|
||||
n > 0) {
|
||||
sum += n;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
static size_t ff_seek(void *fp, size_t offset) {
|
||||
@@ -1865,9 +1866,9 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
|
||||
mg_http_reply(c, 400, "", "open(%s): %d", path, errno);
|
||||
return -2;
|
||||
} else {
|
||||
fs->write(fd->fd, hm->body.ptr, hm->body.len);
|
||||
int written = (int) fs->write(fd->fd, hm->body.ptr, hm->body.len);
|
||||
mg_fs_close(fd);
|
||||
mg_http_reply(c, 200, "", "");
|
||||
mg_http_reply(c, 200, "", "%d", written);
|
||||
return (int) hm->body.len;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user