mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-30 21:12:55 +08:00
propagate error code for close
This commit is contained in:
parent
40e0be29ee
commit
412db2e339
@ -343,13 +343,17 @@ static void lnet_netconn_callback(struct netconn *netconn, enum netconn_evt evt,
|
|||||||
#include "lwip/priv/api_msg.h"
|
#include "lwip/priv/api_msg.h"
|
||||||
#define NETCONN_DELETE(conn) \
|
#define NETCONN_DELETE(conn) \
|
||||||
if (netconn_delete(conn) == ERR_OK) netconn_free(conn);
|
if (netconn_delete(conn) == ERR_OK) netconn_free(conn);
|
||||||
#define NETCONN_CLOSE(conn) netconn_close_wa(conn);
|
#define NETCONN_CLOSE(conn) netconn_close_wa(conn)
|
||||||
static void netconn_close_wa(struct netconn *conn) {
|
static err_t netconn_close_wa(struct netconn *conn) {
|
||||||
if (netconn_close(conn) != ERR_OK) {
|
err_t err = netconn_close(conn);
|
||||||
NETCONN_DELETE(conn);
|
if (err == ERR_OK) {
|
||||||
} else {
|
err = netconn_delete(conn);
|
||||||
netconn_free(conn);
|
if (err == ERR_OK) {
|
||||||
|
netconn_free(conn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -477,12 +481,12 @@ int net_listen( lua_State *L ) {
|
|||||||
ud->closing = true;
|
ud->closing = true;
|
||||||
switch (ud->type) {
|
switch (ud->type) {
|
||||||
case TYPE_TCP_SERVER:
|
case TYPE_TCP_SERVER:
|
||||||
NETCONN_CLOSE(ud->netconn);
|
if (NETCONN_CLOSE(ud->netconn) == ERR_OK)
|
||||||
ud->netconn = NULL;
|
ud->netconn = NULL;
|
||||||
break;
|
break;
|
||||||
case TYPE_UDP_SOCKET:
|
case TYPE_UDP_SOCKET:
|
||||||
NETCONN_CLOSE(ud->netconn);
|
if (NETCONN_CLOSE(ud->netconn) == ERR_OK)
|
||||||
ud->netconn = NULL;
|
ud->netconn = NULL;
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -538,8 +542,8 @@ int net_connect( lua_State *L ) {
|
|||||||
ud->self_ref = LUA_NOREF;
|
ud->self_ref = LUA_NOREF;
|
||||||
}
|
}
|
||||||
ud->closing = true;
|
ud->closing = true;
|
||||||
NETCONN_CLOSE(ud->netconn);
|
if (NETCONN_CLOSE(ud->netconn) == ERR_OK)
|
||||||
ud->netconn = NULL;
|
ud->netconn = NULL;
|
||||||
return lwip_lua_checkerr(L, err);
|
return lwip_lua_checkerr(L, err);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -620,8 +624,8 @@ int net_send( lua_State *L ) {
|
|||||||
err_t err = netconn_bind(ud->netconn, IP_ADDR_ANY, 0);
|
err_t err = netconn_bind(ud->netconn, IP_ADDR_ANY, 0);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
ud->closing = true;
|
ud->closing = true;
|
||||||
NETCONN_CLOSE(ud->netconn);
|
if (NETCONN_CLOSE(ud->netconn) == ERR_OK)
|
||||||
ud->netconn = NULL;
|
ud->netconn = NULL;
|
||||||
return lwip_lua_checkerr(L, err);
|
return lwip_lua_checkerr(L, err);
|
||||||
}
|
}
|
||||||
if (ud->self_ref == LUA_NOREF) {
|
if (ud->self_ref == LUA_NOREF) {
|
||||||
@ -786,6 +790,7 @@ int net_getaddr( lua_State *L ) {
|
|||||||
|
|
||||||
// Lua: client/server/socket:close()
|
// Lua: client/server/socket:close()
|
||||||
int net_close( lua_State *L ) {
|
int net_close( lua_State *L ) {
|
||||||
|
err_t err = ERR_OK;
|
||||||
lnet_userdata *ud = net_get_udata(L);
|
lnet_userdata *ud = net_get_udata(L);
|
||||||
if (!ud) return luaL_error(L, "invalid user data");
|
if (!ud) return luaL_error(L, "invalid user data");
|
||||||
if (ud->netconn) {
|
if (ud->netconn) {
|
||||||
@ -794,8 +799,9 @@ int net_close( lua_State *L ) {
|
|||||||
case TYPE_TCP_SERVER:
|
case TYPE_TCP_SERVER:
|
||||||
case TYPE_UDP_SOCKET:
|
case TYPE_UDP_SOCKET:
|
||||||
ud->closing = true;
|
ud->closing = true;
|
||||||
NETCONN_CLOSE(ud->netconn);
|
err = NETCONN_CLOSE(ud->netconn);
|
||||||
ud->netconn = NULL;
|
if (err == ERR_OK)
|
||||||
|
ud->netconn = NULL;
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -809,7 +815,7 @@ int net_close( lua_State *L ) {
|
|||||||
ud->self_ref = LUA_NOREF;
|
ud->self_ref = LUA_NOREF;
|
||||||
lua_gc(L, LUA_GCRESTART, 0);
|
lua_gc(L, LUA_GCRESTART, 0);
|
||||||
}
|
}
|
||||||
return 0;
|
return lwip_lua_checkerr(L, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_delete( lua_State *L ) {
|
int net_delete( lua_State *L ) {
|
||||||
@ -821,7 +827,7 @@ int net_delete( lua_State *L ) {
|
|||||||
case TYPE_TCP_SERVER:
|
case TYPE_TCP_SERVER:
|
||||||
case TYPE_UDP_SOCKET:
|
case TYPE_UDP_SOCKET:
|
||||||
ud->closing = true;
|
ud->closing = true;
|
||||||
NETCONN_CLOSE(ud->netconn);
|
NETCONN_DELETE(ud->netconn);
|
||||||
ud->netconn = NULL;
|
ud->netconn = NULL;
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user