Merge branch 'asyncio-protocol-attempt' into asyncio-protocol-patch

This commit is contained in:
Jahongir Qurbonov 2024-10-22 11:35:47 +05:00 committed by GitHub
commit 9a9fcf8b80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,11 +10,11 @@ from typing import Generic, Optional, Protocol, Type, TypeVar
from typing_extensions import Self
from .protocol import BufferedTransportProtocol
from ..crypto import AuthKey
from ..mtproto import (
BadMessageError,
Encrypted,
MissingBytesError,
MsgId,
Mtp,
Plain,
@ -32,7 +32,6 @@ from ..tl.types import UpdateDeleteMessages, UpdateShort
from ..tl.types.messages import AffectedFoundMessages, AffectedHistory, AffectedMessages
from .protocol import BufferedStreamingProtocol
MAXIMUM_DATA = (1024 * 1024) + (8 * 1024)
PING_DELAY = 60
@ -124,6 +123,7 @@ class Sender:
_reader: StreamReader
_writer: StreamWriter
_transport: Transport
_protocol: BufferedTransportProtocol
_mtp: Mtp
_mtp_buffer: bytearray
_updates: list[Updates]
@ -146,16 +146,19 @@ class Sender:
base_logger: logging.Logger,
) -> Self:
ip, port = addr.split(":")
reader, writer = await connector(ip, int(port))
# TODO BRING BACK SUPPORT FOR connector
connection, protocol = await asyncio.get_running_loop().create_connection(
lambda: BufferedTransportProtocol(transport), ip, int(port)
)
sender = cls(
dc_id=dc_id,
addr=addr,
lock=Lock(),
_logger=base_logger.getChild("mtsender"),
_reader=reader,
_writer=writer,
_connection=connection,
_transport=transport,
_protocol=protocol,
_mtp=mtp,
_mtp_buffer=bytearray(),
_updates=[],
@ -224,6 +227,7 @@ class Sender:
self._try_fill_write()
await self._wait_response()
def _try_fill_write(self) -> None:
for request in self._requests:
if isinstance(request.state, NotSerialized):