File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed
Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change 1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
1919import logging
20+ import threading
2021import time
2122
2223from .transport import *
@@ -34,6 +35,7 @@ class Connection:
3435 def __init__ (self , ipv4 : str , mode : int = 1 ):
3536 self .address = (ipv4 , 80 )
3637 self .mode = self .MODES .get (mode , TCPAbridged )
38+ self .lock = threading .Lock ()
3739 self .connection = None
3840
3941 def connect (self ):
@@ -53,7 +55,8 @@ def close(self):
5355 self .connection .close ()
5456
5557 def send (self , data : bytes ):
56- self .connection .send (data )
58+ with self .lock :
59+ self .connection .send (data )
5760
5861 def recv (self ) -> bytes or None :
5962 return self .connection .recv ()
Original file line number Diff line number Diff line change 1919import logging
2020from binascii import crc32
2121from struct import pack , unpack
22- from threading import Lock
2322
2423from .tcp import TCP
2524
@@ -30,22 +29,19 @@ class TCPFull(TCP):
3029 def __init__ (self ):
3130 super ().__init__ ()
3231 self .seq_no = None
33- self .lock = Lock ()
3432
3533 def connect (self , address : tuple ):
3634 super ().connect (address )
3735 self .seq_no = 0
3836 log .info ("Connected!" )
3937
4038 def send (self , data : bytes ):
41- with self . lock :
42- # 12 = packet_length (4), seq_no (4), crc32 (4) (at the end)
43- data = pack ("<II " , len (data ) + 12 , self . seq_no ) + data
44- data += pack ( "<I" , crc32 ( data ))
39+ # 12 = packet_length (4), seq_no (4), crc32 (4) (at the end)
40+ data = pack ( "<II" , len ( data ) + 12 , self . seq_no ) + data
41+ data + = pack ("<I " , crc32 (data ))
42+ self . seq_no += 1
4543
46- self .seq_no += 1
47-
48- super ().sendall (data )
44+ super ().sendall (data )
4945
5046 def recv (self ) -> bytes or None :
5147 length = self .recvall (4 )
You can’t perform that action at this time.
0 commit comments