Merge pull request #35 from zeroflow/connection

Implicitly close sockets in destructor methods
This commit is contained in:
Dinner Bone
2017-04-01 17:19:13 +02:00
committed by GitHub

View File

@@ -149,6 +149,9 @@ class TCPSocketConnection(Connection):
def write(self, data):
self.socket.send(data)
def __del__(self):
self.socket.close()
class UDPSocketConnection(Connection):
def __init__(self, addr, timeout=3):
@@ -175,4 +178,7 @@ class UDPSocketConnection(Connection):
def write(self, data):
if isinstance(data, Connection):
data = bytearray(data.flush())
self.socket.sendto(data, self.addr)
self.socket.sendto(data, self.addr)
def __del__(self):
self.socket.close()