Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
412db2e3
Commit
412db2e3
authored
Aug 14, 2017
by
devsaurus
Browse files
propagate error code for close
parent
40e0be29
Changes
1
Hide whitespace changes
Inline
Side-by-side
components/modules/net.c
View file @
412db2e3
...
@@ -343,13 +343,17 @@ static void lnet_netconn_callback(struct netconn *netconn, enum netconn_evt evt,
...
@@ -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 ) {
...
@@ -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 ) {
...
@@ -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 ) {
...
@@ -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 ) {
...
@@ -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 ) {
...
@@ -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 ) {
...
@@ -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 ) {
...
@@ -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_
CLOS
E
(
ud
->
netconn
);
NETCONN_
DELET
E
(
ud
->
netconn
);
ud
->
netconn
=
NULL
;
ud
->
netconn
=
NULL
;
break
;
break
;
default:
break
;
default:
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment