def handle_disconnect(self):
        """Socket gets disconnected"""
        # signal disconnected terminal with control lines
        try:
            self.serial.rts = False
            self.serial.dtr = False
        finally:
            # restore original port configuration in case it was changed
            self.serial.apply_settings(self.serial_settings_backup)
            # stop RFC 2217 state machine
            self.rfc2217 = None
            # clear send buffer
            self.buffer_ser2net = bytearray()
            # close network connection
            if self.socket is not None:
                self.socket.close()
                self.socket = None
                if self.log is not None:
                    self.log.warning('%s: Disconnected' % self.device)
dataset/ETHPy150Open pyserial/pyserial/examples/port_publisher.py/Forwarder.handle_disconnect/original