mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Always acknowledge received errors for server not to resend them
This commit is contained in:
parent
639a17aa5a
commit
efd1c1ba64
|
@ -50,13 +50,7 @@ class MtProtoSender:
|
||||||
self._logger.debug('send() acquired the lock')
|
self._logger.debug('send() acquired the lock')
|
||||||
|
|
||||||
# If any message needs confirmation send an AckRequest first
|
# If any message needs confirmation send an AckRequest first
|
||||||
if self._need_confirmation:
|
self._send_acknowledges()
|
||||||
msgs_ack = MsgsAck(self._need_confirmation)
|
|
||||||
with BinaryWriter() as writer:
|
|
||||||
msgs_ack.on_send(writer)
|
|
||||||
self._send_packet(writer.get_bytes(), msgs_ack)
|
|
||||||
|
|
||||||
del self._need_confirmation[:]
|
|
||||||
|
|
||||||
# Finally send our packed request
|
# Finally send our packed request
|
||||||
with BinaryWriter() as writer:
|
with BinaryWriter() as writer:
|
||||||
|
@ -68,6 +62,16 @@ class MtProtoSender:
|
||||||
|
|
||||||
self._logger.debug('send() released the lock')
|
self._logger.debug('send() released the lock')
|
||||||
|
|
||||||
|
def _send_acknowledges(self):
|
||||||
|
"""Sends a messages acknowledge for all those who _need_confirmation"""
|
||||||
|
if self._need_confirmation:
|
||||||
|
msgs_ack = MsgsAck(self._need_confirmation)
|
||||||
|
with BinaryWriter() as writer:
|
||||||
|
msgs_ack.on_send(writer)
|
||||||
|
self._send_packet(writer.get_bytes(), msgs_ack)
|
||||||
|
|
||||||
|
del self._need_confirmation[:]
|
||||||
|
|
||||||
def receive(self, request=None, timeout=timedelta(seconds=5), updates=None):
|
def receive(self, request=None, timeout=timedelta(seconds=5), updates=None):
|
||||||
"""Receives the specified MTProtoRequest ("fills in it"
|
"""Receives the specified MTProtoRequest ("fills in it"
|
||||||
the received data). This also restores the updates thread.
|
the received data). This also restores the updates thread.
|
||||||
|
@ -324,6 +328,10 @@ class MtProtoSender:
|
||||||
error = RPCError(
|
error = RPCError(
|
||||||
code=reader.read_int(), message=reader.tgread_string())
|
code=reader.read_int(), message=reader.tgread_string())
|
||||||
|
|
||||||
|
# Acknowledge that we received the error
|
||||||
|
self._need_confirmation.append(request_id)
|
||||||
|
self._send_acknowledges()
|
||||||
|
|
||||||
self._logger.warning('Read RPC error: %s', str(error))
|
self._logger.warning('Read RPC error: %s', str(error))
|
||||||
if error.must_resend:
|
if error.must_resend:
|
||||||
if not request:
|
if not request:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user