2018-05-10 15:22:19 +03:00
|
|
|
import struct
|
|
|
|
|
2018-09-27 20:22:35 +03:00
|
|
|
from .connection import Connection
|
2018-05-10 15:22:19 +03:00
|
|
|
|
|
|
|
|
2018-09-27 20:22:35 +03:00
|
|
|
class ConnectionTcpIntermediate(Connection):
|
2018-05-10 15:22:19 +03:00
|
|
|
"""
|
|
|
|
Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`.
|
|
|
|
Always sends 4 extra bytes for the packet length.
|
|
|
|
"""
|
2018-10-04 18:11:31 +03:00
|
|
|
async def connect(self, timeout=None, ssl=None):
|
|
|
|
await super().connect(timeout=timeout, ssl=ssl)
|
2018-10-04 18:34:58 +03:00
|
|
|
self._writer.write(b'\xee\xee\xee\xee')
|
|
|
|
await self._writer.drain()
|
2018-05-10 15:22:19 +03:00
|
|
|
|
2018-09-27 20:22:35 +03:00
|
|
|
def _send(self, data):
|
|
|
|
self._writer.write(struct.pack('<i', len(data)) + data)
|
2018-05-10 15:22:19 +03:00
|
|
|
|
2018-09-27 20:22:35 +03:00
|
|
|
async def _recv(self):
|
|
|
|
return await self._reader.readexactly(
|
|
|
|
struct.unpack('<i', await self._reader.readexactly(4))[0])
|