mirror of
https://github.com/Dinnerbone/mcstatus.git
synced 2026-04-06 12:01:24 +08:00
Merge pull request #35 from zeroflow/connection
Implicitly close sockets in destructor methods
This commit is contained in:
@@ -149,6 +149,9 @@ class TCPSocketConnection(Connection):
|
|||||||
def write(self, data):
|
def write(self, data):
|
||||||
self.socket.send(data)
|
self.socket.send(data)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.socket.close()
|
||||||
|
|
||||||
|
|
||||||
class UDPSocketConnection(Connection):
|
class UDPSocketConnection(Connection):
|
||||||
def __init__(self, addr, timeout=3):
|
def __init__(self, addr, timeout=3):
|
||||||
@@ -175,4 +178,7 @@ class UDPSocketConnection(Connection):
|
|||||||
def write(self, data):
|
def write(self, data):
|
||||||
if isinstance(data, Connection):
|
if isinstance(data, Connection):
|
||||||
data = bytearray(data.flush())
|
data = bytearray(data.flush())
|
||||||
self.socket.sendto(data, self.addr)
|
self.socket.sendto(data, self.addr)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.socket.close()
|
||||||
Reference in New Issue
Block a user