mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-24 07:51:44 +00:00
Don't raise write() and close() exceptions
This commit is contained in:
parent
7e5d593544
commit
9ee1807e42
@ -93,19 +93,13 @@ class TCP:
|
|||||||
await self.send_task
|
await self.send_task
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if self.writer is not None:
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
except AttributeError:
|
await asyncio.wait_for(self.writer.wait_closed(), TCP.TIMEOUT)
|
||||||
try:
|
except Exception as e:
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
log.info("Close exception: %s %s", type(e).__name__, e)
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
# A tiny sleep placed here helps avoiding .recv(n) hanging until the timeout.
|
|
||||||
# This is a workaround that seems to fix the occasional delayed stop of a client.
|
|
||||||
time.sleep(0.001)
|
|
||||||
self.socket.close()
|
|
||||||
|
|
||||||
async def send(self, data: Optional[bytes]):
|
async def send(self, data: bytes):
|
||||||
await self.send_queue.put(data)
|
await self.send_queue.put(data)
|
||||||
|
|
||||||
async def send_worker(self):
|
async def send_worker(self):
|
||||||
@ -115,8 +109,11 @@ class TCP:
|
|||||||
if data is None:
|
if data is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
self.writer.write(data)
|
self.writer.write(data)
|
||||||
await self.writer.drain()
|
await self.writer.drain()
|
||||||
|
except Exception as e:
|
||||||
|
log.info("Send exception: %s %s", type(e).__name__, e)
|
||||||
|
|
||||||
async def recv(self, length: int = 0):
|
async def recv(self, length: int = 0):
|
||||||
data = b""
|
data = b""
|
||||||
|
Loading…
Reference in New Issue
Block a user