@@ -220,7 +220,7 @@ def __init__(
220
220
self .client_id = client_id
221
221
else :
222
222
# assign a unique client_id
223
- time_int = (self .get_monotonic_ns_time () % 10000000000 ) // 10000000
223
+ time_int = (self .get_monotonic_time () % 10000000000 ) // 10000000
224
224
self .client_id = f"cpy{ randint (0 , time_int )} { randint (0 , 99 )} "
225
225
# generated client_id's enforce spec.'s length rules
226
226
if len (self .client_id .encode ("utf-8" )) > 23 or not self .client_id :
@@ -244,7 +244,7 @@ def __init__(
244
244
self .on_subscribe = None
245
245
self .on_unsubscribe = None
246
246
247
- def get_monotonic_ns_time (self ) -> float :
247
+ def get_monotonic_time (self ) -> float :
248
248
"""
249
249
Provide monotonic time in nanoseconds. Based on underlying implementation
250
250
this might result in imprecise time, that will result in the library
@@ -261,7 +261,7 @@ def diff_ns(self, stamp_ns):
261
261
Taking timestamp differences using nanosecond ints before dividing
262
262
should maintain precision.
263
263
"""
264
- return (self .get_monotonic_ns_time () - stamp_ns ) / 1000000000
264
+ return (self .get_monotonic_time () - stamp_ns ) / 1000000000
265
265
266
266
def __enter__ (self ):
267
267
return self
@@ -534,9 +534,9 @@ def _connect(
534
534
if self ._username is not None :
535
535
self ._send_str (self ._username )
536
536
self ._send_str (self ._password )
537
- self ._last_msg_sent_timestamp_ns = self .get_monotonic_ns_time ()
537
+ self ._last_msg_sent_timestamp_ns = self .get_monotonic_time ()
538
538
self .logger .debug ("Receiving CONNACK packet from broker" )
539
- stamp_ns = self .get_monotonic_ns_time ()
539
+ stamp_ns = self .get_monotonic_time ()
540
540
while True :
541
541
op = self ._wait_for_msg ()
542
542
if op == 32 :
@@ -602,7 +602,7 @@ def ping(self) -> list[int]:
602
602
self .logger .debug ("Sending PINGREQ" )
603
603
self ._sock .send (MQTT_PINGREQ )
604
604
ping_timeout = self .keep_alive
605
- stamp_ns = self .get_monotonic_ns_time ()
605
+ stamp_ns = self .get_monotonic_time ()
606
606
self ._last_msg_sent_timestamp_ns = stamp_ns
607
607
rc , rcs = None , []
608
608
while rc != MQTT_PINGRESP :
@@ -678,11 +678,11 @@ def publish(
678
678
self ._sock .send (pub_hdr_fixed )
679
679
self ._sock .send (pub_hdr_var )
680
680
self ._sock .send (msg )
681
- self ._last_msg_sent_timestamp_ns = self .get_monotonic_ns_time ()
681
+ self ._last_msg_sent_timestamp_ns = self .get_monotonic_time ()
682
682
if qos == 0 and self .on_publish is not None :
683
683
self .on_publish (self , self .user_data , topic , self ._pid )
684
684
if qos == 1 :
685
- stamp_ns = self .get_monotonic_ns_time ()
685
+ stamp_ns = self .get_monotonic_time ()
686
686
while True :
687
687
op = self ._wait_for_msg ()
688
688
if op == 0x40 :
@@ -755,7 +755,7 @@ def subscribe(self, topic: Optional[Union[tuple, str, list]], qos: int = 0) -> N
755
755
self .logger .debug (f"SUBSCRIBING to topic { t } with QoS { q } " )
756
756
self .logger .debug (f"payload: { payload } " )
757
757
self ._sock .send (payload )
758
- stamp_ns = self .get_monotonic_ns_time ()
758
+ stamp_ns = self .get_monotonic_time ()
759
759
self ._last_msg_sent_timestamp_ns = stamp_ns
760
760
while True :
761
761
op = self ._wait_for_msg ()
@@ -832,10 +832,10 @@ def unsubscribe(self, topic: Optional[Union[str, list]]) -> None:
832
832
for t in topics :
833
833
self .logger .debug (f"UNSUBSCRIBING from topic { t } " )
834
834
self ._sock .send (payload )
835
- self ._last_msg_sent_timestamp_ns = self .get_monotonic_ns_time ()
835
+ self ._last_msg_sent_timestamp_ns = self .get_monotonic_time ()
836
836
self .logger .debug ("Waiting for UNSUBACK..." )
837
837
while True :
838
- stamp_ns = self .get_monotonic_ns_time ()
838
+ stamp_ns = self .get_monotonic_time ()
839
839
op = self ._wait_for_msg ()
840
840
if op is None :
841
841
if self .diff_ns (stamp_ns ) > self ._recv_timeout :
@@ -938,7 +938,7 @@ def loop(self, timeout: float = 0) -> Optional[list[int]]:
938
938
self ._connected ()
939
939
self .logger .debug (f"waiting for messages for { timeout } seconds" )
940
940
941
- stamp_ns = self .get_monotonic_ns_time ()
941
+ stamp_ns = self .get_monotonic_time ()
942
942
rcs = []
943
943
944
944
while True :
@@ -1063,7 +1063,7 @@ def _sock_exact_recv(
1063
1063
:param float timeout: timeout, in seconds. Defaults to keep_alive
1064
1064
:return: byte array
1065
1065
"""
1066
- stamp_ns = self .get_monotonic_ns_time ()
1066
+ stamp_ns = self .get_monotonic_time ()
1067
1067
if not self ._backwards_compatible_sock :
1068
1068
# CPython/Socketpool Impl.
1069
1069
rc = bytearray (bufsize )
0 commit comments