Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
c9cf02ba
Commit
c9cf02ba
authored
Feb 01, 2016
by
philip
Browse files
Send any queued packets when possible
parent
fcb14a33
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/mqtt.c
View file @
c9cf02ba
...
...
@@ -431,25 +431,43 @@ static void mqtt_socket_sent(void *arg)
return
;
}
NODE_DBG
(
"sent1, queue size: %d
\n
"
,
msg_size
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)));
uint8_t
try_send
=
1
;
// qos = 0, publish and forgot.
msg_queue_t
*
node
=
msg_peek
(
&
(
mud
->
mqtt_state
.
pending_msg_q
));
if
(
node
&&
node
->
msg_type
==
MQTT_MSG_TYPE_PUBLISH
&&
node
->
publish_qos
==
0
)
{
msg_destroy
(
msg_dequeue
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)));
if
(
mud
->
cb_puback_ref
==
LUA_NOREF
)
return
;
if
(
mud
->
self_ref
==
LUA_NOREF
)
return
;
if
(
mud
->
L
==
NULL
)
return
;
lua_rawgeti
(
mud
->
L
,
LUA_REGISTRYINDEX
,
mud
->
cb_puback_ref
);
lua_rawgeti
(
mud
->
L
,
LUA_REGISTRYINDEX
,
mud
->
self_ref
);
// pass the userdata to callback func in lua
lua_call
(
mud
->
L
,
1
,
0
);
if
(
mud
->
cb_puback_ref
!=
LUA_NOREF
&&
mud
->
self_ref
!=
LUA_NOREF
)
{
lua_State
*
L
=
lua_getstate
();
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mud
->
cb_puback_ref
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mud
->
self_ref
);
// pass the userdata to callback func in lua
lua_call
(
L
,
1
,
0
);
}
}
else
if
(
node
&&
node
->
msg_type
==
MQTT_MSG_TYPE_PUBACK
)
{
msg_destroy
(
msg_dequeue
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)));
}
else
if
(
node
&&
node
->
msg_type
==
MQTT_MSG_TYPE_PUBCOMP
)
{
msg_destroy
(
msg_dequeue
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)));
}
else
if
(
node
&&
node
->
msg_type
==
MQTT_MSG_TYPE_PINGREQ
)
{
msg_destroy
(
msg_dequeue
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)));
}
else
{
try_send
=
0
;
}
if
(
try_send
)
{
msg_queue_t
*
node
=
msg_peek
(
&
(
mud
->
mqtt_state
.
pending_msg_q
));
if
(
node
)
{
mud
->
event_timeout
=
MQTT_SEND_TIMEOUT
;
NODE_DBG
(
"Sent: %d
\n
"
,
node
->
msg
.
length
);
#ifdef CLIENT_SSL_ENABLE
if
(
mud
->
secure
)
{
(
void
)
espconn_secure_send
(
mud
->
pesp_conn
,
node
->
msg
.
data
,
node
->
msg
.
length
);
}
else
#endif
{
(
void
)
espconn_send
(
mud
->
pesp_conn
,
node
->
msg
.
data
,
node
->
msg
.
length
);
}
mud
->
keep_alive_tick
=
0
;
}
}
NODE_DBG
(
"sent2, queue size: %d
\n
"
,
msg_size
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)));
NODE_DBG
(
"leave mqtt_socket_sent.
\n
"
);
...
...
@@ -1322,7 +1340,7 @@ static int mqtt_socket_publish( lua_State* L )
msg_queue_t
*
node
=
msg_enqueue
(
&
(
mud
->
mqtt_state
.
pending_msg_q
),
temp_msg
,
msg_id
,
MQTT_MSG_TYPE_PUBLISH
,
(
int
)
qos
);
sint8
espconn_status
=
ESPCONN_
IF
;
sint8
espconn_status
=
ESPCONN_
OK
;
if
(
node
&&
(
1
==
msg_size
(
&
(
mud
->
mqtt_state
.
pending_msg_q
)))
&&
mud
->
event_timeout
==
0
){
mud
->
event_timeout
=
MQTT_SEND_TIMEOUT
;
...
...
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