Telethon/telethon/network/connection/tcpintermediate.py

20 lines
558 B
Python
Raw Normal View History

import struct
from .connection import Connection
class ConnectionTcpIntermediate(Connection):
"""
Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`.
Always sends 4 extra bytes for the packet length.
"""
2019-02-21 12:41:33 +03:00
def _init_conn(self):
2018-10-04 18:34:58 +03:00
self._writer.write(b'\xee\xee\xee\xee')
def _send(self, data):
self._writer.write(struct.pack('<i', len(data)) + data)
async def _recv(self):
return await self._reader.readexactly(
struct.unpack('<i', await self._reader.readexactly(4))[0])