mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Add timeout parameter on TcpClient.connect() too
This commit is contained in:
		
							parent
							
								
									e4fbd87c75
								
							
						
					
					
						commit
						843c16215c
					
				| 
						 | 
					@ -30,9 +30,12 @@ class TcpClient:
 | 
				
			||||||
            else:  # tuple, list, etc.
 | 
					            else:  # tuple, list, etc.
 | 
				
			||||||
                self._socket.set_proxy(*self._proxy)
 | 
					                self._socket.set_proxy(*self._proxy)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def connect(self, ip, port):
 | 
					    def connect(self, ip, port, timeout):
 | 
				
			||||||
        """Connects to the specified IP and port number"""
 | 
					        """Connects to the specified IP and port number.
 | 
				
			||||||
 | 
					           'timeout' must be given in seconds
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
        if not self.connected:
 | 
					        if not self.connected:
 | 
				
			||||||
 | 
					            self._socket.settimeout(timeout)
 | 
				
			||||||
            self._socket.connect((ip, port))
 | 
					            self._socket.connect((ip, port))
 | 
				
			||||||
            self._socket.setblocking(False)
 | 
					            self._socket.setblocking(False)
 | 
				
			||||||
            self.connected = True
 | 
					            self.connected = True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,8 @@ class TcpTransport:
 | 
				
			||||||
    def connect(self):
 | 
					    def connect(self):
 | 
				
			||||||
        """Connects to the specified IP address and port"""
 | 
					        """Connects to the specified IP address and port"""
 | 
				
			||||||
        self.send_counter = 0
 | 
					        self.send_counter = 0
 | 
				
			||||||
        self.tcp_client.connect(self.ip, self.port)
 | 
					        self.tcp_client.connect(self.ip, self.port,
 | 
				
			||||||
 | 
					                                timeout=round(self.timeout.seconds))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def is_connected(self):
 | 
					    def is_connected(self):
 | 
				
			||||||
        return self.tcp_client.connected
 | 
					        return self.tcp_client.connected
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user