mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Don't do anything on .connect() if it's already connected
This commit is contained in:
parent
daa626aa04
commit
697434be37
|
@ -35,6 +35,9 @@ class MtProtoSender:
|
|||
"""Connects to the server"""
|
||||
self._transport.connect()
|
||||
|
||||
def is_connected(self):
|
||||
return self._transport.is_connected()
|
||||
|
||||
def disconnect(self):
|
||||
"""Disconnects from the server"""
|
||||
self._transport.close()
|
||||
|
|
|
@ -18,6 +18,9 @@ class TcpTransport:
|
|||
self.send_counter = 0
|
||||
self.tcp_client.connect(self.ip, self.port)
|
||||
|
||||
def is_connected(self):
|
||||
return self.tcp_client.connected
|
||||
|
||||
# Original reference: https://core.telegram.org/mtproto#tcp-transport
|
||||
# The packets are encoded as: total length, sequence number, packet and checksum (CRC32)
|
||||
def send(self, packet):
|
||||
|
|
|
@ -79,6 +79,12 @@ class TelegramBareClient:
|
|||
If 'exported_auth' is not None, it will be used instead to
|
||||
determine the authorization key for the current session.
|
||||
"""
|
||||
if self.sender and self.sender.is_connected():
|
||||
self._logger.warning(
|
||||
'Attempted to connect when the client was already connected.'
|
||||
)
|
||||
return
|
||||
|
||||
transport = TcpTransport(self.session.server_address,
|
||||
self.session.port, proxy=self.proxy)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user