mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-19 12:57:56 +00:00
Fixes issue when asyncio read is cancelled and data is still sent by Dynamips hypervisor. Fixes #113.
This commit is contained in:
parent
056ff14437
commit
ee8362d89a
@ -265,6 +265,7 @@ class DynamipsHypervisor:
|
|||||||
command = command.strip() + '\n'
|
command = command.strip() + '\n'
|
||||||
log.debug("sending {}".format(command))
|
log.debug("sending {}".format(command))
|
||||||
self._writer.write(command.encode())
|
self._writer.write(command.encode())
|
||||||
|
yield from self._writer.drain()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Lost communication with {host}:{port} :{error}, Dynamips process running: {run}"
|
raise DynamipsError("Lost communication with {host}:{port} :{error}, Dynamips process running: {run}"
|
||||||
.format(host=self._host, port=self._port, error=e, run=self.is_running()))
|
.format(host=self._host, port=self._port, error=e, run=self.is_running()))
|
||||||
@ -274,11 +275,16 @@ class DynamipsHypervisor:
|
|||||||
buf = ''
|
buf = ''
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
chunk = yield from self._reader.read(1024) # match to Dynamips' buffer size
|
try:
|
||||||
if not chunk:
|
line = yield from self._reader.readline()
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
# task has been canceled but continue to read
|
||||||
|
# any remaining data sent by the hypervisor
|
||||||
|
continue
|
||||||
|
if not line:
|
||||||
raise DynamipsError("No data returned from {host}:{port}, Dynamips process running: {run}"
|
raise DynamipsError("No data returned from {host}:{port}, Dynamips process running: {run}"
|
||||||
.format(host=self._host, port=self._port, run=self.is_running()))
|
.format(host=self._host, port=self._port, run=self.is_running()))
|
||||||
buf += chunk.decode()
|
buf += line.decode()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Lost communication with {host}:{port} :{error}, Dynamips process running: {run}"
|
raise DynamipsError("Lost communication with {host}:{port} :{error}, Dynamips process running: {run}"
|
||||||
.format(host=self._host, port=self._port, error=e, run=self.is_running()))
|
.format(host=self._host, port=self._port, error=e, run=self.is_running()))
|
||||||
|
Loading…
Reference in New Issue
Block a user