'Closes the current Telnet connection.
Remaining output in the connection is read, logged, and returned.
It is not an error to close an already closed connection.
Use `Close All Connections` if you want to make sure all opened
connections are closed.
See `Logging` section for more information about log levels.'

def close_connection(self, loglevel=None):

    if self.sock:
        self.sock.shutdown(socket.SHUT_RDWR)
    self.close()
    output = self._decode(self.read_all())
    self._log(output, loglevel)
    return output
