@@ -2153,30 +2153,27 @@ def loop_misc(self) -> MQTTErrorCode:
21532153 now = time_func ()
21542154 self ._check_keepalive ()
21552155
2156- if self ._ping_t == 0 :
2157- return MQTTErrorCode .MQTT_ERR_SUCCESS
2158- if now - self ._ping_t < self ._keepalive :
2159- return MQTTErrorCode .MQTT_ERR_SUCCESS
2160- if now - self ._last_msg_in < self ._keepalive :
2161- return MQTTErrorCode .MQTT_ERR_SUCCESS
2156+ if self ._ping_t > 0 and now - self ._last_msg_in >= self ._keepalive :
2157+ # client->ping_t != 0 means we are waiting for a pingresp.
2158+ # This hasn't happened in the keepalive time so we should disconnect.
2159+ self ._sock_close ()
21622160
2163- # client->ping_t != 0 means we are waiting for a pingresp.
2164- # This hasn't happened in the keepalive time so we should disconnect.
2165- self ._sock_close ()
2161+ if self ._state in (_ConnectionState .MQTT_CS_DISCONNECTING , _ConnectionState .MQTT_CS_DISCONNECTED ):
2162+ self ._state = _ConnectionState .MQTT_CS_DISCONNECTED
2163+ rc = MQTTErrorCode .MQTT_ERR_SUCCESS
2164+ else :
2165+ self ._state = _ConnectionState .MQTT_CS_CONNECTION_LOST
2166+ rc = MQTTErrorCode .MQTT_ERR_KEEPALIVE
21662167
2167- if self ._state in (_ConnectionState .MQTT_CS_DISCONNECTING , _ConnectionState .MQTT_CS_DISCONNECTED ):
2168- self ._state = _ConnectionState .MQTT_CS_DISCONNECTED
2169- rc = MQTTErrorCode .MQTT_ERR_SUCCESS
2170- else :
2171- self ._state = _ConnectionState .MQTT_CS_CONNECTION_LOST
2172- rc = MQTTErrorCode .MQTT_ERR_KEEPALIVE
2168+ self ._do_on_disconnect (
2169+ packet_from_broker = False ,
2170+ v1_rc = rc ,
2171+ )
21732172
2174- self ._do_on_disconnect (
2175- packet_from_broker = False ,
2176- v1_rc = rc ,
2177- )
2173+ return MQTTErrorCode .MQTT_ERR_CONN_LOST
2174+
2175+ return MQTTErrorCode .MQTT_ERR_SUCCESS
21782176
2179- return MQTTErrorCode .MQTT_ERR_CONN_LOST
21802177
21812178
21822179 def max_inflight_messages_set (self , inflight : int ) -> None :
0 commit comments