mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Fix basic requests sending and receiving
This commit is contained in:
@@ -22,7 +22,7 @@ class ConnectionTcpFull(Connection):
|
||||
|
||||
async def connect(self, ip, port):
|
||||
try:
|
||||
self.conn.connect(ip, port)
|
||||
await self.conn.connect(ip, port)
|
||||
except OSError as e:
|
||||
if e.errno == errno.EISCONN:
|
||||
return # Already connected, no need to re-set everything up
|
||||
@@ -35,7 +35,7 @@ class ConnectionTcpFull(Connection):
|
||||
return self.conn.timeout
|
||||
|
||||
def is_connected(self):
|
||||
return self.conn.connected
|
||||
return self.conn.is_connected
|
||||
|
||||
async def close(self):
|
||||
self.conn.close()
|
||||
@@ -44,10 +44,11 @@ class ConnectionTcpFull(Connection):
|
||||
return ConnectionTcpFull(self._proxy, self._timeout)
|
||||
|
||||
async def recv(self):
|
||||
packet_len_seq = self.read(8) # 4 and 4
|
||||
packet_len_seq = await self.read(8) # 4 and 4
|
||||
packet_len, seq = struct.unpack('<ii', packet_len_seq)
|
||||
body = self.read(packet_len - 12)
|
||||
checksum = struct.unpack('<I', self.read(4))[0]
|
||||
body = await self.read(packet_len - 8)
|
||||
checksum = struct.unpack('<I', body[-4:])[0]
|
||||
body = body[:-4]
|
||||
|
||||
valid_checksum = crc32(packet_len_seq + body)
|
||||
if checksum != valid_checksum:
|
||||
@@ -62,4 +63,4 @@ class ConnectionTcpFull(Connection):
|
||||
data = struct.pack('<ii', length, self._send_counter) + message
|
||||
crc = struct.pack('<I', crc32(data))
|
||||
self._send_counter += 1
|
||||
self.write(data + crc)
|
||||
await self.write(data + crc)
|
||||
|
Reference in New Issue
Block a user