Skip to content

Commit

Permalink
Merge branch 'master' of https://gitee.com/openLuat/LuatOS
Browse files Browse the repository at this point in the history
  • Loading branch information
allewalker committed Dec 25, 2024
2 parents afa0653 + d8fc2a1 commit 05e3147
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
14 changes: 8 additions & 6 deletions components/network/adapter_lwip2/net_lwip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void net_lwip2_set_netif(uint8_t adapter_index, struct netif *netif) {
#ifdef udp_bind_netif
udp_bind_netif(prvlwip.dns_udp[adapter_index], netif);
#endif
prvlwip.dns_timer[adapter_index] = platform_create_timer(net_lwip2_timer_cb, (void *)adapter_index, 0);
int tmp = adapter_index;
prvlwip.dns_timer[adapter_index] = platform_create_timer(net_lwip2_timer_cb, (void *)tmp, NULL);
}
prvlwip.lwip_netif[adapter_index] = netif;
}
Expand Down Expand Up @@ -922,21 +923,22 @@ static void net_lwip2_check_network_ready(uint8_t adapter_index)
else
{
NET_DBG("network ready");
uint32_t tmp = adapter_index;
if (prvlwip.lwip_netif[adapter_index] != NULL && !ip_addr_isany(&prvlwip.lwip_netif[adapter_index]->gw)) {
NET_DBG("使用网关作为默认DNS服务器");
net_lwip2_set_dns_server(0, &prvlwip.lwip_netif[adapter_index]->gw, (void*)adapter_index);
net_lwip2_set_dns_server(0, &prvlwip.lwip_netif[adapter_index]->gw, (void*)tmp);
}
else {
NET_DBG("使用223.5.5.5作为默认DNS服务器");
ip4addr_aton("223.5.5.5", &addr);
net_lwip2_set_dns_server(0, &addr, (void*)adapter_index);
net_lwip2_set_dns_server(0, &addr, (void*)tmp);
}
ip4addr_aton("114.114.114.114", &addr);
net_lwip2_set_dns_server(1, &addr, (void*)adapter_index);
net_lwip2_set_dns_server(1, &addr, (void*)tmp);
ip4addr_aton("223.5.5.5", &addr);
net_lwip2_set_dns_server(2, &addr, (void*)adapter_index);
net_lwip2_set_dns_server(2, &addr, (void*)tmp);
ip4addr_aton("119.29.29.29", &addr);
net_lwip2_set_dns_server(3, &addr, (void*)adapter_index);
net_lwip2_set_dns_server(3, &addr, (void*)tmp);
net_lwip2_callback_to_nw_task(adapter_index, EV_NW_STATE, 0, 1, adapter_index);
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/network/libftp/luat_ftp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static int32_t luat_ftp_data_callback(void *data, void *param){
{
if (g_s_ftp.fd)
{
luat_rtos_event_send(g_s_ftp.task_handle, FTP_EVENT_DATA_WRITE_FILE, rx_buffer, rx_len, 0, LUAT_WAIT_FOREVER);
luat_rtos_event_send(g_s_ftp.task_handle, FTP_EVENT_DATA_WRITE_FILE, (uint32_t)rx_buffer, rx_len, 0, LUAT_WAIT_FOREVER);
rx_buffer = NULL;
continue;
}
Expand Down
12 changes: 6 additions & 6 deletions components/network/libhttp/luat_lib_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ static int l_http_request(lua_State *L) {

lua_pushstring(L, "callback");
if (LUA_TFUNCTION == lua_gettable(L, 5)) {
http_ctrl->http_cb = luaL_ref(L, LUA_REGISTRYINDEX);
http_ctrl->http_cb = (void*)luaL_ref(L, LUA_REGISTRYINDEX);
}

if (http_ctrl->http_cb){
lua_pushstring(L, "userdata");
lua_gettable(L, 5);
http_ctrl->http_cb_userdata = luaL_ref(L, LUA_REGISTRYINDEX);
http_ctrl->http_cb_userdata = (void*)luaL_ref(L, LUA_REGISTRYINDEX);
}
}else{
adapter_index = network_get_last_register_adapter();
Expand Down Expand Up @@ -384,13 +384,13 @@ int32_t l_http_callback(lua_State *L, void* ptr){
LLOGD("l_http_callback arg1:%d is_download:%d idp:%d",msg->arg1,http_ctrl->is_download,idp);
if (msg->arg1!=0 && msg->arg1!=HTTP_ERROR_FOTA ){
if (msg->arg1 == HTTP_CALLBACK){
lua_geti(L, LUA_REGISTRYINDEX, http_ctrl->http_cb);
lua_geti(L, LUA_REGISTRYINDEX, (int)http_ctrl->http_cb);
// int userdata_type = lua_type(L, -2);
if (lua_isfunction(L, -1)) {
lua_pushinteger(L, http_ctrl->resp_content_len);
lua_pushinteger(L, msg->arg2);
if (http_ctrl->http_cb_userdata){
lua_geti(L, LUA_REGISTRYINDEX, http_ctrl->http_cb_userdata);
lua_geti(L, LUA_REGISTRYINDEX, (int)http_ctrl->http_cb_userdata);
lua_call(L, 3, 0);
}else{
lua_call(L, 2, 0);
Expand Down Expand Up @@ -456,10 +456,10 @@ int32_t l_http_callback(lua_State *L, void* ptr){
}
exit:
if (http_ctrl->http_cb){
luaL_unref(L, LUA_REGISTRYINDEX, http_ctrl->http_cb);
luaL_unref(L, LUA_REGISTRYINDEX, (int)http_ctrl->http_cb);
http_ctrl->http_cb = 0;
if (http_ctrl->http_cb_userdata){
luaL_unref(L, LUA_REGISTRYINDEX, http_ctrl->http_cb_userdata);
luaL_unref(L, LUA_REGISTRYINDEX, (int)http_ctrl->http_cb_userdata);
http_ctrl->http_cb_userdata = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion luat/vfs/luat_fs_lfs2.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int luat_vfs_lfs2_getc(void* userdata, FILE* stream) {
lfs_file_t* file = (lfs_file_t*)stream;
char buff = 0;
int ret = lfs_file_read(fs, file, &buff, 1);
if (ret < 0)
if (ret != 1)
return -1;
return (int)buff;
}
Expand Down
9 changes: 7 additions & 2 deletions luat/vfs/luat_fs_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct luat_ram_fd
{
int fid;
uint32_t offset;
uint8_t readonly;
}luat_raw_fd_t;

#define RAM_FILE_MAX (8)
Expand All @@ -40,13 +41,14 @@ FILE* luat_vfs_ram_fopen(void* userdata, const char *filename, const char *mode)
}
fd->fid = i;
fd->offset = 0;
fd->readonly = 1;
return (FILE*)fd;
}
}
return NULL;
}
// 写文件
if (!strcmp("w", mode) || !strcmp("wb", mode) || !strcmp("w+", mode) || !strcmp("wb+", mode) || !strcmp("r+", mode) || !strcmp("rb+", mode)) {
if (!strcmp("w", mode) || !strcmp("wb", mode) || !strcmp("w+", mode) || !strcmp("wb+", mode) || !strcmp("w+b", mode) || !strcmp("r+", mode) || !strcmp("rb+", mode) || !strcmp("r+b", mode)) {
// 先看看是否存在, 如果存在就重用老的
for (size_t i = 0; i < RAM_FILE_MAX; i++)
{
Expand All @@ -59,7 +61,7 @@ FILE* luat_vfs_ram_fopen(void* userdata, const char *filename, const char *mode)
return NULL;
}
fd->fid = i;
if (!strcmp("w+", mode) || !strcmp("wb+", mode)) {
if (!strcmp("w+", mode) || !strcmp("wb+", mode) || !strcmp("w+b", mode)) {
// 截断模式
char* tmp = luat_heap_realloc(files[i], sizeof(ram_file_t));
if (tmp) {
Expand Down Expand Up @@ -198,6 +200,9 @@ size_t luat_vfs_ram_fwrite(void* userdata, const void *ptr, size_t size, size_t
(void)userdata;
luat_raw_fd_t* fd = (luat_raw_fd_t*)stream;
size_t write_size = size*nmemb;
if (fd->readonly) {
return 0;
}

if (fd->offset + write_size > files[fd->fid]->size) {
char* ptr = luat_heap_realloc(files[fd->fid], fd->offset + write_size + sizeof(ram_file_t));
Expand Down

0 comments on commit 05e3147

Please sign in to comment.