Commit 0c412496 by Bach Dániel

handle disconnect

parent 6be953f1
...@@ -57,6 +57,9 @@ class SerialLineReceiver(SerialLineReceiverBase): ...@@ -57,6 +57,9 @@ class SerialLineReceiver(SerialLineReceiverBase):
return d return d
reactor.addSystemEventTrigger("before", "shutdown", shutdown) reactor.addSystemEventTrigger("before", "shutdown", shutdown)
def connectionLost(self, reason):
reactor.stop()
def connectionLost2(self, reason): def connectionLost2(self, reason):
self.send_command(command='agent_stopped', self.send_command(command='agent_stopped',
args={}) args={})
......
...@@ -7,7 +7,9 @@ Virtio-Serial Port Protocol ...@@ -7,7 +7,9 @@ Virtio-Serial Port Protocol
""" """
# system imports # system imports
import logging
import os import os
from time import sleep
# dependent on pyserial ( http://pyserial.sf.net/ ) # dependent on pyserial ( http://pyserial.sf.net/ )
# only tested w/ 1.18 (5 Dec 2002) # only tested w/ 1.18 (5 Dec 2002)
...@@ -15,6 +17,8 @@ import os ...@@ -15,6 +17,8 @@ import os
# twisted imports # twisted imports
from twisted.internet import abstract, fdesc from twisted.internet import abstract, fdesc
logger = logging.getLogger()
class SerialPort(abstract.FileDescriptor): class SerialPort(abstract.FileDescriptor):
""" """
...@@ -57,4 +61,8 @@ class SerialPort(abstract.FileDescriptor): ...@@ -57,4 +61,8 @@ class SerialPort(abstract.FileDescriptor):
""" """
abstract.FileDescriptor.connectionLost(self, reason) abstract.FileDescriptor.connectionLost(self, reason)
os.close(self._serial) os.close(self._serial)
self.protocol.connectionLost(reason) sleep(2)
self._serial = os.open(
self.port, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
self.startReading()
logger.info("Reconnecting")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment