mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-31 01:13:01 +08:00
SLFS file size hint
PUBLISHED_FROM=532200881406349585612ea5d59aaa323789a688
This commit is contained in:
parent
063c017bb7
commit
bf9a2b45ef
@ -31,7 +31,6 @@ SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
|
|||||||
|
|
||||||
CFLAGS += -Os -Wall -Werror \
|
CFLAGS += -Os -Wall -Werror \
|
||||||
$(SDK_FLAGS) -DCS_PLATFORM=4 -DCC3200_FS_SLFS \
|
$(SDK_FLAGS) -DCS_PLATFORM=4 -DCC3200_FS_SLFS \
|
||||||
-DFS_SLFS_MAX_FILE_SIZE=262144 \
|
|
||||||
$(MONGOOSE_FEATURES) $(CFLAGS_EXTRA)
|
$(MONGOOSE_FEATURES) $(CFLAGS_EXTRA)
|
||||||
|
|
||||||
FW_ELF = $(FW_DIR)/$(PROG).axf
|
FW_ELF = $(FW_DIR)/$(PROG).axf
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
|
||||||
|
void fs_slfs_set_new_file_size(const char *name, size_t size);
|
||||||
|
|
||||||
static const char *upload_form =
|
static const char *upload_form =
|
||||||
"\
|
"\
|
||||||
<h1>Upload file</h1> \
|
<h1>Upload file</h1> \
|
||||||
@ -53,10 +55,18 @@ static const char *upload_form =
|
|||||||
static struct mg_str upload_fname(struct mg_connection *nc,
|
static struct mg_str upload_fname(struct mg_connection *nc,
|
||||||
struct mg_str fname) {
|
struct mg_str fname) {
|
||||||
struct mg_str lfn;
|
struct mg_str lfn;
|
||||||
lfn.len = fname.len + 3;
|
char *fn = malloc(fname.len + 4);
|
||||||
lfn.p = malloc(lfn.len);
|
memcpy(fn, "SL:", 3);
|
||||||
memcpy((char *) lfn.p, "SL:", 3);
|
memcpy(fn + 3, fname.p, fname.len);
|
||||||
memcpy((char *) lfn.p + 3, fname.p, fname.len);
|
fn[3 + fname.len] = '\0';
|
||||||
|
if (nc->user_data != NULL) {
|
||||||
|
intptr_t cl = (intptr_t) nc->user_data;
|
||||||
|
if (cl >= 0) {
|
||||||
|
fs_slfs_set_new_file_size(fn + 3, cl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lfn.len = fname.len + 4;
|
||||||
|
lfn.p = fn;
|
||||||
return lfn;
|
return lfn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +106,23 @@ void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
|||||||
LOG(LL_INFO, ("Connection %p closed", nc));
|
LOG(LL_INFO, ("Connection %p closed", nc));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* SimpleLink FS requires pre-declaring max file size. We use Content-Length
|
||||||
|
* for that purpose - it will not exactly match file size, but is guaranteed
|
||||||
|
* to exceed it and should be close enough. */
|
||||||
|
case MG_EV_HTTP_MULTIPART_REQUEST: {
|
||||||
|
struct http_message *hm = (struct http_message *) ev_data;
|
||||||
|
struct mg_str *cl_header = mg_get_http_header(hm, "Content-Length");
|
||||||
|
intptr_t cl = -1;
|
||||||
|
if (cl_header != NULL && cl_header->len < 20) {
|
||||||
|
char buf[20];
|
||||||
|
memcpy(buf, cl_header->p, cl_header->len);
|
||||||
|
buf[cl_header->len] = '\0';
|
||||||
|
cl = atoi(buf);
|
||||||
|
if (cl < 0) cl = -1;
|
||||||
|
}
|
||||||
|
nc->user_data = (void *) cl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case MG_EV_HTTP_PART_BEGIN:
|
case MG_EV_HTTP_PART_BEGIN:
|
||||||
case MG_EV_HTTP_PART_DATA:
|
case MG_EV_HTTP_PART_DATA:
|
||||||
case MG_EV_HTTP_PART_END: {
|
case MG_EV_HTTP_PART_END: {
|
||||||
@ -115,6 +142,7 @@ static void mg_init(struct mg_mgr *mgr) {
|
|||||||
LOG(LL_INFO, ("MG task running"));
|
LOG(LL_INFO, ("MG task running"));
|
||||||
|
|
||||||
stop_nwp(); /* See function description in wifi.c */
|
stop_nwp(); /* See function description in wifi.c */
|
||||||
|
LOG(LL_INFO, ("Starting NWP..."));
|
||||||
int role = sl_Start(0, 0, 0);
|
int role = sl_Start(0, 0, 0);
|
||||||
if (role < 0) {
|
if (role < 0) {
|
||||||
LOG(LL_ERROR, ("Failed to start NWP"));
|
LOG(LL_ERROR, ("Failed to start NWP"));
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.2068422510" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols">
|
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.2068422510" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols">
|
||||||
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/>
|
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/>
|
||||||
<listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/>
|
<listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/>
|
||||||
<listOptionValue builtIn="false" value="FS_SLFS_MAX_FILE_SIZE=262144"/>
|
|
||||||
<listOptionValue builtIn="false" value="MG_FS_SLFS=1"/>
|
<listOptionValue builtIn="false" value="MG_FS_SLFS=1"/>
|
||||||
<listOptionValue builtIn="false" value="cc3200"/>
|
<listOptionValue builtIn="false" value="cc3200"/>
|
||||||
</option>
|
</option>
|
||||||
@ -95,7 +94,6 @@
|
|||||||
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.1633469996" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols">
|
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.1633469996" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols">
|
||||||
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/>
|
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/>
|
||||||
<listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/>
|
<listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/>
|
||||||
<listOptionValue builtIn="false" value="FS_SLFS_MAX_FILE_SIZE=262144"/>
|
|
||||||
<listOptionValue builtIn="false" value="MG_FS_SLFS=1"/>
|
<listOptionValue builtIn="false" value="MG_FS_SLFS=1"/>
|
||||||
<listOptionValue builtIn="false" value="cc3200"/>
|
<listOptionValue builtIn="false" value="cc3200"/>
|
||||||
</option>
|
</option>
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
#define BM222_ADDR 0x18
|
#define BM222_ADDR 0x18
|
||||||
#define TMP006_ADDR 0x41
|
#define TMP006_ADDR 0x41
|
||||||
|
|
||||||
|
void fs_slfs_set_new_file_size(const char *name, size_t size);
|
||||||
|
|
||||||
static const char *upload_form =
|
static const char *upload_form =
|
||||||
"\
|
"\
|
||||||
<h1>Upload file</h1> \
|
<h1>Upload file</h1> \
|
||||||
@ -61,10 +63,18 @@ static const char *upload_form =
|
|||||||
static struct mg_str upload_fname(struct mg_connection *nc,
|
static struct mg_str upload_fname(struct mg_connection *nc,
|
||||||
struct mg_str fname) {
|
struct mg_str fname) {
|
||||||
struct mg_str lfn;
|
struct mg_str lfn;
|
||||||
lfn.len = fname.len + 3;
|
char *fn = malloc(fname.len + 4);
|
||||||
lfn.p = malloc(lfn.len);
|
memcpy(fn, "SL:", 3);
|
||||||
memcpy((char *) lfn.p, "SL:", 3);
|
memcpy(fn + 3, fname.p, fname.len);
|
||||||
memcpy((char *) lfn.p + 3, fname.p, fname.len);
|
fn[3 + fname.len] = '\0';
|
||||||
|
if (nc->user_data != NULL) {
|
||||||
|
intptr_t cl = (intptr_t) nc->user_data;
|
||||||
|
if (cl >= 0) {
|
||||||
|
fs_slfs_set_new_file_size(fn + 3, cl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lfn.len = fname.len + 4;
|
||||||
|
lfn.p = fn;
|
||||||
return lfn;
|
return lfn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +123,24 @@ static void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
|||||||
case MG_EV_TIMER: {
|
case MG_EV_TIMER: {
|
||||||
data_collect();
|
data_collect();
|
||||||
nc->ev_timer_time = mg_time() + (DATA_COLLECTION_INTERVAL_MS * 0.001);
|
nc->ev_timer_time = mg_time() + (DATA_COLLECTION_INTERVAL_MS * 0.001);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* SimpleLink FS requires pre-declaring max file size. We use Content-Length
|
||||||
|
* for that purpose - it will not exactly match file size, but is guaranteed
|
||||||
|
* to exceed it and should be close enough. */
|
||||||
|
case MG_EV_HTTP_MULTIPART_REQUEST: {
|
||||||
|
struct http_message *hm = (struct http_message *) ev_data;
|
||||||
|
struct mg_str *cl_header = mg_get_http_header(hm, "Content-Length");
|
||||||
|
intptr_t cl = -1;
|
||||||
|
if (cl_header != NULL && cl_header->len < 20) {
|
||||||
|
char buf[20];
|
||||||
|
memcpy(buf, cl_header->p, cl_header->len);
|
||||||
|
buf[cl_header->len] = '\0';
|
||||||
|
cl = atoi(buf);
|
||||||
|
if (cl < 0) cl = -1;
|
||||||
|
}
|
||||||
|
nc->user_data = (void *) cl;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case MG_EV_HTTP_PART_BEGIN:
|
case MG_EV_HTTP_PART_BEGIN:
|
||||||
case MG_EV_HTTP_PART_DATA:
|
case MG_EV_HTTP_PART_DATA:
|
||||||
@ -133,6 +161,7 @@ static void mg_init(struct mg_mgr *mgr) {
|
|||||||
LOG(LL_INFO, ("MG task running"));
|
LOG(LL_INFO, ("MG task running"));
|
||||||
|
|
||||||
stop_nwp(); /* See function description in wifi.c */
|
stop_nwp(); /* See function description in wifi.c */
|
||||||
|
LOG(LL_INFO, ("Starting NWP..."));
|
||||||
int role = sl_Start(0, 0, 0);
|
int role = sl_Start(0, 0, 0);
|
||||||
if (role < 0) {
|
if (role < 0) {
|
||||||
LOG(LL_ERROR, ("Failed to start NWP"));
|
LOG(LL_ERROR, ("Failed to start NWP"));
|
||||||
|
33
mongoose.c
33
mongoose.c
@ -10216,6 +10216,8 @@ off_t fs_slfs_lseek(int fd, off_t offset, int whence);
|
|||||||
int fs_slfs_unlink(const char *filename);
|
int fs_slfs_unlink(const char *filename);
|
||||||
int fs_slfs_rename(const char *from, const char *to);
|
int fs_slfs_rename(const char *from, const char *to);
|
||||||
|
|
||||||
|
void fs_slfs_set_new_file_size(const char *name, size_t size);
|
||||||
|
|
||||||
#endif /* defined(MG_FS_SLFS) */
|
#endif /* defined(MG_FS_SLFS) */
|
||||||
|
|
||||||
#endif /* CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_ */
|
#endif /* CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_ */
|
||||||
@ -10253,6 +10255,11 @@ extern int set_errno(int e); /* From sl_fs.c */
|
|||||||
#define FS_SLFS_MAX_FILE_SIZE (64 * 1024)
|
#define FS_SLFS_MAX_FILE_SIZE (64 * 1024)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct sl_file_size_hint {
|
||||||
|
char *name;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
struct sl_fd_info {
|
struct sl_fd_info {
|
||||||
_i32 fh;
|
_i32 fh;
|
||||||
_off_t pos;
|
_off_t pos;
|
||||||
@ -10260,6 +10267,7 @@ struct sl_fd_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct sl_fd_info s_sl_fds[MAX_OPEN_SLFS_FILES];
|
static struct sl_fd_info s_sl_fds[MAX_OPEN_SLFS_FILES];
|
||||||
|
static struct sl_file_size_hint s_sl_file_size_hints[MAX_OPEN_SLFS_FILES];
|
||||||
|
|
||||||
static int sl_fs_to_errno(_i32 r) {
|
static int sl_fs_to_errno(_i32 r) {
|
||||||
DBG(("SL error: %d", (int) r));
|
DBG(("SL error: %d", (int) r));
|
||||||
@ -10309,7 +10317,18 @@ int fs_slfs_open(const char *pathname, int flags, mode_t mode) {
|
|||||||
return set_errno(ENOTSUP);
|
return set_errno(ENOTSUP);
|
||||||
}
|
}
|
||||||
if (flags & O_CREAT) {
|
if (flags & O_CREAT) {
|
||||||
am = FS_MODE_OPEN_CREATE(FS_SLFS_MAX_FILE_SIZE, 0);
|
size_t i, size = FS_SLFS_MAX_FILE_SIZE;
|
||||||
|
for (i = 0; i < MAX_OPEN_SLFS_FILES; i++) {
|
||||||
|
if (s_sl_file_size_hints[i].name != NULL &&
|
||||||
|
strcmp(s_sl_file_size_hints[i].name, pathname) == 0) {
|
||||||
|
size = s_sl_file_size_hints[i].size;
|
||||||
|
free(s_sl_file_size_hints[i].name);
|
||||||
|
s_sl_file_size_hints[i].name = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBG(("creating %s with max size %d", pathname, (int) size));
|
||||||
|
am = FS_MODE_OPEN_CREATE(size, 0);
|
||||||
} else {
|
} else {
|
||||||
am = FS_MODE_OPEN_WRITE;
|
am = FS_MODE_OPEN_WRITE;
|
||||||
}
|
}
|
||||||
@ -10410,6 +10429,18 @@ int fs_slfs_rename(const char *from, const char *to) {
|
|||||||
return set_errno(ENOTSUP);
|
return set_errno(ENOTSUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fs_slfs_set_new_file_size(const char *name, size_t size) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < MAX_OPEN_SLFS_FILES; i++) {
|
||||||
|
if (s_sl_file_size_hints[i].name == NULL) {
|
||||||
|
DBG(("File size hint: %s %d", name, (int) size));
|
||||||
|
s_sl_file_size_hints[i].name = strdup(name);
|
||||||
|
s_sl_file_size_hints[i].size = size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* defined(MG_FS_SLFS) || defined(CC3200_FS_SLFS) */
|
#endif /* defined(MG_FS_SLFS) || defined(CC3200_FS_SLFS) */
|
||||||
#ifdef MG_MODULE_LINES
|
#ifdef MG_MODULE_LINES
|
||||||
#line 1 "./src/../../common/platforms/simplelink/sl_fs.c"
|
#line 1 "./src/../../common/platforms/simplelink/sl_fs.c"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user