Correclty cleanup packet capture objects when closing server

Fix #592
This commit is contained in:
Julien Duponchelle committed 2016-08-19 11:05:54 +02:00
1 parent 8eab94f01e
commit f0fad5289c
5 files changed
+30 -13

No files matched your search

+12 -11
View File
@@ -116,17 +116,18 @@ class Link:
Dump a pcap file on disk
"""
stream = yield from self.read_pcap_from_source()
with open(self.capture_file_path, "wb+") as f:
while self._capturing:
# We read 1 bytes by 1 otherwise the remaining data is not read if the traffic stops
data = yield from stream.read(1)
if data:
f.write(data)
# Flush to disk otherwise the live is not really live
f.flush()
else:
break
stream_content = yield from self.read_pcap_from_source()
with stream_content as stream:
with open(self.capture_file_path, "wb+") as f:
while self._capturing:
# We read 1 bytes by 1 otherwise the remaining data is not read if the traffic stops
data = yield from stream.read(1)
if data:
f.write(data)
# Flush to disk otherwise the live is not really live
f.flush()
else:
break
@asyncio.coroutine
def stop_capture(self):