mirror of
https://github.com/Dinnerbone/mcstatus.git
synced 2026-04-06 03:51:23 +08:00
Merge pull request #25 from totokaka/master
Raise IOError when TCPConnection.read(length) recieves no data.
This commit is contained in:
@@ -140,7 +140,10 @@ class TCPSocketConnection(Connection):
|
|||||||
def read(self, length):
|
def read(self, length):
|
||||||
result = bytearray()
|
result = bytearray()
|
||||||
while len(result) < length:
|
while len(result) < length:
|
||||||
result.extend(self.socket.recv(length - len(result)))
|
new = self.socket.recv(length - len(result))
|
||||||
|
if len(new) == 0:
|
||||||
|
raise IOError("Server did not respond with any information!")
|
||||||
|
result.extend(new)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
|||||||
@@ -225,6 +225,12 @@ class TCPSocketConnectionTest(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(self.connection.read(2), bytearray.fromhex("7FAA"))
|
self.assertEqual(self.connection.read(2), bytearray.fromhex("7FAA"))
|
||||||
|
|
||||||
|
def test_read_empty(self):
|
||||||
|
self.connection.socket.recv.return_value = bytearray.fromhex("")
|
||||||
|
|
||||||
|
with self.assertRaises(IOError):
|
||||||
|
self.connection.read(2)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
self.connection.write(bytearray.fromhex("7FAA"))
|
self.connection.write(bytearray.fromhex("7FAA"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user