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
0b998e56
Commit
0b998e56
authored
Nov 12, 2017
by
devsaurus
Browse files
tolerate multiple netconn callbacks for a single send job
parent
7448d21a
Changes
1
Show whitespace changes
Inline
Side-by-side
components/modules/net.c
View file @
0b998e56
...
@@ -61,6 +61,7 @@ typedef struct lnet_userdata {
...
@@ -61,6 +61,7 @@ typedef struct lnet_userdata {
bool
connecting
;
bool
connecting
;
int
hold
;
int
hold
;
size_t
num_held
;
size_t
num_held
;
size_t
num_send
;
int
cb_connect_ref
;
int
cb_connect_ref
;
int
cb_disconnect_ref
;
int
cb_disconnect_ref
;
int
cb_reconnect_ref
;
int
cb_reconnect_ref
;
...
@@ -290,9 +291,14 @@ static void lnet_netconn_callback(struct netconn *netconn, enum netconn_evt evt,
...
@@ -290,9 +291,14 @@ static void lnet_netconn_callback(struct netconn *netconn, enum netconn_evt evt,
ud
->
client
.
connecting
=
false
;
ud
->
client
.
connecting
=
false
;
post_net_connected
(
ud
);
post_net_connected
(
ud
);
}
else
if
(
len
>
0
)
{
}
else
if
(
len
>
0
)
{
// data sent, trigger Lua callback
// we're potentially called back from netconn several times for a single send job
// keep track of them in num_send and postpone the Lua callback until all data is sent
ud
->
client
.
num_send
-=
len
;
if
(
ud
->
client
.
num_send
==
0
)
{
// all data sent, trigger Lua callback
post_net_sent
(
ud
);
post_net_sent
(
ud
);
}
}
}
break
;
break
;
case
NETCONN_EVT_ERROR
:
case
NETCONN_EVT_ERROR
:
...
@@ -608,6 +614,7 @@ int net_send( lua_State *L ) {
...
@@ -608,6 +614,7 @@ int net_send( lua_State *L ) {
}
}
data
=
luaL_checklstring
(
L
,
stack
++
,
&
datalen
);
data
=
luaL_checklstring
(
L
,
stack
++
,
&
datalen
);
if
(
!
data
||
datalen
==
0
)
return
luaL_error
(
L
,
"no data to send"
);
if
(
!
data
||
datalen
==
0
)
return
luaL_error
(
L
,
"no data to send"
);
ud
->
client
.
num_send
=
datalen
;
if
(
lua_isfunction
(
L
,
stack
)
||
lua_islightfunction
(
L
,
stack
))
{
if
(
lua_isfunction
(
L
,
stack
)
||
lua_islightfunction
(
L
,
stack
))
{
lua_pushvalue
(
L
,
stack
++
);
lua_pushvalue
(
L
,
stack
++
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
ud
->
client
.
cb_sent_ref
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
ud
->
client
.
cb_sent_ref
);
...
...
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